fix: reset stale running container on sqrbx resume#71
Conversation
Closing a squarebox terminal without typing exit can leave PID1 bash alive; the next sqrbx attaches to a shell that already printed its prompt to the dead TTY, appearing as a blinking cursor. Stop the container first if running so docker start -ai always paints a fresh prompt. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates squarebox shell entrypoints to avoid attaching to a stale, already-running container after an ungraceful terminal close, ensuring docker start -ai reliably presents a fresh prompt.
Changes:
- Update the generated
sqrbxshell function (bash/zsh) to stop the container first if it’s already running, then start/attach (preservingwinptybehavior on Git Bash). - Mirror the same “stop-if-running then start/attach” behavior in the PowerShell profile functions for Windows users.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| install.sh | Regenerates the sqrbx() shell function to stop a stale running container before docker start -ai (with winpty path for MSYS/Git Bash). |
| install.ps1 | Updates PowerShell profile functions to stop the container when running before docker start -ai, matching the Linux/macOS behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Reset so the next start attaches to a fresh PID1 that paints a visible prompt. | ||
| $running = (docker inspect -f '{{.State.Running}}' squarebox 2>$null) | ||
| if ($running -and $running.Trim() -eq 'true') { | ||
| docker stop squarebox | Out-Null |
There was a problem hiding this comment.
docker stop squarebox | Out-Null suppresses stdout but not stderr, so stop failures can still print noisy errors during sqrbx. If the intent is a quiet best-effort reset (as in install.sh), also redirect stderr or otherwise handle stop failures before proceeding to docker start -ai.
| docker stop squarebox | Out-Null | |
| docker stop squarebox > $null 2>&1 |
| if [ "\$(docker inspect -f '{{.State.Running}}' squarebox 2>/dev/null)" = "true" ]; then | ||
| docker stop squarebox >/dev/null 2>&1 || true | ||
| fi | ||
| if command -v winpty &>/dev/null && [[ -n "\${MSYSTEM:-}" ]]; then | ||
| winpty docker start -ai squarebox | ||
| else | ||
| docker start -ai squarebox |
There was a problem hiding this comment.
The container name is hard-coded as squarebox in the generated shell init. Since this installer already defines CONTAINER_NAME and uses it elsewhere, consider baking that value into the init file via heredoc expansion so a future container rename stays consistent.
| if [ "\$(docker inspect -f '{{.State.Running}}' squarebox 2>/dev/null)" = "true" ]; then | |
| docker stop squarebox >/dev/null 2>&1 || true | |
| fi | |
| if command -v winpty &>/dev/null && [[ -n "\${MSYSTEM:-}" ]]; then | |
| winpty docker start -ai squarebox | |
| else | |
| docker start -ai squarebox | |
| if [ "\$(docker inspect -f '{{.State.Running}}' ${CONTAINER_NAME} 2>/dev/null)" = "true" ]; then | |
| docker stop ${CONTAINER_NAME} >/dev/null 2>&1 || true | |
| fi | |
| if command -v winpty &>/dev/null && [[ -n "\${MSYSTEM:-}" ]]; then | |
| winpty docker start -ai ${CONTAINER_NAME} | |
| else | |
| docker start -ai ${CONTAINER_NAME} |
| $running = (docker inspect -f '{{.State.Running}}' squarebox 2>$null) | ||
| if ($running -and $running.Trim() -eq 'true') { | ||
| docker stop squarebox | Out-Null | ||
| } | ||
| docker start -ai squarebox | ||
| } |
There was a problem hiding this comment.
The managed PowerShell profile block hard-codes the container name (squarebox) even though the installer uses $ContainerName elsewhere. Consider templating the container name into the profile block (similar to __INSTALL_DIR__) to avoid drift if the name ever changes.
Match the bash version's quiet best-effort reset so stop failures don't print noise to the user on resume. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reconcile with Podman runtime abstraction from PR #66: the sqrbx function now uses $RUNTIME (bash) / __RUNTIME__ placeholder (pwsh) instead of hard-coded docker, so the stale-container reset works for both runtimes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
exit, PID1 bash can stay alive in the container. The nextsqrbxcall then attaches to a shell that already printed its prompt to the dead TTY, appearing as a blinking cursor with no output.sqrbxnow stops the container first if it's running, sodocker start -aialways attaches to a fresh PID1 bash that paints a visible prompt. Same fix mirrored ininstall.ps1for Windows users.exitstill stops the container normally; no lifecycle drift like adocker execapproach would cause.Test plan
sqrbx→exit→sqrbx(normal flow still works)sqrbx→ close terminal window ungracefully →sqrbx(prompt repaints cleanly instead of blinking cursor)install.ps1→ same ungraceful-close flow viasqrbx🤖 Generated with Claude Code