Repository navigation
refactor(daemon): Convert the remaining daemon modules to structured events - #5072
Conversation
|
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 32 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 (44)
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 |
The stage list driving a from-scratch rebuild reported its work as prose, so a reader of a multi-hour rebuild log could not tell a degraded stage from a clean one. Every stage check and execute now emits a dotted event with an explicit outcome, and the Sinex drain keeps transport failures, payload failures and durable debt as separate counted lanes instead of collapsing them into one sentence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Periodic blob GC, embedding backlog/orphan reconcile and the secret-scan sweep now run inside spans, so a pass that was deferred by policy or cut short by per-item errors is distinguishable from one that found nothing. The read-only status probes report their fallback as an explicit degraded outcome instead of an interpolated warning. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
The derivation kernel now names the phase that failed (quiet, compute, publish, reinspect, inspect, discover) on its own field rather than in a sentence, so a rebuild reader can count failures per phase and per domain. The writer gate emits one release event whose level follows its hold budget, instead of an INFO line next to a separate WARNING. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Judgment automation, intake, the service supervisor, the event bus, lifecycle, health, notifications and their backends, the web UI panels and the whale outbox now emit dotted events with explicit outcomes. Refusals (a terminal intake item, a rate-limited email batch, an unsafely-owned outbox record) say refused rather than warning in prose. The Apprise URL that a failed add() used to interpolate is deliberately not a field: those URLs routinely embed a token. Its position is logged instead. Correlation is propagated into the bounded compute pool at the two operation-runtime submit sites; the pool predates every bind and does not carry context on its own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
event_bus, intake and supervisor were the only daemon modules the rule matched (it matches logger acquisition, not each call site), so the baseline drops from 23 entries to 20. The gate was already failing before this branch: #5056 added an unbaselined logging.getLogger in sources/retained_acquisition.py. Fixed forward by converting that one site rather than growing the ratchet. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
emit()'s second positional parameter is the level, so splatting a dict[str, object] of fields could not type-check. The drain names its fields explicitly and passes the level positionally, which also lets the per-path scope stay the only one carrying a path field. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
marker_id, reclaimed and interval_ms were registered while converting and then not used. An allowlist entry is a review point; keep only the names something actually emits. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
The module count and the baseline figure were both written against the state at the reference conversion. State the current numbers and which modules the prune covered. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Seven tests pinned the old sentences through caplog or subprocess stderr. Each now asserts on the event name plus the fields that carry the meaning, which is strictly stronger: the raw-authority-cache test can now require that the first pass reported degraded with cohorts still pending and the second reported ok, a distinction the single INFO line could not express. Each names its anti-vacuity condition: delete the emit and it goes red. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
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
3b342d7 to
c8bb4bf
Compare
## Summary The logging conversion changed files every atlas sheet cites, so `devtools gate atlas` went from 0 back to **53 BLOCKs**. All five affected sheets were re-read against the code at head. **53 → 0.** Docs only; no code touched. ## Why this needed reading rather than re-stamping The expected answer was that a logging conversion changes how a module *reports*, not what it *does* — so most prose should hold and need only an anchor fix. That expectation was mostly right and would have been the wrong thing to trust, because it is not uniformly right. `storage/blob_gc.py` and `daemon/convergence.py` changed real behaviour, and one section was found to overclaim as a direct result. `#5072` landed mid-task and was caught on a re-fetch before stamping, so `daemon.md` and `00-core.md` were re-verified **twice** — the second pass against `write_coordinator.py`, `convergence_stages.py`, `derivation.py`, `fts_status.py` and `intake.py` as they now stand. Nothing was deleted. `mcp.md`'s twelve-tool inventory and per-capability gates were checked by **executing** `declared_tool_names` at each capability combination rather than by reading it. ## The finding worth having **Six blob-GC refusals still emit nothing, and one of them reports deletions that did happen.** `storage/blob_gc.py::_execute_gc_generation_members` sets `report.blocked_reason` and returns at lines **752, 757, 781, 786, 801, 886** with no `_emit_gc_refusal` call. The conversion collapsed twelve refusal lines into `storage.blob_gc.refused` precisely so a refusal cannot be read as a clean pass — but these six were never logged before either, so the conversion never touched them, and the hazard survives inside the locked execution window. Line 801 is the sharp one: a per-member protection blocker during the final locked recheck does ```python report.blocked_reason = "; ".join(protection.blockers) return deleted_now, reclaimed_bytes_now ``` so an aborted unlink pass emits **nothing** and returns a **nonzero** deletion count. Pre-existing, not introduced by the conversion. `storage.md` now documents the exception rather than leaving the sheet overclaiming, and it is filed separately. ## Other disagreements recorded - **`polylogue-4u79w` was narrowed, not closed, and the manual now contradicts itself inside one document.** `agent_integration/spec.py:499-517` was corrected to the three live operations, matching the handler — but the hand-written prose rendered into the *same* manual still calls `maintenance` "Preview/status/reconcile and administrative execution" and prescribes `operation="preview"` with a dry-run mode, which the `Literal` rejects. - **`polylogue-nysan` unchanged at head** — `render_agent_manual.py:125`, `agent_integration/spec.py:5` and `tests/infra/mcp.py:20` still say "ten-tool" against a declaration-derived twelve. - **A doc defect the gate cannot catch**: two `tests/infra/mcp.py` anchors were off by two lines. The gate only checks that a cited line *exists*, not that it says what the prose claims. ## Verification ``` devtools gate atlas (baseline) -> exit 1, 53 BLOCKs devtools gate atlas (post-rebase onto #5072) -> exit 1, 9 BLOCKs devtools gate atlas (final) -> exit 0, "citations and verification stamps are current" devtools verify --quick -> exit 0, all 15 gates ``` Exit statuses read from `$?` on the command itself; gate output was redirected to a file rather than piped, since a pipe reports the pipe's status. 🤖 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 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
All 34 remaining daemon modules converted to structured events. Zero legacy loggers remain anywhere in
polylogue/daemon/outsidecli.py/http.py, which landed separately in #5067. Ratchet baseline 23 → 20 — exactly the three eliminated.Largest:
judgment_automation23 sites,convergence_stages17,metrics12,status11,embedding_backlog11,write_coordinator10,derivation8. A dead logger inbackup.pywas removed outright.What this makes legible
The old code logged
gaps=2inside an INFO sentence — a degraded stage reported at the same level as a healthy one. And prose collapsed transport failures, payload failures and rejections into a single line; they now have separate counted lanes with a reason naming the dominant one.convergence_stages.pycarriesmake_default_convergence_stages, the stage list that drives the entire from-scratch rebuild, so this is the module that decides whether a multi-hour build's degradation is visible without reading source.propagate()— verified, not assumedBoundedComputeAdapter.__init__builds theThreadPoolExecutoreagerly and_run_tasksubmits a bare closure. Measured with the pool pre-warmed: bare submit →{}, wrapped →{'run_id': 'rebuild01'}. Added at bothoperation_runtime.pysubmit sites.Fields
46 new, all count/token/identifier/duration/flag; three registered but never emitted were dropped.
error_detailremains the onlytext-kind field, asserted by its pinning test.One deliberate omission: a failed Apprise
add()used to interpolate the notification URL with%r, and those URLs embed tokens. The position is logged instead of the URL.Verification
The tip was checked before and after that run (
3b342d756, clean both times), because a green belonging to a different tree than the one reported has already bitten this campaign twice today in both directions. The count is 2233 rather than an earlier 2230 because the rebase brought three more daemon tests in with #5063/#5064 — both numbers are real measurements of different trees.Seven tests pinned the old prose through
caplogor subprocess stderr; each now asserts on the event and its fields and names its anti-vacuity condition. The raw-authority-cache test is strictly stronger than before: it now requires the first pass to reportdegradedwith cohorts pending and the secondok, a distinction a single INFO line could not express.Landing order
polylogue/daemon/write_coordinator.pyandpolylogue/logging_fields.pyare IN the derived-schema closure; the other 35 changed files areout. The index identity moves, ops does not. This must land before a from-scratch rebuild starts, never during one — encountered for real during development, where editing mid-run produced 133SchemaSkewErrorfailures because the seeded-artifact cache keys onderived_schema_identity.Note
write_coordinator.pynow carries both #5062's lease-delegation imports and this change's event imports, so both feed the index identity. The interim identity hashes measured during development are superseded by each rebase; only the finally-landed identity is worth recording.🤖 Generated with Claude Code
https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK