Skip to content

sessions: Prepare sandbox repositories before session creation - #336294

Closed
Osvaldo Ortega (osortega) wants to merge 2 commits into
mainfrom
agents/run-the-agent-sandbox-gap-watch-and-report-7374cf59
Closed

Osvaldo Ortega (osortega) wants to merge 2 commits into
mainfrom
agents/run-the-agent-sandbox-gap-watch-and-report-7374cf59

Conversation

@osortega

@osortega Osvaldo Ortega (osortega) commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Prepare the selected repository on a capable sandbox host before creating the session, rather than assuming that connecting also supplies a ready checkout.

  • Reuse ready or in-progress checkouts, or request a shallow host-side clone and show progress until it is ready.
  • Keep host-specific operations behind the advertised capability and a typed, connection-owned project adapter. Preserve older pre-cloned hosts and existing sessions.
  • Pass the resolved host directory into session creation and rebind workspace-scoped customizations when the directory changes.
  • Surface failures and cancellation, allow an explicit user retry after a failed clone, and apply a three-minute deadline to both acknowledgement and readiness.
  • Add regression coverage and document the client-side lifecycle. No token-provisioning changes are included.

Protocol boundary

The shared IAgentConnection interface does not expose arbitrary RPC dispatch. The concrete transport client retains the low-level host-extension sender, while CloudSandboxProjectsClient exposes typed project operations and validates the capability, catalogue entries, and clone response. The resolver no longer names wire methods or handles untyped RPC responses.

The sandbox connection factory owns each adapter by connection identity. Teardown cancels preparation and removes only that connection's adapter, leaving a replacement at the same address intact. No standard AHP schema, command-map, protocol-version, or clone wire-payload changes are introduced.

Validation

  • 135 focused unit tests passed, covering adapter validation and lifetime, repository preparation, sandbox provisioning and credentials, transport requests, and customization scopes.
  • npm run typecheck-client passed.
  • Repository hygiene passed for the staged files, including during the commit hook.
  • npm run valid-layers-check and git diff --check passed.

Manual verification still needed

  • Start a sandbox session whose repository has not been cloned; verify progress and that the first turn runs in the returned checkout.
  • Confirm a ready checkout is reused and existing sessions retain their directories.
  • Cancel preparation and retry a failed clone; verify that no turn starts before preparation succeeds.
  • Verify workspace-scoped MCP configuration follows the prepared checkout.

Full-build and live-sandbox/end-to-end verification have not been run.

Resolve a ready host checkout after authentication before creating a sandbox session. Keep project requests capability-gated, preserve legacy hosts, and align customization scopes with the prepared directory.

Surface clone failures and cancellation, allow explicit retries, and bound clone acknowledgement and readiness with one deadline. Add focused regression coverage and document the client lifecycle.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 15, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Cancellation does not stop queued extension requests, and preparation failures are misclassified in telemetry.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
What changed in this PR

Adds host-side repository preparation to remote sandbox session creation.

Changes:

  • Resolves or clones sandbox repositories before session creation.
  • Rebinds workspace customizations to prepared directories.
  • Adds capability checks, cancellation, progress, documentation, and tests.
File Description
agentHostChatContribution.test.ts Tests preparation lifecycle and scope rebinding.
agentHostSessionHandler.ts Adds pre-creation directory preparation.
cloudSandboxProjectResolver.test.ts Covers clone, reuse, failure, and cancellation paths.
cloudSandboxAgentHostContribution.test.ts Stubs the new progress dependency.
REMOTE_AGENT_HOST_SESSIONS_PROVIDER.md Documents remote workspace preparation.
remoteAgentHostConnectionCustomization.ts Exposes the preparation customization hook.
remoteAgentHost.contribution.ts Connects preparation to session handling.
cloudSandboxProjectResolver.ts Implements host checkout resolution and cloning.
cloudSandboxConnectionCustomization.ts Enables preparation for sandbox connections.
cloudSandboxAgentHostContribution.ts Instantiates and registers the resolver.
copilotChatSessionsProvider.ts Reuses the shared repository parser.
gitHubRepository.ts Provides shared GitHub repository parsing.
agentHostProtocolClient.test.ts Tests host-specific extension requests.
agentHostProjectMeta.ts Validates project-management capability metadata.
agentService.ts Adds extension requests to the connection API.
agentHostProtocolClient.ts Dispatches extension JSON-RPC requests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +205 to +208
const response = await raceCancellationError(connection.requestExtension('extensions/cloneProject', {
url: `https://github.com/${repository}`,
depth: 1,
}), cts.token);
Comment on lines +5602 to +5605
onFailureStage?.('createSession');
const requestedDirectory = this._resolveRequestedWorkingDirectory(sessionResource);
const preparedDirectory = this._config.prepareWorkingDirectory
? await this._config.prepareWorkingDirectory(sessionResource, requestedDirectory, cancellationToken)
@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Base: bb45ea6a Current: f94a657e

No screenshot changes.

Remove arbitrary RPC dispatch from the shared agent connection. Keep the low-level sender on the concrete transport and expose validated project operations through a connection-owned sandbox adapter.

Bind preparation to the exact connection lifetime, cancel outstanding work on teardown, and preserve replacement connections at the same address. Add adapter and factory regression coverage and document the narrowed client boundary without changing the AHP wire contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@osortega

Copy link
Copy Markdown
Contributor Author

Closed in favor of a protocol-first repository-session design. Replacement drafts: microsoft/agent-host-protocol#451 defines optional schema-discovered repository intent, and #336361 consumes that contract through ordinary session creation. The new client draft does not carry this PR’s vendor-cloning adapter. Both remain drafts pending protocol and interoperability review.

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