Skip to content

agentHost: manage additional chat workspaces - #337166

Merged
Sandeep Somavarapu (sandy081) merged 4 commits into
mainfrom
sandy081/sessions-chat-repository-lifecycle
Sep 22, 2026
Merged

Sandeep Somavarapu (sandy081) merged 4 commits into
mainfrom
sandy081/sessions-chat-repository-lifecycle

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR adds the Agent Host infrastructure for sessions that own multiple repositories and detached worktrees, without changing create_session behavior yet.

Additional worktree ownership

  • persist each session-owned detached worktree by opaque handle, effective checkout URI, and authoritative source repository-root URI
  • validate malformed metadata, invalid URIs and handles, and duplicate ownership records
  • keep repository inference through Git for new records; the path-based convention remains private legacy-metadata recovery only

Lifecycle integration

  • archive, unarchive, automatic cleanup, automatic-deletion eligibility, and permanent deletion now cover every session-owned worktree
  • resolve deletion cleanup against persisted source repository roots even when an additional checkout has disappeared from live session workingDirectories
  • delete detached worktrees before dropping their ownership records so failed cleanup remains retryable
  • synchronize archive state through an ordered, failure-isolated chat contribution backed by an injected lifecycle service

Chat workspace preparation

  • add an internal operation that prepares a folder or detached worktree for a chat and returns the effective directory for explicit chat assignment
  • resolve repositories authoritatively through Git, reuse an existing owned checkout by default, and support explicitly creating another worktree
  • pin chats that inherit the aggregate session workspace before expanding it, preserving their previous effective folders
  • persist and claim newly created worktrees, with rollback that deletes successful creations or retains ownership when deletion itself fails
  • expose the operation through the internal session-server-tool accessor so the follow-up can wire it without duplicating repository logic

Scope boundary

This PR intentionally does not change the create_session schema, descriptions, argument parsing, relationship semantics, or execution behavior. The follow-up only needs to parse the requested folder/repository options, call the preparation operation, and pass its returned URI as the new chat's explicit workingDirectories.

Chat-scoped changesets, repository operations, artifacts, pull requests, Agent Merge ownership, and final multi-project presentation remain separate follow-ups.

Validation

  • 301 Agent Host contribution, side-effect, lifecycle, and disposal tests
  • all 87 session server-tool unit tests
  • npm run typecheck-client
  • npm run hygiene
  • npm run valid-layers-check
  • git diff --check

Persist additional detached worktree ownership with the session so archive, automatic deletion, and permanent deletion apply consistently across every repository without changing create_session behavior.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 21, 2026 21:50
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.140.0 milestone Sep 21, 2026

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

Archive synchronization bypasses the established contribution model, and the missing-live-checkout cleanup path lacks direct regression coverage.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Adds lifecycle infrastructure for session-owned detached worktrees beyond the primary workspace.

Changes:

  • Persists and validates additional-worktree ownership metadata.
  • Extends archive, deletion safety, cleanup, and deletion behavior.
  • Adds focused tests and architecture documentation.
File Description
AGENT_HOST_SESSIONS_PROVIDER.md Documents additional-worktree ownership.
worktreeIsolation.test.ts Tests repository-root derivation.
sessionAdditionalWorktrees.test.ts Tests ownership metadata persistence.
agentService.test.ts Tests lifecycle integration.
worktreeIsolation.ts Extends detached-worktree lifecycle operations.
sessionAdditionalWorktrees.ts Implements metadata validation and persistence.
agentSideEffects.ts Triggers archive lifecycle updates.
agentServiceComposition.ts Wires the lifecycle callback.
agentService.ts Applies safety, cleanup, and deletion across worktrees.
worktreePaths.ts Exposes repository-root derivation.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Additional worktree ownership persists the authoritative repository root. Keep the path-based convention only as the existing private legacy metadata fallback instead of exposing it as shared API.

Co-authored-by: Copilot <[email protected]>
Add the internal repository and worktree preparation path needed to expand a session while preserving existing chat folder ownership. Keep create_session behavior unchanged so tool argument wiring can land separately.

Co-authored-by: Copilot <[email protected]>
@sandy081 Sandeep Somavarapu (sandy081) changed the title agentHost: manage additional session worktrees agentHost: manage additional chat workspaces Sep 22, 2026
Keep additional-worktree archive synchronization in an ordered chat contribution backed by an injected lifecycle service, and cover cleanup when a persisted checkout is absent from live session state.

Co-authored-by: Copilot <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants