Skip to content

agentHost: harden passive session flag persistence across restart - #338970

Merged
roblourens merged 3 commits into
mainfrom
roblou/agents/fix-vscode-issue-338063
Oct 1, 2026
Merged

roblourens merged 3 commits into
mainfrom
roblou/agents/fix-vscode-issue-338063

Conversation

@roblourens

Copy link
Copy Markdown
Member

Addresses #338063.

Changes

  • Preserve newer, validated local pending catalog state when applying passive archive/read updates, rather than rebuilding from a stale central payload. Respect generation/revision boundaries and fall back to central data if the pending payload is corrupt.
  • Keep general catalog reconciliation cancelled during shutdown. After providers stop, replay only failed passive writes, once per session, within a shared 250 ms budget. Reuse the existing replay validation and CAS logic, without listing sessions or resolving provider metadata.
  • Retain full available Agent Host logs from before and after restart, plus Copilot runtime logs, in the CI logs artifact before temporary-home cleanup.
  • Add deterministic failure-injection tests for flag preservation, shutdown ordering, bounded retries, cancellation, corruption, deletion fencing, and a real SQLite close race.

Investigation and limitations

Injected catalog-write failures reproduced two concrete problems: a subsequent flag update could overwrite locally pending flags, and cancelling scheduled reconciliation on shutdown could leave the first listing after restart stale. Regression tests failed before the fixes.

The original intermittent Windows failure mechanism is still unconfirmed because the failing jobs did not retain Agent Host logs. Windows/Linux and Azure validation remain outstanding; this draft adds defenses for the demonstrated failure paths and preserves evidence for another CI failure. No E2E assertions were weakened, tests skipped, or existing timeouts raised.

Latest main was merged without rewriting history.

Validation

Run locally on macOS against the merged branch:

  • npm run compile-client - passed, zero compilation errors.
  • Focused unit coverage - passed, 93 tests:
./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentService.test.ts --run src/vs/platform/agentHost/test/node/agentHostCatalogSyncService.test.ts --run src/vs/platform/agentHost/test/node/agentHostCatalogReconciliationService.test.ts --run src/vs/platform/agentHost/test/node/agentHostE2EDiagnostics.test.ts --grep 'AgentHostCatalog|Agent Host E2E diagnostics|shutdown|passive|read/archive toggle|queued.*toggle|archiving.*session|unarchiving.*session'
  • Existing cross-provider restart scenarios - passed, 9 tests across Claude, Copilot, and Codex:
./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/e2e/providers/claudeAgentHostE2E.integrationTest.ts --run src/vs/platform/agentHost/test/node/e2e/providers/copilotAgentHostE2E.integrationTest.ts --run src/vs/platform/agentHost/test/node/e2e/providers/codexAgentHostE2E.integrationTest.ts --grep 'archiving a never-restored session|session metadata history and provider context survive a host restart|peer chat catalog and transcript survive a host restart'
  • Changed-file lint - passed:
npm run eslint -- src/vs/platform/agentHost/node/agentService.ts src/vs/platform/agentHost/node/agentHostCatalogSyncService.ts src/vs/platform/agentHost/node/agentHostCatalogReconciliationService.ts src/vs/platform/agentHost/test/node/agentService.test.ts src/vs/platform/agentHost/test/node/agentHostCatalogSyncService.test.ts src/vs/platform/agentHost/test/node/agentHostE2EDiagnostics.test.ts src/vs/platform/agentHost/test/node/e2e/harness/agentHostE2EDiagnostics.ts src/vs/platform/agentHost/test/node/e2e/harness/agentHostE2ETestHarness.ts

(Written by Copilot)

roblourens and others added 2 commits September 30, 2026 12:28
Preserve newer local catalog snapshots when applying passive archive/read updates. Replay failed writes after provider shutdown with a shared 250 ms budget, and retain restart logs in CI artifacts.

Addresses #338063; the original intermittent Windows failure still needs cross-platform validation.

(Written by Copilot)

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 19:32

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

Teardown-originated failures can still lose their logs because preservation runs only before release().

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Hardens Agent Host passive archive/read flag persistence across restarts and improves failure diagnostics.

Changes:

  • Preserves and replays validated pending catalog snapshots during shutdown.
  • Adds cancellation, revision, corruption, deletion, and SQLite race coverage.
  • Retains Agent Host and Copilot runtime logs for failed E2E tests.
File Description
agentService.ts Preserves pending flags and performs bounded shutdown replay.
agentHostCatalogSyncService.ts Adds targeted pending-snapshot replay.
agentHostCatalogReconciliationService.ts Reuses shared replay validation logic.
agentService.test.ts Tests passive updates and shutdown ordering.
agentHostCatalogSyncService.test.ts Tests replay, cancellation, and close races.
agentHostE2EDiagnostics.ts Copies full runtime logs into CI artifacts.
agentHostE2EDiagnostics.test.ts Tests diagnostic log preservation.
agentHostE2ETestHarness.ts Invokes log preservation on test failure.
e2e/​README.md Documents retained diagnostic artifacts.

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

Capture logs on the first resource-cleanup error and again after shutdown, including suite cleanup failures before removing isolated homes. Cover these lifecycle paths with unit tests and replace the platform-dependent ENOTDIR assertion that failed on Windows.

(Written by Copilot)

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

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: ec2e5806 Current: 54fc959f

Changed (1)

chat/aiCustomizations/aiCustomizationManagementEditor/DiscoverPluginsLoadingMore/Light
Before After
before after

4 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

@roblourens
roblourens marked this pull request as ready for review October 1, 2026 04:38
@roblourens
roblourens enabled auto-merge (squash) October 1, 2026 04:38
@roblourens
roblourens merged commit 8e43fc6 into main Oct 1, 2026
55 of 56 checks passed
@roblourens
roblourens deleted the roblou/agents/fix-vscode-issue-338063 branch October 1, 2026 05:08
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Oct 1, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants