Skip to content

Add opt-in auto-archive/delete inactive sessions with merged pull requests - #334341

Merged
Megan Rogge (meganrogge) merged 23 commits into
mainfrom
meganrogge/auto-archive-merged-sessions
Sep 9, 2026
Merged

Megan Rogge (meganrogge) merged 23 commits into
mainfrom
meganrogge/auto-archive-merged-sessions

Conversation

@meganrogge

@meganrogge Megan Rogge (meganrogge) commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR adds two application-scoped Preview settings for inactive agent sessions that have at least one merged pull request and no open related pull requests:

  • chat.agentSessions.autoArchiveMergedSessionsAfterDays
    • disabled by default (0)
    • accepts any positive whole number of inactive days; 15 is the recommended value
    • archives eligible sessions through the normal archive lifecycle, including safe worktree cleanup and provider notification
  • chat.agentSessions.autoDeleteArchivedMergedSessionsAfterDays
    • disabled by default (0)
    • accepts any positive whole number for the separate post-archive deletion grace period; 15 is the recommended value
    • permanently deletes only sessions that carry durable automatic-archive provenance

Worktree cleanup is part of archiving rather than a separate setting. If a retained worktree is still present when permanent deletion becomes eligible, deletion applies the same safe cleanup first.

Lifecycle behavior

  • lifecycle candidates are prefiltered from durable session metadata before restoring sessions
  • active and external sessions are excluded
  • every related pull request is refreshed before restoration and again immediately before lifecycle side effects, so reopening a closed PR blocks the action
  • no related pull request may be open, and at least one must be merged; closed-unmerged PRs do not block cleanup once another related PR has merged
  • archive/delete settings, session state, retention periods, and pull request identity are revalidated after session restoration
  • automatic deletion applies only to sessions carrying durable automatic-archive provenance
  • manually archived sessions are never made deletion-eligible by this lifecycle
  • unarchiving clears automatic-archive provenance
  • automatic archive uses the normal archive action and side-effect path
  • deletion cleans a retained worktree inside the disposal critical section, where concurrent unarchive is rejected
  • deletion uses the persisted primary repository root when removing checkpoint/review refs, including after worktree cleanup and Agent Host restart
  • startup/hourly evaluation remains active when either lifecycle setting is enabled

Worktree cleanup safety

Archiving or deleting an eligible session removes its worktree only when Git reports all of the following:

  • the worktree has a branch
  • the branch tracks an upstream
  • outgoing and uncommitted change counts are both known
  • there are zero outgoing commits
  • there are zero uncommitted changes

Incoming commits do not block cleanup. Missing or unknown Git state fails closed. Cleanup uses ordinary, non-force git worktree remove, so Git performs a final dirty-worktree check as well. The lifecycle does not commit local changes or force-remove the worktree.

Removing a worktree is reversible for an archived session: the checkout can be recreated when the session is unarchived.

User experience

Both settings default to disabled, so sessions remain visible, are not automatically archived, and are not permanently deleted.

The existing one-time Turn On Session Cleanup notification appears for an eligible merged-PR session after 15 days of inactivity while both settings are disabled. Its actions are:

  • Turn On Session Cleanup: sets archive and delete thresholds to 15 days
  • Open Settings: opens the chat.agentSessions.auto* settings

Validation

  • client transpilation
  • focused Agent Host lifecycle tests
  • AgentService unit tests
  • targeted ESLint for changed TypeScript files
  • git diff --check

Fixes #334334
Fixes #334352

Copilot AI balanced review requested due to automatic review settings September 3, 2026 18:28

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

Multi-PR sessions may be archived while an associated pull request remains open.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity src/​vs/​sessions/​contrib/​github/​browser/​github.contribution.ts — Evaluate the lifecycle decision once per session rather than once per pull request.…
What changed in this PR

Adds configurable automatic archival for inactive sessions with merged pull requests, including a one-time opt-in notification.

Changes:

  • Registers inactivity-window settings and periodic eligibility checks.
  • Adds archival, active-session safeguards, prompting, and tests.
File Description
github.contribution.ts Implements configuration, prompting, and automatic archival.
githubContribution.test.ts Tests archival eligibility and prompting.

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

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Base: 2adb41dd Current: 44b0bfc0

