Skip to content

fix: release host terminals after usage scans - #32

Open
MayankBansal12 wants to merge 9 commits into
mainfrom
fix/issue-28-terminal-lifecycle
Open

fix: release host terminals after usage scans#32
MayankBansal12 wants to merge 9 commits into
mainfrom
fix/issue-28-terminal-lifecycle

Conversation

@MayankBansal12

@MayankBansal12 MayankBansal12 commented Sep 1, 2026

Copy link
Copy Markdown
Owner
  • let host scan commands exit naturally instead of holding their shells with an infinite sleep loop
  • read final output and exit status after the terminal exits
  • use clean close for completed commands, reserving force close for timeout or cancellation
  • log terminal cleanup failures
  • cap collection at three concurrent terminals per machine

Why

On bb 0.40.0 for macOS, repeated forced closes can leak PTY resources. The prior keep-alive loop and nine parallel scans accelerated that leak until bb could no longer open terminals.

Fixes #28

@MayankBansal12

Copy link
Copy Markdown
Owner Author

Follow-up validation: bb only exposes terminal output while a session is running, so reading after natural exit caused HTTP 409 failures across all collectors. The branch now uses a bounded handshake: capture output while running, send a release line, then wait for natural exit. The shell fallback is capped at 30 seconds—there is no infinite hold.

Live-tested with an isolated copy of the actual plugin restricted to the current machine. Codex, Claude, fx, Grok, Pi, Prime, Antigravity, OpenCode, and OpenCode Go all completed without terminal-output 409s. The temporary test plugin was removed afterward.

…ontract

Migrate to @get-bb/plugin-sdk 0.4.47 (BB >= 0.42), dropping the vendored
type stubs. Add a bb.host entry (host.ts, host-contract.ts) that executes
usage scans in a non-PTY host worker instead of long-lived terminals:
short polling calls, cancellation and timeouts kill the command process
group, and scans run with a concurrency limit of three per machine.

Also add unit/integration tests for the host worker, a CI matrix over
ubuntu/macos, and bump the version to 0.3.7.
…code-go test

macOS keeps cat and rm in /bin, so the nodeOnly symlinks dangled and the
fake curl saw an empty auth header (exit 9). Resolve cat, mktemp, and rm
via command -v at test setup.
Supersedes the earlier host-worker commits on this branch: migrates to
@get-bb/plugin-sdk 0.4.47 (BB >= 0.42), runs usage scans in non-PTY host
workers with short polling calls and a three-scan-per-machine concurrency
cap, adds host/usage integration tests, an ubuntu/macos CI matrix, and
the tool-path fix for macOS.
… >= 0.36)

Revert the 9bc08bd..97cf306 SDK/host-worker work so the PR stays compatible
with BB >= 0.36; the plugin-sdk 0.4.47 migration ships separately.

Removed: host.ts, host-contract.ts, host.test.ts, host.integration.test.ts,
usage.integration.test.ts, the @get-bb/plugin-sdk devDependency and all
experimental_* host APIs; server.ts/server.test.ts back to the terminal-based
runHostCommand with vendored sdk stubs and paths restored; engines back to
bb >= 0.36; package deps split and import specifiers restored; README back
to "Requires BB 0.36 or newer".

Kept: the macOS tool-path resolution fix in lib/opencode-go.test.ts
(command -v for cat/mktemp/rm) and the ubuntu/macos CI matrix, with the
build tool pinned back to bb-app@0.39.0.
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.

Scan loop holds a PTY with sleep 3600; on bb 0.40.0 that exhausts macOS ptmx

1 participant