Skip to content

fix(daemon): Refuse a cold build that cannot fit before it allocates - #5325

Merged
Sinity merged 1 commit into
masterfrom
fix/cold-build-capacity-guard
Sep 21, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/cold-build-capacity-guard

Conversation

@Sinity

@Sinity Sinity commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Summary

A cold build could allocate a ~38 GiB index generation without ever checking
free space. The capacity guard existed but sat on a dead route; it now runs on
the live one, and a promoted build calibrates the next projection.

Problem

require_candidate_capacity had exactly one call site repo-wide —
storage/index_generation.py:779, inside create_transaction, which has zero
non-test callers
(verified: only its own definitions plus 9 test sites). The
entire maintenance/candidate_capacity.py module was therefore
production-unreachable.

The real driver is daemon/cli.py:3002 → ColdBuildGeneration.begin →
IndexGenerationStore.create, which reached root.mkdir with no capacity call
at all. record_capacity_observation hung off the same dead
save_transaction, so calibrated_index_ratio returned (4.0, 'default') on a
fresh archive and always would.

Solution

require_candidate_capacity runs in ColdBuildGeneration.begin, after the
durable bootstrap and blob mkdir, before for_archive_root/create.
promote() calls observe_candidate_capacity after
run_generation_readiness_pass and before the pointer swap, so the second build
onward calibrates from a real measurement.

Unconditional, deliberately: measured on a fresh root, required_free_bytes is
290,211,431 (276.8 MiB) and sufficient=True — the 256 MiB reserve and 16 MiB
receipt floors dominate, so this does not refuse a first daemon start.
Gating on the cold_build_index flag would have left the auto-engaged 38 GiB
rebuild unguarded and protected only the explicit case.

daemon/cli.py needed no edit: nothing between run_daemon_services's try:
and the begin call swallows the exception (the only contextlib.suppress in
that window closes at :2952), so InsufficientCapacityError propagates and
terminates startup. That is the correct outcome and is now stated in the
docstring — there is no smaller build to fall back to, and continuing would let
ingest allocate the same ~38 GiB into the active generation with readers
attached. A daemon.cold_build.capacity_refused ERROR is emitted before raising.

Verification

  • devtools test over 7 selections — 168 passed
  • Both anti-vacuity mutations executed, each isolating exactly its own test:
    • deleting require_candidate_capacity from begin → 3 failed, incl.
      test_the_cold_build_refuses_before_it_allocates_a_generation
    • deleting observe_candidate_capacity from promote → 1 failed,
      test_a_promoted_cold_build_calibrates_the_next_projection
  • devtools verify --quick — exit 0 (captured directly, not through a pipe)
  • devtools render all --check — exit 0, grep -c 'out of sync' = 0 across 8 surfaces
  • Exercised against the real archive: measure_archive_capacity resolved
    gen-1785377665711-06297b00 at 37.77 GiB behind a pointer stub whose
    index_root population measured 0.000 GiB

⚠ The default ratio is measurably low for this archive

On /realm/state/polylogue: durable tiers 1.762 GiB + blob 5.710 GiB = 7.47 GiB
of evidence produced a 37.77 GiB index — ratio 5.05
, against
DEFAULT_INDEX_BYTES_PER_EVIDENCE_BYTE = 4.0.

Today the projection is saved by max(observed_index_bytes, evidence * 4.0)
picking the 37.77 GiB term. The dangerous case is durable evidence present
with no index generation
— i.e. exactly the fresh-start rebuild — where the
4.0 default under-predicts by ~21%. The observation wiring fixes this from the
second build onward, not the first. Raising the default needs more than one
datapoint, so it is untouched here.

⚠ Landing constraint

cold_build.py and index_generation.py both report IN the derived closure.
candidate_capacity.py was already IN at base, so the new module-level import
did not widen it. Must land before a rebuild starts, never during one.

Residuals

  • measure_archive_capacity took 76.9 s on the live 76 GiB / ~790k-inode
    archive. Not gated: begin() is reached only when a cold build actually
    starts, so this is once per multi-hour build. Recorded in a comment at the call site.
  • Retirement follow-up, deliberately not done here: create_transaction,
    IndexRebuildTransaction, seal_candidate_membership,
    candidate_membership_status and next_raw_page are retired-product residue
    with no production caller. Removing them before this lift would have turned
    an unreachable guard into a nonexistent one; now it is safe to schedule.
  • Pre-existing and not fixed: owner_id and page_size are unregistered fields
    on the existing daemon.cold_build.generation_created emit and are dropped
    with warnings today. Six more unregistered names were avoided by putting the
    numbers in the registered error_detail field, since logging_fields.py was
    out of scope.
  • Capacity receipts accumulate one JSON per cold build; a discarded build leaves
    actual_peak_index_bytes=0 forever. Harmless — calibrated_index_ratio filters
    peaks ≤ 0 — but unbounded.