No screenshot changes.

James-DeVore-MU

This comment was marked as off-topic.

@meganrogge Megan Rogge (meganrogge) changed the title Auto-archive inactive sessions with merged pull requests Add opt-in auto-archive inactive sessions with merged pull requests Sep 3, 2026
@meganrogge
Megan Rogge (meganrogge) marked this pull request as ready for review September 4, 2026 19:59
@meganrogge
Megan Rogge (meganrogge) force-pushed the meganrogge/auto-archive-merged-sessions branch from 64a5c36 to 597a753 Compare September 4, 2026 20:05

@roblourens roblourens left a comment

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.

[Experimental performance review bot]

Automated experimental performance review.

(Written by Copilot)

@roblourens roblourens left a comment

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.

[Experimental performance review bot]

Automated experimental performance review.

(Written by Copilot)

@meganrogge
Megan Rogge (meganrogge) force-pushed the meganrogge/auto-archive-merged-sessions branch from 7e6d141 to 0b7eb20 Compare September 8, 2026 14:16
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 85ad2220-1132-4b10-86b1-266e38e2ba29
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 85ad2220-1132-4b10-86b1-266e38e2ba29
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 85ad2220-1132-4b10-86b1-266e38e2ba29
Retain automatically archived sessions for a second grace period, then use the existing deletion lifecycle after authoritative PR and session revalidation. Preserve manually archived sessions and retained worktrees, and serialize the final safety checks with deletion.

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 314ea45a-b321-4127-9f67-91b50794644d
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 314ea45a-b321-4127-9f67-91b50794644d
Clarify that archival and permanent deletion use independent retention periods, and link each setting to the other in Settings.

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 557c3448-77ae-43aa-9ac8-785c2c42b9a7
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 557c3448-77ae-43aa-9ac8-785c2c42b9a7
@meganrogge
Megan Rogge (meganrogge) force-pushed the meganrogge/auto-archive-merged-sessions branch from 0b7eb20 to 2e7a3d6 Compare September 8, 2026 16:11
@meganrogge Megan Rogge (meganrogge) changed the title Add opt-in auto-archive inactive sessions with merged pull requests Add opt-in auto-archive/delete inactive sessions with merged pull requests Sep 8, 2026
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 9600876a-8143-4338-b588-d956e3ada89b
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 9600876a-8143-4338-b588-d956e3ada89b
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 9600876a-8143-4338-b588-d956e3ada89b

@roblourens roblourens left a comment

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.

[Experimental performance review bot]

Automated experimental performance review.

(Written by Copilot)

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 9600876a-8143-4338-b588-d956e3ada89b
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Ulugbek Abdullaev (@ulugbekna)

Matched files:

  • src/vs/platform/agentHost/node/agentService.ts

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 9600876a-8143-4338-b588-d956e3ada89b
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 9600876a-8143-4338-b588-d956e3ada89b
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 9600876a-8143-4338-b588-d956e3ada89b
@meganrogge
Megan Rogge (meganrogge) merged commit b5db36c into main Sep 9, 2026
52 of 54 checks passed
@meganrogge
Megan Rogge (meganrogge) deleted the meganrogge/auto-archive-merged-sessions branch September 9, 2026 22:30
@vs-code-engineering vs-code-engineering Bot added this to the 1.138.0 milestone Sep 9, 2026
Pascal Berger (pascalberger) added a commit to cake-contrib/Cake.Issues that referenced this pull request Sep 20, 2026
## Summary
- enable VS Code's preview merged agent session auto-archive setting
with the recommended 15-day threshold
- enable the matching auto-delete grace period so automatically archived
merged sessions are cleaned up after 15 more days

## Why
VS Code added safe lifecycle settings for inactive agent sessions with
merged pull requests in microsoft/vscode#334341. Enabling them keeps
completed agent sessions and their eligible worktrees from accumulating
in this workspace.

## Validation
- `Get-Content -Raw .\.vscode\settings.json | ConvertFrom-Json`

Documentation/configuration-only change; no .NET build or test run was
needed.

Co-authored-by: Copilot <[email protected]>
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 26, 2026
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.

Permanently delete archived sessions with merged pull requests after a retention period Auto-archive a session when the linked PR has been merged

5 participants