Skip to content

refactor(acp): make terminal cleanup session-owned - #4699

Merged
dgageot merged 1 commit into
mainfrom
refactor/acp-terminal-cleanup
Oct 22, 2026
Merged

dgageot merged 1 commit into
mainfrom
refactor/acp-terminal-cleanup

Conversation

@dgageot

@dgageot dgageot commented Oct 22, 2026

Copy link
Copy Markdown
Member

Why

terminalManager split cleanup into separate stop/wait calls and cached the result in done/closeErr fields. That split ownership made the lifecycle harder to reason about and race-prone: callers had to coordinate stop-then-wait themselves, and the cached fields could be read/written from multiple goroutines without a clear single owner.

What

Collapses the split stop/wait into a single cleanup(ctx) call, and makes Session.close the sole owner of the cleanup result:

  • terminalManager drops the done/closeErr fields in favor of a single cleanup(ctx) method.
  • Session.close buffers the cleanup result locally, retires/cancels immediately, and blocks on the manager cleanup — while still running terminal/runtime/MCP shutdown in parallel.
  • Callers and tests migrated accordingly, including fixture ownership in terminal_test.go and tracing_test.go.
  • Added terminal_cleanup_test.go with race-focused coverage: synchronous retirement, simultaneous first closers, exactly-one final release, cached failure results, late terminal creation, and trace context propagation.

Validation

  • task build, task test, task lint all pass.
  • go test ./pkg/acp/... -race -count=1 run 3x, all green (no flakes).
  • Cross-compilation (go vet) verified for linux/amd64 and windows/amd64.

Collapse terminalManager's split stop/wait into a single cleanup(ctx) call owned by the Session, dropping the done/closeErr fields in favor of a local result channel.

Assisted-By: docker-agent
@dgageot
dgageot requested a review from a team as a code owner October 22, 2026 10:58
@aheritier aheritier added area/core Core agent runtime, session management kind/refactor PR refactors code without behavior change labels Oct 22, 2026
@dgageot
dgageot added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit a2bdf5d Oct 22, 2026
26 of 28 checks passed
@dgageot
dgageot deleted the refactor/acp-terminal-cleanup branch October 22, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Core agent runtime, session management kind/refactor PR refactors code without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants