CL-6481: stop mention fan-out test from polluting agent-chat reuse dedup - #212
Merged
Merged
Conversation
"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
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.
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/definitionIdpersistence — 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.findExistingAgentChatcorrectly 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 rowreuseExistingalways 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 akind: "chat"conversation. A plain workbench never entersfindExistingAgentChat'slistWorkbenchSettings(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 lintfrom repo root — 0 errors (12 pre-existing, unrelated warnings)Fixes CL-6481