Skip to content

refactor: make tool supervision context-owned - #4678

Closed
dgageot wants to merge 1 commit into
mainfrom
refactor/tool-supervisor-run
Closed

dgageot wants to merge 1 commit into
mainfrom
refactor/tool-supervisor-run

Conversation

@dgageot

@dgageot dgageot commented Oct 20, 2026

Copy link
Copy Markdown
Member

Builds on #4674 (transcription context-ownership refactor). This PR applies the same ownership split to tool supervision.

What changed

  • Supervisor.Run is now immutable and owns connections, retry timers, and cleanup for the lifetime of a tool server.
  • A compatibility Owner handles request-scoped startup/adoption and serializes crash recovery, sitting on top of Run.
  • Gateway temp files are now tied to connection lifetime instead of request lifetime.
  • Fixes: canceled setup no longer leaks, first-ready recovery works correctly, and incomplete startups are joined instead of racing.
  • Genuine cleanup errors are preserved and no longer masked by re-reporting an already-recovered stdio crash.
  • Incoming sampling requests are cleaned up correctly for session-owned stdio connections.

Scope note: toolsets and shared MCP/LSP clients are still stateful, and Startable remains — this is not a full stateless toolset redesign, just the supervisor/ownership layer.

Testing

  • task build (CI=true), task test, task lint all pass.
  • Broader -race runs across tools, acp, agent, team, runtime, teamloader pass.
  • Linux and Windows cross-builds pass.
  • Targeted tests for real subprocess gateway/crash/sampling scenarios, plus MCP/LSP/CodeMode/tools/ACP race tests, and 100 shuffled repetitions of the lifecycle race suite all pass.

Run-owned connections/retries/cleanup, with a compatibility Owner for
request-scoped startup and late adoption. Gateway temp files now track
connection lifetime, and shutdown/error propagation is complete across
cancellation and crash-recovery paths, backed by regression tests.

Assisted-By: cagent
@dgageot
dgageot requested a review from a team as a code owner October 20, 2026 22:48
values context.Context //nolint:containedctx // Carries the adopting request's values, never its lifetime.
}

// NewOwner creates an inert legacy API adapter. Stop permanently closes it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is an inert legacy API adapter? Why do we handle legacy?

}

// MarkReadyForTesting bypasses connection setup for transport tests.
func (o *Owner) MarkReadyForTesting() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we really adding public methods that should only be used in tests?

@aheritier aheritier added area/docs Documentation changes area/tools For features/issues/fixes related to the usage of built-in and MCP tools kind/refactor PR refactors code without behavior change labels Oct 20, 2026
@dgageot
dgageot marked this pull request as draft October 21, 2026 05:39
@dgageot dgageot closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation changes area/tools For features/issues/fixes related to the usage of built-in and MCP tools kind/refactor PR refactors code without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants