Repository navigation
fix(cli): exit after local OpenAI agent replies - #170391
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR releases cached provider connections during CLI teardown so local agent commands exit after replying. Example: Run openclaw agent --local --json using openai-responses with gpt-5-mini.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR: it fixes a confirmed CLI cleanup omission still present on main, follows existing lifecycle ownership, and introduces no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI dispatch runs the agent and writes its result, then invokes process-local cleanup; the existing AI resource registry closes retained provider transports after harness disposal. flowchart TD
A[Local agent command] --> B[Agent harness]
B --> C[OpenAI Responses transport]
C --> D[Reply output]
D --> E[CLI teardown]
E --> F[Session resource registry]
F --> G[Close cached sockets]
Technical reviewBest possible solution: Use the existing provider-resource registry during terminal CLI cleanup while preserving Gateway custody and natural process exit. Do we have a high-confidence way to reproduce the issue? Source confirms the retained WebSocket cleanup hook and the missing CLI invocation; the author supplies matching before-and-after real-provider observations, which were not rerun during this read-only review. Is this the best way to solve the issue? The patch repairs the missing lifecycle connection through the existing owner, preserves transport reuse during execution, and avoids forced exit or a parallel cleanup mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 58fda0da7614. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +15, Docs 0. Total +20 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 12, 2026, 7:43 PM ET / 23:43 UTC. |
|
Landed in f4d984d. openclaw agent --local exits after the turn again. |
openclaw agent --local printed its result but did not exit when the turn used the native OpenAI Responses WebSocket transport. The transport's session cache keeps the ws TLS socket open for connection reuse (packages/ai/src/transports/openai-responses-websocket.ts), and the CLI's closeCliResources never ran the AI session-resource cleanup registry that the Gateway already drains on shutdown. CLI cleanup now runs that registry after harness disposal. There is no forced exit, and Gateway mode is unchanged. Proof: on main feb893c a real-provider turn printed its answer and was still alive at the 120 s kill, with async-hooks identifying the retained TLS socket. With the PR the same command exited 0 about 0.27 s after printing, in JSON mode, text mode and with plugins enabled. A provider 401 exited 1 promptly, and Gateway mode with its shutdown was unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes
openclaw agent --local --jsonprinting a completed OpenAI reply but keeping the process alive on its cached WebSocket connection.Found during live-provider verification of #167736.
User Impact
Local one-shot agent commands release cached provider connections after the reply and exit normally. JSON/text output and exit status are unchanged; the running Gateway retains its own session resources.
Why This Change Was Made
The native OpenAI Responses transport registers its cached WebSocket with the existing AI session-resource cleanup registry. Gateway shutdown already drains that registry, but CLI cleanup omitted it. Call the same cleanup during one-shot CLI teardown, after agent harness disposal, rather than forcing process exit or disabling connection reuse between turns.
No overlap with Pash/Sarah changes in the touched files.
Evidence
Node 24.21.0, isolated state, real
openai-responses/gpt-5-mini, minimal tools, bootstrap skipped:6315f8adc18:agent --local --agent main --session-id … --message … --thinking minimal --timeout 90 --jsonprintedLIVE_OK, then was still alive at the 120-second harness deadline. The same happened with diagnostics enabled. Active-handle tracing identifiedTLSSocket→ws/lib/websocket.js; the cached connection has a five-minute idle TTL. A loopback SSE provider exited normally, isolating the native WebSocket transport.95ec4e8210bb: real-provider JSON replyLIVE_OKat 10,275 ms; exit 0 at 10,554 ms (279 ms after output).pnpm openclaw,--timeout 90, same provider/config/flags as the baseline):LIVE_OK, natural exit 0 in 14,301 ms; no harness kill.LIVE_OK, exit 0, 272 ms after reply. Plugins enabled:LIVE_OK, exit 0, 244 ms after reply.--local): real-providerLIVE_OK, exit 0, 33 ms after output; Gateway shutdown also exited 0 in 328 ms.Two-way door: reverting restores only the previous CLI cleanup omission; no config or persisted-data changes. Blast radius: one-shot CLI provider-resource teardown. Gateway-owned connections are not retired by another CLI process.