Skip to content

fix(chat): show revert after network_error - #7983

Draft
ImBIOS wants to merge 3 commits into
pingdotgg:mainfrom
ImBIOS:fix-chat-show-revert-after-network-error
Draft

fix(chat): show revert after network_error#7983
ImBIOS wants to merge 3 commits into
pingdotgg:mainfrom
ImBIOS:fix-chat-show-revert-after-network-error

Conversation

@ImBIOS

@ImBIOS ImBIOS commented Aug 23, 2026

Copy link
Copy Markdown

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_error and sanitize terminal escapes from CLI output

  • Adds stripTerminalEscapes and sanitizeTerminalValue utilities in stripTerminalEscapes.ts to remove OSC, ANSI CSI, charset, and single-char ESC sequences from strings
  • Applies sanitization across OpenCode CLI parsers (opencodeRuntime.ts, OpenCodeProvider.ts, OpenCodeAdapter.ts) and shared model utilities so model/agent/variant IDs and version strings are parsed correctly even when stdout is polluted with escape sequences
  • Adds a chronological fallback in ChatView.tsx that maps user messages to turn diff summaries by completion time when direct assistant-message matching fails, so diff indicators still appear when the assistant turn is missing (e.g. after network_error)
  • Risk: sanitizeTerminalValue is now applied to all string option values via getProviderOptionStringSelectionValue and trimOrNull; any caller relying on raw escape sequences in those fields will see them stripped

Macroscope summarized aae06e7.

ImBIOS added 3 commits August 21, 2026 11:05
…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.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 655f9b21-469d-4eba-b25b-cbac6556f9b9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Provider finish_reason network_error hides revert button

1 participant