Skip to content

fix(gateway): stop completed task terminals from blocking restarts - #121055

Merged
steipete merged 3 commits into
mainfrom
codex/terminal-task-cleanup
Aug 9, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/terminal-task-cleanup

Conversation

@steipete

@steipete steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where completed detached tasks could leave their agent-owned workspace terminals alive indefinitely. On a busy Gateway, twelve idle PTYs from already-succeeded cron tasks remained restart blockers, repeatedly fencing a verified deployment even though the task ledger correctly reported completion.

Why This Change Was Made

Task completion now closes every terminal owned by that exact run-scoped cron, subagent, or ACP session after the authoritative task row reaches a terminal state. Persistent normal-chat sessions and connection-owned operator terminals keep their existing lifetime, while shared viewers receive the normal terminal exit event and PTY teardown remains centralized in the terminal session manager.

The task event is broadcast before teardown, preserving the observable order: durable task completion, task status update, then terminal closure. Later updates to an already-terminal task do not close resources belonging to a newer lifecycle owner.

User Impact

Completed background tasks no longer strand invisible workspace shells or indefinitely block safe Gateway restarts and managed deployments. Operators can still keep ordinary chat-owned terminals open, and attached connection-owned terminals retain their documented persistence behavior.

Evidence

  • Production incident: twelve agent-owned PTYs remained live after their cron task rows reached succeeded; the Gateway suspension gate continued reporting terminal-session blockers.
  • Blacksmith Testbox run 31312266194: changed format, generated Plugin SDK API baseline, dependency, plugin-boundary, dead-export, production/test typecheck, lint, database/storage, import-cycle, and webhook/pairing guards passed.
  • The same Testbox run passed 11/11 focused task-transition and terminal-lifecycle tests, including running-task retention, completed cron cleanup, persistent chat retention, connection-terminal retention, viewer exit delivery, and PTY drain symmetry.
  • Earlier focused owner-boundary run passed 53/53 existing plus new terminal/subscription tests before the lifecycle regression was split into its max-lines-safe dedicated file.
  • Structured autoreview: clean, no accepted/actionable findings, confidence 0.98.
  • Production LOC: +48/-0. Tests: +131/-1. Generated API manifest: +32/-32.

AI-assisted: yes. The implementation and proof were reviewed against the task registry, cron finalization, Gateway subscription, terminal ownership, and viewer cleanup boundaries.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 12:12
@steipete
steipete force-pushed the codex/terminal-task-cleanup branch from 0bd67f3 to 6b62e8d Compare August 9, 2026 12:21
@steipete
steipete merged commit 8dad2bf into main Aug 9, 2026
120 checks passed
@steipete
steipete deleted the codex/terminal-task-cleanup branch August 9, 2026 12:39
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…penclaw#121055)

* fix(gateway): close task-owned terminals on completion

* test(gateway): isolate terminal task lifecycle coverage

* chore(plugin-sdk): refresh API baseline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant