Skip to content

fix: reset stale running container on sqrbx resume#71

Merged
BrettKinny merged 3 commits into
mainfrom
fix/sqrbx-reset-stale-container
Apr 13, 2026
Merged

fix: reset stale running container on sqrbx resume#71
BrettKinny merged 3 commits into
mainfrom
fix/sqrbx-reset-stale-container

Conversation

@BrettKinny
Copy link
Copy Markdown
Collaborator

Summary

  • When a squarebox terminal is closed without typing exit, PID1 bash can stay alive in the container. The next sqrbx call then attaches to a shell that already printed its prompt to the dead TTY, appearing as a blinking cursor with no output.
  • sqrbx now stops the container first if it's running, so docker start -ai always attaches to a fresh PID1 bash that paints a visible prompt. Same fix mirrored in install.ps1 for Windows users.
  • Preserves the documented "suspends on exit" lifecycle — exit still stops the container normally; no lifecycle drift like a docker exec approach would cause.

Test plan

  • Fresh install → sqrbxexitsqrbx (normal flow still works)
  • sqrbx → close terminal window ungracefully → sqrbx (prompt repaints cleanly instead of blinking cursor)
  • Windows pwsh: install.ps1 → same ungraceful-close flow via sqrbx
  • Git Bash on Windows: winpty branch still wraps the start command

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 13, 2026 10:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sqrbx shell function (bash/zsh) to stop the container first if it’s already running, then start/attach (preserving winpty behavior 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.

Comment thread install.ps1 Outdated
# 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
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
docker stop squarebox | Out-Null
docker stop squarebox > $null 2>&1

Copilot uses AI. Check for mistakes.
Comment thread install.sh Outdated
Comment on lines +176 to +182
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
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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}

Copilot uses AI. Check for mistakes.
Comment thread install.ps1 Outdated
Comment on lines +205 to +210
$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
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
BrettKinny and others added 2 commits April 13, 2026 20:24
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>
@BrettKinny BrettKinny merged commit 4d6769c into main Apr 13, 2026
1 check passed
@BrettKinny BrettKinny deleted the fix/sqrbx-reset-stale-container branch April 13, 2026 11:03
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.

2 participants