Skip to content

fix(daemon): Close eight live P1 findings in the daemon surface - #5414

Merged
Sinity merged 8 commits into
masterfrom
fix/p1-review-daemon
Sep 22, 2026
Merged

Sinity merged 8 commits into
masterfrom
fix/p1-review-daemon

Conversation

@Sinity

@Sinity Sinity commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Summary

Eight live P1 review findings closed in polylogue/daemon/, from a triage of all 38 anchored daemon findings.

24 STALE (63%), 8 LIVE-and-fixed, 3 declined with measurements, 2 superseded, 6 exact duplicates.

What the stale rate says about the filter

63% is the highest of any lane — storage measured 34%, devtools 57%. The cause is specific and worth recording:

Ten rows (F04, F16–F21, F23–F25, F29) were invalidated at once by the wholesale replacement of the raw-materialization frontier machinery with the raw-observation derivation — without touching their anchored lines.

With six exact duplicates, a 38-row brief was really ~22 distinct questions, ten of which one refactor had already answered. The filter asks "did this line move?" when the real question is "does this code still exist?"

Fixed

The event ledger's cursor completeness proof was unsound. Age retention deleted WHERE ts_ms < horizon, while _cursor_refusal_reason infers completeness from MIN(id) alone. Timestamps are caller-supplied (observed_at_ms, wall-clock step), so a legitimately out-of-order interior row is removed and a subscriber below the hole gets an OK page silently missing it. Retention now deletes the id prefix below the first row the horizon retains.

Mutation: assert ['third'] == ['out-of-order', 'third'], with test_expired_prefix_is_removed staying green to pin the opposite direction.

The same file took two read snapshots per page. open_readonly_connection leaves the connection in autocommit and ops.db is WAL, so _retained_range and the page SELECT could straddle a prune — delivering a short page with status OK. Now one BEGIN/rollback read transaction. Mutation: assert ['c'] == ['a', 'b', 'c'].

Half of all published status snapshots served unknown-readiness defaults. Measured over the production StatusComponentRegistry at the real 10.5 s cadence against the default 10 s ttl_s: fresh, stale, fresh, stale — each stale snapshot carrying a perfectly good previous value, while build_daemon_status listed stale among the unmeasured states. Replaced with _component_is_unmeasured, which keeps a stale value only while the fingerprint it was collected under still holds, so the original concern (a changed or absent fingerprint must stay unmeasured) is preserved exactly.

Two non-interactive classes could jointly take the interactive reserve. With max_workers=8, queue_units=16, control and incremental-background each have ceiling_slots=4; four blocking tasks in each filled all 8 workers while both stayed inside their own bound, and a subsequent interactive read never started. The queue half left 1 of 24 units against an interactive reserve of 9. Admission and dispatch now check the complement.

A whale could never be selected. RawObservationDerivation.compute budgets sum(sizes.values()) over the expanded membership, but RawMaterializationDiscovery._with_costs reports each seed row's own blob_size — and the whale predicate compared the latter. A component whose members are each inside the ordinary limit but whose total is not failed every ordinary admission and was never escalated. Selection now measures the expanded component.

A cancel reported the operation it had just cancelled as unknown. Cancelling a queued mutation.session.delete.preview returned {'code': 'operation_reference_unknown', 'retryable': False}, because the scheduler settles the future synchronously and settled removes the exchange in the same call. control() now answers cancelled with effect: no-effect.

A non-exact watch baseline produced a definitive false delta. A pre-guard user.db baseline with exactness='capped' made same_snapshot False, advanced the baseline, and compared an exact merkle root against a partial one — emitting a definitive query-delta. A non-exact stored baseline is now unmeasured.

/w/compare stringified its envelope. Measured: 20,205 bytes of HTML and 480 copies of the message-text fragment for 12 short messages, as escaped Python reprs. Same fixture now 6,092 bytes, 0 reprs.

