Skip to content

fix: close 14 daemon/operations Codex findings; stage tier resets - #5824

Merged
Sinity merged 15 commits into
masterfrom
fix/9kemf-daemon-operations
Sep 29, 2026
Merged

Sinity merged 15 commits into
masterfrom
fix/9kemf-daemon-operations

Conversation

@Sinity

@Sinity Sinity commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes the 14 confirmed Codex P1 findings on bead polylogue-9kemf (daemon and operations). 13 were implemented by the previous owner in lanes that are now integrated; this head adds the missing half of 07.F012 (a working, quiescent reset of the derived tiers), fixes three defects the self-review found in the earlier fixes, and merges master through c950478.

Problem

Each finding names a concrete input and wrong outcome at master 64a9bd0; the per-finding table below gives the fix and the regression test. Evidence for the one design choice beyond the findings: a probe that initializes an archive root, deletes one tier and re-initializes shows index.db and ops.db re-bootstrap, while a missing source.db or user.db is refused ("archive format marker names a missing durable tier"). So reset --database --include-source-db/--include-user-db produced an archive that no longer opens.

Solution

07.F012: the daemon never unlinks a tier it holds open. maintenance.reset naming index.db/ops.db now prepares, authorizes and begins the audited plan and returns result.state = "staged" with nothing deleted. The attempt belongs to the daemon process; after it exits, the next start resolves the plan at a new seam, apply_staged_archive_resets, which runs under exclusive archive ownership right after durable migrations and before the schema preflight or anything else opens a tier. There each identity-matched database is deleted with every sidecar beside it (a stale -wal would otherwise replay into the file bootstrap creates next), the plan's other targets go with it, bootstrap recreates the tiers, and the empty index cold-builds. Ordinary recovery and live APPLY keep refusing tier files (RecoveryDeferredError, reset_live_archive_tier). A reset now deletes only index.db and ops.db: --include-source-db, --include-user-db, their request fields and the source-risk helper are removed, and a target that is or holds a durable tier, embeddings.db or a directory of tiers is refused with reset_unresettable_archive_tier before any audit row. Operator guidance that said ops reset --index && polylogued run now says to restart the daemon.

Self-review fixes to earlier commits on this branch:

  • 07.F032 exposed the raw sweep as pending for its whole traversal, so the service ran at its 50 ms cadence through every sweep and re-swept after each 5 s idle, on any archive size. A sweep after a completed one now pages at the idle cadence until nine times the previous sweep's duration has passed, so prompt paging holds about a tenth of wall time at most, and a raw that becomes owed without an arrival is still reached within about ten sweep durations.
  • 03.F036 snapshotted two callers, but the multi-COUNT read is FtsDerivationAdapter.inspect_partition, which the status component (operations/daemon_status.py) and the archive search check also call in autocommit. The owner now reads one snapshot outside a caller's transaction.
  • The migration gate's new blob-closure cache kept a full blob-hash set for every backup root a process ever gated; it now keeps one package.

Lane reconciliation

Every lane commit has the same git patch-id --stable as a commit already in this branch; no lane had uncommitted work.

Lane branch Lane commit In this branch
fix/9kemf-acquisition c9187ea5ca f970e73
fix/9kemf-backup dcc71f553d b874844
fix/9kemf-reads, fix/9kemf-reset-lifecycle a69ea8ee8a 49e8e2f
fix/9kemf-finalize 94899b5889 b242cca
fix/9kemf-evidence-paging 62ea7fb 242158c

Per-finding table

Finding Thread Fix Regression test
07.F002 rate-limit 403 PRRT_kwDOR7_N4c6htlUB Drive gateway types a 403 as DriveAccessDeniedError only when its body names no quota or rate reason; _permanent_failure trusts only the typed errors (sources/drive/gateway.py, operations/attachment_convergence.py) tests/unit/sources/test_drive_gateway.py, tests/unit/daemon/test_attachment_convergence.py
07.F004 supplying acquisition PRRT_kwDOR7_N4c6htlUJ attachment_refs.supplying_raw_id carried through projection carry-forward; blob refs keyed on it and rechecked under the writer tests/unit/daemon/test_attachment_convergence.py, tests/unit/daemon/test_attachment_convergence_excision.py
03.F003 self-contained backups PRRT_kwDOR7_N4c6dhFJo Recoverable source blobs are copied into the package as exact bytes; verification and the migration gate require the package's own closure (storage/backup_blob_closure.py) tests/unit/daemon/test_backup.py
07.F050 ZIP admission on replay PRRT_kwDOR7_N4c6dhFJy Reacquisition and blob-integrity replay run acquisition's admission over the whole central directory first tests/unit/sources/test_export_member_addressing.py
07.F039 transient SQLITE_IOERR PRRT_kwDOR7_N4c6mZP1a IOERR is retryable with a settlement deadline tests/unit/daemon/test_daemon_cli.py
07.F012 reset under open handles PRRT_kwDOR7_N4c6hxRpC Staged reset applied at the startup seam; durable tiers never deleted tests/unit/cli/test_reset.py, tests/unit/operations/test_mutation_actuators.py, tests/unit/daemon/test_daemon_cli.py
03.F036 FTS snapshot PRRT_kwDOR7_N4c6fB1LQ One read snapshot in inspect_partition, fallback readiness and search admission tests/unit/storage/test_search_readiness_snapshot.py, tests/unit/daemon/test_fts_readiness_fallback.py
03.F031 backfill failures PRRT_kwDOR7_N4c6lBTsi Any failed key makes the backfill outcome failed (embedding_keys_failed); CLI exits 1 tests/unit/daemon/test_daemon_operation_route.py, tests/unit/cli/test_embed_activation.py
03.F045 HTTP import re-ingest PRRT_kwDOR7_N4c6hsun8 Imports stage in unwatched import-staging/, keyed on the caller's path tests/unit/cli/test_import.py, tests/unit/operations/test_ingest_inputs.py
07.F024 remote poll cadence PRRT_kwDOR7_N4c6hvRWI Configured remote polls hourly from completion tests/unit/daemon/test_intake_scheduling_lifetimes.py
07.F032 valid-only pages PRRT_kwDOR7_N4c6hy_V0 Raw discovery reports an unfinished sweep, paced as above tests/unit/daemon/test_intake_scheduling_lifetimes.py
07.F036 restart-scoped halts PRRT_kwDOR7_N4c6kob3F Structural source halts stay process-local and visible in status tests/unit/daemon/test_fair_resumable_intake.py, tests/unit/daemon/test_intake_scheduling_lifetimes.py
03.F018 restore blob bytes PRRT_kwDOR7_N4c6h1J9g Raw derivation stages exact direct-source bytes for an absent retained blob; the writer publishes them and consumes their receipts tests/unit/storage/test_raw_observation_derivation.py
07.F049 oversized evidence rows PRRT_kwDOR7_N4c6khB6q Byte-bounded field fragments with a snapshot-bound cursor across daemon, API, CLI and MCP tests/unit/operations/test_session_evidence_readers.py, tests/unit/cli/test_evidence_fragments.py, tests/unit/mcp/test_session_projection_table.py

Derived-identity closure

These closure members change, so this PR must land before any rebuild starts: archive/artifact_taxonomy/runtime.py, archive/query/transaction.py, core/errors.py, operations/specs.py, sources/drive/{gateway,source_client,types}.py, sources/live/watcher.py, storage/backup_blob_closure.py, storage/blob_integrity.py, storage/blob_publication.py, storage/derived/session/input_binding.py, storage/fts/derivation.py, storage/sqlite/archive_tiers/{archive_tiers_specs,bootstrap,embeddings,index,query_unit_frame,write}.py, storage/sqlite/migration_runner.py. The closure baseline grows by two members, storage/backup_blob_closure.py and storage/blob_integrity.py, both imported by the migration gate that now decides package completeness. The index DDL gains attachment_refs.supplying_raw_id and the file_edits/web_content_constructs frame triggers (index-only); no durable-tier or embeddings DDL changes.

Verification

  • agentctl job start --workspace /realm/worktrees/astra-9kemf polylogue verify_quick: job 3373 succeeded on 7d5c109 (all static gates, including mypy, layering, schema-closure and generated-surfaces)
  • agentctl job start --workspace /realm/worktrees/astra-9kemf polylogue pytest_focused -- <58 affected files>: job 3374 on 7d5c109: 9 failed, 1904 passed, 1 xfailed; the 9 are the inherited failures below. The selection is in the job argv.
  • Inherited failures, checked with pytest_focused -- --on-default-branch <ids> in a detached master worktree at c950478 (job 3368, 9 failed, 1 passed): the four test_raw_observation_derivation.py worker cases, three test_schema_policy_contracts.py cases, test_durable_migrations.py::test_one_open_applies_every_numbered_step_to_the_declared_version and test_daemon_http_security.py::TestNoTokenLogging::test_no_token_in_log_or_print_calls fail identically on master.
  • test_daemon_operation_route.py::test_cancelled_long_delete_retains_writer_until_blocked_apply_releases failed once on 2adba04 (job 3358) under four-worker load, passes alone on master (job 3368) and passed in job 3374.

Self-review

Codex review is off for this PR, so this pass is the review. Checklist from docs/review/codex-review-guide.md and the orchestrate worker contract, final pass over the whole diff against master:

  1. Siblings and owners. FTS snapshot moved into inspect_partition, the one owner for all four callers. The reset CLI preview and the daemon's _reset_targets both resolve targets (pre-existing split); both now name only index and ops. Two sibling gaps are filed rather than fixed: ZIP-member blob restoration in raw derivation (polylogue-0y17g) and a single owner for which source window proves a retained blob, shared by backup proofs and raw restoration (polylogue-ihq32).
  2. The fix itself. The staged reset leaves a running run until restart; overlapping resets are refused as concurrent work, other mutations are unaffected because the owner is live. The raw sweep fix introduced continuous resweeping; paced. The new next_action text failed the runnable-command contract; now a command chain.
  3. Memory and limits. The unbounded closure cache is now one slot. No new cap or truncation; the resweep pacing delays work and drops none.
  4. Cost per unit. Prompt paging duty cycle no longer grows with archive size. ZIP admission per replayed member walks the central directory the replay already reads.
  5. Interruption. Seam deletion is convergent: a crash after a database is unlinked leaves its sidecars for the next start, which deletes them because the database is gone; a recreated database (new inode) is left with its sidecars.
  6. Ordering and races. The seam runs under exclusive ownership before any tier opens; the test asserts no descriptor on a tier file at the seam.
  7. Failure classification. A deletion error at the seam becomes a typed replay-failed resolution; outside the seam a tier reset stays pending (RecoveryDeferredError).
  8. Silent outcomes. The staged response says state: staged, deleted: 0; the CLI prints "Nothing has been deleted yet" and the restart step.
  9. Cleanup on failure. Unresettable targets are refused before any audit row.
  10. Identity and keys. Reset identity is (st_dev, st_ino) from PREPARE.
  11. Lossless transforms. N/A to the reset; carry-forward keeps supplying_raw_id.
  12. Degenerate inputs. No existing tier targets takes the live route; an absent database with a stale sidecar is swept.
  13. Consumers. Removed flags and request fields have no remaining reference (grep for include_source_db|include_user_db|unresolvable_raw_source_count is empty); CLI reference regenerated; stale daemon/backup.py paths updated.
  14. Tests and stubs. Each new test names the mutation that turns it red and drives the production route.
  15. Trust boundaries. N/A.

Residuals

  • test_cancelled_long_delete_retains_writer_until_blocked_apply_releases asserts a timeout within a fixed window and failed once under four-worker load and passed on the final head; see Verification.
  • The staged reset applies at the next daemon start; the daemon does not restart itself.
  • polylogue-0y17g and polylogue-ihq32 track the two sibling gaps above.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

Sinity and others added 15 commits September 29, 2026 14:20
- maintenance.reset refuses any target that is, or holds, an archive tier database or sidecar the serving daemon has open (typed reset_live_archive_tier), before any audit row or deletion (07.F012).
- The unbound FTS status fallback and sync search admission read every COUNT and the admitted rows from one snapshot (03.F036).
- An embedding backfill pass with failed keys finalizes as failed with error embedding_keys_failed in the durable receipt and the returned envelope; the CLI exits 1 on that outcome (03.F031).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lob bytes

Backup copies a missing source-owned blob into the package only as the
exact bytes its acquisition source still holds; verification and the
migration backup gate derive the required blob set from the package's
own tiers and never replay an acquisition file, so a signed package
missing a required blob is refused (03.F003).

ZIP reacquisition runs acquisition's ZipEntryValidator over the whole
central directory before decompressing a member (07.F050).

Raw derivation stages an absent retained blob from the exact window of
its direct source and publishes it through the writer's reservation
protocol instead of retrying forever; an unrecoverable raw fails with a
typed reason (03.F018).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve polylogue-9kemf 07.F049 with snapshot-bound field-byte continuations shared by daemon, Python API, CLI and MCP. Preserve exact completed-row counts and normal small-row projections; never materialize a whole oversized file edit before paging it.

Validated: 115 focused regression/parity tests passed; all 12 devtools verify --quick gates passed. Index-only schema change: epoch triggers for file_edits and web_content_constructs.
…erations

# Conflicts:
#	docs/plans/schema-closure-baseline.json
…le tiers

The daemon holds index.db and ops.db open, so maintenance.reset naming
them now records the authorized plan and a running attempt and deletes
nothing. The next polylogued start resolves the plan at a new seam,
apply_staged_archive_resets, under exclusive ownership and before any
tier opens: identity-matched databases go with every sidecar beside
them, and bootstrap recreates the tiers. Ordinary recovery leaves such
a plan pending.

An established archive missing source.db or user.db refuses to open, so
--include-source-db and --include-user-db are removed with their request
fields and the source-risk helper. A target that is or holds a durable
tier, embeddings.db or a directory of tiers is a typed refusal before
any audit row.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
…losure cache

