Skip to content

fix: recover orphaned assistant messages after restart#19079

Open
Haohao-end wants to merge 2 commits intoanomalyco:devfrom
Haohao-end:fix/19023-startup-recover-orphaned-sessions
Open

fix: recover orphaned assistant messages after restart#19079
Haohao-end wants to merge 2 commits intoanomalyco:devfrom
Haohao-end:fix/19023-startup-recover-orphaned-sessions

Conversation

@Haohao-end
Copy link

@Haohao-end Haohao-end commented Mar 25, 2026

Issue for this PR

Closes #19023

Type of change

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

What does this PR do?

This fixes a case where a session can stay stuck in a thinking state after the server restarts or a stream is interrupted.

Before this change, unfinished tool parts were only cleaned up at the end of the normal processor flow. If the process exited before that cleanup ran, the assistant message could remain incomplete and its tool parts could stay in pending or running.

This change extracts that cleanup into a reusable session helper and reuses it in two places:

  • the existing processor shutdown path
  • instance bootstrap, so interrupted assistant messages are recovered when the instance starts

During recovery, unfinished tool parts are marked as error and the assistant message is completed. This reuses the existing message/part update flow so clients receive the normal update events instead of staying stuck.

How did you verify your code works?

I verified the change by tracing the existing session update flow and confirming that the recovery path uses the same updatePart() and updateMessage() calls as the normal cleanup path.

I was not able to run the full local typecheck in my current environment because the typecheck script depends on tsgo, which was not available (tsgo: command not found).

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 25, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Haohao-end Haohao-end force-pushed the fix/19023-startup-recover-orphaned-sessions branch from 158e88b to 45151a6 Compare March 25, 2026 08:25
@Haohao-end
Copy link
Author

Rebased on latest dev and all checks are now passing. Happy to make follow-up changes if needed.

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.

Sessions permanently stuck after server restart or stream interruption — no startup recovery for orphaned messages/tool parts

1 participant