Skip to content

fix: Give the rebuild denominator an operator route and rebind attachments per attachment - #5304

Merged
Sinity merged 3 commits into
masterfrom
fix/w4-source-custody
Sep 20, 2026
Merged

Sinity merged 3 commits into
masterfrom
fix/w4-source-custody

Conversation

@Sinity

@Sinity Sinity commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Summary

Source-custody lane. Two real defects fixed; four beads found already satisfied at head with no change manufactured.

co2iz — the frozen rebuild denominator had no operator route

preflight_rebuild / require_rebuild_preflight existed but had no production caller at all — grep over the checkout returned its own definition and two test callers. No operator could produce or consume the wanted-source receipt outside tests, so "ingests the intended retained material" had no verifiable denominator.

Adds polylogue ops maintenance wanted-sources, which authorizes from the frozen receipt and emits receipt_sha256, policy_identity, declaration_sha256, frontier_sha256 and item/byte counts. There is no fallback path that walks the roots — it accepts only a complete, valid receipt.

Output is digest/count shaped and never a path; the receipt lives under <archive_root>/.maintenance-state/wanted-sources/ with a 0o700 state dir.

ck5v — attachments of one raw were indistinguishable after a rebuild

New defect, found red-first. Convergence wrote every attachment's blob_ref under one raw-wide coordinate, source_url or "attachment-convergence" — and source_url is None for every Drive document. A raw with two live-fetched attachments produced two indistinguishable refs; after a derived-tier rebuild _surviving_blob_ref refused as ambiguous, both rows fell through to the provider, and a deleted Drive file marked them terminally unavailable while the retained bytes sat unreferenced in the blob store.

Red at head, verbatim: AssertionError: assert ['drive-file-...drive-file-a'] == []
(receipt 20260920T194301Z-focused-test-1810967-23fd3bd4)

Fixed with a per-attachment acquisition coordinate. The test asserts durable index rows and blob_refs counts, not helper calls; reverting the coordinate restores the red.

Found already satisfied — no change manufactured

  • nru50 AC4/AC5 — refuse-before-allocate (candidate_capacity.py:757-763 called from index_generation.py:779 before create) and predicted-vs-actual peak recording both implemented at head.
  • om8dh AC2 — one row per distinct (raw_id, capture_mode) with an explicit no-op for None, so content-hash dedup collapses bytes without collapsing acquisition evidence.
  • lisa2 producer half — the attachment_unreferenced producer defect is already fixed at write.py:1631-1646.
  • k8wv AC2/AC6/AC7 — the 383 root-level journal mirrors now get a typed refusal rather than being folded.

Verification

Thirteen focused runs, all receipts recorded. devtools verify --quick exit 0 on the rebased head. devtools render all --check exit 0, out of sync count 0. devtools schema closure: every production file touched is out — no identity movement, so landing order is unconstrained by closure.

One red was reported honestly as contention, not inheritance: a 10k-event throughput assertion measured 1747 events/s against a 2000 floor under a contended pool, then passed alone on the same head. The lane declined to claim inheritance without building an origin/master worktree to prove it.

Residuals that need owners

  • The two attachment-ref vocabularies do not meet. Ingest writes blob_refs keyed by the raw session coordinate; convergence looks up by the attachment coordinate. Correct today, but it means widening the upload_origin='drive' filter alone would be a no-op — it selects rows the survival probe cannot match. A future non-Drive backfill owner must fix the key, not the filter.
  • The precomputed_blob branch marks a ChatGPT .dat asset acquired without appending an ArchiveSourceBlobRef, unlike the inline_bytes branch beside it. Nothing is unreachable (the index owner keeps it GC-visible), but the durable source ledger has no attachment ref for that acquisition. Worth a ruling before the build.
  • The hook spool is growing, not draining: 716,754 pending files today vs 632,311 at the 2026-09-13 freeze. The manifest must be re-frozen immediately before the drain or conservation will not close. Measured drain rate: 10k fold+materialize in 3.09s.
  • IndexGenerationStore.create_transaction still has no production caller — the final-build driver does not exist yet. When it lands it should call require_rebuild_preflight beside require_candidate_capacity.
  • co2iz AC6 names two test selectors that do not exist at head; the AC text is stale.

🤖 Generated with Claude Code

https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq

Sinity and others added 3 commits September 20, 2026 22:11
…rebuild (polylogue-ck5v)

Attachment convergence wrote every durable `blob_refs` row for a fetched
attachment under one raw-wide coordinate: `source_url or
"attachment-convergence"`, and `source_url` is `None` for every Drive-hosted
document (sources/parsers/drive_support_attachments.py:114,145 never set it).
A raw carrying two live-fetched attachments therefore produced two refs the
survival probe could not tell apart. After a derived-tier rebuild both index
rows came back `unfetched`, `_surviving_blob_ref` refused as ambiguous, both
rows fell through to the provider, and a deleted Drive file marked them
terminally `unavailable` while the retained bytes sat unreferenced in the blob
store.

The acquisition coordinate is now per attachment: `source_url` when the row
has one, otherwise the provider file id. The probe and the written ref use the
same name, so the ambiguity refusal is reserved for genuinely
indistinguishable evidence.

`devtools schema closure polylogue/operations/attachment_convergence.py`
reports `out`: no derived-schema identity movement, no reconvergence
consequence.

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

`source_manifest_continuity` already builds, seals, loads and preflights the
private wanted-source receipt, and `preflight_rebuild` already refuses a
missing, tampered, incomplete or policy-revised one. Nothing in production
called any of it: `require_rebuild_preflight` had test callers only, so no
operator could produce the receipt the final build is supposed to be
authorized against, and a rebuild that started without one would simply walk
whatever the source roots held at the time.

`polylogue ops maintenance wanted-sources` is that route. `--freeze`
enumerates the configured declarations once under the campaign policy and
atomically publishes the receipt into the archive's private maintenance
state; the default direction is read-only and authorizes from the frozen
receipt alone, printing the receipt digest, policy identity, declaration and
frontier digests and the denominator totals. The output is digest- and
count-shaped: source ids, roles and root states, never a path.

`devtools schema closure` reports `out` for both production files.

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

The plain-text branch read its digests and counts back out of the JSON
payload dict, so mypy saw `object` where an int format spec and an iteration
were required. The command now carries typed locals and a `_RootRow` tuple,
and the payload is derived from them rather than the other way round.

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 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 44 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: 8349fe91-09a6-4869-8e62-c2979eae3e73

📥 Commits

Reviewing files that changed from the base of the PR and between 9d0fdac and 4b485b0.

📒 Files selected for processing (5)
  • polylogue/cli/commands/maintenance/_wanted_sources.py
  • polylogue/maintenance/declarations.py
  • polylogue/operations/attachment_convergence.py
  • tests/unit/cli/test_wanted_sources_cli.py
  • tests/unit/daemon/test_attachment_convergence.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 20, 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-20T20:43:32.387877Z 4b485b0 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.

@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: 4b485b0a8d

ℹ️ 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".

@Sinity
Sinity merged commit 5c2fae0 into master Sep 20, 2026
3 checks passed
@Sinity
Sinity deleted the fix/w4-source-custody branch September 20, 2026 20:51
Sinity added a commit that referenced this pull request Sep 20, 2026
…e conflicts

polylogue-8v4rm AC1 and AC2.

AC1 -- ownership. `source_attachments` declares acquired material with a
verified `blob_hash` (its DDL CHECK requires hash, bytes and payload identity
for `disposition = 'acquired'`, and the writer re-hashes the payload), but
`BLOB_OWNERS` did not recognise the table. The only liveness surface for
those bytes was `index.attachments`, so a rebuildable tier decided whether
durable bytes survived -- the same root polylogue-o0uw5 measured as 1240 of
1446 acquired attachment hashes with no payload left.

Direction check: `_direct_surfaces` APPENDS to the surface list, so adding an
owner can only move a hash from `unreferenced` to `live`. No path can make a
currently reachable hash collectable. The new owner pins exactly the hashes a
`source_attachments` row claims were retained -- an acquired original, or a
`duplicate`/`partial` row that genuinely carries stored bytes -- so it does
not blanket-pin and does not hide a genuine orphan. `source_attachments` is
in the current fresh-floor source DDL, so it stays a REQUIRED owner in
`_schema_blockers` rather than joining `_OPTIONAL_OWNER_TABLES`, which exists
for owners a later additive migration introduced.

AC2 -- replay semantics. `record_source_attachments` used
`ON CONFLICT(source_generation_id, reference_id) DO NOTHING`, so two
different terminal facts for one reference silently kept whichever arrived
first, with no record that the archive had been told two incompatible
things. Recording now compares the ten declared columns:

* identical replay is a no-op (the stored `updated_at_ms` does not move);
* `pending` -> terminal is the one allowed progress transition and updates
  every declared column, inside the caller's batch transaction;
* anything else raises the typed `SourceAttachmentConflictError`, naming the
  reference, the field, and both values. The stored row is unchanged.

Row reads select positionally and zip against the declared field tuple: this
module does not own the caller's `row_factory`.

Not addressed here, reported as unresolved: AC3's explicit representation of
unresolved attachment attribution, and AC4's retirement of the remaining
per-table liveness interpretations. #5304's finding that ingest keys
attachment refs by the RAW SESSION coordinate while convergence keys them by
the ATTACHMENT coordinate is untouched by this change -- it adds a direct
`blob_hash` owner, not a `blob_refs` ledger entry, so neither vocabulary
moves.

Verification: devtools test tests/unit/storage/test_blob_gc_durable_intent.py
tests/unit/storage/test_blob_gc.py tests/unit/storage/test_blob_liveness.py
tests/unit/storage/test_blob_gc_ref_type_liveness.py
tests/unit/storage/test_blob_gc_generation_gate.py
tests/unit/storage/test_blob_gc_raw_authority_verdict_invariant.py
tests/unit/storage/test_source_attachments.py -> 84 of 85 passed, receipt
.cache/verify/runs/20260920T213448Z-focused-test-2089150-536344e1/run.json.

