Repository navigation
fix(intake): keep budget-unattempted files ahead of an acknowledged sibling - #5674
Merged
Merged
Conversation
|
You have reached your Codex usage limits for security reviews. Please try again later. |
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. |
This was referenced Sep 27, 2026
Sinity
added a commit
that referenced
this pull request
Sep 28, 2026
#5691) ## Summary This PR also fixes polylogue-slc55: preparation is never abandoned at a wall-clock deadline, and cold-build cursor corroboration reads the candidate index. Live intake now prepares the next files while the writer publishes the current group. It also caps the default process parse pool and decodes each sealed prepared session once instead of once per pass. ### polylogue-slc55: never abandon progressing preparation A 419 MB Codex file never finished a cold build. Its preparation outlived the 60 s warm deadline, so the writer deferred the file and re-acquired it on the next pass, eight times. When one pass finally succeeded, cursor corroboration checked the still-empty *active* index rather than the candidate generation being built, demoted the new cursor and re-ingested the file. The run wrote 117 GiB and never promoted. - `warm_paths`, the in-memory `warm`, `CensusParseStage.warm` and retained raw preparation no longer have deadlines. They wait for their workers. - Forward progress (attempt-directory growth, or completions) decides only when a stall is reported: `live.parse_prefetch.preparation_stalled`, `daemon.parse_prefetch.preparation_stalled` and `storage.raw_observation.preparation_stalled`. A report never defers, terminates or discards work. - Cursor corroboration resolves `_published_index_path`, which is the candidate generation during a cold build. - Tests that asserted the retired deadline behaviour are rewritten to the new contract or removed where the pending state they covered no longer exists. Deferral on worker failure keeps its tests. ## Problem (evidence) Numbers come from `devtools bench fresh-build` (#5678). Each run cold-builds a sealed 144-file (276 MiB) private sample of Claude Code, Codex and Gemini sources through `polylogued run --cold-build-index` on a shared host (load 18-35). Only aggregate numbers are quoted. Wall times move with host load; writer holds, stage timers and CPU seconds move less. On master plus #5674, intake ran at 0.45 MiB/s with a mean of 0.34 cores. A stack profile of the daemon (the benchmark's in-process sampler, because py-spy cannot attach to 3.14t) showed three causes: - At most 2 parse paths ran in parallel. `_max_path_pending` was 1 per worker slot, and nothing was submitted until the writer asked for a path. - The unconfigured process pool took every core (23 workers here). Peak RSS for the daemon tree reached 3.7 GB. - The writer re-validated each sealed session's messages with pydantic on every pass over it, about 20 passes per session. This was 45% of writer CPU. ## Solution - `LiveParseStage.prefetch_paths` starts preparing the next page's cursorless paths while the current page publishes. Read-ahead has a bounded lifecycle: - The parent only stats a path and reads its cursor. Candidate sampling and preparation run in the stage's executor (`live_lookahead_path_worker`), so a stalled source read never blocks a parent thread. - Read-ahead is charged to the slot and byte budget from submission until it ends. It never takes the last worker. - A warm whose required path does not fit preempts running unclaimed read-ahead. After a short grace the read-ahead is reaped: the process pool is terminated and restarted, and the warm resubmits its own collateral work. Unclaimed read-ahead that outlives eight stage calls is reaped the same way. - Finished read-ahead releases its charge at once and pays its full artifact digest only when a warm claims it. - Publication order is enforced in one place, reconciliation. A warm reconciles its paths in intake order, admits one path per canonical session, and returns later same-session paths as held. The batch publishes held paths in the next progress group, after a fresh warm. A reconciliation is valid only for the warm that made it. - The path-pending bound is one per worker. The default process pool is capped at 8 unless configured (`_DEFAULT_PROCESS_WORKER_CAP`). - `SqliteMessageSink` keeps a bounded LRU of decoded sessions (64 MiB; a session larger than half the budget is not retained). The key is the sealed file's path, ordinal, and dev/ino/mtime/ctime/size, so a changed file never serves a stale decode. `PreparedJsonl.discard` drops the entries. ## Verification - `devtools test tests/unit/sources/test_prepared_jsonl.py tests/unit/sources/test_live_watcher_parse_stage_equivalence.py tests/unit/daemon/test_fair_resumable_intake.py`: `223 passed`. The run includes new tests for decode-once, discard or oversize re-decode, a sealed-digest-bound cache key, prefetch without waiting, and the pool cap. - Benchmark: with the 23-worker pool, intake reached 1.44 MiB/s at 3.7 GB RSS. With the cap it runs at 1.9 GB RSS. The combined branch (this PR plus the drains, ops and digest PRs) promoted in 114.6 s (intake alone took 623 s before), reached terminal and qualified, and its per-origin intake projection for the sampled population fell from 37.8 h to 6.2 h. - Lookahead rework: `devtools test` over the parse-stage equivalence, live watcher, fair intake, parse prefetch, cursor locking, schema preflight, watcher locking, batch support and read-amplification files: `530 passed, 4 failed`. Two of the four failures (`test_watcher_queues_behind_daemon_maintenance_writer`, `test_live_full_ingest_offloads_sync_work_to_keep_loop_responsive`) also fail on origin/master cf6d12d. The third, `test_source_only_full_ingest_streams_admitted_zip_members_without_decoding`, patches a `batch._detect_provider_from_raw_bytes` attribute that does not exist on master. The fourth, `test_path_stage_shutdown_terminates_stalled_process`, hit its 5 s spawn wait under load and passes when run alone. Each of the three new P1 regression tests (wedge, reap of a worker stuck on a FIFO read, same-session order) fails when its fix is disabled. `devtools verify --quick`: PASSED. ## Residuals - These files are in the derived schema-identity closure (`devtools schema closure`: batch.py, parse_prefetch.py, watcher.py, prepared_jsonl.py and prepared_message_sink.py are IN). The change must land before the fresh build starts. - The individual contribution of prefetch versus the decode cache is not separated. Both runs share the other changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4 --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sinity
added a commit
that referenced
this pull request
Sep 29, 2026
…#5678) ## Summary Add `devtools bench fresh-build`, which builds a fresh archive from a sealed source corpus through the ordinary daemon route and writes a comparable receipt. The receipt covers stage timings, writer share, queue depth, per-origin cost with a population projection, process-tree RSS and CPU, time to promotion and to terminal convergence, terminal checks, asserted budgets, and a per-table output fingerprint. `compare` diffs two receipts and says whether their stored output is identical. `components` times one production stage over the same corpus. An in-daemon stack sampler stands in for py-spy, which cannot attach to 3.14t. The one-off whale qualification driver (`devtools/daemon_finished_build.py`) is retired: a single large source is now a `corpus files` corpus run with `--max-rss-mib`. A declared `fresh_build_bench` AgentCTL operation runs it in the bulk pool. ## Problem Nothing measured the fresh build the operator will actually run. The existing finished-build measurements call `backfill_historical_revision_evidence` directly and bypass intake, the cold-build generation, promotion and derived convergence. `devtools/daemon_finished_build.py` ran the real daemon, but only as a pass/fail qualification for one input file. It had no stage attribution, no comparison, and no corpus seal. Running the new benchmark on a private 0.5% stratified sample of the operator's sources (148 files, 290 MB, Claude Code/Codex/Gemini CLI) at the base commit showed where a full build stands: - Intake ran at 0.45 MiB/s. That projects to about 38 hours of intake for the claude-code, codex and gemini-cli population alone (60 GiB). - Mean CPU use was 0.34 cores. The writer was busy 45% of the time. - An intake starvation bug (#5674), a promotion refusal (`polylogue-se08w`), and derived stages that never converged kept the build from finishing. ## Solution - `corpus sample|files` lays sources out under a stand-in `$HOME`, so the typed default sources resolve exactly as in production. The manifest seals every file's path, size and SHA-256 under one digest, and the sample is seeded and stratified by origin and size bucket. - `run` isolates `HOME`, XDG and the archive root in the work directory. It starts `polylogued run --no-browser-capture --no-api --cold-build-index` with JSON events, samples the process tree once a second, and polls the archive read-only. It stops on terminal convergence, a stall, a settle timeout or SIGTERM, and the receipt is written in every case. A cancelled job still leaves its evidence. - Terminal means: promoted, every cursor complete or excluded, every membership settled, zero convergence debt, and every required readiness domain ready. `qualified` additionally requires zero raw parse failures, exact FTS, and every asserted budget. - `report --refresh` recomputes a receipt from its run directory, and `profile` summarises the sampler's wall/CPU stacks. - `docs/fresh-build-benchmark.md` documents corpora, running, the receipt and how to read it. ## Verification - `devtools test tests/unit/devtools/test_fresh_build_bench.py`: `8 passed` (receipt `.cache/verify/runs/20260927T202649Z-focused-test-2750767-52bc166f`). The tests cover the event-log reduction (intake window and writer share scoped to promotion), leaf-only stage rollup, the population projection, fail-closed budgets, the terminal predicate's readiness and membership conditions, the corpus seal, and seeded session-unit sampling. Each names its anti-vacuity mutation. - `devtools gate generated-surfaces|doc-commands|patterns|layering|oracle-integrity|test-packages`: passed. `mypy devtools/fresh_build_bench/`: no issues. - End to end on the private sample (numbers only; corpus and receipts stay private): the receipts above, and later runs on the same corpus after the fixes in #5674 and the follow-up performance PRs, compare through this tool. ## Residual - Synthetic corpora (`corpus synthetic`) arrive once the workload generator in #5670 lands. Committed receipts should use them. - Wall time on a shared host moves with load, and the receipt records load at start. CPU seconds and writer holds are the steadier comparison. - Whale qualifications for `polylogue-58bwo` are now runs of this benchmark. They have not been run here. ## Self-review I reviewed the complete diff at the final head: 146 review threads over four rounds, re-read against the code rather than against the replies. The findings are grouped by the property a receipt promises. **A receipt is comparable only when its inputs are the same** - The corpus manifest seals every file's path, size and SHA-256. The run verifies the corpus before and after. - Sampling uses production's own admission predicate (`_is_supported_source_path`) plus the unit's sidecar directories. - A full fraction copies every unit, zero-byte ones included. - Each copy is verified against its source's content digest, and each source is checked again against its copy's digest at the end of sampling. File stamps alone missed a same-size rewrite within one timestamp tick; this was found in the final review. The population census is also recounted. - The candidate is identified by git SHA, tracked-diff digest and a stamp of every unignored file taken before and after the run. The benchmark's own identity hashes the package, the fingerprint helper, and the transitive closure of the `polylogue` modules it imports (absolute, relative and submodule imports). - The interpreter is probed from the candidate's working directory, where the daemon is launched. **A receipt says what happened, even on failure** - The receipt is written atomically on every outcome: terminal, stall, settle timeout, interrupted, or unreadable archive. - An interrupted run skips the census and the fingerprint. SQLite fingerprint passes are cancellable (progress handler, `FingerprintCancelledError`). - Shutdown waits while there is progress, measured as I/O counters and event-log growth, not CPU, because the injected sampler keeps CPU moving. There is no fixed deadline. The 8-hour AgentCTL ceiling is recorded in polylogue-hesa2. - The evidence digests cover `events.jsonl`, `ops.db` and `ops.db-wal`, so `report --refresh` can tell whether it re-reads the same evidence. **Qualification cannot be satisfied vacuously** - Terminal requires all of: promotion, every cursor complete or excluded, memberships settled, zero debt, and every required readiness domain ready. - `qualified` further requires: - zero raw failures; - exact FTS; - positive output; - a steady wall clock, where clock steps are sampled every poll and the largest counts; - complete sampler delivery; - a measured source timing for every sampled origin; - every asserted budget. - Found in this last review and fixed with a receipt-level test: the source-timing check read a projection key that does not exist (`origins` instead of `by_origin`), so every `build_receipt` call raised. The unit test had called the helper through the same wrong key. The new test drives `build_receipt` end to end. **Resource bounds**: component preparations keep at most 2×workers in flight. The stack sampler keeps full-depth stacks, and its dump overhead is reported. **Verification**: - `devtools test tests/unit/devtools/test_fresh_build_bench.py` on the final head fb913b8: 102 passed, 0 failed. `test_daemon_finished_build.py` is retired with its driver. - `agentctl job start polylogue verify_quick` on the final head: succeeded (job 2338). **Residuals**: - The projection is intake only. Promotion and derived convergence are measured, not scaled. - The receipts quoted under Problem were taken at the base commit on a private sample and are not reproducible from this repository. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4 --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Keep a file that an intake pass never reached in the adapter's fresh continuation even when a later-sorting sibling in the same page was acknowledged. Also point six raw-discovery tests at the name
make_raw_observation_derivationactually reads, so their stand-in derivation is used.Problem
FileIntakeAdapter.acknowledgeadvances the walk cursor_afterto the largest acknowledged path. The next discovery then filtered the pending continuation to paths after_after. A live batch admits a page in its own order (source groups, then progress groups), and when the pass runs out of its time budget it leaves the rest of the pageunattempted. Any unattempted file that sorts before an acknowledged sibling was dropped from the continuation, and the resumed walk starts after_afteras well. Nothing offered those files again until the exhausted-walk rescan, 600 s later.Measured with the new fresh-build benchmark (private stratified sample of real sources, 148 files, 290 MB, ordinary
polylogued run --cold-build-index): 10 files, mostly Claude Code subagent transcripts, never got a cursor. Each was reportedunattempted_time_budgetthree times, went into cooldown, and dropped out of discovery. The drained backlog then triggered cold-build settlement, which refused promotion on every retry (production source baseline has 13 unretained revision(s)), and the build stalled for over 10 minutes with 138 of 148 files admitted. At full-archive scale every time-budgeted page can strand its early-sorting tail this way.The six
test_raw_discovery_*tests patchedpolylogue.storage.derived.raw.RawObservationDerivation.make_raw_observation_derivationconstructs the class through the name bound inpolylogue.operations.raw_observation_derivation, so the patch never took effect and the tests ran the real derivation against their fixture. They fail on the base commit whether or not this change is applied.Solution
_discover_fresh_pathskeeps a page's never-attempted paths in_fresh_pendingwhatever_aftersays. Attempted-and-failed paths still move to retry debt as before, and acknowledged paths are still filtered by position.polylogue.operations.raw_observation_derivation.RawObservationDerivation. The module-level import that pins the real class'srecipe_versionbefore any patch stays, and its comment now names the right binding.Verification
test_acquisition_budget_retains_unattempted_file_sorting_before_an_acknowledged_sibling:b.jsonsucceeds whilea.jsonandc.jsonare left unattempted. The second pass admits both. Without the carve-out it admits nothing (anti-vacuity).devtools test tests/unit/daemon/test_fair_resumable_intake.py:118 passed(receipt.cache/verify/runs/20260927T201738Z-focused-test-2632574-76fe6459).polylogue-se08w: three files the baseline accepts but intake excludes by rule.Residual
polylogue-se08w.🤖 Generated with Claude Code
https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4