Promote test → main#565
Conversation
- Implemented a new PATCH endpoint for updating a session's title or status, allowing optional fields to be modified. - Authenticates requests using a Privy Bearer token or x-api-key header. - Added comprehensive tests for the PATCH handler, covering scenarios such as unauthorized access, session not found, and successful updates. This enhancement improves the API's functionality by enabling users to modify session details dynamically.
- Implemented tests for the GET and PATCH session API endpoints to handle scenarios where the database returns an error, ensuring a 500 status response with appropriate error messages. - Updated the `selectSessions` function to return `null` on database errors, allowing for better error handling in the API responses. - Enhanced existing tests to verify that the API correctly responds to internal server errors, improving overall robustness and reliability of the session management functionality.
- Updated the `selectSessions` function calls in `clearLifecycleRunIdIfOwned`, `computeLifecycleWakeDecision`, and `evaluateSandboxLifecycle` to handle potential database errors more gracefully. - Added console error logging in `clearLifecycleRunIdIfOwned` for better debugging. - Enhanced return values in `computeLifecycleWakeDecision` and `evaluateSandboxLifecycle` to provide clearer failure reasons when session queries fail. These changes enhance the robustness of session management by ensuring that errors are properly logged and handled.
- Enhanced error handling in the `evaluateSandboxLifecycle` function by ensuring that an error is thrown with a clear message when session refresh fails during lifecycle extension checks. This change improves the robustness of session management by providing better feedback in case of failures.
…nal status values and line counters - Updated the API documentation to reflect the new optional fields for line counters and expanded status options (running, completed, failed, archived). - Modified the patchSessionByIdHandler to handle updates for linesAdded and linesRemoved, returning a 200 status when no updates are provided. - Added tests to ensure correct handling of new status values and line counter mappings in the session update process.
* fix(stripe): fall back to Checkout for any card-level off-session error Surfaced during open-agents preview UI testing of #559: an off-session charge against an account that has a card on file but where Stripe returned a non-authentication_required error (declined / fraud check / expired / invalid request) bubbled out as a 500 instead of falling through to Checkout. Before: only StripeCardError with code === "authentication_required" returned kind: "requires_action". Everything else rethrew → handler returned 500 → UI showed "Couldn't create a checkout session". After: any StripeCardError or StripeInvalidRequestError returns kind: "requires_action" so the caller falls back to a Stripe Checkout Session — the customer can update the card, complete 3DS, or pick a different payment method interactively. Only genuinely unexpected errors (network, our own bugs) still bubble as 500. Tests: existing 9 cases plus a parameterized check across 4 common card error codes plus an InvalidRequestError case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(stripe): surface Stripe decline reason in the API response Per real-world finding: when an off-session charge fails with insufficient_funds / card_declined / expired_card / etc., the API was silently falling through to Checkout with no signal of why. UI and LLM-driven callers couldn't tell their human "your card has insufficient funds" — they just saw a new Checkout URL. Adds optional declineReason to the Checkout-fallback response shape: { id: "cs_…", url: "…", declineReason: { code: "card_declined", // Stripe error code declineCode: "insufficient_funds", // Stripe decline_code on card errors message: "Your card has insufficient funds." } } declineReason is omitted when fallback is from no_payment_method (no prior off-session attempt was made), so fresh users still see the clean { id, url } shape. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(stripe): narrow Stripe errors via instanceof, drop ad-hoc cast DRY: reuse Stripe SDK's typed error classes (StripeCardError / StripeInvalidRequestError) instead of defining our own structural type to read `type`, `code`, `decline_code`, `message`. TypeScript narrows each branch automatically; `decline_code` is only accessed on the StripeCardError branch where the SDK guarantees it. Tests updated to construct real Stripe error instances with the StripeCardError / StripeInvalidRequestError constructors so the `instanceof` path is what's exercised — the previous plain-object fixtures relied on duck-typing that no longer matches the impl. Addresses CodeRabbit nitpick on PR #561. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…d JSON body - Added a new utility function to read and validate the JSON body of PATCH requests, returning an empty object for empty bodies and a 400 error for malformed JSON. - Updated the test suite to include a case for handling malformed JSON, ensuring the API responds correctly with a 400 status and an appropriate error message. - Adjusted the validation logic in `validatePatchSessionBody` to utilize the new JSON reading function, improving error handling for invalid input.
feat(api): add PATCH handler for updating session details
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (15)
📝 WalkthroughWalkthroughThe PR implements a new ChangesSession PATCH & Error-Handling Contract Propagation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Routine promotion of
testtomain.Notable items:
PATCH /api/sessions/{sessionId}— manually smoke-tested on preview (17 cases, see PR comment); two doc-divergences flagged (pathon validation 400s,messagevserroron bogus-Bearer 401)selectSessionsnow returnsnullon DB error so callers can distinguish "DB down" from "no rows" (PATCH/GET handlers return 500)This will be back-synced into
testafter merge.Summary by cubic
Promotes
testtomainwith a new PATCH session endpoint and stronger DB error handling across session APIs and sandbox workflows. Adds support to update session title, status, and optional line counters.New Features
PATCH /api/sessions/{sessionId}to updatetitle,status(running|completed|failed|archived),linesAdded, andlinesRemoved; all optional.x-api-key. Returns 404 when missing, 403 when not owned, 400 on malformed/invalid body, and 200 with no-op when body has no updates.Bug Fixes
selectSessionsnow returnsnullon DB errors; GET/PATCH handlers return 500 instead of treating as no rows.pathfield; bad Bearer 401 useserrorinstead ofmessage.Written for commit 3cb13d6. Summary will update on new commits.
Summary by CodeRabbit
New Features
Bug Fixes