Skip to content

fix(copilot): keep a file-preview failure from stripping a tool call's arguments - #6621

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/copilot-workspace-file-tool-args
Aug 12, 2026
Merged

fix(copilot): keep a file-preview failure from stripping a tool call's arguments#6621
waleedlatif1 merged 1 commit into
stagingfrom
fix/copilot-workspace-file-tool-args

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The workspace file preview adapter runs while the workspace_file tool-call frame is still on the wire, before per-call dispatch builds a call-scoped context — so the execution context it receives is turn-scoped and carries no toolCallId. The file delegation requires one, so resolving a path-shaped preview target threw on every call.
  • The SSE handler swallows a handler throw and moves to the next event, which abandoned the rest of that event. The tool-call frame therefore never registered its arguments, and the call was later dispatched from the checkpoint with an empty payload — failing schema validation with every required property missing. The model got back an opaque error and retried the same call over and over, so the requested file edit never happened.
  • Fix: bind the frame's own tool call id before entering the file use cases; resolve the preview target best effort (matching how the preview base load already degrades); and stop a preview failure from dropping a tool-call frame in the stream loop.
  • The stream fixtures put a synthetic toolCallId on a turn-scoped context, a shape the chat lifecycle never produces — that is why the tests stayed green. Removed, so they now exercise the real shape.

Known-remaining, deliberately out of scope: prePersistClientExecutableToolCall sits in the same window before the frame registers its arguments and is likewise unguarded. It must not get the same swallow — it is where a gated call is stamped awaiting_approval, so swallowing there would let a gated tool through ungated. The structural answer is to register frame state before the presentation and persistence stages, which reorders emissions the client depends on.

Type of Change

  • Bug fix

Testing

bun run type-check and bunx vitest run lib/copilot/request/go/ in apps/sim (27 passing). Reverting only the two source files turns 4 of them red, including the exact error string seen in production.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…s arguments

The workspace file preview adapter runs while the tool-call frame is still
on the wire, so the execution context it gets is turn-scoped and carries no
toolCallId — the file delegation requires one, so resolving a path target
threw on every call. The SSE handler swallows that throw and abandons the
rest of the event, so the frame never registered its arguments and the call
was later dispatched with an empty payload, failing schema validation.

- bind the frame's own tool call id before entering the file use cases
- resolve the preview target best effort, matching the preview base load
- stop a preview failure from dropping the tool-call frame in the stream loop
- drop the synthetic toolCallId the stream fixtures put on a turn context
@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 12, 2026 12:36pm

Request Review

@cursor

cursor Bot commented Aug 12, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches the copilot SSE stream loop and tool-call registration path, so a mistaken swallow could hide real failures—but the change is narrowly scoped to presentation-only preview handling.

Overview
Prevents a file-preview adapter failure from dropping workspace_file tool-call arguments during streaming.

The adapter now binds the frame's toolCallId onto the turn-scoped execution context before resolving path targets or loading preview bases, and treats path resolution as best-effort (log + keep the path target on failure). The stream loop also isolates preview processing in a try/catch so a presentation error no longer abandons the rest of the event and later dispatches the call with an empty payload.

Tests now use the real turn-scoped context shape (no synthetic toolCallId) and cover successful binding plus non-throwing resolution failure.

Reviewed by Cursor Bugbot for commit b7a3e4d. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR prevents workspace-file preview failures from discarding the underlying streamed tool-call frame.

  • Binds preview file operations to the tool-call ID carried by the current frame.
  • Makes path-to-file preview resolution best effort.
  • Isolates preview-adapter errors so normal tool-call registration and dispatch continue.
  • Updates stream fixtures and adds regression coverage for turn-scoped execution contexts.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issues identified.

The changed error boundaries preserve the original tool-call frame after presentation failures, while call identity is supplied only to preview-related file operations and regression tests cover the production context shape.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/request/go/file-preview-adapter.ts Binds streamed call identity to preview file operations and degrades target resolution without aborting the tool frame.
apps/sim/lib/copilot/request/go/stream.ts Contains preview-processing failures while preserving subsequent persistence, event forwarding, and dispatch.
apps/sim/lib/copilot/request/go/file-preview-adapter.test.ts Adds coverage for call-scoped identity binding and failed path resolution.
apps/sim/lib/copilot/request/go/stream.test.ts Aligns stream fixtures with the lifecycle's turn-scoped execution-context shape.

Sequence Diagram

sequenceDiagram
  participant M as Mothership
  participant S as Stream loop
  participant P as File preview adapter
  participant F as File use case
  participant H as Tool event handler
  M->>S: workspace_file call frame
  S->>P: Process preview with turn context
  P->>P: Bind frame toolCallId
  P->>F: Resolve preview target
  alt Resolution succeeds
    F-->>P: Matching workspace file
    P-->>S: Resolved preview target
  else Resolution or preview fails
    F--xP: Error
    P-->>S: Preserve path target or throw
    S->>S: Log preview failure
  end
  S->>H: Persist and register original frame
  H-->>S: Arguments retained for dispatch
Loading

Reviews (1): Last reviewed commit: "fix(copilot): keep a file-preview failur..." | Re-trigger Greptile

@waleedlatif1
waleedlatif1 merged commit 0c4fb13 into staging Aug 12, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/copilot-workspace-file-tool-args branch August 12, 2026 16:01
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