Declined, with the measurement

  • Staged-task shutdown race (F33). Measured directly: future.cancel() returns True and future.done() is True immediately, while the coroutine's finally cleanup has not run — so shutdown() returns while a staged ingest is still unwinding. Declined: every correct remedy changes production shutdown sequencing, and no deterministic anti-vacuity test for "the compute owner was closed while cleanup was pending" was achievable without new harness machinery. Shipping an unproven change to shutdown is worse than the current bounded-but-real gap.
  • Whale quiescence gate (F26). Confirmed the docstring claimed a drain that nothing enforces; the only real check is the head of the bounded discovery page. The docstring is corrected to state what is actually enforced and names the FairIntakeDispatcher/DaemonIntakeService signal a true gate needs — the gate itself lives in operations/intake_adapters.py, outside this scope.
  • Duplicate machine ingest (F12). Verified live: the archive inbox is still a default watch source, and deterministic_raw_session_id hashes source_path, so the ingest operation (caller's path) and the watcher (staged path) mint two raw_ids for identical bytes. Both remedy sites are in cli/ and sources/live/watcher.py. This is an ownership decision — which route owns machine imports — not a daemon-local fix.
  • FTS trigger restoration (F30/F31) — marked superseded, not stale. Trigger presence is owned by canonical schema construction; the reviewer's remedy would re-merge a partition drawn deliberately, as storage_correctness_scenario.py states in its own comment.

Verification

Rebased onto master 1f996e133.

  • devtools verify --quick → exit 0, 25/25 gates green. (At the lane's base this was 21/22 with the then-inherited gate atlas red, byte-identical at base and branch; fix(storage): Close seventeen live P1 review findings in the storage tier #5408 has since fixed it.)
  • devtools render all --check → exit 0, grep -c 'out of sync' = 0.
  • Two focused batches covering every changed file plus the pre-existing fairness, standing-query and daemon-status suites → both PASSED, exit 0.
  • Inherited-red baselines, three separate selections detached at base: 2 of 46, 7 of 107, and 7 of 24 — the same nodeids on the branch in every case. Attributed to base, not absorbed.

Schema closure

All eight changed production files report out — independently re-confirmed after rebase. The derived schema identity does not move and no reconvergence is implied by this PR.

Anti-vacuity

Seven mutations executed, each restored, each with its opposite direction pinned. Notably, three first-draft tests were refuted by their own mutations and rebuilt: one self-referential, one that varied with message count (which both implementations grow with), and one where a probing collect consumed the stale tick, leaving the build finalising a settled attempt as fresh.

The whale test deserves note: the fixture is two revisions of one source path, each under the limit and together over it — because a seed that alone exceeds the limit is selected by both predicates and could not separate them.

Residuals

  • storage/raw_authority.py:606 carries a docstring cross-reference to auto_resolve_stale_plan_blockers, a function that no longer exists anywhere. Cosmetic, outside this scope.
  • The whale still holds RawObservationConvergenceOwner._converge_lock for its duration.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

Sinity and others added 8 commits September 22, 2026 12:09
A resuming subscriber's completeness is inferred from MIN(id) alone, but
two routes could break that inference and deliver a short OK page instead
of the AGED_OUT refusal the gap is supposed to raise:

- age retention deleted by ts_ms, which is not monotonic in id
  (observed_at_ms is caller-supplied and the wall clock can step back), so
  an interior row could be removed while an older id survived;
- query_events_since read the retained range and the page in autocommit, so
  a writer pruning between the two statements was observed by the second
  read but not the first.

Age retention now removes the id prefix below the first row the horizon
retains, and the range check and page query share one read transaction.

Verification: devtools test tests/unit/daemon/test_event_cursor.py
tests/unit/daemon/test_daemon_events_endpoint.py
tests/unit/daemon/test_events_sse_framing.py
tests/unit/daemon/test_event_bus.py -> PASSED exit=0.
Anti-vacuity executed: restoring the ts_ms predicate makes
test_out_of_order_row_survives_age_prune and
test_cursor_page_keeps_every_event red (assert 1 == 0; assert ['third'] ==
['out-of-order', 'third']); dropping the BEGIN/rollback pair makes
test_prune_between_range_and_page_unseen red (assert ['c'] == ['a','b','c']).
Derived schema closure: polylogue/daemon/events.py is OUT; identity unmoved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
The guard that stopped persisting capped/sampled/estimated evaluations as a
watch baseline only prevented new ones. A user.db written before it can still
carry a baseline whose own exactness is not 'exact', and the first exact
evaluation after upgrading compared its full merkle root against that partial
root -- emitting a definitive query-delta for a membership change nobody ever
observed, which is the same false claim the guard exists to prevent.

A non-exact stored baseline is now unmeasured rather than a prior observation:
the first exact evaluation replaces it silently and claims no delta against
it, and a non-exact tick facing one records only its degraded receipt because
there was never a measured membership to drift from.

Verification: devtools test tests/unit/daemon/test_standing_queries.py
tests/unit/daemon/test_standing_queries_default_evaluator.py
tests/unit/daemon/test_maintenance_read_profiles.py -> PASSED exit=0.
Anti-vacuity executed: restoring the unguarded `baseline` comparison makes all
three new tests red, the first with
`baseline_ref":"result-set:watch-legacy-capped"` inside an emitted
query-delta finding. test_exact_delta_after_legacy_baseline_replaced pins the
opposite direction, so silencing every delta cannot pass.
Derived schema closure: polylogue/daemon/convergence_standing_queries.py is
OUT; identity unmoved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
… once

A class may consume its own reserve plus the shared remainder and never
another class's -- but admission and dispatch checked only the submitting
group's own ceiling. That is true of each group taken separately and false of
any two together: on the default eight-worker pool control and
incremental-background each have a four-slot ceiling, so four blocking tasks
in each occupied the whole pool while both stayed inside their bound, and the
three slots the snapshot advertised as reserved for interactive-read stopped
existing. The queue behaved the same way: two saturated non-interactive groups
left one unit of twenty-four for an interactive request whose declared reserve
is nine.

Both paths now check the complement: a unit starts only if what remains still
covers every other group's unmet reserve. The reserve stays hard, so a
saturated non-interactive mix now leaves the reserved capacity idle when the
reserved class has nothing queued; that is the cost the per-group ceilings
already paid for a single class, and a soft reserve would hand the slot away
exactly at the moment an interactive request arrives.

Verification: devtools test tests/unit/daemon/test_execution.py -> PASSED
exit=0 (all pre-existing fairness laws included).
Anti-vacuity executed: restoring the per-group-only dispatch check makes
test_combined_classes_cannot_take_the_interactive_reserve red
(`assert False where False = wait_started(1)`); restoring the raw
capacity_units admission check makes
test_combined_classes_cannot_take_the_interactive_queue red
(`assert 1 >= 9`).
Derived schema closure: polylogue/daemon/execution.py is OUT; identity unmoved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
…dget

Ordinary raw admission budgets the whole expanded component:
RawObservationDerivation.compute calls expand_raw_membership_selection and
compares sum(sizes.values()) against its payload limit. Whale selection
compared the seed row's own size, which discovery reports. A
membership/revision component whose members are each inside the 64 MiB
ordinary limit but whose total is not therefore failed every ordinary
admission and was never offered to the whale owner, so it stayed
unmaterialized indefinitely.

The whale predicate now asks the same question the budget asks, skipping the
extra bounded read when the seed alone already exceeds the limit. An
unreadable component size is reported as unmeasured and the raw is left to
ordinary admission rather than failing the periodic pass.

The docstring also claimed the pass runs "only after the ordinary trickle
conveyor has drained to quiescence". Nothing enforces that: the caller sets
the intake wakeup event and immediately awaits this pass. The real check is
the head of the discovery page, and the docstring now says so and names the
dispatcher signal a true quiescence gate would need.

Verification: devtools test tests/unit/daemon/test_whale_selection.py
tests/unit/daemon/test_raw_materialization_parse_stage_equivalence.py ->
PASSED exit=0.
Anti-vacuity executed: restoring the per-raw predicate makes
test_whale_selection_measures_component red (`assert False` on the pass's
return) with no session published. Its fixture is two revisions of one source
path, each under the limit and together over it; a seed that alone exceeds
the limit is selected by both predicates and proves nothing.
Derived schema closure: polylogue/daemon/cli.py is OUT; identity unmoved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
…e holds

build_daemon_status treated `stale` as a sixth refusal state. It is not: it
means "the last good value, plus a background refresh that has not landed".
The persistent periodic registry is polled every
_STATUS_SNAPSHOT_REFRESH_INTERVAL_SECONDS plus jitter while its components
carry StatusComponentSpec's 10s ttl_s, so the TTL expires on essentially every
tick. Measured over the production registry at a 10.5s cadence: fresh, stale,
fresh, stale. On every stale tick the published snapshot threw away a
ten-second-old reading and served the unknown-readiness defaults for
raw-materialization, session-summary and live-ingest -- an unknown raw
frontier with ok: false for half of the daemon's life.

What decides whether that value is a current measurement is the fingerprint it
was collected under. The registry keys its components on the index/ops tier
mtimes, so an unchanged fingerprint means the value still describes the live
frame, and a changed one means the collector in flight is answering a question
the held value cannot -- which is precisely the "frame that is no longer
authoritative" case the blanket rule stood in for. A snapshot with no
fingerprint establishes no currency and stays unmeasured, so the ephemeral
per-call registry is unaffected.

Verification: devtools test tests/unit/daemon/test_status_stale.py
tests/unit/daemon/test_daemon_status.py -> PASSED exit=0.
Anti-vacuity executed both ways: putting "stale" back into the unmeasured set
makes test_stale_with_current_fingerprint_is_measured and the production-route
test_second_tick_keeps_the_raw_frontier_reading red; replacing the fingerprint
arm with `return False` makes test_stale_with_changed_fingerprint_unmeasured
and test_stale_without_fingerprint_is_unmeasured red.
Derived schema closure: polylogue/daemon/status.py is OUT; identity unmoved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
…g it

GET /w/compare fell through to the generic typed-data page, whose scalar
branch projects any value with str(). The compare envelope's left, right,
pairs and metadata_diff are whole session payloads and a full pairing over
them, so that branch emitted an escaped Python repr of every message, once per
key that holds it. Measured on a twelve-message fixture: 20 205 bytes of HTML
carrying 480 copies of the message-text fragment, unbounded in the length of
the transcripts behind it. The page was also unreadable -- four `<dd>` blobs of
`{&#x27;session_id&#x27;: ...}`.

Compare now has a structure-aware renderer: a metadata table, an aligned-pair
table with one bounded `_compact_preview` per message, and the window,
alignment and unresolved sides kept on the page because the pairing covers
exactly that window. The same fixture renders in 6 092 bytes with each message
appearing once and no repr. The generic page's scalar slot now reports a
bounded count for a nested structure rather than its repr, so no future typed
route can dump one either.

Verification: devtools test tests/unit/daemon/test_webui_compare.py
tests/unit/daemon/test_daemon_http_security.py
tests/visual/test_reader_dom_smoke.py -> PASSED exit=0.
Anti-vacuity executed: delegating render_compare_page back to
render_typed_data_page and restoring the str() scalar projection turns four
tests red, including `assert 135477 < (18837 * 1.5)` for a tenfold longer
message and the literal `{&#x27;session_id&#x27;: ...` dump; removing the
route dispatch alone turns test_compare_route_uses_the_compare_renderer red
with the payload landing in the generic renderer. Two first-draft assertions
were refuted by that mutation (one was self-referential, one varied message
count, which both implementations grow with) and were rebuilt against the
preview bound and against message length instead.
Derived schema closure: polylogue/daemon/webui.py and polylogue/daemon/http.py
are both OUT; identity unmoved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
`operation.cancel` against a queued, pre-acceptance mutation was rejected with
`operation_reference_unknown` -- for the operation it had just cancelled. The
scheduler completes a queued task's future synchronously inside `cancel()`,
and the runtime's `settled` callback removes the exchange in the same call, so
the control loop's next look found neither a live exchange nor a durable
machine record and read that absence as "no such operation".

Reproduced at HEAD against the production runtime with a saturated kernel:
`mutation.session.delete.preview` reports `cancelled` to its own caller while
the cancel request returns
`{'code': 'operation_reference_unknown', 'retryable': False}`.

The control request now remembers that it released a live exchange which had
not started acceptance, and answers `cancelled` with `effect: no-effect`.
Nothing is committed before acceptance, so the cancellation is the whole
outcome. An absence this request did not cause is still
`operation_reference_unknown`.

Verification: devtools test tests/unit/daemon/test_queued_cancel.py
tests/unit/daemon/test_operation_recovery_identity.py -> PASSED exit=0.
Anti-vacuity executed: removing the pre-acceptance branch restores the
`operation_reference_unknown` rejection above.
test_cancel_of_an_unknown_reference_is_refused pins the opposite direction, so
answering `cancelled` unconditionally cannot pass.
Derived schema closure: polylogue/daemon/operation_runtime.py is OUT; identity
unmoved.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
`gate mypy` refused three things the focused runs did not: `data.get("left")`
narrows to `object` across two separate calls, `RawMaterializationReadiness`
has no `broken_head_count` field, and the admission-class loop's cast was
redundant.

Verification: devtools verify --quick -> 21/22 gates green, `gate atlas` red
with the same docs/atlas/daemon.md hook-carrier anchor it reports at the base
SHA 17566b0 (PR #5408 owns it). devtools render all --check -> exit 0, zero
"out of sync" lines. devtools test over every changed file, in two batches ->
PASSED exit=0.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 19 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: 4bc58dc0-7a3b-471d-acc0-0ea2afd84491

📥 Commits

Reviewing files that changed from the base of the PR and between 1f996e1 and 5b7cc82.

📒 Files selected for processing (15)
  • polylogue/daemon/cli.py
  • polylogue/daemon/convergence_standing_queries.py
  • polylogue/daemon/events.py
  • polylogue/daemon/execution.py
  • polylogue/daemon/http.py
  • polylogue/daemon/operation_runtime.py
  • polylogue/daemon/status.py
  • polylogue/daemon/webui.py
  • tests/unit/daemon/test_event_cursor.py
  • tests/unit/daemon/test_execution.py
  • tests/unit/daemon/test_queued_cancel.py
  • tests/unit/daemon/test_standing_queries.py
  • tests/unit/daemon/test_status_stale.py
  • tests/unit/daemon/test_webui_compare.py
  • tests/unit/daemon/test_whale_selection.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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T10:24:01.657913Z 5b7cc82 PR opened
🔒 Security Review ✅ Completed 2026-09-22T10:26:09.477025Z 5b7cc82 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity enabled auto-merge (squash) September 22, 2026 10:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b7cc828bd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/daemon/webui.py Resolved
Comment thread polylogue/daemon/status.py Resolved
Comment thread polylogue/daemon/events.py Resolved
Comment thread polylogue/daemon/operation_runtime.py Resolved
@Sinity
Sinity merged commit b06368b into master Sep 22, 2026
3 checks passed
@Sinity
Sinity deleted the fix/p1-review-daemon branch September 22, 2026 10:26
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 0914f89):

  • P2 polylogue/daemon/events.py:205: Not a defect (checked at 0914f89): Age retention deliberately deletes only an ID prefix so cursor completeness holds; the enforcement point documents that deleting through the highest expired ID, as proposed, would drop in-window rows (polylogue/daemon/events.py:183-194). No production code installs a bound: the enforced retention defaults to unbounded, and set_daemon_event_retention has no callers outside events.py (polylogue/daemon/events.py:155).

Resolving every thread listed; confirmed defects are fixed under the named bead.

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