Ask before switching while sessions are live, and recover the ones already broken
Acts on docs/incident-mode-switch-corrupts-live-sessions.md, which is added here as the record of why. The report identifies a consequence that was not modelled. A failed call is recoverable; a *successful* one may not be. If a running session takes even one completion from the provider being switched to - which happens when that mode matches the base URL it already had cached - that provider's message-id format lands in its transcript. OpenRouter issues `gen-<epoch>-<rand>` where Anthropic issues `msg_...`, and native Anthropic then refuses to resume the session at all, with a 400 naming previous_message_id. The only way back is to truncate the transcript, losing every turn after the cut. That happened here, and was fixed by hand. Two changes follow. Sessions are now settled before the write, not reported after it. A switch with anything running stops, names the sessions, explains what is about to happen to them, and offers restart (the only answer that ends with everything on the mode the bar now claims), close, proceed anyway, or abort - defaulting to abort. Non-interactively it refuses outright unless given --yes. The old after-the-fact reporter is deleted rather than left as a second, contradictory account. `claude-mode repair-session` replaces the hand surgery: it finds a project's transcripts, reports which are resumable, and on --apply backs the file up and truncates to the last Anthropic-issued message. Verified against the real corrupted transcript from the incident - it reproduces the manual cut exactly, 1921 lines to 1813, dropping the two `gen-` completions and the error placeholders after them, leaving a transcript that ends on a genuine msg_ id. It refuses a transcript written to in the last 90 seconds, since that one belongs to a session still running. The panel passes --yes, having already asked in its own card, and that card now names the transcript risk rather than only the inconvenient one. Requirement 4 of the report - documenting the mechanism - landed in 9c301e1; the README now carries the unrecoverable half as well.
This commit is contained in:
@@ -220,8 +220,11 @@ Panel {
|
||||
root.busy = true
|
||||
root.stage = "list"
|
||||
switchProc.sessionAction = sessionAction
|
||||
// --yes because the confirmation already happened, in the card above. The
|
||||
// CLI now refuses a non-interactive switch while sessions are running, and
|
||||
// without this the panel's switch would simply stop working.
|
||||
switchProc.command = root.cli(root.pendingPreset === ""
|
||||
? [root.pendingMode] : [root.pendingMode, root.pendingPreset])
|
||||
? [root.pendingMode, "--yes"] : [root.pendingMode, root.pendingPreset, "--yes"])
|
||||
switchProc.running = true
|
||||
}
|
||||
|
||||
@@ -875,8 +878,9 @@ Panel {
|
||||
Text {
|
||||
width: parent.width
|
||||
text: "They keep pointing at " + Modes.title(root.mode) + ", but their key is "
|
||||
+ "re-fetched on a timer and will switch under them. Their calls start "
|
||||
+ "failing from that moment, not at a clean stop."
|
||||
+ "re-fetched on a timer and will switch under them. Worse, if one takes a "
|
||||
+ "reply from the new provider first, that provider's message-id format "
|
||||
+ "goes into its transcript and Anthropic will refuse to resume it at all."
|
||||
color: Color.muted
|
||||
wrapMode: Text.WordWrap
|
||||
lineHeight: 1.2
|
||||
@@ -950,6 +954,8 @@ Panel {
|
||||
width: parent.width
|
||||
spacing: Style.space(7)
|
||||
|
||||
// Restart is the only option that ends with every session on the mode
|
||||
// the bar is now claiming, so it leads and it is the primary.
|
||||
PillButton {
|
||||
label: "Switch and restart"
|
||||
primary: true
|
||||
|
||||
Reference in New Issue
Block a user