Repository navigation
fix: Replace global spool preemption with fair, resumable intake - #4913
Conversation
…' into batch/polylogue-20260912-092839-0a685d40/integration
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e143f6811
ℹ️ 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".
## Summary
Stop the daemon supervisor demoting a terminal service state to
`stopped`, and
repair six test scopes that were red on clean master — three
memorializing
deliberately changed behaviour, three broken fixtures.
## Problem
Clean master `3faacef23` fails these files. Splitting real defects from
stale
tests was the point of the exercise; the split came out 1 product bug, 3
stale tests, 3 broken fixtures.
**The product bug.** `halt()` sets `ServiceState.HALTED`, then cancels.
One loop
turn later the cancellation handler calls `_settle(spec, STOPPED, ...)`,
and
`_settle` had no terminal-state guard, so it overwrote `HALTED` and
republished
a *measured* `STOPPED`. Halt durability itself was never at risk —
`HaltRegistry`
still refuses the unit on restart — but a terminally refused service
appeared on
the status board as a clean `stopped`, which is the one thing an
operator reads
to decide nothing is wrong. Introduced whole in `b2ad5ef1b`; never green
on this
path.
## Solution
`TERMINAL_SERVICE_STATES = {HALTED, FAILED, ORPHANED}` as a general set
`_settle` never demotes, rather than a `HALTED` special case.
Cancellation is
the common ending for all three — a halt, a crash under `FAIL_DAEMON`,
and an
expired shutdown deadline each leave a child whose `CancelledError`
handler
settles `STOPPED` one turn later. No priority ordering is needed because
none of
the three is reachable from another, so first-writer-wins is the whole
rule.
`SKIPPED`/`UNAVAILABLE` are set through `_resolve` and have no task, so
they have
no demotion path.
Test repairs, each with its anti-vacuity condition:
- **Renamed service.** `raw_materialization_convergence` →
`raw_observation_convergence`
(`services.py:321-330`, wired at `cli.py:2752`). The service was renamed
by
`#4913`/`#5005`, not removed. The two sibling registry assertions
previously
asserted `not in` against a *nonexistent* name and so could not go red
at all;
now adding `RESIDENT_CORE` to the spec makes all three red.
- **Embedding readiness.** `_FakeCfg` replaced with a real
`PolylogueConfig`
after `embedding_status_settings_from_config` moved to nominal dispatch.
Reintroducing an attribute-only double makes all seven red.
- **WAL checkpoint.** The fixture closed its seeding connection in a
`finally:`,
and SQLite deletes the `-wal` on last close, so `checkpoint_wal`
returned at
its size gate with `mode='none'` before opening anything — every mode
read
`'none'` regardless of policy, so escalation was entirely unbound.
Seeding now
holds the connection open and asserts a non-empty `-wal` exists. The
busy-reader case closes the seeding writer once the reader holds its
snapshot,
so the reader is the sole WAL holder. **Proved empirically rather than
asserted:** temporarily dropping `TRUNCATE` from
`CHECKPOINT_ESCALATION_MODES["exclusive"]` turns the suite red with
`assert 'restart' == 'truncate'`, then reverted.
- **Orphan test** was a different defect than reported — its body
passed, but its
`uncancellable` child suppressed cancellation unconditionally, so
`asyncio.run`'s `_cancel_all_tasks` could never reap it and the test
died on
pytest-timeout at 120s. It now releases the child after the assertions
and
additionally asserts that reaping it leaves `ORPHANED` intact,
exercising the
new guard.
- **Per-stage timings.** `#4694` deliberately added
`parse.check`/`fts.check`/
`derived.check` sub-timings; the assertion now expects the six-key set.
Verified the consumer does not double-count:
`_per_stage_timings_from_attempts`
(`daemon_workload_probe.py:2150-2161`) keys per stage and summarises
each
independently, never summing across keys.
- **Audit tier v3.** The future version is now derived as
`ARCHIVE_VERSION_BY_TIER[AUDIT] + 1` instead of a literal, so audit 004
will
not break it again; the relocation clone fixture loops over the derived
chain
with no literal versions. Beyond the documented fields, the validator
also
binds `proof.restart_convergence.observed_user_version`
(`migration_runner.py:3610`).
## Verification
```
devtools test <all 7 touched files> 215 passed
receipt 20260913T185337Z-focused-test-1203290-0e0ce220
devtools verify --quick all 14 gates ok, exit 0
```
## Residuals
**Archive-root relocation is genuinely broken for one real class of
archives,
and this PR does not fix it** — the fixture repair here makes the test
green
without closing the product gap, so it is called out rather than hidden.
A durable tier below the runtime version is refused at open
(`bootstrap.py:593-596`), so an operator must run `migrate-tier` first,
and
`snapshot.user_version` is therefore always 3 at relocation time.
Migrating
writes only `audit-003.json`; it does not backfill `audit-002.json`. The
broken
class is any archive whose audit tier reached v2 *without* a v2 train
manifest —
pre-marker archives, `--adopt-established-audit`,
`--initialize-missing`. Those
end with manifests `{3}` against `expected_targets {2,3}` and hit the
raise. The
`validate_audit_adoption_receipt` bypass does not cover them: it is
gated on
`not manifests`, and `audit-003.json` exists by then. Archives that
walked 1→2
through the train route are fine, and the `.bootstrap` guard intercepts
fresh
archives first — into a hard refusal, not success.
Root cause: `archive_root_relocation.py:1194` uses the raw
`DURABLE_MIGRATION_ADOPTION_FLOORS[tier]` where every other chain check
uses
`_chain_floor()` (`durable_change_train.py:3179-3182`). Relocation's own
`.bootstrap` refusal made the two equal until a tier gained a migration
above a
version some archives reached without a train — which is exactly what
`003` did.
The same shape latently exists for SOURCE (floor 37, live 44), masked
because
real source archives carry the intermediate manifests.
Needs a separate owner, a `_chain_floor`-based fix, and a regression
test built
on a v2-era audit archive carrying only `audit-003.json`. Recorded in
the
`6c7513327` commit body so it is not lost.
**`embedding_readiness.py:62-68` needs no fix.** The seam is
unreachable:
`embedding_readiness_info` passes only
`SimpleNamespace(config=SimpleNamespace(db_path=...))`,
and `embedding_status_payload` calls `load_polylogue_config()` itself
(`status_payload.py:1307`) and passes *that* to the nominal dispatch
(`:1320`).
Broadening to `except Exception` would be actively wrong — it would
convert a
wrong-type programming error into `embedding_status="empty" /
retrieval_ready=False`,
indistinguishable from a fresh archive, which is the precise failure the
existing `polylogue-cpf.4` comment exists to prevent.
🤖 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]>
Triage of the daemon/async share of the 58 corpus failures. **21 of 23 fixed** across 17 commits — and it uncovered **silent production data loss** that would have crippled the from-scratch rebuild. ## The finding that matters The brief framed the four `test_daemon_resilience` failures as "grouping or daemon lifecycle". Raising the module timeout — a 300s wait under a 120s ceiling could **never** complete — unmasked the real diagnostics. On an **idle** machine `sigkill_recovery` reported *byte-identically* the same "20 messages" as the corpus run, proving load was not the cause. **The daemon ingested one session per root and stopped.** `FileIntakeAdapter.discover` advanced its cursor past the entire discovered page while the dispatcher consumed only its head, and the walk only moves forward. Compounding it, adapters charge `estimated_cost` in **bytes** while the service budget was `64` — a *count*. Every session after the lexicographically-first was retained on disk and never archived. Introduced by `#4913`, which made the dispatcher the sole discovery authority and disabled the watcher's own catch-up. This is not a test defect. The fresh-start ruling is *"move the six database files aside, start the daemon fresh, let ordinary convergence rebuild everything from the actual sources"* — so the rebuild **is** this code path. Building on the previous head would have produced an archive containing roughly one session per source root and reported success. ## Classification of all 23 **PRODUCT-BUG (8)** — the discovery/budget loss above (resilience ×3 + `large_session_file`); workload probe ×2 (the adapter treated "file exists" as "tier bootstrapped", and `inspect` opened a DB to answer an empty question); MCP clamp (the CLI clamps `limit=-1`, MCP refused it — the declared clamp was applied to the routing probe but not the typed request); daemon SIGTERM forensics (the signal handler wrote without the process-wide lease, `UnleasedWriteError` swallowed → `(None, 'signal')`). **STALE-TEST (8)** — the insight cluster ×4 (still calling the facade #5030 retired); visual ×2, red since #4645's WebUI cutover because `tests/visual/` is not in the fast gate; `daemon_status` (`(0 sessions, 1 message)` is unreachable by construction post-#5027); demo seed. **ORDER-DEPENDENT (3)** — `test_daemon_cli.py`. Passed alone *and* across `tests/unit/daemon`; the corpus receipt showed a `MagicMock` and a shut-down adapter leaking through the process-global `_SHARED_COMPUTE_ADAPTER`. `reset_daemon_compute_adapter()` already existed and **nothing called it**. Verified red→green with a deterministic two-file reproducer. **TEST-INFRA (3)** — `live_read_amplification` (double drifted from a keyword-only signature); `resume` (rename debris from #4614, `insights` vs `analysis`); `write_path_state_machine`. **Root verb (1)** — `verification-export` regrew the surface `985e0f9d9` folded. The verb was wrong, not the test. ## Two left unfixed, deliberately - **`test_demo_seed_verify`** — Codex declares `parent_dispatch` structurally absent, so `mapping_state:resolved` is unreachable for that fixture (confirmed by counterfactual: forcing the origin gate only changes the refusal reason). A Claude Code delegation fixture was started; each step revealed another required piece, so it was **reverted cleanly** rather than left half-built. - **`test_installed_package_smoke`** — diagnosed precisely, then **both commits reverted** after three fixes each broke a different legitimate caller. The third was rejected by `devtools gate layering`'s own ratchet. That the architecture refuses the CLI-layer catch says this needs a deliberate owner decision, not a triage patch. Full rationale is in the revert commit. ## Verification ``` 2,976 passed, 0 failed devtools verify --quick exit 0, 15/15 gates ``` ## Residuals recorded in commits A pre-existing `_assert_resolved_link` property failure (replayed against base — fails there too, no delete involved); an unleased-writer bug in the daemon health/cursor-lag path; a whale-pass deadlock against the daemon's own ownership flock; and a note that two reds in `tests/unit/sources/` assert FTS convergence debt which the inline repair here makes obsolete. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Updated the verification export command to use `verify export`. * Newly ingested sessions become searchable immediately. * Improved intake processing so skipped items can be rediscovered. * **Bug Fixes** * Out-of-range session list limits are now handled safely. * Improved daemon lifecycle signaling under write-lease enforcement. * Clearer errors are provided when source databases are missing required data. * Intake processing now uses a byte-based default budget. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
…ute (#5233) ## Summary One intake route (polylogue-v4dcc, operator ruling 2026-09-16): the fair-intake dispatcher admits whole pages as one live ingest batch, and the watcher's chunk/catch-up/debounce/failed-retry route is deleted. Measured 3.0x end-to-end on a synthetic 500-file corpus through the production dispatcher. ## Problem `polylogued run` has intaked through `FairIntakeDispatcher` one file per `ingest_files` call since #4913, so every per-batch fixed cost (retention scan, six-tier bootstrap, convergence pass, cursor initialise, one writer hold) was paid per file, and the parse-stage prefetch received one path at a time. The watcher's own 4-file chunk route was still in the tree, exercised only by tests and the perf harness, and every campaign number measured that dead route. ## Solution - `FairIntakeDispatcher._service_class` plans a page against the class deficit (bytes-aware, stops at the class share, never splits below one file) and calls one `admit_page`; adapters without it still get per-item `admit`. - `FileIntakeAdapter.admit_page`: authority gate → `cursor.initialize` → `select_ingest_candidates` → one `ingest_files` batch → one embedding and one session-profile convergence for the page → one outcome per path from `LiveBatchMetrics` (`succeeded_paths`, new `excluded_paths`/`deferred_paths`, `failed_paths`), so deficit, retry_after and isolation stay per item; `AdmissionOutcome.DEFERRED` is new; `MultiplexIntakeAdapter` splits a page along source ownership; `LiveParseStage` is warmed with the page. - Deleted (ledger in the commit, pinned by `tests/unit/architecture/test_one_intake_route.py`): `_catch_up` and its planner/candidate/chunk/pledge helpers, `_periodic_catch_up`, the debounce queue, the failed-retry scan, `_flush_convergence_off_writer`, `_stage_write_admission`, `intake_hints_only`, `catch_up_active`, `debounce_s`, the `_CATCH_UP_*` constants, and `run_live_watcher` (no production caller). The unclaimed-file sweep moved into the dispatcher's discovery walk; cursor comparison and reconciliation scope became `LiveWatcher.select_ingest_candidates`. - Kept deliberately: the writer hold around `_ingest_files`, now per page rather than per file. Removing it refuses the daemon's own ingest because `ingest_files`' ops-tier writes are not self-admitting (follow-up bead filed). - Discovery follows directory symlinks with cycle detection over resolved real paths (polylogue-lu1dk, a regression since #4913 the deleted scan had masked): a cycle or dangling link is a typed `daemon.intake.discovery_failed` per path, a link into the archive root is never followed, and source ownership matches the lexical path as well as the resolved one (a second bug: linked files were discovered, then disowned). - New events: `daemon.intake.page_refused`, `daemon.intake.item_retryable`. - Harness: `/realm/tmp/work/perf-2026-09-15/real_ingest_driver.py` gained `--dispatcher`, `--admit-per-item`, `--synthetic N`, `--budget/--page-size`. ## Measured (500 synthetic claude-code files, 8.44 MB, same host, 17 dispatcher passes) | shape | wall | end-to-end MB/s | files/s | peak RSS | |---|---|---|---|---| | per-item admission (base) | 155.28 s | 0.054 | 3.22 | 180 MB | | page admission (after) | 51.66 s | 0.163 | 9.68 | 237 MB | Receipts under `/realm/tmp/work/intake-route-perf/`. Run in the foreground because host backpressure had frozen the bulk pool for ~50 min; rerunnable through the `scratch` operation. ## Closure `sources/live/{watcher,batch,metrics,parse_prefetch}.py` are IN the derived-schema closure; the identity moves. Lands before the rebuild, never during one. ## Verification - `agentctl ... verify_quick` → job 2637 **succeeded** (2634 failed on two stale test typings, fixed in bd15f51) - `agentctl ... pytest_focused -- <13 touched test files + fair intake + daemon cli>` → job 2635: 518 passed, 3 failed (the two master-red test_daemon_cli tests fixed in #5229 and the inherited codex goal-materials test); the two fixed test files re-ran 92/92 green - Worker: 518 passed / 3 inherited failures over the 13 touched files; `gate atlas`, `gate layering`, `gate patterns` green; ruff/mypy clean. ## Residuals (filed as beads) - Ops-tier writes inside `ingest_files` are not self-admitting (hold stays per page). - Dead `catch_up_cycle` readers, inert `--debounce-s`, `catch_up_complete` now meaning "watcher ready", coarser unreadable-subtree accounting, Claude sidecar forced reparse gone. Sequenced after PR #5220 (daemon/status.py). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
|
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. |
|
Closing out open Codex review threads on this PR (evidence checked against master at 64a9bd0):
Resolving every thread listed; confirmed defects are fixed under the named bead. |
|
Closing out open Codex review threads on this PR (evidence checked against master at 64a9bd0):
Resolving every thread listed; confirmed defects are fixed under the named bead. |
|
Closing out open Codex review threads on this PR (evidence checked against master at bf68918):
Resolving every thread listed; confirmed defects are fixed under the named bead. |
|
Fix record for Codex review threads on this PR (checked at master 5d56c3a):
These threads were already resolved by the triage post that assigned them to polylogue-9kemf; this comment records the fix. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Batch
polylogue-20260912-092839-0a685d40on baseda15131c1c16.polylogue-gmw2 Replace global spool preemption with fair, resumable intake