Skip to content

fix(ai): preserve numeric status field in RUN_ERROR payloads - #985

Open
jan-kubica wants to merge 1 commit into
TanStack:mainfrom
jan-kubica:fix/run-error-preserve-numeric-status
Open

fix(ai): preserve numeric status field in RUN_ERROR payloads#985
jan-kubica wants to merge 1 commit into
TanStack:mainfrom
jan-kubica:fix/run-error-preserve-numeric-status

Conversation

@jan-kubica

@jan-kubica jan-kubica commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

toRunErrorPayload dropped the HTTP status for SDK error classes that report it only as a numeric status field with no code (e.g. Google's @google/genai ApiError), leaving RUN_ERROR events with code: undefined and making 401/403/404/429 indistinguishable from unknown failures. Fall back to a numeric status when no code is present; ignore a string status (reason phrase / symbolic status) so only the numeric HTTP code is forwarded.

🎯 Changes

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Error payloads now preserve numeric status codes when an explicit error code is unavailable.
    • Explicit error codes continue to take precedence.
    • String-based statuses are ignored to prevent invalid error codes.
    • Improved handling of API errors with JSON-formatted messages.

toRunErrorPayload dropped the HTTP status for SDK error classes that report
it only as a numeric `status` field with no `code` (e.g. Google's
@google/genai ApiError), leaving RUN_ERROR events with code: undefined and
making 401/403/404/429 indistinguishable from unknown failures. Fall back to
a numeric `status` when no `code` is present; ignore a string `status`
(reason phrase / symbolic status) so only the numeric HTTP code is forwarded.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0e4cbaca-f108-40e5-8723-5f9615c16aeb

📥 Commits

Reviewing files that changed from the base of the PR and between 50d7a7d and b55ce89.

📒 Files selected for processing (3)
  • .changeset/run-error-numeric-status.md
  • packages/ai/src/activities/error-payload.ts
  • packages/ai/tests/error-payload.test.ts

📝 Walkthrough

Walkthrough

toRunErrorPayload now uses numeric status values as fallback error codes when code is absent. Explicit codes remain preferred, string statuses remain ignored, and provider messages remain unchanged.

Changes

Error payload status handling

Layer / File(s) Summary
Extract and wire numeric error codes
packages/ai/src/activities/error-payload.ts
Adds extractCode and uses it for Error instances and generic objects. Numeric status values provide fallback codes, while explicit code values take precedence.
Validate and document fallback behavior
packages/ai/tests/error-payload.test.ts, .changeset/run-error-numeric-status.md
Tests cover numeric statuses, explicit code precedence, ignored string statuses, and @google/genai messages. The changeset documents the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: tombeckenham

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: preserving numeric status values in RUN_ERROR payloads.
Description check ✅ Passed The description explains the change, motivation, testing, contributing-guide compliance, and changeset status.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@jan-kubica
jan-kubica marked this pull request as ready for review August 7, 2026 16:09
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