Repository navigation
agentHost: fix flaky chat movability test racing a background catalog write - #342256
Merged
Alexandru Dima (alexdima) merged 2 commits intoOct 17, 2026
Merged
Alexandru Dima (alexdima) merged 2 commits into
Alexandru Dima (alexdima) merged 2 commits into
Conversation
… write The "movability follows the events" test parks the source session and expects its peer chat to stop being movable. The earlier steps of the test flip the chat's movable flag, which marks the session summary dirty; its debounced (100 ms) flush queues a background catalog write for the session. On a slow machine that write can overlap the parking step: it bumps the session's payload dirty marker, so `_park` declines as superseded, and when it ends pending it also wakes the session. Either way the chat stays movable. Stop queueing background catalog writes and drain those in flight before parking, so the dirty marker the test passes to `_park` stays current. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow test-only fix addresses both late and in-flight writes without weakening the movability assertions.
No open issues 🎉
What changed in this PR
Stabilizes the chat movability unit test by preventing background catalog writes from racing its parking assertions. No product code changes.
Changes:
- Stops new catalog writes before parking.
- Waits for in-flight writes to finish while preserving existing assertions.
No actionable findings remain.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/agentService.test.ts |
Adds catalog-write isolation and draining before the parking step. |
Review effort: Balanced
…he movability test Rather than replacing `_queueCatalogSync` with a no-op, flush the session's dirty summary through `prepareSessionSummariesForListing` (as a listing does), which queues its catalog write now instead of after the 100 ms debounce, and drain it before parking. The test also records `_park`'s reason, so a future regression reports `superseded` instead of only `parked: true`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Alexandru Dima (alexdima)
marked this pull request as ready for review
October 17, 2026 17:59
Alexandru Dima (alexdima)
enabled auto-merge (squash)
October 17, 2026 17:59
Ladislau Szomoru (lszomoru)
approved these changes
Oct 17, 2026
Alexandru Dima (alexdima)
deleted the
agents/investigate-vscode-test-intermittent-failure
branch
October 17, 2026 18:15
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.
cc Sandeep Somavarapu (@sandy081)
This fixes an intermittent failure of a node unit test. No issue is filed for it. The change is test-only; no product code changes.
Test:
AgentService (node dispatcher)›peer chat catalog persistence›chat moves (Block 4)› "a chat's movability follows the events of the services that hold its session's state, and a refused move keeps its reason" insrc/vs/platform/agentHost/test/node/agentService.test.ts.Failure
It failed once in about 11 runs of the whole file on a busy machine, in the "parked" step. After
_catalogReconciliationService._park(...), the chat was still reported as movable:Root cause
The movability update itself is not slow.
_parkfiresonDidChangeParkedSessionssynchronously, andAgentHostChatMovabilityrecomputesmovableinside that listener, readingisParkedlive. Soparked: truemeans the session was not parked when the test read it. That happens because_parkitself declined, or because something woke the session right after.Both come from a background catalog write that the test never awaits:
movableflag. That changes the session summary, andSessionSummaryNotifierflushes summary changes on a 100 ms debounce.onDidChangeSessionSummarylistener inAgentService, which calls_queueCatalogSync(source)and starts a background catalog write (_drainBackgroundCatalogStateWrites→_persistListVisibleSessionStateNow).synchronizeWithFactory. In this test it also endspending(acknowledgementSuperseded), so it then calls_markCatalogPayloadDirty. That bumps the marker again and callswakeParkedSessions(source)._park._parkre-reads the marker and, by design, declines assupersededwhen it changed. A wake that lands after a successful park releases the session just the same.Normally the 100 ms flush fires after the test finished. When the machine is busy and the steps take longer, it fires mid-test, and the write can overlap the parking step.
Evidence
_park, the single test fails every time with exactly the diff above. Logging showedobservedDirty: 6,currentDirty: 9and_parkreturning{ status: 'retry', reason: 'superseded' }. Stacks showed two bumps from_drainBackgroundCatalogStateWrites→_persistListVisibleSessionStateNowand a third from_markCatalogPayloadDirty.reason: 'sourceUnresolvable').Fix
Just before parking, the test flushes the session's dirty summary through the normal path and waits for the catalog write that it queues:
prepareSessionSummariesForListingflushes a published session's dirty summary right away, as a listing does. TheonDidChangeSessionSummary→_queueCatalogSyncwrite is queued now instead of 100 ms later. When the debounce timer fires later, it finds nothing new to emit. The same file already uses this in itsunloadSessionhelper.whenCatalogReconciliationIdle()then waits for that write, including the dirty-marker bump and wake from itspendingresult, so all of it lands before the test reads the marker and parks._park, the drain alone still fails the same way: the debounced write lands in that window.The test also records
_park's outcome reason in its snapshot. If this regresses, the failure will sayreason: 'superseded'rather than onlyparked: true.No product behavior is disabled. An earlier revision of this PR replaced
_queueCatalogSyncwith a no-op; this revision replaces that.This is a test-only fix. When parking races a concurrent catalog write, the product code declines or re-wakes on purpose, so a mutation is never hidden behind a parked session.
Why the write ends
pendinghereThe background write returns
pending(acknowledgementSuperseded), which adds the third dirty-marker bump and the wake. This is very likely a fixture artifact, not a product bug.setupMove()withoutperSessionDatashares oneTestSessionDatabase, and so one catalog sync snapshot, across all sessions and chat storage. So writes for the target or peer can supersede the source's acknowledgement, which can't happen with one database per session in production. The fix doesn't depend on this.How to test
Note: the node runner ignores
--grep, so this runs the whole file. To run only this test, temporarily mark ittest.only.Validation
_park. Control: the drain alone with the same wait fails withreason: 'superseded',parked: true.npm run test-node -- --run src/vs/platform/agentHost/test/node/agentService.test.tspassed: 1134 passing, 16 pending.npm run eslint -- src/vs/platform/agentHost/test/node/agentService.test.tspassed.typecheck-client.