Skip to content

fix: Responses API cancel requests can still end as completed#789

Closed
sam-saffron-jarvis wants to merge 1 commit into
SamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-ec2bf5b0
Closed

fix: Responses API cancel requests can still end as completed#789
sam-saffron-jarvis wants to merge 1 commit into
SamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-ec2bf5b0

Conversation

@sam-saffron-jarvis

Copy link
Copy Markdown
Contributor

What changed

  • Updated responseRun.complete to give pending cancellation precedence over completion.
  • When a cancel request has already been recorded, the run now transitions to cancelled, emits response.cancelled, and strips completion-only usage fields from the terminal response payload.
  • Added a regression test covering the race where cancelRun() wins just before complete() finalizes the run.

Why this is high-value

This fixes a user-visible correctness bug in the Responses API: a client could successfully POST /cancel and still receive response.completed if generation had already finished but the final completion transition had not run yet. That made cancellation flaky on long-running web/API sessions, left the run snapshot looking successful, and could mislead reconnecting SSE clients.

Validation

  • gofmt -w cmd/serve_response_runs.go cmd/serve_response_runs_test.go
  • go build ./...
  • go test ./...
  • Added TestResponseRunCompleteHonorsPendingCancellation to verify cancellation wins over completion.
  • git diff --check

@SamSaffron

Copy link
Copy Markdown
Owner

Applied to the working tree locally (along with #789/#790/#791 as a combined cancellation-correctness pass); will land in a direct commit.

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.

2 participants