The single failure,
test_blob_gc_durable_intent.py::test_v33_source_migrates_additively_to_exact_gc_member_intent,
is INHERITED: it fails identically on a detached checkout of origin/master
005b688 with none of this branch applied (receipt
.cache/verify/runs/20260920T213728Z-focused-test-2093977-caf71c1c/run.json,
"source migration target 35 is newer than this runtime expects (1)"). It
drives a retired source migration chain. Not fixed here.

Anti-vacuity, stated on each new test: dropping the `source_attachments`
entry from `BLOB_OWNERS` makes the owner test red; restoring
`ON CONFLICT ... DO NOTHING` makes the conflict test red; raising on every
difference makes the pending-to-terminal test red; raising unconditionally on
a second recording makes the idempotent-replay test red.

Closure: polylogue/storage/blob_liveness.py and
polylogue/storage/sqlite/archive_tiers/source_attachments.py are both IN the
derived schema identity closure, so this moves the identity and must land
before a rebuild starts.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq
Sinity added a commit that referenced this pull request Sep 22, 2026
)

## Summary

`polylogue-co2iz` AC3 requires the final rebuild preflight to accept
only a complete, valid receipt and **never silently fresh-walk ambient
source roots**. The check existed; the build driver never called it.

## Problem (evidence at `158d1363e`)

`require_rebuild_preflight`
(`maintenance/source_manifest_continuity.py:664`, real entry
`preflight_rebuild` at `:641`) has owned this since #5304. Its complete
production caller set was **one CLI command** —
`cli/commands/maintenance/_wanted_sources.py:103,138`.

`ColdBuildGeneration.begin` — the actual final-build driver — called
only `require_candidate_capacity` (`sources/live/cold_build.py:120`). So
a cold build could start with **no frozen denominator at all**, and the
rebuild's conservation proof would have nothing fixed to reconcile
against.

## Solution

Authorization runs before allocation and before the capacity walk,
because its refusal means *"this build must not happen"* rather than
*"not here, not now"*.

Like the capacity preflight, it is **not** conditioned on operator
intent — the docstring at `cold_build.py:97-102` already settles that:
the build engages automatically whenever the active generation is empty,
which is exactly the unattended whole-archive case that must not run
unauthorized.

It *is* conditioned on a denominator existing at all, which is a
different question. `build_wanted_source_receipt` itself refuses an
empty denominator, so requiring a receipt where no source is declared
would make every live-capture-only archive permanently unbuildable. That
bootstrap path emits `daemon.cold_build.wanted_sources_undeclared` and
is pinned by a test — declared, not silent. Once a receipt *is*
published it validates unconditionally even if the roots were later
undeclared: a frozen denominator the current configuration no longer
matches is a **typed refusal**, never a downgrade.

`wanted_source_receipt_is_published` exists to separate "there is no
receipt" from "the receipt is tampered", which
`load_wanted_source_receipt` reports through one exception type. No
branch falls back to walking source roots fresh.

## Verification

Exit codes read directly, not through a filter.

```
devtools test tests/unit/sources/test_cold_build_generation.py \
              tests/unit/maintenance/test_source_manifest_continuity.py
  -> PASSED exit=0
  receipt .cache/verify/runs/20260922T010507Z-focused-test-224388-d3e0f78c/run.json

devtools verify --quick   -> exit 0, all 25 gates ok (test-collection 100.0s)
devtools gate schema-closure -> ok, 557 members, 0 added, 0 removed
```

Four tests: refuse-unfrozen, refuse-tampered, authorize-valid, and the
undeclared bootstrap path — the last pinning the opposite direction so
"refuse everything" fails.

## Schema identity

`cold_build.py` and `source_manifest_continuity.py` are both closure
**IN**, so the derived index identity moves `d5e285b3… → 7cb86235…`; ops
is unchanged at `86866235…`. Closure *membership* is unchanged (557 both
sides), so no baseline update is required. **This must land before a
fresh rebuild starts, never during one.**

## Residual

The live host currently declares no source roots
(`resolve_runtime_config().source_paths.explicit == ()`), so on that
archive this guard takes the declared bootstrap path. Declaring the
roots and freezing the receipt against the fresh root is an operator
action, and `co2iz` stays open for it — this PR closes AC3's code half
only.

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

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

Co-authored-by: Claude Opus 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 64a9bd0):

  • P1 polylogue/operations/attachment_convergence.py:117: Not a defect (checked at 64a9bd0): The remedy asks for a compatibility read or migration of blob_refs written under a pre-upgrade attachment-convergence coordinate. Repository policy starts every tier fresh at v1 and treats a compatibility path or a migration of prior archive state as a defect (AGENTS.md:74-77, 192-194).

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

@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 f88b4a6):

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