Skip to content

refactor(daemon): Convert the remaining daemon modules to structured events - #5072

Merged
Sinity merged 11 commits into
masterfrom
work/log-daemon-rest
Sep 14, 2026
Merged

Sinity merged 11 commits into
masterfrom
work/log-daemon-rest

Conversation

@Sinity

@Sinity Sinity commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

All 34 remaining daemon modules converted to structured events. Zero legacy loggers remain anywhere in polylogue/daemon/ outside cli.py/http.py, which landed separately in #5067. Ratchet baseline 23 → 20 — exactly the three eliminated.

Largest: judgment_automation 23 sites, convergence_stages 17, metrics 12, status 11, embedding_backlog 11, write_coordinator 10, derivation 8. A dead logger in backup.py was removed outright.

What this makes legible

INFO  daemon.stage.executed duration_ms=0.0 outcome=ok path=claude-code/a.jsonl stage=acquire
WARNI daemon.stage.execute.degraded attempts=44 calls=40 gaps=2 outcome=degraded
      path=claude-code/a.jsonl reason=unresolved_workflow_gaps runs=12 stage=claude_workflow
WARNI daemon.stage.drained action=batch attempted=3 confirmed=1 debt=1 failed=2 outcome=degraded
      payload_failures=0 reason=transport_failures rejected=0 remaining=2 transport_failures=2

The old code logged gaps=2 inside 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.py carries make_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 assumed

BoundedComputeAdapter.__init__ builds the ThreadPoolExecutor eagerly and _run_task submits a bare closure. Measured with the pool pre-warmed: bare submit → {}, wrapped → {'run_id': 'rebuild01'}. Added at both operation_runtime.py submit sites.

Fields

46 new, all count/token/identifier/duration/flag; three registered but never emitted were dropped. error_detail remains the only text-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

devtools test tests/unit/daemon   ->  PASSED 2233/2233, exit 0 (429s)
devtools verify --quick           ->  exit 0, all 15 gates
devtools gate layering            ->  exit 0
devtools gate patterns            ->  passed, 20 matches, 0 prunable
devtools render all --check       ->  exit 0, "out of sync" -> 0

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 caplog or 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 report degraded with cohorts pending and the second ok, a distinction a single INFO line could not express.

Landing order

polylogue/daemon/write_coordinator.py and polylogue/logging_fields.py are IN the derived-schema closure; the other 35 changed files are out. 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 133 SchemaSkewError failures because the seeded-artifact cache keys on derived_schema_identity.

Note write_coordinator.py now 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

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 98464b9b-11d3-4b1d-b394-db45cf0563e3

📥 Commits

Reviewing files that changed from the base of the PR and between ab850e0 and c8bb4bf.

📒 Files selected for processing (44)
  • devtools/patterns/baselines/sqlite-error-default.txt
  • docs/structured-logging.md
  • polylogue/daemon/api_auth.py
  • polylogue/daemon/backup.py
  • polylogue/daemon/blob_gc_periodic.py
  • polylogue/daemon/catchup_status.py
  • polylogue/daemon/convergence_debt_status.py
  • polylogue/daemon/convergence_stages.py
  • polylogue/daemon/convergence_standing_queries.py
  • polylogue/daemon/cursor_lag_baseline.py
  • polylogue/daemon/cursor_lag_status.py
  • polylogue/daemon/derivation.py
  • polylogue/daemon/embedding_backlog.py
  • polylogue/daemon/embedding_readiness.py
  • polylogue/daemon/event_bus.py
  • polylogue/daemon/fts_automerge.py
  • polylogue/daemon/fts_status.py
  • polylogue/daemon/health.py
  • polylogue/daemon/healthz.py
  • polylogue/daemon/http.py
  • polylogue/daemon/intake.py
  • polylogue/daemon/judgment_automation.py
  • polylogue/daemon/lifecycle.py
  • polylogue/daemon/lineage_startup.py
  • polylogue/daemon/metrics.py
  • polylogue/daemon/notification_backends/apprise_backend.py
  • polylogue/daemon/notification_backends/email.py
  • polylogue/daemon/notification_backends/journald.py
  • polylogue/daemon/notification_backends/webhook.py
  • polylogue/daemon/notifications.py
  • polylogue/daemon/operation_runtime.py
  • polylogue/daemon/provenance.py
  • polylogue/daemon/secret_scan_sweep.py
  • polylogue/daemon/status.py
  • polylogue/daemon/supervisor.py
  • polylogue/daemon/webui.py
  • polylogue/daemon/whale_outbox.py
  • polylogue/daemon/write_coordinator.py
  • polylogue/logging_fields.py
  • tests/unit/daemon/test_convergence_stages.py
  • tests/unit/daemon/test_daemon_status.py
  • tests/unit/daemon/test_embedding_readiness.py
  • tests/unit/daemon/test_judgment_automation.py
  • tests/unit/daemon/test_write_coordinator.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sinity and others added 11 commits September 14, 2026 14:03
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
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
@Sinity
Sinity force-pushed the work/log-daemon-rest branch from 3b342d7 to c8bb4bf Compare September 14, 2026 12:07
@Sinity
Sinity merged commit 5eb2707 into master Sep 14, 2026
3 checks passed
@Sinity
Sinity deleted the work/log-daemon-rest branch September 14, 2026 12:14
Sinity added a commit that referenced this pull request Sep 14, 2026
## 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]>
Sinity added a commit that referenced this pull request Sep 14, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant