Skip to content

feat(cli): route the last CLI writers through daemon operations - #5845

Merged
Sinity merged 3 commits into
masterfrom
feat/cli-daemon-authority
Sep 29, 2026
Merged

Sinity merged 3 commits into
masterfrom
feat/cli-daemon-authority

Conversation

@Sinity

@Sinity Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Summary

Moves the last CLI writers of durable and derived tiers behind declared daemon operations, deletes the hand-maintained CLI operation registry, and fixes four smaller defects on the same surfaces:

  • ops maintenance raw-authority-frontier now submits a new declared operation, maintenance.raw-authority-frontier. Before this change it wrote raw_authority_blockers rows into source.db from the CLI process.
  • demo verify and ops maintenance gc-history now open read-only connections. Both used to open writable connections for a read.
  • polylogue/cli/operation_bindings.py is deleted, together with its registry test. The daemon-down matrix and the offline-writer test now take their routes from the CLI source itself.
  • import --daemon-url is deleted. The command accepted the value and then discarded it.
  • When a read finds no archive, the refusal now names commands that exist. It used to name a polylogue ingest command and an --archive-root option, and neither exists.
  • The session_profiles writers have one insert shape. The column probes and the payload serializer for the nonexistent payload_json column are gone.
  • analyze portfolio decides one terminal outcome in every output format.

Beads: polylogue-5vps8, polylogue-re6s3, polylogue-l65ry, polylogue-77tzg, polylogue-t4115 (portfolio half).

Problem

  • Surviving writers. I ran every CLI leaf command on a bootstrapped root with no daemon, recording writable tier opens through the production interception seam (maintenance.offline_guard.refuse_writable_tier_opens). At 60c373b482 the sweep found:
    • ops maintenance raw-authority-frontier opened source.db writable. The census it runs publishes durable blockers, and the only guard was the offline-maintenance residency check.
    • demo verify opened index.db, source.db and user.db with plain sqlite3.connect, which creates a tier file when it is missing.
    • ops maintenance gc-history opened index.db with a write profile.
    • status, ops status and the agents views open ops.db for route telemetry. That route is filed as polylogue-k5iaf, because it belongs to the route-observability owner.
  • Registry drift. CLI_OPERATION_BINDINGS was a hand-maintained mirror that no production code read, yet it drove the daemon-down matrix's coverage test. The matrix exempted maintenance.blob-publications.abandon and mutation.raw-authority-blocker.resolve on the stated grounds that they need live ids. Both routes submit before they read anything.
  • Cold-agent error (l65ry AC7). On a fresh root every read verb said "run polylogue ingest to create the archive, or point --archive-root at an existing one". Following that advice fails again with "No such command 'ingest'".
  • Profile writes (77tzg). Every write serialized a merged payload for a payload_json column that the canonical DDL does not have, and then discarded it. It also probed PRAGMA table_info through a cache keyed by id(conn), which can go stale when a connection id is reused.
  • Portfolio outcome (t4115). analyze portfolio wrapped a truncated or partly unprofiled scope in a bare success with exit 0, and an empty scope also exited 0.

Solution

  • Frontier census. maintenance.raw-authority-frontier is a WRITE operation with fallback NEVER. Its handler daemon_mutations.maintenance_raw_authority_frontier runs inspect_raw_authority_frontier under the daemon writer (run_write). The CLI renders the census the daemon returns. maintenance.raw_authority.inspect_frontier, the predecessor product function, is deleted. The docs and the archive-debt action text now say that running the command records the census.
  • Read-only views. demo/verify.py and demo/constructs.py open through open_readonly_connection and attach_readonly_database. read_gc_history reads the GC ledger tier read-only and resolves that tier the same way run_blob_gc_report does, through _gc_control_db_path.
  • Registry deletion.
    • test_cli_operation_authority.py builds its coverage set from every declared mutating operation name that appears as a literal in polylogue/cli.
    • The matrix gains rows for blob-publication abandonment, blocker resolution, the frontier census and the ops reset tier branch (terminal format only, since that branch has no JSON envelope).
    • The only remaining exemptions are maintenance.demo.augment, which is reachable only after a completed ingest, and the context-ledger receipt.
    • The offline-writer test derives its rows from the demo commands that call the guarded seeder.
    • The lowering tests from the deleted registry test move to tests/unit/cli/test_cli_lowering.py.
  • Layering. The CLI mutation-authority rule now also disallows polylogue/api/facade_client and polylogue/api/ingest, the facade's write routes. The CLI baseline stays empty.
  • import --daemon-url. The option, its default helper and every test argv that passed it are gone. The integration test now asserts the socket the command really uses.
  • First-run guidance. core/errors.py holds one guidance constant, FIRST_RUN_INDEX_GUIDANCE, used by both the storage open and the CLI pre-check. It names polylogue init, polylogued run, polylogue import PATH and POLYLOGUE_ARCHIVE_ROOT. A new test resolves each suggested command against the real Click groups.
  • Profiles. SESSION_PROFILE_INSERT_COLUMNS is the single insert shape, used by the sync writers and the async bulk writer. The probes, their caches, _fallback_profile_payload_json, _compose_bindings and _with_fallback_payload_column are deleted. The round-trip test now writes into the fresh canonical table.
  • Portfolio outcome. analysis.portfolio.portfolio_outcome names match_cap_exceeded, session_profile_unavailable and session_digest_unavailable. The CLI attaches the outcome to the JSON result, prints the outcome line in the other formats, and exits through outcome_exit_code.
  • Tests on the production route.
    • A zero-match find ... then delete --yes against a real daemon refuses with the empty-selection error and submits no delete operation.
    • demo verify and gc-history open no writable tier.

