Skip to content

fix: auto-close zombie sessions on queue owner shutdown (#47)#66

Closed
manthan787 wants to merge 1 commit intoopenclaw:mainfrom
manthan787:fix/auto-close-zombie-sessions-47
Closed

fix: auto-close zombie sessions on queue owner shutdown (#47)#66
manthan787 wants to merge 1 commit intoopenclaw:mainfrom
manthan787:fix/auto-close-zombie-sessions-47

Conversation

@manthan787
Copy link
Contributor

@manthan787 manthan787 commented Mar 9, 2026

Summary

  • When the queue owner shuts down (TTL expired, no more tasks), auto-close the session if the agent process has already exited
  • Prevents zombie session records from accumulating in ~/.acpx/sessions/ with closed=false despite the agent being dead
  • Adds regression test that verifies sessions are properly closed after queue owner exit

Fixes #47

Details

The fix is in runSessionQueueOwner's finally block in src/session-runtime.ts. After releasing the queue owner lease, it reads the session record and marks it closed: true if lastAgentExitAt is set (indicating the agent has exited). This is best-effort — if the record is already cleaned up, the error is silently ignored.

The condition !record.closed && record.lastAgentExitAt ensures:

  • Sessions already closed by sessions close are not double-written
  • Sessions where the agent is still alive (edge case) are left open

Test plan

  • New integration test: session auto-closes when queue owner exits and agent has exited (#47) — creates a session, sends a prompt with --ttl 1, waits for queue owner exit, verifies closed: true and closed_at are set on the session record
  • All 150 existing tests continue to pass (including prompt reuses warm queue owner pid across turns which verifies the fix doesn't break warm queue owner behavior)

…penclaw#47)

When the queue owner shuts down (TTL expired, no more tasks), mark the
session as closed if the agent process has already exited. This prevents
zombie session records from accumulating in ~/.acpx/sessions/ with
closed=false despite the agent being dead.
@vincentkoc
Copy link
Member

Superseded by #70, which merged the queue-owner shutdown auto-close fix into main on 2026-03-09.

@vincentkoc vincentkoc closed this Mar 9, 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.

Oneshot sessions not auto-closed after agent exit — causes zombie accumulation

2 participants