Repository navigation
headless run with an openai-codex OAuth route lingers 5 minutes after completion (pi-ai session WebSocket cache is never cleaned up) #4190
Replies: 4 comments
|
I implemented and verified a reference fix for this report:
The adapter now claims pi-ai's session-keyed resources at actual stream use and installs one exact-ID cleanup in the live Agent's own scope. This preserves Codex WebSocket reuse while the Agent is live; then AgentLoop quiesces model work before scope teardown synchronously clears the five-minute idle timer and closes the cached socket. The Agent-scope owner survives concurrent llm-pi-ai listener unload during whole-runtime shutdown. Same-ID replacement is keyed by the Agent object. A quiesced direct Session caller retains an explicit The deterministic account-free regression first reproduced the whole-runtime shutdown leak, then passed with the fix. Validation passed: 268/268 llm-pi-ai tests, 100% statements/branches/functions/lines for the changed |
|
Independent reproduction of exactly this, from our E2E harness — posting as corroboration since we hit it before understanding it. Our codex-route acceptance test (real ChatGPT-subscription OAuth through pi2dsh on a stock That an ordinary text-only turn on the same route lingers too (your report) fits a session-scoped resource with a timed expiry rather than anything turn-specific — consistent with your WebSocket-cache diagnosis. Two data points from different harnesses making the same observation hopefully helps this get picked up; the clean fix (dispose the cache when the driver finishes, or unref the socket) belongs upstream in the route's session handling. |
|
Still reproducible on my current DSH installation ( This was already reproducible on upstream My normal headless configuration uses GPT-5.6 Luna via the ChatGPT subscription route. I have now independently verified the effective composed DSH configuration with: DSH_HOME="$HOME/.dsh" dsh --profile headless --dump-configRelevant section: - id: agent-default-model
name: '@deepseek-ai/dsh-agent-default-model'
config:
provider: openai-codex
model: gpt-5.6-luna
reasoningEffort: mediumSo this reproduction is definitely using the The original reproduction on DSH Upstream commit: Minimal reproduction: timeout 8s dsh --profile headless \
'Reply exactly DSH_EXIT_TEST_OK and then finish.'
echo "EXIT=$?"Result: The turn completes and the final response is printed, but the headless DSH process remains alive instead of exiting. Without the external I am still seeing the same behavior with DSH This is especially problematic for autonomous/headless orchestration: the semantic work has already completed, but the parent process cannot rely on DSH exiting to detect completion. Our current workaround is to detect an explicit completion marker in actual stdout, allow a short grace period, and terminate the lingering DSH process if necessary. |
|
Update — November 3, 2026 Still reproducible with DSH 0.2.0-rc.2 on Arch Linux ( The headless agent completes its task and prints the expected response, but the process remains alive. A 90-second I also tested:
The standard profile reports a missing experimental Ralph bundle, but the alternative profile also hangs, so the missing bundle does not appear to be the sole cause. This remains a blocker for reliable headless agent orchestration. The symptoms are consistent with the session WebSocket cleanup issue reported here. Has the proposed session-resource cleanup fix been merged into a release? If so, which version should we test? |
Uh oh!
There was an error while loading. Please reload this page.
Summary
A headless
dsh --profile headless "<prompt>"run whose turn uses an openai-codex OAuth route does not exit when the turn completes. The final answer and thecompletedlog are durable immediately, but the process stays alive for exactly five more minutes, then exits normally.Root cause (verified on stock npm packages)
@earendil-works/pi-ai(0.82.1, as resolved by@deepseek-ai/dsh-llm-pi-ai@0.1.1-rc.2) keeps the Codex session WebSocket cached for reuse when asessionIdis supplied:dist/api/openai-codex-responses.js— after a completed request,processWebSocketStream → release({ keep: true }) → scheduleSessionWebSocketExpiry(sessionId, entry).SESSION_WEBSOCKET_CACHE_TTL_MS = 5 * 60 * 1000, created with plainsetTimeout(notunrefed), and the cached WebSocket itself is also a referenced handle — so the Node event loop cannot drain.dsh-llm-pi-aiforwards the DSHsessionIdinto pi-ai (enabling this cache), but nothing calls pi-ai's provided cleanup —cleanupSessionResources(sessionId?)fromdist/session-resources.js— when the headless session/agent finishes. We found no caller ofcleanupSessionResourcesanywhere in the@deepseek-ai/*tree.Isolation evidence
The 5-minute wait reproduces with unrelated plugin sets, and disappears whenever the Codex OAuth route is not used — it tracks the provider, not any plugin.
Suggested fix
Have
dsh-llm-pi-aicallcleanupSessionResources(sessionId)when a session/agent is disposed (or at least when a headless run finishes its last turn).unrefing the timer alone would not be enough — the cached WebSocket is a referenced handle too.Happy to provide the full reproduction runs if useful.
All reactions