Skip to content

fix(daemon): name the archive at every write under a root-bound lease - #5782

Merged
Sinity merged 3 commits into
masterfrom
fix/daemon-cli-lease-tests
Sep 29, 2026
Merged

Sinity merged 3 commits into
masterfrom
fix/daemon-cli-lease-tests

Conversation

@Sinity

@Sinity Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Summary

tests/unit/daemon/test_daemon_cli.py failed on master because of a production defect, not the dependency bump. #5727 made a root-bound writer lease refuse any write that omits its archive identity, but it left callers that open without one. On fddc7a1 the daemon could not start: DaemonLifecycle.start opened ops.db unnamed under polylogued's root-bound lease. #5769 has since fixed the lifecycle and several daemon ops writers. This PR fixes the routes that were still refused and realigns three tests with contracts that later PRs changed.

Problem (evidence)

  • devtools test tests/unit/daemon/test_daemon_cli.py on plain origin/master 4cbf83b, with no lockfile bump: 29 failed, the same set as the bumped run. That rules out starlette, uvicorn, watchfiles, ruff, hypothesis and networkx.
  • 28 of the 29 were UnleasedWriteError: open_daemon_connection(.../ops.db) omitted archive identity for writer daemon.lifecycle.start, raised while the daemon started. The tests' own watch stopped, server stopped and shutdown marker failed expectations never ran. The 29th was the fix: Codex review debt: surfaces (51 findings) #5727 pidfile message change.
  • With the lifecycle fixed, nine more failures appeared. The same tests pass on 841bbb3, the commit before fix: Codex review debt: surfaces (51 findings) #5727. Traced causes:
    • SQLiteBackend.__init__ now runs the lease-gated initialize_active_archive_root on every construction, even for an established archive. The live batch reads Polylogue.backend outside the lease, so each intake item came back retryable: UnleasedWriteError: active archive bootstrap requires the daemon write lease.
    • Nested write_lease(actor) re-entry called require_write_lease without a root, so any derivation publish under a root-bound lease raised "omitted archive identity".
    • Daemon-emitted events re-resolved the ambient archive root instead of the daemon's own.
  • On master tip 14a63dc, the three touched test files still fail 14 tests: devtools test --on-default-branch tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_daemon_lifecycle.py tests/unit/storage/test_write_lease.py gives 151 passed, 14 failed.

Solution

Production (fix(daemon) commit):

  • Pass archive_root at the write opens that still omitted it. These are the FTS automerge, judgment automation, daemon assertion mutation, schema drift sampling, schema sampling and verification, secret scan, blob GC history, sqlite-vec runtime, the non-daemon branch of open_initialized_tier_connection, and connection_context, which gains the parameter.
  • Daemon lifecycle, parked-loop and live-batch events name archive_root_path.
  • Nested write_lease re-entry checks the held lease's own identity. It no longer checks an absent one.
  • initialize_backend_state runs the active-root bootstrap only when the caller may write: the bootstrap is needed, a lease is held, or enforcement is off. A daemon-armed caller without a lease gets the read-only assert_archive_format_lineage proof. An established archive therefore still has to prove its lineage marker, as fix: Codex review debt: surfaces (51 findings) #5727 intended.
  • arm_write_lease_enforcement(process_wide=True) no longer saves and restores the thread-local flag. fix: Codex P2 review debt: polylogue/cli part 1 (25 findings) #5722's overlapping-arming test exits out of order, which restored a stale armed=True and left the pytest thread armed for every later test in test_write_lease.py.

Tests, each disposition against the PR that changed the contract:

Test(s) Cause Disposition
14 UnleasedWriteError plus 13 watch/server stopped and shutdown marker failed lifecycle start under the root-bound lease (#5727) production bug. #5769 fixed the lifecycle, and this PR fixes the remaining writers
test_pidfile_remains_locked_until_admitted_writers_are_drained #5727 widened the refusal wording superseded contract. #5769 already realigned it
test_an_orphaned_service_retains_archive_ownership_on_the_production_route (TimeoutError) never reached health_check because the lifecycle start raised production bug, same root cause
test_daemon_watcher_hints_wake_fair_intake_and_canonical_derivation ×4 backend bootstrap outside the lease (#5727) production bug, fixed
test_cold_build_* ×4, test_daemon_startup_catch_up_and_restart_repair_session_profiles nested-lease re-entry, event root, and state leaked from the failing watcher test production bug, fixed
test_run_daemon_services_waits_for_fts_startup_before_watcher ×2 #5727 reads operation_runtime.embedding_convergence superseded test stub. The fake server declares the attribute
test_raw_owner_cancellation_settles_publication_and_fts (fails on the current tip) #5691 made a cancelled compute owner stop its retained preparation superseded contract. Renamed to ..._stops_preparation_and_the_next_pass_publishes: cancellation publishes nothing, and the next pass publishes the session and its FTS rows
test_archive_bound_lease_can_delegate_without_dropping_identity asserted adopted is lease, but adoption returns a per-thread view by design the test was wrong when #5727 added it. It now asserts that the adopted view carries the archive identity and authorizes a write for that archive

New regression tests, each naming its anti-vacuity condition: nested re-entry inherits the outer archive identity; an unleased backend admits an established archive read-only and still refuses one without a marker; lifecycle start and the signal marker persist under a root-bound lease.

Verification

  • devtools test tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_daemon_lifecycle.py tests/unit/storage/test_write_lease.py tests/unit/cli/test_cli_write_authority.py tests/unit/daemon/test_daemon_events_endpoint.py tests/unit/storage/test_write_guard.py tests/unit/daemon/test_write_coordinator.py tests/unit/daemon/test_judgment_automation.py tests/unit/daemon/test_secret_scan_sweep.py tests/unit/daemon/test_standing_queries.py tests/unit/daemon/test_standing_queries_default_evaluator.py tests/unit/daemon/test_standing_query_clock.py tests/unit/mcp/test_mcp_call_log.py tests/unit/pipeline/test_schema_drift_sentinel_ingest.py tests/unit/schemas/test_drift_sentinel.py tests/unit/schemas/test_drift_sentinel_sampling.py tests/unit/security/test_secret_scan.py at 3a56a1e: devtools test: PASSED, 445 passed.
  • devtools verify --quick at 3a56a1e: verify: PASSED.
  • The head was then rebased over fix: close Codex review findings from the #5722 landing #5778, which touches none of these files.

Residuals

  • devtools schema closure reports these touched files as IN: write_lease.py, async_sqlite.py, connection_profile.py, bootstrap.py, blob_gc.py, sqlite_vec_runtime.py and sampling_db.py. The derived schema identity may move, so this must land before a fresh build starts.
  • Some writers outside the daemon still resolve the ambient root: the HTTP reset event, browser capture and judgment receipt events. In production that root equals the lease root. In tests it can differ when polylogue.daemon.events is first imported under a patch("polylogue.paths.archive_root"), which binds the mock into the module.
  • open_profiled_connection still has no archive_root for write profiles. Every current caller uses a read profile.
  • An arm_write_lease_enforcement(armed=False, process_wide=True) suppressor no longer clears a thread-local arming. Nothing calls that combination.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

Sinity and others added 2 commits September 29, 2026 03:34
#5727 made a root-bound writer lease refuse any write that omits its
archive identity. #5769 fixed the lifecycle and several daemon ops
writers; the routes below still refused or wrote to a re-resolved root.

- Pass archive_root at the remaining daemon, schema, security and
  storage write opens.
- Daemon-emitted lifecycle and live-batch events name the daemon's
  archive instead of re-resolving the ambient root.
- Nested write_lease re-entry checks the held lease's own identity;
  it raised "omitted archive identity" under any root-bound lease.
- SQLiteBackend over an established archive admits it through the
  read-only format-marker proof when the caller holds no lease, so the
  live batch probing Polylogue.backend is not refused (#5727 made the
  constructor run the lease-gated active-root bootstrap every time).
- A process-wide arming no longer saves and restores the thread-local
  flag, which left a thread armed after out-of-order exits (#5722).

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

The run route reads operation_runtime.embedding_convergence from the
API server (#5727), so the fake server declares it. Since #5691 a
cancelled compute owner stops its retained preparation, so the raw
owner test asserts nothing is published on cancel and the next pass
publishes the session and its FTS rows.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
@Sinity
Sinity enabled auto-merge (squash) September 29, 2026 01:34
@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
📝 Code Review ✅ Completed 2026-09-29T01:44:13.815633Z d234fef PR opened
🔒 Security Review ✅ Completed 2026-09-29T01:39:35.311805Z d234fef 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: d234fefbcd

ℹ️ 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
…luded

The unleased SQLiteBackend branch now makes no filesystem change: the
directory creation and index chmod move to the writer-admitted branch.
It also opens the index read-only with schema validation, so a stale
derived identity raises SchemaSkew instead of being served.

_emit_live_batch_event requires the daemon's archive root; its tests
name an isolated archive whose ops.db the readers resolve.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
@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 commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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 f7ad8d8 into master Sep 29, 2026
3 of 4 checks passed
@Sinity
Sinity deleted the fix/daemon-cli-lease-tests branch September 29, 2026 02:11
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