Skip to content

fix(commandcode): retry on transient stream error and avoid fake stop chunks - #4130

Closed
Christian-Gennari wants to merge 1 commit into
decolua:masterfrom
Christian-Gennari:fix/commandcode-network-lost-retry
Closed

Christian-Gennari wants to merge 1 commit into
decolua:masterfrom
Christian-Gennari:fix/commandcode-network-lost-retry

Conversation

@Christian-Gennari

@Christian-Gennari Christian-Gennari commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4129

Summary

Improves CommandCode upstream reliability by automatically retrying transient server connection drops, preventing mid-stream errors from emitting fake stop chunks to clients, and ensuring assistant turns with tool calls pass reasoning blocks.

To be clear, the primary root cause for the connection drops is upstream instability on CommandCode's own infrastructure (tracked in CommandCodeAI/command-code#597). This PR provides defensive resiliency on 9Router's side so downstream clients do not experience interrupted turns while CommandCode resolves their backend stability.

Details

  • Automatic retry on initial drops: CommandCodeExecutor.execute() retries upstream up to 2 times with backoff when inspectAndWrapCommandCodeResponse returns 502/503/504 status codes.
  • Mid-stream error termination: commandcode-to-openai.js now throws on upstream error events instead of emitting [CommandCode error: ...] followed by finish_reason: "stop", preventing clients from treating server disconnects as valid completions.
  • Reasoning block in assistant requests: openai-to-commandcode.js includes reasoning blocks for assistant messages with tool calls or thought content to comply with upstream thinking mode expectations.
  • Tests: Extended tests/unit/commandcode-executor.test.js to verify retry recovery and status handling.

@decolua

decolua commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Thanks @Christian-Gennari for the contribution! Reviewed and merged into master. 🙏

@decolua decolua closed this Sep 18, 2026
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.

CommandCode provider: retry transient network drops and prevent fake stop chunks

2 participants