Skip to content

fix(cli): Lower annotations import onto a declared daemon operation - #5400

Merged
Sinity merged 2 commits into
masterfrom
fix/cli-write-authority-sweep
Sep 22, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/cli-write-authority-sweep

Conversation

@Sinity

@Sinity Sinity commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Summary

polylogue-r29bv AC3, asserted by gjwto/re6s3. polylogue annotations import was the last CLI-invisible durable writer — it drove OperationExecutor against user.db in-process. It now goes through a declared daemon operation, and the CLI-mutation-authority baseline shrinks 3 → 2.

A real bug the work surfaced

Driving the actuator's async def import_annotation_batch from a synchronous handler with a bare asyncio.run(...) mints a new asyncio task and loses the write lease, which is bound to the calling thread/task — UnleasedWriteError, confirmed by direct reproduction.

That is the same property #5382 recorded from the other side: write_lease binds owner_task_id/owner_thread_id at mint time. Fixed with the declared delegate_write_lease()/adopt_write_lease() handoff — the existing write_coordinator.py pattern, not a new one — and verified end to end against a real daemon stack (session written, audit row present).

A gap it exposed by keeping a test honest

Adding a 12th CLI-bound mutating operation tripped re6s3 AC4's coverage test. Fixing that surfaced an independent defect: annotations import had no --format option at all, so the machine-format daemon-down check failed on Click's own --format json before ever reaching the daemon probe. Added -f/--format text|json, defaulting to json so every existing caller is unaffected.

The lane could have exempted the new operation from the matrix. It extended the matrix instead, which is why the missing flag was found.

Verification

devtools test test_annotation_import_command.py            3 passed
devtools test <+ test_cli_operation_authority.py>         33 passed
devtools test <10 modules>                     87 passed, 9 failed
devtools verify --quick        25/25 ok (run once per commit)
devtools render all --check    exit 0, zero 'out of sync'
devtools schema closure        every changed file OUT — no rebuild implication

All 9 failures are in test_layering_gates.py (KeyError: 'file', the durable_write_census renderer gap). Confirmed inherited: git diff --stat HEAD -- over the three implicated files is empty — none was touched. That is polylogue-1or21, fixed in #5393.

Anti-vacuity executed: reverted annotations.py to the in-process writer, ran test_annotations_import_refuses_without_a_daemon → real failure (assert 0 != 0; the row imported with no daemon running), restored, re-ran → 3 passed.

d02y8 deliberately not implemented — and its bead contradicts itself

The bead carries a 2026-09-20 note recording "DECISION RESOLVED (coordinator): the daemon DOES hold the provider credential" with reasoning, and a later 2026-09-22 scoping note saying "NOT DISPATCHABLE: an operator policy decision a worker must not answer" — apparently written against the stale DESIGN section rather than the resolution above it.

The lane treated neither as authorization and made no credential choice. The three options and the implementation path under (a) are recorded on the PR for whoever rules.

Residuals

  • gjwto AC6 asks to reopen/supersede polylogue-5vps8.2, which is closed on a reason resting on a baseline the extended rule now proves could not see facade-routed writes. A Beads action for the coordinator.
  • gjwto AC1/AC2 stay blocked on decision D2: _execute_facade_mutation still has 20 call sites, and the 2 surviving baseline entries are both polylogue/api.
  • re6s3 AC3's pipeline/services/archive_ingest.py and the direct-tier-writer list (embed backfill, scan-secrets, backup, demo, archive-init, blob-*) were out of the collision boundary and untouched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

Sinity and others added 2 commits September 22, 2026 08:55
`polylogue annotations import` was the last CLI-invisible durable writer:
it drove `OperationExecutor` against `user.db` from the CLI process via
`polylogue.annotations.importer.import_annotation_batch`, a module the
mutation-authority layering rule did not name until the rule was
extended to match by drive rather than by spelling (polylogue-gjwto).
That extension turned the hole into a reviewed baseline entry
(`docs/plans/layering-cli-mutation-authority-baseline.json`); this closes
it by declaring `mutation.annotation.import_batch`, giving it a daemon
handler that reuses the existing actuator plus the shared
`resolve_ref_against_archive` implementation (PR #5370) instead of a
second ref-resolution path, and rewiring the CLI command onto
`submit_cli_mutation` (polylogue-r29bv AC3).

The handler drives the actuator's `async def import_annotation_batch`
from a synchronous daemon handler. A bare `asyncio.run(...)` would mint a
new task and lose the write lease bound to the calling thread/task, so
the handler mints a `delegate_write_lease()` on the calling thread and
adopts it inside the new task -- the declared mechanism for exactly this
handoff (`polylogue/daemon/write_coordinator.py` uses the same pattern).

The CLI-side `polylogue.annotations.importer` import is gone, so the
baseline shrinks from three entries to two (the two `polylogue/api`
entries stay, blocked on decision D2 per the existing baseline reason).

Verification:
- devtools test tests/unit/cli/test_annotation_import_command.py -- 3 passed
- devtools test tests/unit/api/test_operation_executor_routes.py
  tests/unit/operations/test_cli_operation_binding_registry.py
  tests/unit/operations/test_operation_bindings.py
  tests/unit/cli/test_cli_storage_boundary.py
  tests/unit/devtools/test_layering_gates.py
  tests/unit/api/test_facade_contracts.py::test_facade_import_annotation_batch_persists_candidate_provenance
  tests/unit/api/test_facade_contracts.py::test_facade_import_annotation_batch_uses_default_registry
  tests/unit/cli/test_setting_command.py tests/unit/annotations/test_importer.py
  -- 87 passed, 9 failed, all 9 in test_layering_gates.py over an
  unrelated durable-write-census fixture gap (devtools/, zero diff here,
  reproduces identically against origin/master 6fa8440; not fixed by
  this lane)
- devtools gate layering, gate api-parity, gate declaration-bindings -- ok
- devtools verify --quick -- 25/25 gates ok
- devtools render all --check -- no "out of sync"
- devtools schema closure -- every changed file OUT of the derived
  schema identity closure
- Anti-vacuity (executed): reverted annotations.py to the pre-fix
  in-process writer, ran
  test_annotations_import_refuses_without_a_daemon -- failed with the
  row importing successfully with no daemon running
  (assert 0 != 0 / exit_code 0), then restored the fix and reran the
  full file -- 3 passed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
polylogue-re6s3 AC4's coverage test fails closed when a new mutating
operation gains a CLI binding without a matrix row
(test_the_matrix_covers_every_cli_bound_mutating_operation); the
previous commit's mutation.annotation.import_batch tripped exactly
that. Add its row, which surfaced a real, independent gap:
`annotations import` had no `--format` option at all, so appending
`--format json` (every machine-format invocation does this) failed
with Click's own "No such option" before the daemon probe ever ran.
Give it the same `-f/--format text|json` shape as `note`/`setting set`,
defaulting to `json` to preserve its existing unconditional-JSON
behavior for every caller that omits the flag.

Verification:
- devtools test tests/unit/cli/test_cli_operation_authority.py
  tests/unit/cli/test_annotation_import_command.py -- 33 passed
- devtools verify --quick -- 25/25 gates ok
- devtools render all --check -- no "out of sync" (annotations import
  is not part of the generated CLI-reference surface)
- devtools schema closure -- both changed files OUT of the derived
  schema identity closure

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

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: efbdf765-f585-41ea-b2eb-bb45c79e0bf8

📥 Commits

Reviewing files that changed from the base of the PR and between eb54a24 and a94178b.

📒 Files selected for processing (7)
  • docs/plans/layering-cli-mutation-authority-baseline.json
  • polylogue/cli/commands/annotations.py
  • polylogue/cli/operation_bindings.py
  • polylogue/operations/daemon_mutations.py
  • polylogue/operations/daemon_protocol.py
  • tests/unit/cli/test_annotation_import_command.py
  • tests/unit/cli/test_cli_operation_authority.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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-22T07:06:33.488410Z a94178b PR opened
🔒 Security Review ✅ Completed 2026-09-22T07:07:50.146118Z a94178b 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: a94178b8d5

ℹ️ 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/operations/daemon_protocol.py Resolved
Comment thread polylogue/operations/daemon_protocol.py Resolved
@Sinity
Sinity merged commit 449ddea into master Sep 22, 2026
3 checks passed
@Sinity
Sinity deleted the fix/cli-write-authority-sweep branch September 22, 2026 07:09
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

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