Skip to content

fix(daemon): repair backup scope, restart resume and derivation barrier - #5664

Merged
Sinity merged 8 commits into
masterfrom
claude/bugsweep-bc
Sep 27, 2026
Merged

Sinity merged 8 commits into
masterfrom
claude/bugsweep-bc

Conversation

@Sinity

@Sinity Sinity commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Summary

Four daemon and backup defects from the bug sweep:

  • Backups copy every source generation's live blobs, so a restore no longer carries earlier generations' rows without their bytes.
  • Restart resumes an accepted request whose daemon died before its first part, instead of reporting accepted forever.
  • Derivation owners honor the Sinex primary publication barrier that the staged routes already honored.
  • DaemonConverger.summary() counts a file that failed and later converged once.

Problem

  • backup.py copied source.db whole but scoped the copied blob set, and the debt report computed from it, to the newest sealed generation. Earlier generations' raw_sessions and blob_refs rows came back without their blobs, and nothing counted the gap.
  • operation_runtime.py returned any durable non-terminal record without dispatching. An execution batch durably accepted just before its daemon died, with every part unattempted, stayed at accepted on every retry. Its handler already resumes unstarted parts and never replays a consumed one.
  • Derivation owners (FTS, session profile, summary, usage rollup, embeddings) run their own DaemonConverger with no stages. The Sinex stage's blocks_following_stages never reached them, so in primary mode they could derive a session whose newest revision was unpublished.
  • summary() counted error_count > 0 as failed even for a converged file, so the buckets overlapped and in_progress went negative.

Solution

  • Blob liveness and backup: blob liveness drops its generation filter. Backup, its debt report and restore verification all use the same all-generations reference set. A referenced blob missing from any generation is counted debt and fails verification.
  • Recovery authority: only a started attempt (running/indeterminate) is the recovery authority. accepted falls through to the live exchange if one exists, and otherwise to the handler.
  • Derivation barrier: the derivation kernel takes a PublicationBarrier. A session-derived domain implements barrier_sessions(frame, keys). A held key is pending/blocked, and an unreadable barrier holds everything. configured_derivation_barrier() returns the barrier only in primary mode, and composition passes it to all three owners. The blocking query moves to a module-level read, primary_blocking_object_ids, paged under SQLite's parameter ceiling.
  • Summary buckets: summary() makes the buckets mutually exclusive.

Verification

  • devtools test tests/unit/daemon/test_backup.py tests/unit/storage/test_blob_liveness.py tests/unit/daemon/test_converger_summary.py tests/unit/daemon/test_daemon_operation_route.py tests/unit/daemon/test_derivation_kernel_laws.py tests/unit/daemon/test_convergence_stages.py tests/unit/sinex tests/unit/storage/test_blob_conservation.py → 233 passed. test_cancelled_long_delete_retains_writer_until_blocked_apply_releases failed once under a saturated pool and passed alone on the automatic rerun.
  • devtools gate mypy → exit 0; devtools verify --quick → PASSED.

Residuals

  • devtools schema closure: blob_liveness.py, fts/derivation.py and three session derivation modules are IN, so this must land before a rebuild.
  • polylogue/daemon/convergence_stages.py also carries the lineage recompose stage another change is removing; the edits here don't touch it.

🤖 Generated with Claude Code

https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4

Sinity and others added 4 commits September 27, 2026 20:45
Backup copied source.db whole but scoped the blob set, and the debt
report computed from it, to the newest sealed generation. A restore
carried earlier generations' rows without their blobs and nothing
counted the gap. Project liveness over every generation, so the
backup, its debt report and verification see the same reference set.

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

The runtime returned any durable non-terminal record instead of
dispatching, so a request accepted just before a restart stayed at
accepted forever although its handler resumes unstarted parts safely.
Only a started attempt (running or indeterminate) is the recovery
authority now; accepted falls through to the live exchange or the
handler.

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

Staged routes honored the Sinex primary barrier, but derivation owners
run their own convergers without that stage, so FTS, session profiles,
summaries, usage rollups and embeddings could derive a session whose
newest revision was still unpublished. The kernel takes the barrier,
holds a session-derived key as pending/blocked, and holds everything
when the barrier cannot be read.

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

Copy link
Copy Markdown

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 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-27T21:36:45.239502Z 2f49d09 New commits
ℹ️ 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: 474e07de3c

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

…d sessions

Review follow-up. Marker lowering maps each carrier to every session it
names, so the barrier holds the batch when any waits. The barrier
applies only to required keys, since retiring excess output derives
nothing new, and a session no longer in the archive is never held, so
its leftover demand or bindings can retire.

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

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

ℹ️ 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/daemon/convergence.py Resolved
Comment thread polylogue/daemon/convergence_stages.py Resolved
Comment thread polylogue/daemon/convergence.py Resolved
Sinity and others added 2 commits September 27, 2026 22:12
…intenance

Review follow-up. The absent-session exemption moves from the global
barrier into the index-backed session domains, so marker carriers for a
deleted session still wait. Exact-target maintenance consults the same
barrier for required targets. summary() classifies failed from current
stage state only.

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

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

ℹ️ 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/daemon/derivation.py Resolved
…ssion

Review follow-up. Compute runs outside the writer, so a newer
unpublished revision can be staged between the pre-compute barrier
check and publication. Both the kernel and the selected maintenance
route now re-check inside the admitted publish and refuse it as
pending/blocked.

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

@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: 2f49d09d38

ℹ️ 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/daemon/cli.py Resolved
@Sinity
Sinity enabled auto-merge (squash) September 27, 2026 21:37
@Sinity
Sinity merged commit fffec1b into master Sep 27, 2026
3 checks passed
@Sinity
Sinity deleted the claude/bugsweep-bc branch September 27, 2026 21:40
Sinity added a commit that referenced this pull request Sep 27, 2026
## Summary

`polylogued run` now applies pending declared durable migrations when it
opens the archive, before it serves anything. A step that changes
existing data runs only behind a backup the daemon takes itself and
scratch-verifies.

## Problem

- Durable tiers (`source`, `user`, `audit`) evolve by numbered
migrations with change-train sidecars. #5646 deleted `ops maintenance
migrate-tier`, their only application route, so
`execute_durable_change_train` had no production caller.
- No durable migration is declared today. The first one would therefore
have shipped with no way to apply it except a maintenance command, which
the operator has ruled out.

## Solution

- `operations/durable_change_train.py` gains
`pending_durable_migrations`. It lists each durable tier standing below
the runtime's declared version that has a complete declared route (every
step from the current version to the target) and says whether any step
requires a backup. A tier with no declared route is left alone, and
schema preflight still reports its skew.
- `daemon/durable_migrations.py` adds
`apply_declared_durable_migrations`. For each pending tier it runs
`execute_durable_change_train` under the daemon's write lease, with the
daemon's exclusive archive ownership. The daemon keeps that ownership
afterwards, so the train's release is a no-op.
- For a step that requires a backup, `pre_migration_backup` first runs
`backup_archive(verify=True)` into
`.maintenance-state/pre-migration-backups/`:
- It uses the `user_overlays` profile for user and audit, and
`rebuildable_cache_exclude` for source, which carries its blobs.
- The train binds the backup's authenticated receipt to the exact
pre-apply bytes.
  - A failed backup refuses startup.
- `backup_archive` accepts `archive_owner`: the caller's existing
exclusive ownership. The backup copies under that ownership instead of
acquiring its own, which the daemon's own lock would refuse at open.
- `daemon/cli.py` calls the route right after durable-change-train
reconciliation, inside the same ownership scope, and emits
`daemon.durable_migration.applied` for each applied tier.
- The durable-schema section of `docs/maintenance.md` describes the
route.

## Verification

- `tests/unit/daemon/test_durable_migrations.py` ships synthetic
numbered migration packages:
- An archive already at the runtime version is left alone and gets no
backup directory.
- An additive `source` step applies without a backup, and a second open
is a no-op.
- A data-changing `user` step applies only after a verified backup; the
manifest and verification receipt are present.
- `devtools test` over `test_durable_migrations.py`,
`test_daemon_cli.py` and `test_backup.py`: `185 passed, 3 failed`.
-
`test_run_daemon_services_parks_operation_recovery_on_audit_schema_mismatch`
failed because the first version tried to migrate a tier with no
declared route. That is fixed, and it passes on rerun with the migration
tests.
- `test_run_daemon_services_waits_for_fts_startup_before_watcher` (2
parametrizations) fails the same way on current master: its fake
converger lacks the `derivation_barrier` argument #5664 added.
- `devtools gate mypy`: `Success`.
- `devtools gate schema-closure`: `ok`, no change (567).

## Residuals

- The source-tier backup copies referenced blobs, so a data-changing
source migration pays that copy at open.

🤖 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 28, 2026
- expect an unavailable snapshot when no rich observation exists (#5621);
- let the converger test double accept derivation_barrier (#5664);
- expect the request model's normalized mark payload;
- measure a steady-state chunk: the first chunk after seeding also
  prunes the seeding's raw-existence journal, one trigger per row (#5657);
- inject the thread-insight failure at the ArchiveStore the route reads.

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

Fixes one product defect and realigns daemon and MCP tests that fail on
master because they encode superseded contracts.

## Problem

A per-directory run of `tests/unit/daemon` and `tests/unit/mcp` on clean
master (`03c543dfe`) failed 28 and 11 tests. This PR covers the clusters
below. Other failures belong to named owners or need a decision; see
Residuals.

- **Product defect: MCP hides daemon rejections.** When the resident
daemon refused a write before durable acceptance, MCP callers saw
`write: internal error (DaemonOperationRejectedError)`. The daemon's
typed code and detail were lost, for example why a saved view cannot be
watched.
- **MCP tests that write with no daemon.** Public archive writes are
daemon-owned since #5550. Nine MCP tests plus three standing-query tests
still wrote with no daemon and got `FacadeDaemonRequiredError`.
- **Stale daemon expectations:**
- Since #5621 a snapshot with no rich observation is `unavailable`, not
`stale`.
- #5664 passes `derivation_barrier` to the converger, which the test
double did not accept.
- The mark-delete route test compared against the raw payload rather
than the request model's normalized one.
- The chunk-cost test measured the first chunk after seeding. Since
#5657, that chunk also prunes the seeding's raw-existence journal, one
trigger firing per row, so its cost grew with archive size once.
- The insights failure injection patched the facade the route no longer
reads.

## Solution

- `_exception_to_error_json` relays `DaemonOperationRejectedError` with
the daemon's code and detail, as the CLI does.
- New `tests/infra/mcp.py::daemon_served_runtime_services` runs the real
operation stack on the archive's socket for MCP write tests. The
load-evidence test seeds its deliveries under the daemon and measures
reads without it.
- Each stale expectation is realigned; the chunk-cost test converges one
warm-up chunk and measures a steady-state chunk.

## Verification

`devtools test` over the affected daemon and MCP tests plus the MCP
error-translation tests: `165 passed, 1 failed` (receipt
`20260928T000820Z-focused-test-736375-35660df1`, pre-rebase). The one
failure is `test_working_dir_demand_withholds_profile_readiness`,
tracked in polylogue-6remh. The rebase kept master's own fix to
`test_convergence_debt_alert.py` and dropped this branch's change to
that file. No other conflicts.

Review follow-up (`f189af7`): `WatchDefinitionError` declares
`invalid_watch_definition`. MCP reports an undeclared (prose) rejection
code as `rejected`. `DaemonClient` keeps a pre-dispatch refusal's public
detail. `devtools test tests/unit/mcp/test_tool_error_isolation.py
…::test_skewed_write_refusal_is_pre_dispatch_not_an_indeterminate_mutation
tests/unit/daemon/test_standing_queries_default_evaluator.py` passed
(receipt `20260928T003051Z-focused-test-966381-9c978486`). `devtools
schema closure`: `archive/query/watch_definition.py` is IN, so this
lands before a rebuild.

## Residuals

- polylogue-6remh (filed): since #5570, periodic profile ticks run the
startup audit before demanded work. This starves demand and contradicts
#5540's idle-tick contract. It leaves
`test_two_accepted_revisions_survive_one_periodic_profile_pass`,
`test_working_dir_demand_withholds_profile_readiness` and likely
`test_real_factory_defers_hot_target_without_losing_the_no_hint_cursor`
red.
- Not covered here:
- master-fix-owned clusters: the read-authorizer `not authorized`
regression, `selected_session_parts` and `raw_observation_derivation`;
- daemon failures still to diagnose: schema preflight behind the #5657
frontier gate, status baseline `ok`, evidence-summary lineage authority,
stale archive storage, Drive asserted-authority growth, the watcher-hint
timeout, and status component metadata.

🤖 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]>
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