test(release): verify user-facing error contracts#690
Conversation
📝 WalkthroughWalkthroughThe PR improves error handling in ChangesError Classification Enhancement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/runner/pkg/api/controllers/boxlite_exec.go`:
- Around line 238-255: The classifyExecError logic in boxlite_exec.go currently
maps several sdkboxlite error codes to HTTP statuses but misses
sdkboxlite.ErrSessionReaped; update the error switch inside classifyExecError
(the errors.As block that inspects *sdkboxlite.Error) to add a case for
sdkboxlite.ErrSessionReaped and return http.StatusGone (410); ensure you
reference the same bxErr variable and switch structure so all callers of
classifyExecError (Start, Signal, Kill, GetExecution, Resize) will correctly
return 410 instead of 500 for reaped sessions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8ac75ddb-c1ee-4eab-8322-9a8f62340012
📒 Files selected for processing (1)
apps/runner/pkg/api/controllers/boxlite_exec.go
| // Inspect typed boxlite SDK errors that don't have sentinel variants | ||
| // in the runner SDK wrapper. `ErrInvalidArgument` is the C-FFI shape | ||
| // for spawn-time validation failures the caller can fix. | ||
| var bxErr *sdkboxlite.Error | ||
| if errors.As(err, &bxErr) { | ||
| switch bxErr.Code { | ||
| case sdkboxlite.ErrInvalidArgument, sdkboxlite.ErrInvalidState: | ||
| return http.StatusBadRequest | ||
| case sdkboxlite.ErrNotFound: | ||
| return http.StatusNotFound | ||
| case sdkboxlite.ErrAlreadyExists: | ||
| return http.StatusConflict | ||
| case sdkboxlite.ErrUnsupported, sdkboxlite.ErrUnsupportedEngine: | ||
| return http.StatusNotImplemented | ||
| case sdkboxlite.ErrResourceExhausted: | ||
| return http.StatusTooManyRequests | ||
| } | ||
| } |
There was a problem hiding this comment.
Add mapping for ErrSessionReaped → HTTP 410 Gone.
The SDK defines ErrSessionReaped (code 21) with a documented server-side HTTP 410 status (see sdks/go/errors.go:39-42). Since classifyExecError is called by multiple endpoints beyond just Start() (Signal, Kill, GetExecution, Resize), it should comprehensively handle all SDK error codes with documented HTTP statuses to prevent returning 500 for this known client-facing scenario.
🔧 Proposed fix to add ErrSessionReaped mapping
var bxErr *sdkboxlite.Error
if errors.As(err, &bxErr) {
switch bxErr.Code {
case sdkboxlite.ErrInvalidArgument, sdkboxlite.ErrInvalidState:
return http.StatusBadRequest
case sdkboxlite.ErrNotFound:
return http.StatusNotFound
case sdkboxlite.ErrAlreadyExists:
return http.StatusConflict
case sdkboxlite.ErrUnsupported, sdkboxlite.ErrUnsupportedEngine:
return http.StatusNotImplemented
case sdkboxlite.ErrResourceExhausted:
return http.StatusTooManyRequests
+ case sdkboxlite.ErrSessionReaped:
+ return http.StatusGone
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Inspect typed boxlite SDK errors that don't have sentinel variants | |
| // in the runner SDK wrapper. `ErrInvalidArgument` is the C-FFI shape | |
| // for spawn-time validation failures the caller can fix. | |
| var bxErr *sdkboxlite.Error | |
| if errors.As(err, &bxErr) { | |
| switch bxErr.Code { | |
| case sdkboxlite.ErrInvalidArgument, sdkboxlite.ErrInvalidState: | |
| return http.StatusBadRequest | |
| case sdkboxlite.ErrNotFound: | |
| return http.StatusNotFound | |
| case sdkboxlite.ErrAlreadyExists: | |
| return http.StatusConflict | |
| case sdkboxlite.ErrUnsupported, sdkboxlite.ErrUnsupportedEngine: | |
| return http.StatusNotImplemented | |
| case sdkboxlite.ErrResourceExhausted: | |
| return http.StatusTooManyRequests | |
| } | |
| } | |
| // Inspect typed boxlite SDK errors that don't have sentinel variants | |
| // in the runner SDK wrapper. `ErrInvalidArgument` is the C-FFI shape | |
| // for spawn-time validation failures the caller can fix. | |
| var bxErr *sdkboxlite.Error | |
| if errors.As(err, &bxErr) { | |
| switch bxErr.Code { | |
| case sdkboxlite.ErrInvalidArgument, sdkboxlite.ErrInvalidState: | |
| return http.StatusBadRequest | |
| case sdkboxlite.ErrNotFound: | |
| return http.StatusNotFound | |
| case sdkboxlite.ErrAlreadyExists: | |
| return http.StatusConflict | |
| case sdkboxlite.ErrUnsupported, sdkboxlite.ErrUnsupportedEngine: | |
| return http.StatusNotImplemented | |
| case sdkboxlite.ErrResourceExhausted: | |
| return http.StatusTooManyRequests | |
| case sdkboxlite.ErrSessionReaped: | |
| return http.StatusGone | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/runner/pkg/api/controllers/boxlite_exec.go` around lines 238 - 255, The
classifyExecError logic in boxlite_exec.go currently maps several sdkboxlite
error codes to HTTP statuses but misses sdkboxlite.ErrSessionReaped; update the
error switch inside classifyExecError (the errors.As block that inspects
*sdkboxlite.Error) to add a case for sdkboxlite.ErrSessionReaped and return
http.StatusGone (410); ensure you reference the same bxErr variable and switch
structure so all callers of classifyExecError (Start, Signal, Kill,
GetExecution, Resize) will correctly return 410 instead of 500 for reaped
sessions.
e659bbf to
e071a53
Compare
📦 BoxLite review — couldn't completepowered by BoxLite |
e071a53 to
b880a76
Compare
Add a release gate for actionable create and exec errors across the API, CLI, Python, Node, Go, and C SDKs.
Test plan:
python3 -m py_compile scripts/test/e2e/run_error_contracts.pygit diff --checkmake test:e2e:error-contracts(18 passed, 3 expected xfailed, 0 skipped)