Skip to content

fix(acp-adapter): delete owned serve sessions on shutdown (#8313) - #11218

Merged
dezren39 merged 2 commits into
mainfrom
queue/20119-8313-acp-session-cleanup
Nov 17, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/20119-8313-acp-session-cleanup

Conversation

@dezren39

@dezren39 dezren39 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

What

The ACP adapter (bin/opencode-acp-adapter.mjs) now deletes the serve sessions it created when it shuts down — on stdin close and on SIGTERM — instead of leaving them on the ONE standing shared opencode serve forever.

Step 1 evidence (why this branch of the issue)

Verified against the pinned serve (flake.lock opencode = fork rev 34cb01197a2fa9f6fe75ac9f8e2a2ac3774bba53): there is no server-side idle session expiry. The only inactivity mechanism, packages/core/src/location-activity.ts, interrupts inactive executions and evicts cached location service graphs; session records are durable and are removed solely through the explicit DELETE /api/session/:sessionID route (packages/protocol/src/groups/session.ts, operationId session.remove). So the adapter-side cleanup branch of the issue applies.

Change

  • New shutdown path shared by stdin-close and SIGTERM: DELETE /api/session/:id for every key of the adapter's sessions map (exactly the sessions this adapter created via POST /api/session). Best-effort and bounded: each delete is abort-timed against a 2s overall budget, failures are swallowed, and a hard timer guarantees exit is never blocked on the serve.
  • Header comment updated: the "no DELETE call exists here" note now describes the cleanup.
  • Crash-case residual (dispositioned): if the adapter is killed hard (SIGKILL, host death) no cleanup runs and its sessions persist on the serve until the serve restarts. Accepted: only the serve could reap those, and per the evidence above it does not expire sessions; the leak is bounded by serve restarts and carries no correctness risk (sessions are inert records once their execution is interrupted by the serve's inactivity sweep).

Tests

node --test bin/opencode-acp-adapter.test.mjs — 24/24 pass, including two new tests: stdin close and SIGTERM each produce exactly one DELETE /api/session/<created id> at the stub serve before the adapter exits 0. The stub serve gained the DELETE route.

Queue task 20119 (lane code-a). No closing keyword for #8313 in this body — the worker closes the issue with evidence after merge.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Adapter sessions are now cleaned up when the adapter shuts down after stdin closes or it receives a termination signal.
    • Cleanup requests run in parallel and have a shared time limit, so shutdown can finish promptly even if a request fails or stalls.
    • Repeated shutdown signals are ignored, and the adapter exits after a bounded wait.

@dezren39
dezren39 requested a review from a team as a code owner November 17, 2026 10:24
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-17T10:24:32.843481Z
We couldn’t complete this review. Comment @codex review to try again.
792bcd4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7b923061-6b18-4acf-809c-2b7482845bef
Commits

Reviewing files that changed from the base of the PR and between 792bcd4 and 67eb2bc.

Files selected for processing: 2

  • bin/opencode-acp-adapter.mjs
  • bin/opencode-acp-adapter.test.mjs

No actionable comments were generated in the recent review.

Walkthrough

The adapter now deletes its recorded serve sessions when stdin closes or SIGTERM arrives. Cleanup requests run in parallel with a shared deadline. The adapter exits after cleanup or a force-exit timeout.

Changes: ACP adapter session cleanup

Layer / File(s) Summary
Shutdown cleanup
bin/opencode-acp-adapter.mjs, bin/opencode-acp-adapter.test.mjs
The adapter sends a DELETE request for each recorded session on stdin close or SIGTERM. Requests share a 2-second deadline; cleanup failures do not block exit, and a 2.5-second timer forces exit. Tests verify one DELETE and exit code 0 for both shutdown triggers.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • developing-today/code#8313 — The PR adds the requested session DELETE behavior on stdin close and SIGTERM. The SIGKILL case remains unaddressed.
  • developing-today/code#4706 — The PR adds cleanup for the adapter’s recorded sessions on stdin close and SIGTERM. The issue’s broader prompt-lifecycle work remains outside this change.
Merge Risk: Minimal · previous review 792bc

The adapter now deletes the serve sessions it created when stdin closes or SIGTERM arrives, with a bounded shutdown time. A session created in the last moments of shutdown could still be left on the serve. That edge case is narrow and does not block merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the adapter now deletes the serve sessions it owns during shutdown. The raw summary confirms that shutdown issues DELETE requests for each session in the adapter's map…
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: Title check

Explanation

The title names the main change: the adapter now deletes the serve sessions it owns during shutdown. The raw summary confirms that shutdown issues DELETE requests for each session in the adapter's map, and the tests verify one DELETE per session on stdin close and SIGTERM. The title is concise, specific, and follows the conventional-commit style. The issue reference (#8313) adds no ambiguity.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34717e42-d53b-4107-9140-37a006e26467
Commits

Reviewing files that changed from the base of the PR and between 554e140 and 792bcd4.

Files selected for processing: 2

  • bin/opencode-acp-adapter.mjs
  • bin/opencode-acp-adapter.test.mjs

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

@dezren39
dezren39 merged commit ab6b530 into main Nov 17, 2026
@dezren39
dezren39 deleted the queue/20119-8313-acp-session-cleanup branch November 17, 2026 21:19
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