- Raw discovery keeps the first sweep prompt, but a sweep after a
  completed one pages at the idle cadence until nine sweep durations
  have passed, so prompt paging holds a bounded share of wall time on
  any archive size (the 07.F032 fix otherwise re-swept continuously).
- FtsDerivationAdapter.inspect_partition reads its COUNTs in one
  snapshot outside a caller transaction, which covers the status
  component and archive readiness callers the 03.F036 fix missed.
- The migration gate's blob-closure cache keeps one package instead of
  every backup root the process ever gated.
- Point stale daemon/backup.py references at operations/archive_backup.py.

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

# Conflicts:
#	polylogue/sources/live/watcher.py
@Sinity Sinity changed the title fix: address 13 daemon/operations findings in 9kemf; contain unsafe reset fix: close 14 daemon/operations Codex findings; stage tier resets Sep 29, 2026
@Sinity
Sinity marked this pull request as ready for review September 29, 2026 15:53
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Sinity
Sinity merged commit 5d56c3a into master Sep 29, 2026
3 checks passed
@Sinity
Sinity deleted the fix/9kemf-daemon-operations branch September 29, 2026 15:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 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
🔒 Security Review ✅ Completed 2026-09-29T16:00:19.241999Z 7d5c109 Draft marked ready
ℹ️ 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 added a commit that referenced this pull request Sep 29, 2026
## Summary

A full-prefix fallback proof in a `full_evidence` backup now records the
window it proved, so verification rebuilds that window.

| Bead | Finding | Thread |
| --- | --- | --- |
| polylogue-wbv7k | 18.F001 Preserve the full-prefix shape in recovery
proofs | PRRT_kwDOR7_N4c6eyazk |

## Problem

`_source_recoverability_proofs` (`operations/archive_backup.py`) handles
an append row whose retained blob is the whole observed prefix `[0,
end)`, which `admit_raw_observation` writes while recording only the
tail's offsets. It proves the row from that prefix, then emits the proof
with the row's own `append_start_offset`. Verification rebuilt `[start,
end)` from the proof. That hash can never match the prefix blob, so a
correctly proved backup failed its reference evidence.

## Solution

When the fallback proves the blob from `[0, end)`, the proof records
`append_start_offset=0` and `append_end_offset=end`. The historical
legacy-replay window uses the same variables (`proof_append_start` and
`proof_append_end`). A proof is emitted only for a matched payload, so
the window is always the one that was hashed.

Derived-identity closure: none of the changed files is in the closure.

## Verification

- `agentctl job start --workspace <wt> polylogue pytest_focused --
tests/unit/daemon/test_backup.py tests/unit/cli/test_backup_command.py`
(job 3454, head f85601c): `devtools test: PASSED exit=0
diagnosis=pytest_passed`, 77 passed.
- `agentctl job start --workspace <wt> polylogue verify_quick` (job
3440, at 4da20dd, before the test-only follow-up): succeeded. The
pre-push hook's `devtools verify --quick` passed on f85601c.
- The rebase onto master (the backup module moved to
`operations/archive_backup.py` in #5824) renamed the verification key to
`recovered_source_blob_count`. The new test now reads that key.

## Self-review

The final pass against `docs/review/codex-review-guide.md`, over the
whole diff against master:

1. Siblings and owners: ✓. The window is decided in one place, the proof
dict. The windowed, legacy-replay and full-prefix branches all feed it
through `proof_append_start` and `proof_append_end`.
2. The fix itself: ✓. The emitted offsets are strings, as before. With
no proof window, the row's own offsets are emitted unchanged.
3. Memory and limits: ✓ N/A. There are no new reads.
4. Cost per unit: ✓ N/A.
5. Interruption: ✓ N/A. This only builds the manifest.
6. Ordering and races: ✓ N/A.
7. Failure classification: ✓. An unmatched payload still records its
error and emits no proof.
8. Silent outcomes: ✓. Verification now accepts proofs that it
previously rejected by mistake. Nothing is skipped.
9. Cleanup on failure: ✓ N/A.
10. Identity and keys: ✓. The proof names exactly the bytes that were
hashed.
11. Lossless transforms: ✓. The other proof fields are unchanged.
12. Degenerate inputs: ✓. `end` comes from the row's own parsed
`append_end_offset`, and a `ValueError` still records `append_segment:`.
13. Consumers: ✓. The verifier reads `append_start_offset` and
`append_end_offset` and needs no change.
14. Tests and stubs: ✓.
`test_full_evidence_backup_verifies_a_full_prefix_append_proof` drives
`backup_archive(..., verify=True)`. It fails when the proof carries the
row's start offset (3).
15. Trust boundaries: ✓ N/A.

## Residuals

- `_legacy_append_replay` is a pre-envelope path, and it picks its
predecessor by `acquired_at_ms` (wall clock). Both belong to the 9kemf
backup rework. They are not changed 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]>
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