Skip to content

fix: dedupe active live conversation sessions#87

Merged
shaypal5 merged 2 commits into
mainfrom
codex/issue-81-dedupe-live-sessions
May 31, 2026
Merged

fix: dedupe active live conversation sessions#87
shaypal5 merged 2 commits into
mainfrom
codex/issue-81-dedupe-live-sessions

Conversation

@shaypal5
Copy link
Copy Markdown
Contributor

Summary

  • Reuse an existing non-stopped live conversation session when the operator starts live mode for the same DM conversation again.
  • Return normalized session payloads with existing: true|false so callers can distinguish reuse from creation.
  • Update dashboard status copy and API docs to describe idempotent live-mode starts.

Validation

  • npm test -- --run tests/api-auth.test.ts
  • npm test
  • npm run check
  • git diff --check
  • npm run build

Milestone

  • Checked open repository milestones with gh api repos/agent-comms/agent-comms-core/milestones; none were returned.

Closes #81

@shaypal5 shaypal5 added the bug Something isn't working label May 31, 2026
@shaypal5
Copy link
Copy Markdown
Contributor Author

Self-review after implementation, taking the requested outsider/senior-dev stance:

  1. The first version only fixed sequential duplicate starts. It still allowed two concurrent POST /operator/live-conversations requests to both observe no existing session and insert duplicate non-stopped sessions for the same conversationId.

Recommended action/fix: enforce the invariant in the database, not only in application code. Add a partial unique index on live_conversation_sessions(conversation_id) where status <> 'stopped' for both D1 and Postgres migrations.

Applied: added 0007_unique_active_live_sessions.sql in both migration trees.

  1. Once the database owns the invariant, the create handler must handle the natural race loser path. A request can still pass the pre-read, hit the unique constraint on insert, and should return the canonical active session instead of surfacing a generic 500.

Recommended action/fix: after insert failure, re-read the open session for the conversation. If found, return it with existing: true; otherwise rethrow the original error.

Applied: added findOpenLiveConversationSession(...) and race recovery around the insert.

  1. The test coverage needed to prove more than the happy sequential path.

Recommended action/fix: keep the sequential reuse and stopped-session restart tests, and add a targeted race simulation where insert fails after another session appears.

Applied: expanded the live-session mock and added the concurrent-create race test.

@shaypal5 shaypal5 merged commit 01c6a69 into main May 31, 2026
1 check passed
@shaypal5 shaypal5 deleted the codex/issue-81-dedupe-live-sessions branch May 31, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate live sessions on same conversation require redundant receipt updates

1 participant