Skip to content

capture: unnamed scope ships owner-only to the default (not held); --reevaluate-held - #330

Merged
ZacxDev merged 4 commits into
mainfrom
feat/capture-unrouted-scope-owner-only
Dec 4, 2026
Merged

ZacxDev merged 4 commits into
mainfrom
feat/capture-unrouted-scope-owner-only

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

What

Operator decision 2026-12-03 (it changes plan decision 16): on a host with more than one instance, a scope the routing table does not name at all is now treated like *. The session ships to the default instance, owner-only (* declared, new cause OwnerOnlyUnnamedScope) and is no longer held. A session already bound to the default instance that picks up such a scope is no longer withdrawn. One bound to another instance (e.g. client) moves the way a * session does: it is withdrawn from that instance, rebound to the default, and its whole transcript re-shipped there owner-only. At main, it was withdrawn and then held. TestAClientBoundSessionThatReadsAnUnnamedScopeMovesOwnerOnlyToTheDefault pins this path.

  • The only routing hold left is a scope the table explicitly routes to an instance this host does not configure. Its held_reason now says exactly that: scope X is routed by the table to instance Y, which this host does not configure.
  • New mode: cairn-capture --reevaluate-held [-apply], a one-off way to recover the holds the old rule made (details below).
  • Docs updated: the route.go comments, internal/capture/README.md (step 3, plus a new section on --reevaluate-held), plan decision 16 (note with the date and reason) and CHANGELOG.

Why

scopeuse treats header-shaped text anywhere in a transcript as a scope read: grep or test output, a source read, assistant prose. Because a hold was final and withdrew any prefix already shipped, one fixture name in a tool result froze a whole session. On one two-instance host this held 15 sessions: 14 on fixture names (alpha-notes, a, b, checkout-service) and 1 on a real scope that was registered later. One live session was withdrawn from personal.

--reevaluate-held

  1. It selects holds that carry the legacy text scope X routes to no configured instance.
  2. It re-decides each one over its V with the current Decide.
  3. If given -host/-worker/-capture-token-file, it sends the destination the position probe, which stores nothing.

Possible outcomes: ship / unprobed / needs-server-restore / probe-failed / still-held / excluded.

  • -apply refuses to run without probes. All the target holds are legacy (history_kept false), so the local state can't prove they were never withdrawn.
  • -apply clears only ship holds, and re-checks each one at the moment it writes.
  • A 410 is reported as needs-server-restore and left held, with its original reason. The next pass neither re-holds it nor loops on it.
  • The operator-frozen routed back to …, which deleted this session's transcript holds are excluded by name.

Tests

  • New: internal/capture/unnamed_test.go and cmd/cairn-capture/reeval_test.go. The CLI tests run against real in-process worker pods, including a real withdrawal followed by a 410 probe.
  • Red at origin/main 7dc510c and green here:
    • unnamed scope → owner-only on the default
    • a new session ships and is not held
    • an already-shipped session is not withdrawn
    • the new held-reason text
  • The * cases and "explicitly unconfigured → still held" are invariant guards: they were green before and are still green.
  • Mutations of route.go each fail named tests:
    • restore main's multi || named
    • widen only the condition
    • drop the explicit hold
    • drop the unnamed owner-only case
  • Mutations of the reevaluate code, each caught by a test:
    • remove the frozen-hold exclusion
    • stop telling a 410 apart
    • let apply clear non-ship holds
    • allow apply without probes
    • remove the reason re-check when applying

Overlap

The change stays in internal/capture, cmd/cairn-capture and docs. It doesn't touch cmd/cairn log (feat/log-repo-scope) or cmd/cairn-ui/internal/pgstore (#328). CHANGELOG gets one new top row and may conflict textually with other PRs that add rows.

🤖 Generated with Claude Code

ZacxDev and others added 3 commits December 3, 2026 22:52
…--reevaluate-held

Operator decision 2026-12-03 (changes plan decision 16): a scope the routing
table does not name at all is treated like `*` on a multi-instance host — the
session ships to the DEFAULT instance owner-only (`*` declared, new cause
OwnerOnlyUnnamedScope) instead of being HELD. Holding was final and withdrew
an already-shipped prefix, while scopeuse reads header-shaped text anywhere in
a transcript as a read, so fixture names in test output froze and withdrew
whole sessions (measured: 15 such holds on one host, 14 on fixture names).

The only routing hold left is a scope the table EXPLICITLY routes to an
instance this host does not configure; its held_reason now says exactly that.

`cairn-capture --reevaluate-held [-apply]` recovers the holds the old rule
made: it selects legacy "scope X routes to no configured instance" holds,
re-decides each over V, and (given -host/-worker/-capture-token-file) probes
the destination. -apply refuses to run without probes, clears only holds the
destination answered with a position (re-checked at the write), and reports a
410 as needs-server-restore, leaving it held so the next pass neither re-holds
nor loops on it. "routed back to …, which deleted" holds are excluded by name.

Red/green: the routing tests fail at origin/main 7dc510c (held / withdrawn) and
pass here; route.go mutants (main's condition restored, the condition widened,
the explicit hold removed, the unnamed owner-only case dropped) each fail
named tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…cident)

leakscan refused route.go's '2026-12-03' as a dated incident stamp; the
operator decision is now cited by its PR (#330) in code. The plan, README
and CHANGELOG keep the date, which leakscan does not flag there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev

ZacxDev commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Audit round 0: requirements and deletion pass for #330 (head 52cc25f)

Verdict: proceed to the checklist.

Ledger: round 0 · requirements: 7 (unattributed: 0; UNATTRIBUTED-UNKNOWN: 2) · deletion candidates: 1

The brief's ask sources were unreadable. No commit carries a Claude-Session-Id trailer, and the PR has no operator comments. So attribution comes from the operator decisions the dispatching session relayed. They are paraphrased below, not quoted.

Requirements and who asked for them

# requirement author
R1 On a multi-instance host, a scope the routing table does not name goes to the default instance owner-only, like *. It is no longer held, and a default-bound session is no longer withdrawn for it. Zach: operator decision 2026-12-03, which amends plan decision 16
R2 A scope the table explicitly routes to an alias this host does not configure stays held. Zach: keep the hold only for that case
R2b That hold's held_reason gets new wording. UNATTRIBUTED-UNKNOWN (agent-derived; needed so the legacy text can be selected)
R3 A one-off --reevaluate-held mode, read-only by default, prints the list. -apply runs only with probes. Zach: re-evaluate the existing holds once, and show the operator the list before any live apply
R4 A 410 answer is reported needs-server-restore and left held, never cleared. Zach: withdrawn sessions are restored server-side
R5 The routed back to …, which deleted … holds are excluded by name. Zach: those stay frozen
R6 The bytes column (claudeBytes) UNATTRIBUTED-UNKNOWN (a support for reviewing the list)

R1, questioned as Zach's. The rule places {civitai-routed scope, unnamed scope} on the default instance owner-only. That is the same answer {civitai-routed scope, *} and a cross-instance session already get, so it applies the existing accepted trade-off. It does not create a new one.

I ran a read-only dry run of --reevaluate-held on a copy of one host's state, with no probes. The copy's checksum was unchanged afterwards. 8 of the 15 recoverable holds have scopes that route to both personal and civitai. Applying would put content those sessions read from civitai onto personal, owner-only. That is the decision behind the list review Zach asked for, so it is not a new premise. It should be read on the list before -apply.

R4. The PR lists what needs a server restore. It does not do the restore. The restore follows the existing README section, so the second half of the operator's ask is a manual follow-up.

Delete

Examined: route.go (the hold branch and the new owner-only cause), reevaluate.go, the new CLI mode and flag, the README, plan and CHANGELOG rows, and both test files.

  • --reevaluate-held is a one-off by design, and it is running: built from this head and run read-only on a state copy, it selected 15 holds and excluded 5. After the apply it has nothing to select. Removing it is a candidate once its job is done.
    • Closing condition: the read-only listing shows held= with no unprobed, ship or probe-failed rows on every host that has a capture state.
  • Nothing else qualifies. Every other behaviour answers one of the operator decisions above.

Simplify: no candidate. The operator may run /simplify afterwards; I did not.

D1 — remove `--reevaluate-held` (reevaluate.go, the -apply flag, its tests) once the one-off recovery has run on every host with a capture state (closing check: the read-only listing has no unprobed/ship/probe-failed rows)

@ZacxDev

ZacxDev commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Audit round 1: full adversarial audit of #330 (head 52cc25f, base main @ 7dc510c)

Verdict: safe to merge. No 🔴 findings. One 🟡 is a doc claim with a decision consequence, plus a missing test. This round has no 🔴, so the ladder ends here.

Evidence gathered

  • CI on head 52cc25f: all posted checks pass. That covers go (21m), dualrun, leakscan, changes, and the 8 mutants (control) plus 8 mutants (routing) shards. GitHub reports mergeStateStatus as CLEAN.
  • Targeted local tests: go test -count=1 ./internal/capture/ ./cmd/cairn-capture/ in the dev shell (nix develop <cairn>) passes on head.
  • Mutation spot-check: I re-ran four of the PR's own mutants in a detached copy. Each failed the named tests, and an unmutated control passed:
    • -apply clears outcomes other than ship
    • the 410 is not told apart
    • the frozen-hold exclusion is removed
    • the unnamed owner-only case is dropped
  • Dry run on real data: I built --reevaluate-held from head and ran it read-only on a copy of one host's capture state, without -worker, so nothing was probed. The copy's sha256 was unchanged afterwards. Result: held=20 unprobed=15 excluded=5.
    • The 5 excluded holds are exactly the 5 routed back to civitai, which deleted … holds, and nothing else was excluded.
    • Of the 15, 2 are opencode sessions. One has withdrawn_from set to personal and is flagged "expect 410".
    • This matches the PR's count of 15.

Questions the dispatch raised, answered

  • A V with a civitai-routed scope plus an unnamed scope: which wins? The unnamed scope does (route.go:252-260). The session goes to the default instance owner-only, in either order, the same as {civitai scope, *}. That is pinned by TestAnUnnamedScopeIsPlacedOwnerOnlyOnTheDefault. In the dry run, 8 of the 15 recoverable holds route to both personal and civitai. Applying ships them to personal, owner-only. That is the content the operator's list review before -apply should read.
  • Can -apply clear a hold the server withdrew? Not through a 410. ApplyReevaluation (reevaluate.go:156-171) clears only ship, and the 410 case maps to needs-server-restore. A probe sent under a wrong -host gets a 400 because the token is bound to its host (worker.go:302), so it lands on probe-failed, not on a false ship. ErrNotOwner → ship only covers a root held under a different (owner, host), which cannot be this host's own withdrawal.
  • Can the excluded set include more than the 5? No. frozenDeletedHold runs before everything else, and every other non-legacy hold falls to the separate excluded reason. The real-data dry run confirms 5 = 5.
  • Can it race the timer? A dry run takes no lock, but State.Save writes atomically with a rename, so a dry run always reads a whole file. -apply takes the same flock as --run and --clear-held, and loads the state only after it holds the lock. A timer tick during an apply exits with "another run holds the lock". No race.
  • Do the opencode and claude paths agree? Yes. Both reach the single Agent.route (agent.go:938 and agent.go:1250), and reevaluate probes with the session's own runtime.

Findings

🟡 A session bound to client that picks up an unnamed scope IS withdrawn, and its content is re-shipped to personal. The docs say an already-shipped session is no longer withdrawn. Label: payload (docs), and scaffolding (the missing test).

  • Where the claim is made: CHANGELOG.md:32, internal/capture/README.md:46, and the PR body all say it without qualification. Only TestAShippedSessionThatReadsAnUnnamedScopeIsNotWithdrawn backs it, and that test covers a session bound to the default instance.
  • What I measured: a scratch test in a copy (not committed).
    1. A session reads beta-notes and is bound to client.
    2. It then reads the unnamed scope gamma-notes.
    3. At head it is withdrawn from client (withdrawn_from=[client]), rebound to personal, and its whole transcript is shipped there with * declared.
    4. At base 7dc510c it is withdrawn from client and held, and nothing reaches personal.
  • What that means: client-instance content now lands on personal (owner-only) because a fixture name appeared in the transcript. That follows from the operator's "treat it like *" decision, since * does the same, so it is not a leak finding. But the docs tell the reader it does not happen, and no test pins it.
  • Fix: qualify the sentence to "bound to the default instance". Add a test for the client-bound move, and state that path in the CHANGELOG row.

Not findings:

  • ApplyReevaluation's "re-checked at the write" is effectively a no-op inside the CLI, because evaluation and apply share one locked in-memory state. It is harmless.
  • The detail column names the cross-instance or * cause rather than the unnamed scope.

Could not verify: a live -apply against real workers. That is out of scope, and nothing was probed.

Ledger: not measured in round 1. It starts at round 2, and with no 🔴 there is no round 2.

1. an unnamed scope on a multi-instance host is placed on the default instance owner-only (cause OwnerOnlyUnnamedScope) instead of held
2. a scope the table names for an unconfigured alias is still held, with a new held_reason text
3. --reevaluate-held lists legacy unnamed-scope holds, probes only when given workers, and writes nothing without -apply
4. -apply refuses without probes, clears only ship outcomes, and leaves a 410 held as needs-server-restore
5. the operator-frozen "routed back to …, which deleted" holds are excluded by name

…n that path

Round 1 of #330's audit (0 red): the docs said an already-shipped session is
no longer withdrawn for an unnamed scope, which holds only for a session bound
to the DEFAULT instance. One bound to another instance moves as a `*` session
does: withdrawn from there, rebound to the default, re-shipped whole from
offset 0, owner-only (at main it was withdrawn and HELD). CHANGELOG and README
now say so, and TestAClientBoundSessionThatReadsAnUnnamedScopeMovesOwnerOnlyToTheDefault
pins the withdrawal from client and the owner-only rebinding on personal
(mutants: main's hold condition, and the unnamed owner-only case dropped, each fail it).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev
ZacxDev marked this pull request as ready for review December 4, 2026 14:12
@ZacxDev
ZacxDev merged commit 5f362a4 into main Dec 4, 2026
29 checks passed
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