Skip to content

fix(kiro): release leases granted across request cancellation - #6377

Merged
lidge-jun merged 6 commits into
devfrom
fix/luvs01-685-lease-cancellation-20261001
Oct 1, 2026
Merged

lidge-jun merged 6 commits into
devfrom
fix/luvs01-685-lease-cancellation-20261001

Conversation

@luvs01

@luvs01 luvs01 commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A request abort could clear the active Kiro lease while later admission or credential recovery installed a replacement lease. Keep cancellation visible for the entire request, pass the abort signal into lease acquisition, and release any lease granted across the abort race before it can be installed or used. The focused regression observes the queued waiter, grants its lease, confirms that grant happened, and then aborts; it no longer relies on a sleep to hit the race.

Source history is preserved through commit 90186f5bc3a2769238553b04ae8692ca6cf1c969. The local validation below used the integration with dev at 0328373fb88fe0d019b29ae278e153d7fed4bcc7.

Verification

Current upstream integration: a6114b62ed1b65dede802359ccd373d913979b24; published HEAD badac2a859a8bc781605448f314f4f116be18db9. The source history through eae91d906560a8105e41fcdb307adcd076f7e964 is retained without rewriting authors or commits. The PR-specific change was checked again after this integration; typecheck, structure, privacy and file-size gates passed. Cross-platform CI succeeded for this exact HEAD; its checkout tree matches the published HEAD tree. Skipped jobs remain skipped.

Windows, Bun 1.4.0, isolated test temporary directory:

  • bun test tests/providers/kiro/kiro-leased-responses.test.ts --test-name-pattern "a lease granted as the request aborts is released instead of sending": 1 passed, 19 filtered, 0 failed, 8 assertions. The test supplies synthetic credentials, rejects credential refresh and adapter creation, makes catalog refresh a no-op, and makes any fetch throw. It asserts zero transport/refresh/fetch calls, a 499 result, and no remaining lease.
  • bun node_modules/typescript/bin/tsc --noEmit: passed.
  • bun scripts/structure-ssot.ts: passed.
  • bun scripts/privacy-scan.ts: passed.
  • bun scripts/file-size-ratchet.ts: passed.
  • git diff --cached --check 0328373fb88fe0d019b29ae278e153d7fed4bcc7: passed.

The full local suite, test:changed, and broad Kiro transport suites were not run under the focused-validation exception. The single regression deliberately blocks native transport, SOCKS, catalog network work, provider adapters, and real credentials. Live transport coverage remains outstanding. Exact-HEAD CI succeeded; results from another HEAD are not its verification.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Relevant contracts and regression coverage are recorded with the change.
  • Security-sensitive changes have independent maintainer review; sponsorship is required before merge where the sponsored-surface gate applies.
  • Author validation is documented for badac2a859a8bc781605448f314f4f116be18db9, known correct findings are addressed, and exact-HEAD CI is complete; author review readiness is confirmed.

Independent maintainer approval, explicit security review, and any required maintainer-sponsored decision remain pending before merge. These are separate from author review readiness; no approval or sponsorship is claimed.

Summary by CodeRabbit

  • Bug Fixes
    • Kiro requests cancelled during account admission or credential refresh now release any acquired account slot and stop before dispatching. Cancelled requests return a cancellation response instead of proceeding with a late lease.
  • Tests
    • Added coverage for cancellation during credential refresh and when an account slot is granted as cancellation occurs.
  • Documentation
    • Clarified Kiro account admission behavior when a request is cancelled before it resumes.

luvs01 and others added 6 commits September 29, 2026 02:02
…ssion

A capacity waiter can be granted between the holders cancellation cleanup and the lease install. Re-check the cancellation state after acquisition and release the grant so the request stops at the client-cancelled response instead of occupying the account slot until expiry.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (2)
src/AGENTS.md — auto-discovered
structure/AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: bacf276a-b668-4cd5-8b8c-8d983b9a298f

📥 Commits

Reviewing files that changed from the base of the PR and between a6114b6 and badac2a.

📒 Files selected for processing (7)
  • src/oauth/kiro-account-load.ts
  • src/server/responses/core-options.ts
  • src/server/responses/core.ts
  • src/server/responses/request-transport.ts
  • structure/runtime.md
  • structure/transports/responses.md
  • tests/providers/kiro/kiro-leased-responses.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Kiro Responses requests now track cancellation in the account-load holder and pass the request signal to lease acquisition. The transport releases leases when cancellation is detected. Tests cover cancellation during credential refresh and a queued lease grant.

Changes

Kiro lease cancellation

Layer / File(s) Summary
Cancellation state and lease lifecycle
src/server/responses/core-options.ts, src/server/responses/core.ts, structure/transports/responses.md
The account-load holder now includes a cancelled field. handleResponses initializes it from the request signal and marks it cancelled before releasing its lease. The documentation describes this lifecycle.
Signal-aware lease acquisition
src/oauth/kiro-account-load.ts, src/server/responses/request-transport.ts, structure/runtime.md
Kiro replay, failover, and initial admission pass the request signal to lease acquisition and check for cancellation. When cancellation applies, newly acquired leases are released. The test observer exposes queued lease setup. The runtime documentation describes cancellation after a slot grant.
Cancellation regression tests
tests/providers/kiro/kiro-leased-responses.test.ts
Tests cover abort during credential refresh and abort after a queued lease grant. They check lease cleanup and, for the queued-grant race, that refresh, adapter resolution, catalog refresh, and fetch do not occur.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant handleResponses
  participant KiroAccountLoadQueue
  participant requestTransport
  Client->>handleResponses: abort request
  handleResponses->>handleResponses: mark account load cancelled and release lease
  KiroAccountLoadQueue-->>requestTransport: grant queued lease
  requestTransport->>requestTransport: detect cancellation and release lease
  requestTransport-->>Client: return client-cancelled response
Loading

Merge Risk: ⚪ Minimal · up to badac

The change releases leases when cancellation wins and prevents cancelled queued requests from dispatching. No actionable merge-blocking risk is established; merge after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to badac

The change strengthens cancellation handling and prevents late leases from enabling unwanted request work. No new security weakness was identified in the reviewed paths, but live-provider behavior and deployment-wide effects remain unvalidated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected resource is process-local serving capacity keyed by provider and account. Lease cleanup can therefore affect other queued requests sharing that account; the inspected changes do not introduce a new credential authority or cross-service dependency.

Trust Boundaries and Controls

  • observed — Request interruption supplies cancellation, not account identity or credential authority. The handler creates the holder internally, existing OAuth selection remains authoritative for the serving account, and cancellation checks prevent late lease installation before downstream admission work.

Resilience and Maintainability Implications

  • observed — Cancellation fencing does not imply that an already-running credential refresh is interrupted. The refresh regression instead asserts that no account lease remains immediately after abort or after delayed refresh completes; its expected terminal response is 401 rather than the queued-admission case’s 499.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: releasing Kiro account leases that are granted during request cancellation races.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 1, 2026
@luvs01
luvs01 marked this pull request as ready for review October 1, 2026 09:18
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Scoped cancellation/resource-lifecycle review at badac2a. The persistent cancelled bit and post-await signal checks prevent the original holder cleanup from losing a subsequently granted lease; the observed real handoff test does not depend on a timing sleep. My isolated Bun 1.4.0 run of tests/providers/kiro/kiro-leased-responses.test.ts --test-name-pattern "^a lease granted as the request aborts is released instead of sending$" passed 1 test / 8 assertions (19 filtered) under CPUQuota=75%, MemoryMax=1536M with fresh homes. It proves grant-before-abort, 499, zero remaining lease, and no adapter/refresh/catalog/fetch work in that fixture. I did not run the broad transport suite or the separate credential-recovery case, and this is not live-provider or security signoff. The current-head hosted CI is successful, but src/server/responses/core.ts is owner-only in current CODEOWNERS; owner approval and the stated auth boundary review remain required. No sponsorship, merge, scan or service operation was performed.

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration record (MAINTAINERS.md, dev-only) — draft by release lane L2

@lidge-jun
lidge-jun merged commit 3ed275f into dev Oct 1, 2026
42 checks passed
@lidge-jun
lidge-jun deleted the fix/luvs01-685-lease-cancellation-20261001 branch October 1, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants