Skip to content

[Bugfix #418] Fix architect terminal auto-restart in dashboard - #419

Merged
waleedkadous merged 2 commits into
mainfrom
builder/bugfix-418-dashboard-auto-restart-archite
Feb 18, 2026
Merged

[Bugfix #418] Fix architect terminal auto-restart in dashboard#419
waleedkadous merged 2 commits into
mainfrom
builder/bugfix-418-dashboard-auto-restart-archite

Conversation

@waleedkadous

Copy link
Copy Markdown
Contributor

Summary

Fixes #418

Root Cause

The architect terminal already had shellper-level auto-restart configured (restartOnExit: true, restartDelay: 2000, maxRestarts: 50), but exit handling at the PtySession and Tower layers was defeating it:

  1. PtySession.cleanupShellper() cleared all WebSocket clients on exit — the restarted process had no connected clients
  2. Tower exit handler cleared entry.architect = undefined and deleted the DB record — the dashboard couldn't find the restarted session

The process was actually restarting at the shellper level, but was invisible to the dashboard.

Fix

Added a restartOnExit flag to PtySession that suppresses exit cleanup when auto-restart is configured:

  • WebSocket clients stay connected — when the process restarts, output flows seamlessly to the dashboard
  • Tower references preservedentry.architect and DB record remain intact
  • Visual indicator — writes [Process exited — restarting...] to the terminal during the restart gap
  • 10-second safety timeout — if no new data arrives (e.g., max restarts exceeded), falls through to normal exit cleanup

Files changed

  • pty-session.ts — Added restartOnExit property; modified shellper exit handler to suppress cleanup when set
  • tower-instances.ts — Set restartOnExit = true on architect PtySession at creation
  • tower-terminals.ts — Set restartOnExit = true on architect PtySession during reconciliation and on-the-fly reconnection

Test Plan

  • Added 4 regression tests covering:
    • Exit event suppressed when restartOnExit is true
    • Cleanup cancelled when new data arrives (process restarted)
    • Fallback to normal cleanup when no data arrives (max restarts exceeded)
    • Default behavior unchanged when restartOnExit is false
  • All 1705 existing tests pass
  • TypeScript compiles cleanly
  • Net diff: 128 insertions, 3 deletions (well under 300 LOC threshold)

CMAP Review

To be added after review

The architect terminal already had shellper-level auto-restart configured
(restartOnExit: true, restartDelay: 2000, maxRestarts: 50), but exit
handling was defeating it by:

1. PtySession.cleanupShellper() clearing all WebSocket clients on exit
2. Tower exit handler clearing entry.architect and deleting the DB record

This made the restarted process invisible to the dashboard even though
it was running.

Fix: Add a restartOnExit flag to PtySession that suppresses exit cleanup
when auto-restart is configured. WebSocket clients stay connected, Tower
references are preserved, and the dashboard seamlessly shows the restarted
session. A 10-second timeout handles the edge case of max restarts being
exceeded (falls through to normal cleanup if no new data arrives).
…t crash loop stacking

Addresses Codex review feedback:
- Clear exitCode when new data arrives after restart so write/resize continue working
- Guard against stacked listeners/timeouts from rapid exit/restart cycles
- Added test assertions for status='running' and write() working after restart
@waleedkadous
waleedkadous merged commit a480ccc into main Feb 18, 2026
6 checks passed
@waleedkadous
waleedkadous deleted the builder/bugfix-418-dashboard-auto-restart-archite branch February 18, 2026 05:42
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.

Dashboard: Auto-restart architect terminal when it exits

1 participant