Skip to content

fix(harness): don't re-stamp model metadata on a sandbox continuation - #6165

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/dispatch-continuation-no-duplicate-model-stamp-w4
Open

fix(harness): don't re-stamp model metadata on a sandbox continuation#6165
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/dispatch-continuation-no-duplicate-model-stamp-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Follows #6151, which added withModelMetadata to stamp metadata.models.thinking onto the claude-code harness's first start chunk (mirroring what Decopilot already does).

Bug: sandbox-dispatch-client.ts's dispatchOnce wraps every dispatch attempt — including sandbox-lost continuations — in withModelMetadata, and each call gets a fresh generator whose internal stamped flag resets to false. dispatchWithContinuation already drops a continuation's start chunk (documented: forwarding a second one would re-id the message), but it does NOT know about the message-metadata chunk withModelMetadata yields right after start — so a run that survives a sandbox-lost retry gets a second, redundant message-metadata chunk spliced into an already-open message. Harmless when the model id is unchanged, but it's dead weight on every continuation and a landmine if a retry ever picks a different model.

Fix: pass null for the model id on a continuation attempt (resume ? null : modelEnv.CLAUDE_CODE_MODEL) so withModelMetadata no-ops, consistent with dispatchWithContinuation already treating a continuation's start as a no-op.

Verify: bun test apps/api/src/harnesses/sandbox-dispatch-client.test.ts — added a regression test (a continuation does not re-stamp model metadata) composing dispatchWithContinuation + withModelMetadata the same way the real dispatch path does, asserting exactly one message-metadata chunk survives a sandbox-lost retry. Also ran apps/api/src/harnesses/with-model-metadata.test.ts (unchanged, still green) and cd apps/api && bunx tsc --noEmit.

Locally ran: bun run fmt, bunx tsc --noEmit (apps/api), the two targeted test files, bunx oxlint on both changed files. Full CI covers the rest.


Summary by cubic

Prevent duplicate model metadata on sandbox continuation retries. Previously, a continuation emitted a second message-metadata chunk because dispatchOnce always wrapped attempts in withModelMetadata; downstream dropped the second start but not the metadata. Now, continuation attempts pass null as the model id so withModelMetadata no-ops, matching how the continuation’s start is suppressed and avoiding mismatched model ids.

  • Changes: in sandbox-dispatch-client.ts, pass resume ? null : modelEnv.CLAUDE_CODE_MODEL into withModelMetadata.
  • Behavior: first attempt still stamps metadata; continuations no longer add another message-metadata chunk.
  • Tests: adds a regression test asserting exactly one message-metadata survives a sandbox-lost retry.

Written for commit 5d27e27. Summary will update on new commits.

Review in cubic

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.

1 participant