Skip to content

fix: release foreground bash shells after completion#135

Open
Andy963 wants to merge 1 commit intobubbuild:mainfrom
Andy963:fix/foreground-bash-release
Open

fix: release foreground bash shells after completion#135
Andy963 wants to merge 1 commit intobubbuild:mainfrom
Andy963:fix/foreground-bash-release

Conversation

@Andy963
Copy link
Contributor

@Andy963 Andy963 commented Mar 25, 2026

Summary

Foreground bash commands are now released from ShellManager after completion, preventing finished shells (and their buffered stdout/stderr) from being retained in memory in long-running Bub processes (e.g. chat / gateway).

Changes

  • Add ShellManager.release(shell_id) to remove a shell from the internal registry.
  • Ensure foreground bash always calls release() in a finally block (success, non-zero exit, timeout).
  • Add regression tests to assert no foreground shells remain in _shells after execution (including failure).

Notes

  • Background shell lifecycle is unchanged (still accessible via bash.output / bash.kill).

Verification

  • uv run ruff check .
  • uv run mypy src
  • uv run pytest -q

raise KeyError(f"unknown shell id: {shell_id}") from exc

def release(self, shell_id: str) -> ManagedShell | None:
return self._shells.pop(shell_id, None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems it can be moved into wait_closed to make it cleaner, since wait_closed will be called on all paths

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly. The timeout path goes through terminate(), not wait_closed(), so wait_closed() is not called on all paths. This change is intentionally scoped to fixing foreground shell cleanup. Background shell cleanup is a separate concern, and I'm not sure yet where that cleanup should happen, since we haven't defined the lifecycle for completed background shells.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aha, yes, then move to _finalize_shell

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