Repository navigation
agentHost: roll back a failed artifact persistence - #342137
Merged
Sandeep Somavarapu (sandy081) merged 3 commits intoOct 16, 2026
Merged
Conversation
A list-visible write first stores its owned values in the session state store (and session.db's mirror), then synchronizes the session catalog. When that synchronization failed, the owned values stayed: a failed artifact removal left central state and session.db without the artifact while the published state and the catalog still listed it, so a restart would have hidden it. Ordered writes whose caller publishes only after persisting can now roll back. The owned values are swapped in one exclusive section of the store, which records what they replaced; if the synchronization throws, each key that still holds this write's value (or the value its synchronization adopted) gets the previous value back, mirrored to session.db before the error propagates. A newer write is left alone. Artifact persistence opts in; writes of already-published state still roll forward through catalog reconciliation. A crash before the rollback recovers forward: the owned write marks the catalog payload dirty in the same agent-host.db transaction, session.db's mirror is repaired from central state, and the startup reconciliation pass re-projects the catalog. Co-authored-by: Copilot <[email protected]>
Contributor
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Post-commit failures can leave catalog state inconsistent or discard the previous values needed for rollback.
2 open findings
What changed in this PR
Adds rollback for failed artifact persistence so unpublished removals do not remain durable, following the earlier catalog-mirroring fixes.
Changes:
- Enables conditional rollback of artifact-owned session values.
- Adds failure, background-write, and crash-recovery regression tests.
| File | Description |
|---|---|
| src/vs/platform/agentHost/test/node/sessionArtifactRemoval.test.ts | Checks consistency across published state, central storage, session.db, and catalog. |
| src/vs/platform/agentHost/node/agentService.ts | Captures previous owned values and restores them after synchronization failures. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
roblourens
previously approved these changes
Oct 16, 2026
…t failures
Two review findings on the rollback of a failed artifact persistence:
- The values to restore were recorded only once the owned write's
exclusive section resolved. That section commits central state and
session.db, then records the mirror acknowledgement, which can still
reject. The previous values were then lost and a later catalog failure
skipped the rollback, leaving the failed removal durable. Record them in
caller-owned state inside the exclusive section, before the write; the
compare-and-restore rollback stays a no-op if the write never committed.
- A receipt acknowledgement that failed after the catalog upsert committed
was thrown, so the owned values were rolled back while the catalog and
session.db's pending receipt kept the removal. After a restart,
reconciliation replayed that receipt and marked the payload clean, so the
listing omitted an artifact that restore, central state and session.db
still had. The catalog sync now reports such a failure as pending
('acknowledgementFailed'), as it already does for a superseded
acknowledgement: the mutation is committed, the caller publishes it, and
reconciliation acknowledges the receipt. Rollback is thus limited to
synchronizations that did not commit the catalog.
Co-authored-by: Copilot <[email protected]>
Sandeep Somavarapu (sandy081)
dismissed
roblourens’s stale review
via
October 16, 2026 21:56
dfbe5db
Aaron Munger (amunger)
approved these changes
Oct 16, 2026
Sandeep Somavarapu (sandy081)
deleted the
agents/rollback-failed-artifact-removal
branch
October 16, 2026 23:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Follow-up to #341001, #342060 and #342096.
Problem
Since Block 3a (#341626), a list-visible write (
_persistListVisibleSessionStateNow) first writes its owned values to the session state store, which mirrors them to session.db immediately. Only then does it synchronize the session catalog. If that synchronization fails, the owned write stays.For a failed artifact removal, central state and session.db no longer have the artifact, while the published state and the catalog still list it. After a restart it would be gone, even though the user saw the removal fail. The 'logs and propagates…' test encoded that inconsistent state.
Fix
Roll back the owned write when the catalog synchronization fails, for callers that publish only after persisting:
_persistOrderedListVisibleSessionState(..., { rollbackOnFailure })threads the caller's own overrides into_persistListVisibleSessionStateNow._swapOwnedSessionValueswrites the owned values in one exclusive section of the store and records what they replaced._rollBackOwnedSessionValuesrestores the previous value of each key that still holds this write's value, or the value its synchronization adopted. It uses the store's exclusive section and anImmediatemirror, so session.db is restored before the error propagates. A newer write (another caller, a later mutation) is left alone.Scope audit of the seam
All owned writes in
_persistListVisibleSessionStateNowshare the path, but only callers that persist before publishing need rollback:SessionArtifacts.mutate: tool additions and user removals) publishes only after persisting, so it opts in._queueCatalogSync,_drainBackgroundCatalogStateWrites) persist state that is already published, so rolling back would diverge from it. They roll forward through catalog reconciliation, as before._persistListVisibleSessionState), adoption metadata, chat removal and creation, and catalog restores with{}overrides. Each persists state the caller has already applied to the state manager, or carries no owned values.Crash safety
If the process crashes between the owned write and its rollback, it recovers forward to one consistent state, never removed-in-one-place and published-in-another:
writeSessionState) marks the catalog payload dirty in the same agent-host.db transaction.The rollback itself is a single central write, with the same guarantees.
Tests
Validation
rollbackOnFailure): 'logs and propagates…' fails, withcentralandpersistedmissing the PR;CoalescedplusnoteMirrored): 'logs and propagates…' fails, withpersistedmissing the PR.npm run transpile-client: passed.mocha test/unit/node/index.js --delay --ui=tdd --exit --run src/vs/platform/agentHost/test/node/sessionArtifactRemoval.test.ts: 14 passing, and 200/200 consecutive runs passed after rebasing onto main.src/vs/platform/agentHost/test/node/**/*.test.tsfiles): 11644 passing, 75 pending, 14 failing. All 14 are incopilotAgent.test.tsand identical without this change (750 passing, 14 failing), so they are pre-existing.npx tsc --noEmit -p src/tsconfig.json: the only 2 errors are incopilotSdkManagedSettings.integrationTest.ts(ensembleTier), and they are identical on origin/main.npm run eslintandbuild/hygiene.tson the changed files: passed, and the pre-commit hygiene hook passed.