fix(kiloclaw): expire stale checkout sessions instead of rejecting#1208
Merged
jeanduplessis merged 6 commits intomainfrom Mar 18, 2026
Merged
fix(kiloclaw): expire stale checkout sessions instead of rejecting#1208jeanduplessis merged 6 commits intomainfrom
jeanduplessis merged 6 commits intomainfrom
Conversation
Previously, users who abandoned a KiloClaw checkout were blocked from starting a new one until the old session expired naturally. Now we expire stale open checkout sessions before creating a fresh one, letting users retry without manual intervention.
Contributor
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)WARNING
Other Observations (not in diff)N/A Files Reviewed (3 files)
Reviewed by gpt-5.4-20260305 · 192,922 tokens |
… calls Catch StripeInvalidRequestError when expiring stale checkout sessions so concurrent retry requests don't fail if another request already expired the same session.
…rors Catching all StripeInvalidRequestError was too broad — a session completed between list() and expire() would also throw this error type, silently allowing a duplicate checkout. Now only errors matching 'already expired' are swallowed; other reasons (e.g. session completed concurrently) propagate to prevent the duplicate-subscription race.
…ones After expiring stale checkout sessions, re-list open sessions to detect if a concurrent request created a new kiloclaw session in the interim. This closes the race where two requests both expire the same stale session and both proceed to create new checkout sessions.
Remove the re-check list() and narrow error matching — they added complexity without closing the TOCTOU race inherent in read-then-write against the Stripe API. Instead, swallow all expire() errors (the session is gone either way) and document that duplicate open sessions are tolerable since each requires independent user action and the subscription-level guard prevents real harm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
createSubscriptionCheckoutendpoint expires any stale open KiloClaw checkout sessions before creating a new one, allowing users to retry seamlessly..specs/kiloclaw-billing.md) with requirement 9 to document this behavior.Verification
pnpm test -- src/routers/kiloclaw-billing-router.test.ts— 25/25 tests passedpnpm typecheck— passed (pre-existing unrelated failure incollapsible.tsx)Visual Changes
N/A
Reviewer Notes
Promise.allonstripe.checkout.sessions.expire()will reject if any single expire call fails — this is intentional so the user gets an error rather than silently proceeding with a potentially conflicting session.metadata.type === 'kiloclaw'are expired; other open checkout sessions are untouched.