Skip to content

CL-6481: stop mention fan-out test from polluting agent-chat reuse dedup - #212

Merged
TheGreatAxios merged 1 commit into
mainfrom
cl-6481-reuse-existing
Aug 21, 2026
Merged

TheGreatAxios merged 1 commit into
mainfrom
cl-6481-reuse-existing

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

scripts/e2e/chat.test.ts:874 ("kind filter excludes and includes by kind, and re-creating an existing agent chat reuses it") was failing deterministically in CI. Two prior lanes traced the reuse path statically — findExistingAgentChat/sameAgent (packages/chat/src/routes.ts), resolveDefinitionAssetId/resolveAuthoredProjectedDefinition (packages/chat/src/platform-adapter.ts), CL-6451's resident-agent work, chat/definitionId persistence — and concluded the match should hold. It does; the bug isn't in the match logic.

Booted the real hub+sidecar stack against a scratch Postgres and instrumented the decision point live. Both facts below are directly observed, not inferred:

  • echoDefinitionId() returns the same, stable id on every call within a run — no id-resolution non-determinism.
  • findExistingAgentChat correctly finds two genuine matches for that id in the tenant, not zero and not one. Its documented tie-break (oldest wins — "the original conversation, not whichever the caller happens to hit first") then returns the older of the two, which is not the chat the failing test just created and expects back.

The second match is new: commit 80101ec ("Fix stale chat e2e: mention-fan-out test outlived the workbench anchor", landed the day before this ticket was filed) rewrote "mention fan-out drives the mentioned run" to mint its own kind: "chat" echo conversation so it could test CL-6451's resident-participant-reuse contract. That conversation is indistinguishable from any other echo chat to the tenant-wide reuse dedup, and — being created earlier in the suite — became the row reuseExisting always resolves to for the rest of the file's run.

findExistingAgentChat's dedup semantics (oldest-wins, deterministic) are what the real land-hop caller (ensureMyraWorkbench) needs: always find the one true "Myra" conversation, never fork onto a newer accidental duplicate. That's correct and untouched.

Fix

The mention-fan-out test never needed a persisted agent chat — only a resident participant to mention twice. It now invites echo into a dedicated kind: "workbench" room instead of minting a kind: "chat" conversation. A plain workbench never enters findExistingAgentChat's listWorkbenchSettings(tenantId, "chat") listing, so it can't collide with the reuse test again, while still exercising the exact CL-6451 contract (a second mention drives the same resident run, never mints a sibling, participants stay singular).

Test plan

  • DATABASE_URL=postgres://localhost:5432/<scratch> bun test scripts/e2e/chat.test.ts — 10 pass, 0 fail (run twice against fresh scratch databases to confirm determinism)
  • bun run lint from repo root — 0 errors (12 pre-existing, unrelated warnings)

Fixes CL-6481

"mention fan-out drives the mentioned run" was rewritten yesterday (80101ec)
to mint its own kind:"chat" echo conversation so it could exercise a real
resident participant. That conversation is indistinguishable from any other
echo chat to findExistingAgentChat's tenant-wide dedup, and — being older —
became the row it always resolves reuseExisting to (packages/chat/src/routes.ts's
documented oldest-wins tie-break), so the later "kind filter ... reuses it"
test got this stale chat back instead of its own.

Live e2e run with findExistingAgentChat/sameAgent instrumented confirmed both
candidate rows matched genuinely and deterministically on definitionId
equality; the only difference was creation order. The mention test only needs
a resident participant to mention, not a persisted "chat" conversation, so it
now invites echo into a dedicated kind:"workbench" room instead — outside the
dedup's kind:"chat" listing entirely.

Fixes CL-6481
@TheGreatAxios
TheGreatAxios merged commit d6c4ad8 into main Aug 21, 2026
1 of 2 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-6481-reuse-existing branch August 25, 2026 15:29
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.

1 participant