Derived-identity closure. These changed files are members according to docs/plans/schema-closure-baseline.json, and the schema-closure gate passes: polylogue/core/errors.py, polylogue/storage/blob_gc.py, polylogue/storage/derived/session/storage.py, polylogue/storage/sqlite/archive_tiers/archive.py, polylogue/storage/sqlite/queries/mappers_insight_profiles.py and polylogue/storage/sqlite/queries/session_insight_profile_writes.py. This PR moves the derived identity, so it should land before a rebuild starts.

Deletion ledger (5vps8 AC12), from merge-base to head:

Area Added Deleted Net
Production 185 573 -388
Tests 402 215 +187
Docs 16 4 +12
  • Deleted: polylogue/cli/operation_bindings.py (369 lines), tests/unit/operations/test_cli_operation_binding_registry.py, maintenance.raw_authority.inspect_frontier, import --daemon-url, two column-probe helpers with their caches, and the fallback payload serializer.
  • CLI in-process writable-tier opens found by the sweep: 7 commands before, 4 after. The 4 left are the ops.db telemetry route in polylogue-k5iaf. The declared offline demo writers are excluded from both counts.

Verification

  • agentctl job start --workspace <wt> polylogue verify_quick job 3522 on 6758e81: succeeded; every gate passed, including layering, mypy and schema-closure.
  • agentctl job start --workspace <wt> polylogue pytest_focused -- <39 files> job 3523 on 6758e81: 787 selected, 772 passed, 15 failed. Every one of the 15 also fails on master: the baseline runs are job 3505 at 87450e4 and job 3551 at 9e1924a (the two facets snapshot tests), and the dispatch names test_empty_terminal_query_unit_is_an_explicit_outcome and test_every_verb_refuses_a_fresh_root_with_one_machine_envelope as inherited. The earlier run on this branch (job 3485) failed on the GC-history ledger tier, the obsolete offline frontier refusal test and my zero-match test's expected exit code; all three are fixed in 58fbc48. Its demo and daemon-route timeouts did not recur in 3523, and demo receipts finishes in 10 s outside the pool.
  • Anti-vacuity for re6s3 AC5, job 3487: a scratch tree at 60c373b482 with a local user.db write added to submit_cli_mutation's refusal branch turned 17 matrix rows red. This was an uncommitted experiment, not a candidate.
  • Master baseline, jobs 3505 and 3551 with --on-default-branch: these failures reproduce on master and belong to master-green:
    • test_profile_mutation_census_matches_the_declared_owners
    • test_archive_debt_*codex* (2)
    • test_storage_one_shot_readers_cannot_mutate (2)
    • 5 test_demo_command receipt and tour tests
    • test_empty_terminal_query_unit_is_an_explicit_outcome
    • test_every_verb_refuses_a_fresh_root_with_one_machine_envelope (2)
    • test_plain_cli_snapshots facets tests (2)
  • Writer sweep (every CLI leaf command, no daemon, recording writable tier opens) on 6758e81: 4 commands still open a tier writable, all for ops.db route telemetry (status, ops status, agents status, agents work-item).

Self-review

Last pass: pass 3, against docs/review/codex-review-guide.md and the generic worker-contract list. Pass 1 found the GC-history ledger regression and the obsolete offline-frontier test. Pass 2 found a private scratch path in a filed bead and scrubbed it. Pass 3 found nothing new.

Review-guide checklist:

  1. Siblings and owners. ✓ I looked for each class of write on every CLI command, not only on the routes the beads named. The writer sweep ran every leaf command on a bootstrapped root and found 7 commands opening a tier writable. This PR fixes 3 of them; the other 4 are the ops.db telemetry route in polylogue-k5iaf. The first-run text now has one owner, FIRST_RUN_INDEX_GUIDANCE, used by the storage open and the CLI pre-check. The remaining polylogue ingest mentions in operations/import_* docstrings are corrected. One remains in sources/live/watcher.py, a closure file on the live intake route that I left to its owner. The column-probe class outside profiles is filed as polylogue-l91i8.
  2. The fix itself. ✓ The new handler's exceptions become typed operation failures, and mutation_refusal renders them. _gc_control_db_path is shared with run_blob_gc_report, so the report and the history view choose the same ledger tier; its probe uses the existing read-only helper.
  3. Memory and limits. ✓ No new buffers. The census result is the existing bounded sample (to_dict(sample_limit=100)). The frontier operation's 300 s client deadline matches the other maintenance operations; when a census runs past it the client reports indeterminate and the daemon finishes the census. It is never reported as failure or rolled back.
  4. Cost per unit. N/A: no paging, loop or query changes.
  5. Interruption. ✓ The census runs inside run_write under the daemon writer. A lost client cannot release writer ownership, and the census transaction is the storage owner's, unchanged.
  6. Ordering and races. ✓ Moving the census into the daemon removes the CLI race against a daemon that starts during the census. The census opens its own connection while the operation's pinned snapshot is only a reader, which is fine under WAL.
  7. Failure classification. ✓ demo verify now reports a missing tier as archive unreadable, through its existing sqlite3.Error branch, instead of creating an empty file. read_gc_history still raises on a missing ledger.
  8. Silent outcomes. ✓ Portfolio decides one outcome in every format and maps exit codes through outcome_exit_code. Postmortem stays undecided until fix: close 20 Codex P1 findings in sources, backup, browser, MCP #5835 provides its owner (see Residuals).
  9. Cleanup on failure. N/A: nothing acquired.
  10. Identity and keys. N/A: no hash, ID or continuation changes.
  11. Lossless transforms. ✓ On the canonical table the profile insert binds exactly the columns it bound before: has_content_hash was true and has_fallback_payload false. The new test round-trips every payload through _row_to_session_profile_record.
  12. Degenerate inputs. ✓ An empty portfolio scope is empty with exit 2 (test). A zero-match delete refuses and submits nothing (test through a real daemon).
  13. Consumers. ✓ Each removed name was grepped across the repository: operation_bindings (2 test consumers moved), inspect_frontier (1 test replaced), --daemon-url on import (5 test argvs and the integration test), session_profile_insert_columns / table_has_column (2 production and 2 test consumers). No generated reference lists operations or import options (docs/cli-reference.md covers only top-level help).
  14. Tests and stubs. ✓ Every new test drives the Click CLI or the daemon, and each docstring names the change that turns it red. re6s3 AC5 was run for real: job 3487, 17 rows red.
  15. Trust boundaries. N/A: no auth, secrets or file-mode changes.

Generic list:

  1. Criteria on the production path. ✓ Every satisfied criterion was checked on the production route; the unmet ones are listed with their blockers in Residuals.
  2. Each class at every site. ✓ See items 1 and 13; the sweep and the greps are the search.
  3. Consumers and predecessors. ✓ See item 13.
  4. Typed, visible failures. ✓ See items 7 and 8.
  5. Tests fail when the behaviour goes. ✓ See item 14.
  6. No private data. ✓ The diff, PR text and filed beads carry no private path or personal data; the scratch path in polylogue-ctha5 was removed in pass 2.

Residuals

  • polylogue-5vps8 AC3: a from-empty build still issues per-session point deletes (polylogue-ctha5, with probe evidence). That fix belongs in the shared session writer, which is in the closure.
  • polylogue-5vps8 AC13: the isolated lifecycle rehearsal was not run.
  • polylogue-77tzg AC4: the legacy fallback readers (mappers_insight_fallback hydrators and the evidence/inference fallback in archive.py) remain. About 18 test modules insert raw session_profiles rows with '{}' payloads and rely on them, so removing the readers needs its own fixture sweep. The same class at other sites is filed as polylogue-l91i8.
  • polylogue-t4115: the postmortem half waits on postmortem_outcome, which PR fix: close 20 Codex P1 findings in sources, backup, browser, MCP #5835 adds; that PR was still open when this one was opened.
  • polylogue-k5iaf: CLI route observations still write ops.db in-process.
  • The frontier census now runs with the daemon's 300 s client deadline. Before this change it ran unbounded in the CLI process. On an archive whose census takes longer, the command reports indeterminate while the daemon finishes the census.
  • mutation.facade.context_ledger stays a best-effort receipt whose refusal the read views drop. It is exempt from the matrix, with the reason recorded there.

🤖 Generated with Claude Code

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 enabled auto-merge (squash) September 29, 2026 19:14
@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-29T19:24:53.162736Z 6758e81 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.

@Sinity
Sinity merged commit c0dda6f into master Sep 29, 2026
3 checks passed
@Sinity
Sinity deleted the feat/cli-daemon-authority branch September 29, 2026 19:19
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