Skip to content

fix(capture): defer a bound session under F1 for up to 1h, so F1 cannot flip it into a 410 hold - #317

Merged
ZacxDev merged 5 commits into
mainfrom
fix/capture-f1-never-moves-a-bound-session
Nov 13, 2026
Merged

ZacxDev merged 5 commits into
mainfrom
fix/capture-f1-never-moves-a-bound-session

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

The defect

On a two-instance host, a routing flip ends in a permanent hold:

  1. The repo arm binds a session to the non-default instance (the session has no recorded scope). The session then runs a cairn call. Claude Code writes the call's tool input to the transcript before the client appends its read-ledger line. A capture pass that lands between the two sees F1 (names_program and an empty ledger), and DecideRun answers the default instance. The session is withdrawn from where it was and re-shipped to the default (withdraw <id> from <x>: its routing answer changed).
  2. The next pass reads the ledger line. Its scope routes back to the instance the session was just withdrawn from. That instance keeps the withdrawal as a final deletion, so the probe for the move back answers 410 and the session is HELD on the default for good.

Root cause. With V empty, or naming only the bound instance, the only input that can make DecideRun answer the default is f1. F1 is a fact about one run. Routing a bound session on it turned a one-run fact into an irreversible move.

The fix (operator decisions: DEFER, then BOUNDED)

  • DecideRun: a session that is already bound, on a multi-instance host, with F1 live, is Deferred. That holds whatever the answer with or without F1 would be, a hold included, but only for at most F1DeferWindow = 1h.
    • The window runs from the first pass that saw F1 live while the session was bound. Its start is saved per session as f1_since (unix seconds) in the state.
    • The window is cleared on any pass where F1 is false, so a later F1 episode gets a fresh window.
  • After the window, with F1 still live, the session is routed exactly as before fix(capture): defer a bound session under F1 for up to 1h, so F1 cannot flip it into a 410 hold #317: F1's * forces the default instance, through the usual probe and withdrawal.
  • Unbound (new) sessions keep F1's placement on the default, unchanged.
  • One-instance hosts are exempt. F1 changes no answer there and there is nowhere to be withdrawn to.
  • Visibility: an F1 deferral is no longer a refusal.
    • It is counted on a new run-line field deferred=, inserted after export-skipped=. That is mid-line on --run's cairn-capture: run … line, so omitted=, recheck-omitted=, requests= and held-backlog= each shift one position right. Parsers keyed on field names are unaffected; positional parsers must update.
    • It is logged once when the window starts and once when it expires, not on every pass.
    • Exit status is unchanged (it was never a recurring refusal).
    • The fix(capture): defer a bound session its repo no longer routes to; --dry-run reads the binding #293 no-worker deferral is still refused=, unchanged.
  • --dry-run routes F1 as --run does. It reads f1_since read-only against its own clock and prints decision=deferred inside the window, and the base rule's answer after it.
  • Clock skew: a future-dated f1_since (stamped while the clock ran ahead) is restamped to now and persisted, so it cannot stretch the window (TestAFutureDatedF1StartIsRestampedToNow).
  • The worker's tombstone is unchanged.

What it guarantees, and the named residuals

  • Guaranteed: inside the window, a bound session ships nothing and withdraws nothing. So an F1 that clears within the window (the measured race clears within one pass) cannot flip the session into a 410 hold.
  • Cost: up to 1h of capture lag for a bound session while F1 holds. An opencode root is re-exported on each deferred pass, because nothing of it completed.
  • ⚠ Residual 1: the flip survives past the window. A session whose F1 stays live longer than 1h is moved by the base rule. A ledger line that later routes it back to the instance it left is refused 410 and the session is held, exactly as before. Pinned by TestF1PastTheWindowFallsBackToTheBaseRule.
  • ⚠ Residual 2: T3, pre-existing (the new-session path has it on the base too).
    • The pod's view-time F1 hides a session only while its ledger is empty (archive.Meta.LedgerScopes).
    • Once any ledger record lands, earlier output that had no ledger record of its own ships under the scope that later record names, whether deferred or not.
    • Output with no ledger record of its own means: a call whose ledger write was swallowed, or a call run with no session id in its environment (sudo, env -i, ssh). That includes the headerless verbs (transcript, routes, arcs, doctor).
    • Pinned by TestTheUnledgeredOutputResidualShipsUnderTheLaterScope.
  • Not rescued: sessions an older build already moved on F1. Nothing supported un-deletes a root on an instance: --clear-held keeps any hold that names an instance, and the archive's deletion journal has no route that removes an entry.

Red/green matrix

f1move_test.go reaches the new API only through f1seam_test.go (the repo_seam_test.go pattern). So it compiles unchanged on 1c529c5 with a base stand-in seam (not committed; it reports no window, no counter, and the base rule), and each test fails there on its own assertion.

test 1c529c5 HEAD
(a) TestF1DefersABoundSessionAndSoCannotFlipItIntoAHold: bound via the repo arm → 2 passes under F1 → the ledger line lands inside the window; ends bound to client, not held, 0 withdrawals, 0 probes, 0 records during F1, window cleared red: pass at +5m0s (F1 live, in the window): bound to "personal" green
(b) TestF1PastTheWindowFallsBackToTheBaseRule: deferred at window−1s; base move at expiry; expiry logged once; residual 1 pinned red (the base moves on the first F1 pass) green
(c) TestAClearedF1ResetsTheWindow red green
(d) TestTheF1WindowStartSurvivesAStateRoundTrip red green
(e) deferred= counts, not refused=, logged once (inside (a)); plus TestTheRunLinePrintsDeferred red green
TestADryRunPrintsRunsDecisionForABoundSessionUnderF1: deferred before and inside the window, ship:personal at its end, never writes f1_since red (ship:personal inside the window) green
TestF1DefersOnlyABoundSession: 5 bound+F1-in-window rows red green
↳ 2 expired-window rows red on the F1Lapsed flag only; the instance (personal) equals the base answer green
↳ 5 unbound+F1 and bound+!F1 rows (invariant guards) green green
TestTheUnledgeredOutputResidualShipsUnderTheLaterScope (a residual pin) red (the base moved the session, then held it) green

go test ./internal/capture/... ./cmd/cairn-capture/... was run on go 1.25.14 (the flake's dev shell). leakscan.py and --self-test both exit 0.

Mutation battery

mutant result: the specific failing assertion
window never expires killed: at expiry: bound to "client", … deferred=1 — want the base rule's move to personal; a fresh agent at the persisted window's end: deferred=1; the dry run prints decision=deferred at the window's end; both expired-window rows
window never starts (no defer) killed: pass at +5m0s (F1 live, in the window): bound to "personal" (12 failures)
f1_since not cleared when F1 clears killed: ledger landed: … f1_since 946782300 … want the window CLEARED; F1 false: f1_since 946782300 … want the window CLEARED
counter folded back into refused killed: deferred=0 refused=1 — want deferred=1 and NOT a refusal (6 tests)
window restarted every pass (start guard dropped) killed: pass at +10m0s: f1_since …, want the FIRST F1 pass's clock; the deferral was logged 3 times over two episodes, want once per episode (2)
future-dated f1_since not restamped (round 3) killed: a future-dated f1_since 946793100 was not restamped to now 946782600 — it stretches the window by the skew
F1Lapsed not cleared when F1 clears (round 3) killed: F1 false: f1_since 0, lapsed true … want BOTH cleared (TestASecondEpisodeLapsesAgain)
deferral applied to unbound sessions killed: the unbound, … rows get Deferred:true; #309's TestAnF1PassDoesNotFreezeStar* (17 failures)

🤖 Generated with Claude Code

ZacxDev and others added 2 commits November 12, 2026 21:19
F1 ("a tool input names the program and the read ledger is EMPTY this
run") reverts when the ledger line lands; a move does not. The instance a
session is withdrawn from keeps the withdrawal as a final deletion, so
routing a BOUND session on F1 made a two-pass flip that ended in a
permanent hold:

  1. a session the repo arm bound to the non-default instance (empty V)
     runs a `cairn` call. Claude Code writes the tool input to the
     transcript before the client appends its ledger line, so a pass
     landing in between sees F1, answers the default instance and moves
     the session there (`withdraw ... its routing answer changed`);
  2. the next pass reads the ledger line, whose scope routes back to the
     instance it was just withdrawn from; the probe answers 410 and the
     session is HELD on the default for good.

DecideRun now keeps a bound session where it is whenever the answer with
F1 or the answer without it names that instance; only when both leave it
does it move (to the answer with F1, as before). A new session is still
placed on the default by F1. Staying is safe for the bytes: a served call
appends its ledger line before it prints, so a pass that sees F1 over a
served call holds its input, not its output; a failed ledger write (T3)
is covered by the pod's own view-time F1.

--dry-run routed the derived V with F1's * in it as if recorded, which
forces the default; it now routes Declare + F1 through DecideRun, so it
prints --run's decision for a bound session under F1.

Red/green (tests copied onto 1c529c5's route.go/dryrun.go):
  TestF1DoesNotMoveABoundSessionAndSoCannotFlipItIntoAHold  red -> green
  TestF1CanOnlyKeepABoundSessionWhereItIs (2 regression rows) red -> green
  TestADryRunPrintsRunsDecisionForABoundSessionUnderF1      red -> green
The remaining table rows are invariant guards (green at both).

Mutants on the new guard: wrapper removed, alt returned unconditionally,
== Bound flipped, alt computed with F1 -> all killed; the dec==Bound and
Bound=="" short-circuits are equivalent mutants (same instance).

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

ZacxDev commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Round 0 (requirements & deletion) — verdict: requirement questioned (Q1). Ledger: round 0 · requirements: 6 (unattributed: 0; unattributed-unknown: 1) · deletion candidates: 1 · open premises: 1.

D1 — delete F1's placement of NEW sessions on the default instance (decideRun's `multi && f1` arm and the `len(v)==0 && !f1` repo-arm skip, plus the DecideRun wrapper): valid only if Q1 is answered "acceptable"
Q1 — When a bound session's ledger write fails (T3) and F1 stays live, this PR keeps its transcript on the NON-default instance owner-only, where before it moved to the DEFAULT instance owner-only — is that acceptable? · forcing: user

Operator answer to Q1: no — DEFER instead. While F1 is live, a bound session ships nothing and withdraws nothing (the existing deferred decision) and resumes when F1 clears. D1 is therefore moot (it was conditional on "acceptable"); new-session F1 placement is unchanged. The PR is being revised accordingly.

…ing it

Operator decision on #317: while F1 is live, a session already BOUND to an
instance ships nothing and withdraws nothing, through the existing
`deferred` decision (#293), and routes normally on the first pass where F1
is false. This replaces the "stay if either answer names the bound
instance" rule. New sessions keep F1's placement on the default, unchanged.

DecideRun: f1 && Bound != "" && multi-instance => Deferred, whatever either
answer would be (a hold included). One-instance hosts are exempt: F1
changes no answer there and there is nowhere to be withdrawn to, so a
deferral would only stall capture (removing the exemption reds 11 existing
one-instance tests). --dry-run already routes through DecideRun, so it
prints `decision=deferred`; --run counts it `refused=`, exit 0, as #293.

Comments/README/CHANGELOG now state exactly what defer guarantees (no ship
and no withdrawal while F1 is live, so no flip into a 410 hold) and the
pre-existing T3 residual it does NOT close: the pod's view-time F1 hides a
session only while its ledger is empty, so output with no ledger record of
its own ships under a LATER record's scope. Pinned as a known residual by
TestTheUnledgeredOutputResidualShipsUnderTheLaterScope.

Red/green (tests on 1c529c5's route.go/dryrun.go/agent.go):
  TestF1DefersABoundSessionAndSoCannotFlipItIntoAHold          red -> green
  TestADryRunPrintsRunsDecisionForABoundSessionUnderF1         red -> green
  TestF1DefersOnlyABoundSession: 5 bound+F1 rows               red -> green
                                 5 unbound+F1 / bound+!F1 rows green -> green
Mutants: arm removed, arm applied to unbound, arm ignoring F1, exemption
removed, reason without F1 -> all killed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev ZacxDev changed the title fix(capture): F1's one-run * never moves a bound session fix(capture): defer a bound session while F1 is live, so F1 cannot flip it into a 410 hold Nov 13, 2026
@ZacxDev

ZacxDev commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Operator's answer to round 0's Q1 (given in the authoring session, recorded here verbatim as the decision):

Q1=answered: no — DEFER instead of stay. While F1 is live, a bound session on a multi-instance host ships nothing and withdraws nothing (the existing `deferred` decision) and resumes when F1 clears; new-session F1 placement unchanged. Implemented in 15ddd9d.

@ZacxDev

ZacxDev commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Round 1 (nine axes) on 377ed84 — 🔴 0 · 🟡 1 · 🟢 0. The 🟡 (T3 coverage claim wider than the code) is addressed in 15ddd9d together with the operator-decided redesign; because the redesign changes behaviour, a delta round 2 runs on it.

1. DecideRun: a bound session under F1 on a multi-instance host is Deferred (no ship, no withdraw); the either-answer stay rule is removed
2. route.go/README/CHANGELOG/PR body narrowed: the T3 view-time claim holds only while the ledger is empty; the unledgered-output residual is named and pinned by a labelled test

@ZacxDev

ZacxDev commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Round 2 (delta 377ed84..15ddd9d) — 🔴 1 · 🟡 1 · 🟢 1. Prior: deferral-under-F1 = fixed as specified; r1 🟡 (T3 claim) = fixed.

  • 🔴 F1 is sticky (any tool input containing the program name; evidence restored every pass), so a bound session that never makes a ledgered call would be deferred forever — measured ~7% of sessions over 30 days on one workstation, most of their bytes after the first mention; docs called the stall temporary.
  • 🟡 deferral is counted inside refused=, logs every pass, and an opencode session re-exports every pass.
  • 🟢 no end-to-end opencode deferral test.

Operator re-decision on the 🔴: bounded defer — defer for at most a fixed window (1 h, persisted per session, reset when F1 clears), then fall back to the pre-#317 rule (move to the default instance). The 🟡 is being fixed in the same revision (deferred= counter, once-only log).

…e base rule

Audit round 2 on 15ddd9d: F1's evidence is sticky (any tool input naming
the program, restored every pass), so a bound session that never makes a
ledgered call was deferred forever, and the docs called that temporary.

Operator re-decision: a bound session on a multi-instance host under F1 is
deferred (no ship, no withdrawal) for at most F1DeferWindow = 1h, measured
from the first pass that saw F1 live while it was bound. The start is kept
per session as `f1_since` (unix seconds) in the state and cleared on any
pass where F1 is false, so a later episode gets a fresh window. Once the
window expires with F1 still live, DecideRun routes exactly as before
#317: F1's * forces the default instance, through the usual probe and
withdrawal. --dry-run reads `f1_since` read-only against its clock and
prints the same decision.

Round 2's yellow: an F1 deferral is no longer a refusal. It is counted on
a new run-line field `deferred=` (appended after `export-skipped=`, so no
field moved), logged once when the window starts and once when it expires,
and never fails a pass (exit status unchanged). The #293 no-worker
deferral is still `refused=`, unchanged.

Docs name two residuals: the flip into a 410 hold survives for a session
whose F1 outlives the window (pinned by
TestF1PastTheWindowFallsBackToTheBaseRule), and the pre-existing T3
residual (pinned by TestTheUnledgeredOutputResidualShipsUnderTheLaterScope).

f1seam_test.go follows repo_seam_test.go's pattern so f1move_test.go
compiles unchanged on 1c529c5 with a stand-in seam, and its tests fail
there on their own assertions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev ZacxDev changed the title fix(capture): defer a bound session while F1 is live, so F1 cannot flip it into a 410 hold fix(capture): defer a bound session under F1 for up to 1h, so F1 cannot flip it into a 410 hold Nov 13, 2026
@ZacxDev

ZacxDev commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author
1. F1 deferral of a bound session is bounded: 1 h window persisted as f1_since, cleared when F1 is false; after expiry the pre-#317 rule routes (move to default), logged once
2. F1 deferrals counted in a new deferred= run-line field (not refused=), logged once per episode; docs and CHANGELOG updated to match

@ZacxDev

ZacxDev commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Round 3 (delta 15ddd9d..51bfaf7) — 🔴 0 · 🟡 1 · 🟢 2. Ladder ends (no 🔴). Prior: r2 🔴 permanent deferral = fixed (1 h f1_since window, no flap after expiry, expiry is the pre-#317 move at most an hour later); r2 🟡 visibility = fixed. Open items being fixed un-re-audited before merge: 🟡 docs say no run-line field moved but deferred= shifts the four trailing fields; 🟢 future-dated f1_since extends the window (clamp); 🟢 F1Lapsed clear untested (surviving mutant).

1. (no fix this round) r2 🔴 permanent deferral: fixed by the 1 h f1_since window; r2 🟡 visibility: fixed (deferred= counter, once-only logs)
2. open 🟡: deferred= is inserted mid run line (omitted=/recheck-omitted=/requests=/held-backlog= shift); docs say no field moved
3. open 🟢: future-dated f1_since extends the window; F1Lapsed clear untested (surviving mutant)

… skew, F1Lapsed guard)

- The run-line claim is now true: `deferred=` is INSERTED after
  `export-skipped=`, which is mid-line on `--run`'s `cairn-capture: run …`
  line, so `omitted=`, `recheck-omitted=`, `requests=` and `held-backlog=`
  each shift one position right. Name-keyed parsers are unaffected;
  positional ones must update. Corrected in CHANGELOG, the capture README
  and the Summary comments. The field does not move.
- Clock skew: a future-dated `f1_since` (stamped while the clock ran ahead)
  is restamped to now and persisted, so it can no longer stretch the window
  by the skew. TestAFutureDatedF1StartIsRestampedToNow is red without the
  restamp ("a future-dated f1_since … was not restamped to now") and green
  with it. No clamp is needed in the window predicate: a future start is
  "not expired" either way, so `--dry-run` already agrees.
- Surviving mutant killed: TestASecondEpisodeLapsesAgain asserts that
  F1Lapsed clears along with f1_since when F1 clears, and that a second
  lapsed episode's expiry is logged again.
- The literal pin's name matches route.go again
  (TestTheF1DeferWindowIsTheOperatorsDecision).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev
ZacxDev marked this pull request as ready for review November 13, 2026 04:25
@ZacxDev
ZacxDev merged commit 455ef1a into main Nov 13, 2026
29 checks passed
@ZacxDev
ZacxDev deleted the fix/capture-f1-never-moves-a-bound-session branch November 13, 2026 04:50
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