Skip to content

fix(daemon): own checkpoint policy and join orphaned service threads - #5769

Merged
Sinity merged 17 commits into
masterfrom
batch/polylogue-20260928-210329-ed96a9df/integration
Sep 29, 2026
Merged

Sinity merged 17 commits into
masterfrom
batch/polylogue-20260928-210329-ed96a9df/integration

Conversation

@Sinity

@Sinity Sinity commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Batch polylogue-20260928-210329-ed96a9df on base 82e84ec7515d.

polylogue-bp12n.5 Centralize recurring checkpoints and bound read-snapshot lifetime

  • 1. One production module owns WAL/checkpoint/read-connection policy. Every production wal_checkpoint, busy_timeout and nominally read-only SQLite open either delegates to a declared connection/profile

polylogue-bp12n.4 Reserve interactive compute capacity and prove mixed-load progress

  • 1. A checked benchmark profile exercises the actual installed cold CLI and direct UDS operation route for status, find/read, static/live completion, concurrent reads, incremental ingest, derivation ca

polylogue-avmq Supervise every daemon background service through one lifecycle contract

  • 1. One DaemonServiceSpec registry accounts for every service/task spawned by run_daemon_services, including owner, prerequisites, dependencies, trigger/cadence, readiness, failure/retry policy, shutdo

polylogue-enj7 Provide production-valid daemon service profiles and lifecycle harnesses

  • 1. The two remote-bind/API-disabled fixtures and the HTTP executor-close fixture use a production-declared service profile/harness; none patches an informal startup list or constructs DaemonAPIHTTPSer

Sinity and others added 10 commits September 28, 2026 23:10
An immutable=1 reader reads the main file alone, so a non-empty -wal or
rollback journal beside it holds committed state the reader silently skips.
The connection-profile owner now refuses that open with a typed
LiveGenerationImmutableError in open_readonly_connection,
attach_readonly_database and open_sealed_staging_connection. The
adopted-audit restore retry, which may retain committed source WAL, reads the
live tier's user_version through a mode=ro profile instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The index's own derived-identity check refused the unstamped fixture before
any sibling tier was consulted, so every parameter reported tier=index.

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

A watcher with no existing source root returned and settled "stopped:
completed", so its fail_daemon policy never applied and status read a
finished watch. The composition root now resolves it (and its readiness
bridge) as unavailable with the reason before any task exists.

Shutdown now closes the process compute adapter and joins its workers
within a bounded deadline, naming any survivor. The composition inventory
test counts threads that outlive run_daemon_services as orphans; it found
the fallback adapter's worker.

Fix forward the inherited write-lease refusal: lifecycle, events, MCP call
log, and planner-stat maintenance opened archive tiers without their
archive_root, which an armed archive-bound lease rejects, so
daemon.lifecycle.start failed on the composition route.

docs/daemon.md gains the before/after service graph.

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

#5727 moved embedding backfill limits, progress and stop signals from
composition to per-pass call arguments. The catch-up receipt still read
the composition-time `scope_limited` and `quiet`, which the daemon never
sets, so a cancelled or session-limited operator pass with no pending
work was stamped `completed`. Classify it from the per-pass values.

Realign the two backfill route tests whose composition fakes still read
the moved arguments (they failed at base 82e84ec), and drop the HTTP
test that required a non-disconnect error to escape do_GET: #5721 made
the boundary answer it with a 500 envelope, covered by
test_http_request_boundary.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…recurring sweep

A child process arms the recurring checkpoint owner, commits 4 MiB and exits
without closing. The parent reads every row live and drains the WAL through
checkpoint_archive_wals at the recurring boundary, with typed PASSIVE evidence
inside the checkpoint hold budget.

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

#5722 moved the delegation freshness probe from open_readonly_connection to
open_operation_read, so the census spy patched a name the module no longer
has. The route test now audits the pinned archive connection the probe
actually reads through. The query_only test accepts the read authorizer's
DatabaseError, which Python 3.14 raises before query_only would.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#5550 made test_bench_daemon_mixed_load record mixed_load_cache_invalidation but never added it to PROFILE_METRICS, so record_metrics refused the measured run with ValueError and the profile produced no mixed-load evidence. Declare the metric in the workload contract.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An armed archive-bound write lease refuses a tier open that omits its archive root (#5727). Embedding catch-up recovery and receipts, stage recording, workflow stage events and standing-query clock sweeps still omitted it, so polylogued startup failed at startup.embedding_lifecycle. DaemonLifecycle.start now takes the archive the daemon leased instead of re-resolving it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 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-29T00:24:37.288965Z e41c299 Manual request
🔒 Security Review ✅ Completed 2026-09-28T23:41:08.900443Z f3563a2 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.

…lylogue-20260928-210329-ed96a9df/integration

# Conflicts:
#	polylogue/storage/sqlite/migration_runner.py

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

ℹ️ 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
…n.4' into batch/polylogue-20260928-210329-ed96a9df/integration

# Conflicts:
#	tests/unit/daemon/test_daemon_operation_route.py
…' into batch/polylogue-20260928-210329-ed96a9df/integration
@Sinity
Sinity force-pushed the batch/polylogue-20260928-210329-ed96a9df/integration branch from f3563a2 to ca877ee Compare September 28, 2026 23:45
…60928-210329-ed96a9df/integration

# Conflicts:
#	polylogue/sources/live/watcher.py
@Sinity Sinity changed the title chore: Centralize recurring checkpoints and bound read-snapshot lifetime fix(daemon): own checkpoint policy and join orphaned service threads Sep 28, 2026
@Sinity
Sinity enabled auto-merge (squash) September 28, 2026 23:54
@Sinity

Sinity commented Sep 28, 2026

Copy link
Copy Markdown
Owner Author

@codex review

…p on compute survivors

Immutable opens judged a -journal by size alone, so a PERSIST-mode snapshot
with a zeroed journal header was refused. A compute worker that outlived the
shutdown join only emitted a warning; the daemon then released ownership and
reported a clean stop. It now keeps ownership and stops degraded.

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

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

ℹ️ 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/watcher.py Resolved
Comment thread polylogue/daemon/lifecycle.py Resolved
@Sinity

Sinity commented Sep 28, 2026

Copy link
Copy Markdown
Owner Author

@codex review

…rchive root

The watcher re-resolved its roots after the daemon's availability check, so a
root removed in between turned an unavailable watcher into a FAIL_DAEMON exit.
DaemonLifecycle.start kept an ambient archive-root fallback beside the
lease-bound root; only tests used it.

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

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 1316048bf3

ℹ️ 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
Comment thread polylogue/daemon/cli.py Resolved
Also restore LiveWatcher.run() without a roots argument: passing the checked
roots did not close the root-removal race (awatch still fails on missing
paths) and broke the composition-route fake watchers.

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

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

@codex review

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

ℹ️ 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 14a63dc into master Sep 29, 2026
4 of 5 checks passed
@Sinity
Sinity deleted the batch/polylogue-20260928-210329-ed96a9df/integration branch September 29, 2026 00:25
Sinity added a commit that referenced this pull request Sep 29, 2026
#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
Sinity added a commit that referenced this pull request Sep 29, 2026
…#5782)

## 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 #5727 pidfile message change.
- With the lifecycle fixed, nine more failures appeared. The same tests
pass on 841bbb3, the commit before #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 #5727 intended.
- `arm_write_lease_enforcement(process_wide=True)` no longer saves and
restores the thread-local flag. #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 #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.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