Skip to content

Fix citations - #74

Closed
DidierRLopes wants to merge 18 commits into
mainfrom
hotfix/citations
Closed

Fix citations#74
DidierRLopes wants to merge 18 commits into
mainfrom
hotfix/citations

Conversation

@DidierRLopes

@DidierRLopes DidierRLopes commented Sep 14, 2025

Copy link
Copy Markdown
Contributor

What went wrong

  • No stable IDs: The UI renders citation markers from each citation.id. Early on, citations were sent without a usable id, so markers didn’t render. A refresh backfilled ids and injected markers from history, which is why they appeared only after reload.
  • Wrong timing: When citations were emitted before any message chunks, the UI appended markers to an empty aiMessageBuffer — so citations
    showed at the top.

What the UI expects

  • A live AI message must exist when markers arrive. useStreamResponse creates it on the first copilotMessageChunk (or citation) and treats the last AI message as the “stream target”.
  • Citations append to the current aiMessageBuffer at the moment the copilotCitationCollection event is processed.
  • The markers reference citation.id exactly; ids must be strings.

What fixed it

  • Guarantee string ids on each citation before streaming.
  • Stream LLM chunks first, then send copilotCitationCollection so markers land at the end of the final message.
  • Yield typed SSE objects and serialize once at EventSourceResponse to match the UI event schema precisely.

Resulting event order

  • copilotMessageChunk " " → creates the AI message and starts streaming
  • copilotMessageChunk "…tokens…"
  • copilotCitationCollection [{ id: "…" }, …] → markers appear at the end
  • done

@DidierRLopes DidierRLopes changed the title Fix citations? Fix citations Sep 14, 2025
@DidierRLopes
DidierRLopes requested a review from piiq September 14, 2025 14:54
@piiq

piiq commented Sep 15, 2025

Copy link
Copy Markdown
Member

Closing in favor of #76

@piiq piiq closed this Sep 15, 2025
@piiq
piiq deleted the hotfix/citations branch October 7, 2025 12:04
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.

2 participants