Skip to content

fix(core): surface message ID conflicts on session import - #54543

Closed
reynold-hu wants to merge 1 commit into
anomalyco:devfrom
reynold-hu:import-message-conflict
Closed

reynold-hu wants to merge 1 commit into
anomalyco:devfrom
reynold-hu:import-message-conflict

Conversation

@reynold-hu

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #54336

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Importing a session whose message IDs already exist died on the session_message UNIQUE constraint inside the import publication and surfaced as HTTP 500. SessionTransfer.import now checks the imported message IDs before publishing and fails with MessageConflictError, which the import handler maps to a 409 ConflictError with Session messages already exist: <sessionID>.

I used a distinct error instead of reusing ImportConflictError so the 409 message stays accurate: the destination session does not exist here, only its messages do. Session-ID conflicts keep working exactly as before.

How did you verify your code works?

  • packages/server/test/session-import.test.ts: new case imports a second session with a colliding message ID, expects a 409 and asserts the destination session is not created. bun test test/session-import.test.ts → 4 pass.
  • bun test test/session-create.test.ts (existing SessionTransfer behavior) → 44 pass.
  • bun typecheck in packages/core and packages/server both pass.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot closed this Oct 11, 2026
@opencode-agent

Copy link
Copy Markdown
Contributor

Thanks for picking this up, @reynold-hu, and for the clear write-up and test!

I think this duplicates #54353, which is still open. It fixes #54336 the same way: it checks the imported message IDs against session_message before publishing and fails with a conflict that the server returns as a 409. It also adds a matching regression test in packages/server/test/session-import.test.ts. The main difference is that #54353 reuses ImportConflictError instead of adding a separate MessageConflictError.

If you think the more specific 409 message is worth having, a review or comment on #54353 would be the best place to suggest it, and testing it there would help too.

@reynold-hu

Copy link
Copy Markdown
Contributor Author

Agreed — closing in favor of #54353. I left the conflict-message note and an extra assertion suggestion there.

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.

session: importing a session whose message IDs already exist returns HTTP 500 instead of a conflict

1 participant