fix(chat): show revert after network_error - #7983
Conversation
…tored agent selections opencode <=1.18 writes ESC ]0;<cwd>: ready BEL to stdout for every non-help command even when stdout is a pipe (agent list, models --verbose, debug skill). T3's ChildProcessSpawner captures that stdout via collectStreamAsString and the parsers stored a polluted agent id like "\x1b]0;imbios: ready\x07build" in model_selection_json. Later sendTurn used that polluted id and opencode rejected it with "Agent not found: \"\x1b]0;imbios: ready\x07build\"" which was surfaced as session.error UnknownError + a generic SessionPrompt UnknownError wrapper (the stack the user pasted). Fix: - packages/shared/src/stripTerminalEscapes.ts: shared OSC/CSI sanitizer - apps/server/src/provider/opencodeRuntime.ts: strip before parseModels/Agent/Skills and via parse* entry points; keeps skills from silently degrading to [] when polluted - apps/server/src/provider/Layers/OpenCodeProvider.ts: sanitize inventory agent names/variants and --version parsing; build clean capability option ids - apps/server/src/provider/Layers/OpenCodeAdapter.ts & textGeneration/OpenCodeTextGeneration.ts: sanitize stored getModelSelectionStringOptionValue values before promptAsync - packages/shared/src/model.ts: sanitize persisted option values and model slugs on read (repairs 3 polluted threads without DB migration) - tests: add OSC/ANSI regression cases for both parsers Polluted threads still read as clean via model.ts sanitizer; no migration needed but DB can be cleaned with stripTerminalEscapes. Fixes the reported UnknownError at SessionPrompt.createUserMessage and the earlier "Agent not found" session.error.
When provider fails with finish_reason network_error the failed turn
still creates a checkpoint (status error) but has no assistant_message
or a synthetic assistant:${turnId} id that never appears in
timelineEntries. The revertTurnCount derivation only scanned assistant
messages, so the last user row showed only copy.
Add fallback: map nth user message to nth checkpoint sorted by
completedAt, preserving existing assistant-message scan.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
Note 🤖 GPT-5.6 Sol responding on behalf of Theo We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together. Closing this version because it pairs user messages and checkpoints by list position. A steered or interrupted turn can have a different number of each, so it can target the wrong restore point. Issue #7982 remains the bug report. The OpenCode cleanup included here is also covered by #7755, which remains open. The Revert fix needs an explicit message-to-turn checkpoint mapping. If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed. If GitHub does not let you reopen it, leave a comment here and we'll take another look. |
Fixes #7982
When provider fails with finish_reason network_error the failed turn still creates a checkpoint (status error) but has no assistant_message or a synthetic id that never appears in timelineEntries. The revert derivation only scanned assistant messages, so last user row showed only copy.
Add fallback: map nth user message to nth checkpoint sorted by completedAt, preserving existing scan.
Managed via forkhub patch fix-chat-show-revert-after-network-error-vq3yckjy.
Note
Fix revert indicator after
network_errorand sanitize terminal escapes from CLI outputstripTerminalEscapesandsanitizeTerminalValueutilities in stripTerminalEscapes.ts to remove OSC, ANSI CSI, charset, and single-char ESC sequences from stringsnetwork_error)sanitizeTerminalValueis now applied to all string option values viagetProviderOptionStringSelectionValueandtrimOrNull; any caller relying on raw escape sequences in those fields will see them strippedMacroscope summarized aae06e7.