Skip to content

fix: reject compaction waiters when the Codex process exits - #38

Closed
ladydd wants to merge 1 commit into
LodyAI:mainfrom
ladydd:fix/reject-compaction-waiters-on-exit
Closed

ladydd wants to merge 1 commit into
LodyAI:mainfrom
ladydd:fix/reject-compaction-waiters-on-exit

Conversation

@ladydd

@ladydd ladydd commented Sep 9, 2026

Copy link
Copy Markdown

Problem / pressure

/compact waits on a thread/compacted notification. Turn waiters already reject when the Codex process exits (rejectAllPendingTurnCompletions); the comment there says the alternative is a forever hang, then every later prompt is A Codex prompt is already active. Compaction waiters were resolve-only Promises.

If app-server dies after thread/compact/start succeeds, that notification never arrives. The ACP prompt stays occupied. Host Stop/session/cancel does not finish it. The next prompt is already active.

This is not “/compact is broken”: a healthy compact completes. Mid-turn process death already returns -32603 in milliseconds. Compaction is the hole.

This is also not the fork-unsubscribe hang (#37 / Lody#544). Those keep thread/fork children subscribed. This PR does not change fork. Open #30 is stop-during-compact; this is process-exit waiters.

Summary

On connection close/dispose, reject compaction waiters as well as turn waiters. Share the existing connection-terminal error. runCompact still registers the waiter first (so an early thread/compacted is not missed), then Promise.alls start + completion so a close before start returns cannot stall on the in-flight start RPC (vscode-jsonrpc close does not reject responsePromises; dispose does). finally drops this registration only.

Do not fake a successful compact. The error must reach the ACP prompt so the host -32603 recovery path can run.

Visual explanation

sequenceDiagram
  participant Host
  participant Adapter
  participant Codex
  Host->>Adapter: prompt /compact
  Adapter->>Codex: thread/compact/start
  Codex-->>Adapter: start ok
  Note over Codex: process exits
  Note over Adapter: before: wait forever for thread/compacted
  Host->>Adapter: session/prompt
  Adapter-->>Host: already active
  Note over Adapter: after: close rejects compaction waiter, prompt returns -32603
Loading

Before / after

Before After
/compact + process death: UI stays compacting; Stop then already active Prompt returns -32603; next prompt is not already active
Healthy /compact Unchanged
Mid-turn process death Unchanged (-32603)

Test plan

  • vitest run src/__tests__/CodexAppServerClient.test.ts --no-file-parallelism --retry=0 — 7 passed (existing turn-close gap + compact: healthy, early thread/compacted, close after start ack, close while start still in flight, start RPC failure does not leave a waiter, compact after the connection already died).
  • Independent check on this patch (Codex 0.153.4, synthetic model, separate bundle): compact-kill returned -32603 in 10ms with no already active; restart + loadSession then history, a normal prompt, and another compact all completed. Lifecycle 8/8 including real vscode-jsonrpc close while start is still pending. Related adapter regression 130 passed; the known /review slash-command timeout is a pre-existing baseline skip, not this change.

Lody still needs a submodule bump after this merge.

Context

Authored with an AI coding agent. Reviewers should challenge: sharing turnCompletionTerminalError as connection-level vs a second compact flag; Promise.all vs awaiting start then completion; whether finally disposing only this waiter is enough when start fails and the process is still alive.

@ladydd
ladydd force-pushed the fix/reject-compaction-waiters-on-exit branch from 35ca9a1 to a67f231 Compare September 11, 2026 06:24
ladydd added a commit to ladydd/Lody that referenced this pull request Sep 11, 2026
Pin acp-extension-codex to a67f231 (LodyAI/acp-extension-codex#38,
rebased onto current adapter main / 5f0aab0) so compaction waiters
reject when the Codex process exits. Other submodules stay on current
main.

Depends on adapter LodyAI#38. Do not ship a desktop release until that merge.

Closes LodyAI#550
@ladydd

ladydd commented Sep 11, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (5f0aab0f, after #39/#40). Same two files; compact waiter tests still 7/7. New head a67f231. Host pin agentclientprotocol#551 retargeted to this SHA.

Turn waiters already reject on connection close. Compaction waiters
were resolve-only, so /compact hangs forever if app-server dies after
thread/compact/start, and the next prompt is already active.

Reject compaction waiters on close/dispose, share the connection
terminal error, and wait for start + completion together so a close
before start returns cannot stall on the start RPC.
@ladydd
ladydd force-pushed the fix/reject-compaction-waiters-on-exit branch from a67f231 to 31c5ecc Compare September 12, 2026 16:20
ladydd added a commit to ladydd/Lody that referenced this pull request Sep 12, 2026
Pin acp-extension-codex to a67f231 (LodyAI/acp-extension-codex#38,
rebased onto current adapter main / 5f0aab0) so compaction waiters
reject when the Codex process exits. Other submodules stay on current
main.

Depends on adapter LodyAI#38. Do not ship a desktop release until that merge.

Closes LodyAI#550
@ladydd ladydd closed this Sep 15, 2026
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.

1 participant