Advances polylogue-nru50 (AC4, AC5).

🤖 Generated with Claude Code

https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq

Problem: the daemon cold build is the only production route that creates a
candidate index generation (daemon/cli.py -> ColdBuildGeneration.begin ->
IndexGenerationStore.create). The headroom refusal lived on
IndexGenerationStore.create_transaction, which has zero non-test callers, so
the whole maintenance/candidate_capacity module was production-unreachable
and a real cold build allocated a second whole index beside the one serving
reads with no free-space check at all. Measured on the live archive: the
active generation is 37.77 GiB against 246 GiB free.

Solution: call require_candidate_capacity from ColdBuildGeneration.begin,
after the durable bootstrap and before IndexGenerationStore.create, so the
refusal lands before any generation directory exists. The preflight is
unconditional, not gated on the cold_build_index flag: the build engages
automatically whenever the active generation is empty, which is exactly the
unattended case. A fresh root needs 276.8 MiB (the 256 MiB reserve floor
plus the 16 MiB receipt floor dominate), so an unconditional preflight does
not block a first daemon start.

Also closes the calibration loop. record_capacity_observation had the same
dead-route problem, so calibrated_index_ratio returned its unmeasured 4.0
default and always would. ColdBuildGeneration.promote now records the
observed peak after the readiness pass, through a public
IndexGenerationStore.observe_candidate_capacity. Measured evidence that 4.0
is low for this archive: 37.77 GiB of index from 7.47 GiB of durable
evidence is a ratio of 5.05.

Verification: devtools test on the cold-build, index-generation, capacity,
write-lease and write-coordinator selections (168 passed); devtools verify
--quick; devtools render all --check (no "out of sync").

Anti-vacuity, executed not asserted: removing require_candidate_capacity
from begin() turns
test_the_cold_build_refuses_before_it_allocates_a_generation red (3 failed,
6 passed); removing observe_candidate_capacity from promote() turns
test_a_promoted_cold_build_calibrates_the_next_projection red (1 failed, 8
passed).

Landing constraint: devtools schema closure reports both edited production
files IN the derived schema identity, so this must land before a fresh
rebuild starts, never during one.

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

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 37 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: d078c845-57fc-40ac-a0a0-3ca6685bed1e

📥 Commits

Reviewing files that changed from the base of the PR and between f47d4db and b15167a.

📒 Files selected for processing (3)
  • polylogue/sources/live/cold_build.py
  • polylogue/storage/index_generation.py
  • tests/unit/sources/test_cold_build_generation.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 21, 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-21T03:22:16.415237Z b15167a 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 21, 2026 03:17

@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: b15167ae37

ℹ️ 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/sources/live/cold_build.py Resolved
Comment thread polylogue/sources/live/cold_build.py Resolved
@Sinity
Sinity merged commit 1616c55 into master Sep 21, 2026
3 checks passed
@Sinity
Sinity deleted the fix/cold-build-capacity-guard branch September 21, 2026 03:26
Sinity added a commit that referenced this pull request Sep 29, 2026
## Summary

Test-only salvage of Codex-debt worker 16 (`polylogue-1tyq5.122`). Eight
unit tests now fail on the regression each one names, instead of passing
on a weaker proxy. No production code changes.

## Problem

Hosted review findings on earlier PRs showed that these tests could not
catch the defects they claim to guard. For example, the antigravity
symlink test used a `.md` path that the conversation walker never
considers. The blob-store fsync test also passed with every staged-file
fsync removed. The worker's patch arrived truncated. Eight complete
test-file diffs were recoverable. The ninth
(`test_durable_change_train.py`) was cut off after its header and is not
included.

## Solution

| key | disposition | evidence | test |
|---|---|---|---|
| 122.01 #4037 test_migration_load_evidence.py:357 | fixed-kept
(reworked) | query continuations are opaque `q2.` tokens
(`server_support.py` `_budget_envelope`), so the worker's
`arguments["offset"]` read raised KeyError | decodes the token and
requires `request.offset == returned_items` |
| 122.02 #4037 test_migration_load_evidence.py:460 | fixed-kept | status
check rejected only markers | status must contain no seeded session ID
either |
| 122.08 #5470 test_resource_pilot.py:104 | fixed-kept | `perf_counter`
timing test had no `uses_real_clock` marker | marker added with its
reason |
| 122.09 #5470 test_resource_pilot.py:116 | fixed-kept | receipt went to
captured stdout | `emit_receipt("pilot-provider-build-cost")` plus
readback |
| 122.12 #4788 test_antigravity_source_acquisition.py:187 | fixed-kept |
`.md` symlink is never a conversation candidate | symlinked `.pb` next
to a regular `.pb`; only the regular one is admitted |
| 122.13 #5325 test_cold_build_generation.py:263 | fixed-kept |
preflight depended on the runner's free space | `_free_space` pins 512
MiB, and the receipt must record it |
| 122.14 #5334 test_finished_build_equivalence.py:183 | fixed-kept |
both arms call `backfill_historical_revision_evidence` directly | arms
are described as replay configurations; receipt names the executed
`callable_identity`; the unexercised `production_driver` labels are
removed |
| 122.17 #5340 test_tool_result_unknown_reason_contract.py:982 |
fixed-kept | a success-only route would demand an unknown declaration |
origins come only from routes that expect `UNKNOWN` |
| 122.20 #4152 test_blob_store.py:65 | fixed-kept | first `fsync` could
be the directory sync | events are classified by `fstat`; the file fsync
must precede `replace` |
| 122.21 #4976 test_bulk_build_lifecycle.py:615 | fixed-kept | protocol
committed per session; production replay passes
`manage_transaction=False` (`revision_governance.py:555`) | each arm
runs in one caller-owned transaction; a trace callback requires exactly
`BEGIN`, `COMMIT` |
| 122.22 #4976 test_bulk_build_lifecycle.py:699 | fixed-kept |
measurements were dropped after the assertions |
`emit_receipt("finished-build-protocol-synthetic")` plus readback |

Removed from the worker's patch as tautological: an `any(...)` assertion
over the same set it iterated, a test asserting its own marker, and a
check that a dict it had just built lacked a key.

## Verification

- `agentctl job start polylogue verify_quick --workspace
/realm/worktrees/salvage-w16 --wait` → job 2591: `verify: PASSED exit=0
... head=d35b8dc637d8`
- `agentctl job start polylogue pytest_focused --workspace
/realm/worktrees/salvage-w16 --wait -- <all 8 files>` → job 2498 (before
the 122.01 rework): 198 passed, 4 failed. After the rework, job 2560 on
d35b8dc (the five files whose tests had failed or changed since
2498): 138 passed, 2 failed.
- The remaining failures are in tests this PR does not touch, and they
fail the same way on clean master 1beb2e5 (job 2561, 3 failed):
`test_resource_pilot.py::test_parser_resource_needs_only_provider_bytes`
and `::test_parser_resource_acquisition_opens_no_archive_tier` (the
ChatGPT parser opens `sqlite3.connect(":memory:")` at
`chatgpt.py:3017`), and
`test_bulk_build_lifecycle.py::test_fresh_shard_build_finishes_equivalent_to_retained_indexes`.
- Mutation proof, job 2501: with `_walk_source_paths` following symlinks
and the staged fsync removed from `write_from_bytes`, both the new
antigravity test and the new blob-store test fail (`2 failed`).

## Self-review

- **Sibling sites.** Both status and continuation assertions in the MCP
file were reviewed. The three sibling fsync sites in `blob_store.py`
share the same event classification, and only `write_from_bytes` is
exercised here, as before.
- **Cancellation, shutdown, unbounded reads.** Not applicable; no loops
or readers were added.
- **Fail-open fallbacks and compatibility shims.** None. The retired
`_routed_origin_names` and `production_driver` have no remaining
references.
- **Production route.** Every changed test drives the production
callable. 122.14 narrows its claim instead of pretending to exercise
drivers it does not call.
- **Removed symbols.** `rg _routed_origin_names|production_driver tests`
finds no remaining uses.

## Derived-identity closure

No production files are touched, so the closure does not move.

## Residuals

- Worker 16's 22 claimed fixes for `.120` and `.121` never reached a
branch, because the publication connector returned 502. They remain
open.
- Findings 122.10, 122.11, 122.24 and 122.25 were not reached (122.24
and 122.25 were in the truncated diff), along with the other `.122` and
`.123` findings.
- The three failures that already occur on master (above) are not
addressed here.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@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 bf68918):

  • P1 polylogue/sources/live/cold_build.py:120: Fixed on master (checked at bf68918): The capacity preflight now charges the prospective retained blob and source-DB growth of every accepted baseline revision that is not yet retained (cold_build.py:551-561), so pending intake is accounted before the generation is created.

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