Skip to content

agentHost: keep replayed catalog writes from claiming the session.db mirror - #342060

Merged
Sandeep Somavarapu (sandy081) merged 1 commit into
mainfrom
agents/fix-flaky-session-artifact-removal
Oct 16, 2026
Merged

Sandeep Somavarapu (sandy081) merged 1 commit into
mainfrom
agents/fix-flaky-session-artifact-removal

Conversation

@sandy081

Copy link
Copy Markdown
Member

Fixes #341001

Root cause

sessionArtifacts is owned by the session state store (agent-host.db is authoritative since Block 3a, #341626). A catalog sync adopts its legacy values into central state, then writes them to session.db together with the catalog snapshot (_writeThroughCentral). When that write is replayed (the snapshot revision is unchanged), setMetadataValuesAndCatalogSyncSnapshot skips the values. This holds for both the real SessionDatabase and TestSessionDatabase. However, _writeThroughCentral still called noteMirrored, so the store believed session.db held its rendering and never repaired it.

The flaky test hits this when the fixture's 100 ms summary flush lands while the retry is persisting (a slow CI agent):

  1. The flush queues a trailing background write. Since Fix the session removal bug causing many flaky tests #341015, that write carries the retry's unpublished sessionArtifacts override.
  2. The trailing write's store-owned write mirrors that override as the caller serialized it ({...artifact, chat}, with chat last) straight into session.db.
  3. Its catalog sync builds the retry's identical payload, so it replays and writes nothing. The store still records its canonical rendering (chat second) as mirrored.

As a result, session.db keeps the other serialization indefinitely. That is the key-order diff in builds 484717 and 485179.

Did Block 3a cause it? Partly:

  • The flake predates 3a. Builds 482957, 482994 and 483020 ran on commits without 83caa64. There, the final value still contained the PR because a trailing write used a stale source. Fix the session removal bug causing many flaky tests #341015 fixed that by carrying unpublished overrides into trailing writes.
  • The current signature (same entries, different key order, builds 484717 and 485179, both after 3a) is from 3a. It added _writeThroughCentral with notes-on-replay and the second writer (the store's mirror of the owned write). The same commit relaxed the sibling test to a JSON.parse comparison and wrote the non-canonical order into this test's afterFailure expectation.

Fix

  • _writeThroughCentral notes entries as mirrored only when the session.db write applied them. A replay leaves them dirty, so the store, which owns the key, mirrors central state (coalesced, or at whenIdle).
  • Tests: both tests fence on the store (whenIdle(session)) before reading session.db, because it holds the store's mirror. 'keeps a removal durable when a summary change is flushed while it is persisting' compares the exact string again. It forces the trailing-write interleaving deterministically, so it is the regression test for this bug. The flaky test now also asserts the published meta and the central catalog after the retry.

Validation

  • Deterministic repro: holding the retry's catalog write until a summary change is flushed reproduces the CI diff exactly on main. With the fix it passes.
  • Mutation: restoring result !== 'cancelled' && result !== 'generationMismatch' makes 'keeps a removal durable when a summary change is flushed while it is persisting' fail, along with the forced-interleaving variant of the flaky test, with the CI key-order diff.
  • npm run transpile-client: passed.
  • npm run test-node -- --run src/vs/platform/agentHost/test/node/sessionArtifactRemoval.test.ts: 12 passing.
  • 200 consecutive runs of mocha test/unit/node/index.js --delay --ui=tdd --exit --run src/vs/platform/agentHost/test/node/sessionArtifactRemoval.test.ts plus the forced-interleaving variant (temporary file, not committed), at load average 17–27: 200/200 passed.
  • agentHost node suite (all 357 src/vs/platform/agentHost/test/node/**/*.test.ts files): 11608 passing, 75 pending, 14 failing. All 14 are in copilotAgent.test.ts and are identical on unmodified origin/main (748 passing, 14 failing with and without this change), so they're pre-existing and environmental.
  • npm run eslint -- <changed files>: passed.
  • node --experimental-strip-types build/hygiene.ts <changed files>: passed, and the pre-commit hygiene hook passed.

…mirror

A catalog sync adopts its store-owned legacy values into central state and
then writes them to session.db with the catalog snapshot. When that write
is replayed (the snapshot revision is unchanged), the database skips the
values, yet _writeThroughCentral still noted them as mirrored. The session
state store then believed session.db held its rendering and never repaired
it.

A trailing background write after an artifact removal hits this: its owned
write mirrors the caller's serialization of the artifacts, and its catalog
sync replays the removal's identical payload, so session.db keeps a value
the store does not record. Only note entries as mirrored when the write
applied them, so a replay leaves them dirty for the store to mirror.

Fence the session artifact tests on the store before reading session.db,
and compare the mirrored value exactly again.

Fixes #341001

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 13:29
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.143.0 milestone Oct 16, 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.

🟢 Approval recommended

The focused fix matches replay semantics, and the strengthened regression tests cover mirror convergence.

0 open findings

What changed in this PR

Fixes session-state mirror tracking so replayed catalog writes do not prevent repair of session.db.

Changes:

  • Records mirrored entries only when writes return applied.
  • Strengthens regression tests with store-idle waits and exact persisted-state assertions.
  • Clarifies the mirror-tracking contract.
File Description
src/​vs/​platform/​agentHost/​test/​node/​sessionArtifactRemoval.test.ts Verifies mirror convergence and durable artifact removal.
src/​vs/​platform/​agentHost/​node/​agentHostCatalogSyncService.ts Prevents replayed writes from claiming entries were mirrored.
src/​vs/​platform/​agentHost/​common/​agentHostSessionStateStore.ts Clarifies when callers may record mirrored entries.

🧠 Review effort: Balanced


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky Test: Session Artifact Removal > logs and propagates persistence failures without hiding the artifact and allows a durable retry

3 participants