Commit 1ed7618
authored
fix(runner): make RunnerContext.get_env() read live from os.environ (#885)
## Summary
This is a followup PR to ensure that
#726 data is pushed to
Langfuse for product instrumentation
- **Fix stale environment snapshot in `RunnerContext`**: `get_env()` was
reading from a frozen dict captured once at construction. Runtime
mutations to `os.environ` (by `POST /workflow`, `POST /repos/add`, auth
refresh) were invisible to any code using `context.get_env()`.
- **Root cause**: `__post_init__` merged `os.environ` into
`self.environment` and `get_env()` read only from that dict. The context
is never recreated — `mark_dirty()` resets the bridge but reuses the
same stale context.
- **Fix**: Store explicit constructor overrides in `_overrides`.
`get_env()` now checks overrides first, then falls through to live
`os.environ`. `self.environment` remains populated for backward
compatibility.
## Changes
| File | Change |
|------|--------|
| `ambient_runner/platform/context.py` | Store `_overrides` in
`__post_init__`; `get_env()` reads live from `os.environ` with overrides
winning |
| `tests/test_context.py` | Regression tests: runtime mutation
visibility + override precedence |
## Test plan
- [x] New `test_get_env_sees_os_environ_mutations_after_creation` —
creates context, mutates `os.environ` after, asserts `get_env()` returns
mutated value
- [x] New `test_explicit_overrides_win_over_os_environ` — constructor
overrides take precedence even after `os.environ` mutation
- [x] All 73 existing tests pass without modification (test_context,
test_bridge_claude, test_observability)
- [ ] CI green
Made with [Cursor](https://cursor.com)
Co-authored-by: bgregor <348865+bobbravo2@users.noreply.github.com>1 parent f4c5cb5 commit 1ed7618
2 files changed
Lines changed: 49 additions & 3 deletions
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments