Repository navigation
fix: Carry the correlation context into the derivation kernel - #5073
Conversation
`DaemonConverger` submits `converge_derivations` and `_converge_selected_session_parts_sync` into the bounded compute pool, whose `ThreadPoolExecutor` is built eagerly in `BoundedComputeAdapter.__init__` -- before any correlation bind -- and which does not copy contextvars. Every `daemon.derivation.*` event therefore lost its `run_id`, the single most useful correlation during a multi-hour rebuild. `propagate` was typed `Callable[..., object] -> Callable[..., object]`, which erased the result type of both `asyncio.shield` calls at these sites. Under that signature the cheapest way to satisfy the typechecker is to drop the wrapper rather than cast -- and dropping it loses the correlation silently. Make `propagate` generic in both directions so wrapping is type-transparent. `ParamSpec`/`TypeVar` rather than PEP 695 syntax because mypy is configured at `python_version = "3.11"`, though the devshell requires 3.14 free-threading. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reachedNext included review available in 44 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Three `cast(...)` wrappers existed only to absorb `propagate`'s old `Callable[..., object]` signature. #5073 made it generic, so all three are dead. Removing them is not tidying. A `cast` sitting on a `propagate` call is the visible residue of an annotation that made correct use cost more than incorrect use: the next reader who hits a red mypy on a wrapped submit finds the established workaround right there, and the cheaper move beside it is still to drop the wrapper — which loses the correlation id silently. Deleting the casts deletes the precedent. The third, in `http.py`, was added during this branch's own conflict resolution, by someone who had just been warned about exactly this pressure. That is how quiet the failure mode is. `cast` is no longer imported in `operation_runtime.py`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
## Summary Two tests grepped for prose sentences that the structured-logging wave deleted. Both now assert the stable **event token** and its declared fields. ## Which merged PR moved the ground PRs #5072 (`5eb270707`, "Convert the remaining daemon modules to structured events") and #5073 (`ab850e0b7`, "Carry the correlation context into the derivation kernel") retired prose logging in these modules. `polylogue/logging.py:400` `emit()` writes structured records to its own sinks and never touches stdlib logging, so `caplog.text` is empty by construction -- these were failing on an assertion that can no longer be true, not on behaviour. - `daemon/convergence_stages.py:308` now emits `daemon.stage.check_failed` (`reason="probe_failed_assuming_work"`), and the execute path reports through `span.degraded("materialization_failed")`, whose terminal event is `daemon.stage.execute.degraded`. - `daemon/lifecycle.py:287` now emits `daemon.lifecycle.signal_received` (`signal_name=SIGTERM`). CLAUDE.md is explicit: "Do not enforce natural-language wording". ## Solution - `test_convergence_stage_reports_probe_and_materialization_failures_as_pending_work`: drop `caplog`, use `polylogue.logging.capture()`, and assert the exact `(stage, outcome, reason, error_type)` tuple for each of the two events. - `test_sigterm_read_only_daemon_records_forensics` reads the daemon subprocess's own stream, which may render console or JSON. It now selects the line carrying `daemon.lifecycle.signal_received` and asserts it names `SIGTERM`. The `"Current thread"` faulthandler assertion is unchanged. Both assertions are on tokens and fields, which are the storage form; the human sentence was always a rendering concern. ## Verification ``` devtools test tests/unit/insights/test_delegation_work_evidence_materializer.py (receipt 20260914T163857Z-focused-test-3135387-125edb44) -> green devtools test tests/integration/test_daemon_resilience.py (receipt 20260914T165038Z-focused-test-3220954-2ff3e795) -> 7 passed / 7 collected, including test_sigterm_read_only_daemon_records_forensics devtools verify --quick -> exit 0, 15/15 gates ``` ## Anti-vacuity | Test | Mutation that makes it red | |---|---| | convergence stage, probe half | make `check`'s `except` return False, or drop the `emit` | | convergence stage, execute half | swallow the materialization exception into a success; the `degraded`/`materialization_failed` terminal event disappears | | SIGTERM forensics | drop the `emit` from `install_signal_handlers` (no line carries the token), or drop `faulthandler.dump_traceback` (no stack dump) | ## Residuals Test-only change. The integration test still depends on the daemon's configured renderer emitting the token in either format; it does not pin which format, deliberately. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Summary
daemon.derivation.*events lost theirrun_idon exactly the rebuild path they exist to make legible.Problem
DaemonConvergersubmitsconverge_derivationsand_converge_selected_session_parts_syncinto the bounded compute pool.BoundedComputeAdapter.__init__builds thatThreadPoolExecutoreagerly — before any correlation bind — andThreadPoolExecutor.submitdoes not copy contextvars. So every derivation event emitted from a pool thread carried norun_id, which is the single most useful correlation during a multi-hour rebuild: it is what lets you join a degraded derivation back to the run that produced it.Found and reported by the daemon conversion worker, in a file it was scoped out of, with the note that no test would go red for it.
Solution
Wrap both submits in
propagate().propagatewas typedCallable[..., object] -> Callable[..., object], which erased the result type of bothasyncio.shieldcalls at these sites. Under that signature the cheapest way to satisfy the typechecker is to drop the wrapper rather than cast — and dropping it loses the correlation silently, which is how this class of defect reproduces itself. Sopropagateis now generic in both directions and wrapping is type-transparent.ParamSpec/TypeVarrather than PEP 695 syntax, because mypy is configured atpython_version = "3.11"while the devshell requires 3.14 free-threading.Verification
The static half — that a wrapped
submitkeeps its result type — cannot be asserted at runtime, becauseParamSpecerases to*args/**kwargsin the actual signature. An earlier version of the test assertedinspect.signatureequality and was wrong; it failed, and the honest correction was to narrow the test rather than weaken the claim.devtools gate mypyis what enforces the static property: restoring the old signature fails typechecking on bothasyncio.shieldcalls. The test now asserts only what is runtime-observable, and says so.🤖 Generated with Claude Code
https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK