Files
magpie/docs
yetone 36c5ee1e6c claude: a run that ends during a turn keeps its session for the answer, retry or summary after (#6528)
When the Claude Code bridge ended a run in a turn the client still goes
on with (runTimeout on an AskUserQuestion, or letGo when the client went
away mid-reply), removeRun deleted its session file. The late answer,
the tunnel-drop retry and the delayed AgentSummary then found no run and
were told whole to a new Claude Code (recih: 118K and 305K written to
the cache again).

removeRun now keeps such a run (keepEnded, claude_ended.go) in the same
b.mu section that takes it out of runs, so no request in between finds
neither. The bounds: at most endedMost (16), each for endedLongest
(idleLongest, the cache hour), the oldest let go first, with its files
removed. Not kept: shelved, rewound, client cache marks, a handed-over
account, or anything at gateway stop (abortAll drops them all, and
sweepSessions takes what a crash leaves). branch and retryBranch look at
kept runs after live ones, latest first. Each branch cuts its own copy,
so the kept file is never written and the AgentSummary that comes after
a recovery still branches.

Real Claude Code 2.1.316 (mock Anthropic plus an MCP tool that never
answers, both -p and interactive): the text and tool_use lines are in
the jsonl ~30-60ms after the reply streams, and on SIGTERM only
cost-state lines are added, with no result and no interrupt marker. So
a cut after the call line is sound.

Run:
- New tests: TestClaudeAnswerAfterTheRunEndedBranchesOffItsKeptSession,
  TestClaudeEndedRunsSessionsAreBounded (time, count, stop, unkept),
  TestClaudeTurnSentAgainAfterItsRunEndedBranchesOffItsSession (real
  letGo through the interactive harness, -count=10).
- Broken by hand on mote: with keepable() returning false, the answer,
  count and retry tests went red; with (gone || !run.closed) put back to
  !run.closed, the answer and retry tests went red.
- gofmt -l clean. go vet -tags nogui ./... with GOOS=linux, GOOS=windows
  and darwin on mote: ok.
- Full suite, go test -tags nogui ./... -timeout 45m on mica at
  07ed85f97 (origin/main d21cb563e + this change): every package ok
  except the root package's TestNoEagerPackageRegexps
  (internal/davsync/setuptext.go:73). That red was on main and is
  fixed by 48e394146 (#6534). After rebasing onto it (this head): ., internal/davsync,
  internal/gui and internal/gateway ok.

Not tried: a real AskUserQuestion answer through a live magpie with a
real Claude account; the reporter's case is reproduced in tests with an
injected end (abortFor and a cancelled client).
2026-11-13 20:04:42 +08:00
..