Skip to content

fix(kiloclaw): expire stale checkout sessions instead of rejecting#1208

Merged
jeanduplessis merged 6 commits intomainfrom
fix/kiloclaw-expire-stale-checkout-sessions
Mar 18, 2026
Merged

fix(kiloclaw): expire stale checkout sessions instead of rejecting#1208
jeanduplessis merged 6 commits intomainfrom
fix/kiloclaw-expire-stale-checkout-sessions

Conversation

@jeanduplessis
Copy link
Copy Markdown
Contributor

@jeanduplessis jeanduplessis commented Mar 18, 2026

Summary

  • Previously, users who abandoned a KiloClaw checkout were permanently blocked from starting a new one ("A checkout is already in progress") until the Stripe session expired naturally.
  • Now the createSubscriptionCheckout endpoint expires any stale open KiloClaw checkout sessions before creating a new one, allowing users to retry seamlessly.
  • Updated the billing spec (.specs/kiloclaw-billing.md) with requirement 9 to document this behavior.

Verification

  • pnpm test -- src/routers/kiloclaw-billing-router.test.ts — 25/25 tests passed
  • pnpm typecheck — passed (pre-existing unrelated failure in collapsible.tsx)

Visual Changes

N/A

Reviewer Notes

  • The Promise.all on stripe.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.
  • Only sessions with metadata.type === 'kiloclaw' are expired; other open checkout sessions are untouched.

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.
Comment thread src/routers/kiloclaw-router.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 18, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
src/routers/kiloclaw-router.ts 1174 Swallowing every checkout.sessions.expire() failure masks sessions that completed after the initial Stripe subscription check, so this path can still create a fresh Checkout Session for a customer who already has a new KiloClaw subscription.
Other Observations (not in diff)

N/A

Files Reviewed (3 files)
  • .specs/kiloclaw-billing.md - 0 issues
  • src/routers/kiloclaw-billing-router.test.ts - 0 issues
  • src/routers/kiloclaw-router.ts - 1 issue

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.
Comment thread src/routers/kiloclaw-router.ts Outdated
…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.
Comment thread src/routers/kiloclaw-router.ts Outdated
…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.
Comment thread src/routers/kiloclaw-router.ts Outdated
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.
Copy link
Copy Markdown
Contributor

@pandemicsyn pandemicsyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@jeanduplessis jeanduplessis merged commit 631b091 into main Mar 18, 2026
18 checks passed
@jeanduplessis jeanduplessis deleted the fix/kiloclaw-expire-stale-checkout-sessions branch March 18, 2026 14:44
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