Skip to content

fix: retain conversation context when generation is cancelled#25

Merged
quiet-node merged 1 commit intomainfrom
fix/stop-button-context-retention
Apr 4, 2026
Merged

fix: retain conversation context when generation is cancelled#25
quiet-node merged 1 commit intomainfrom
fix/stop-button-context-retention

Conversation

@quiet-node
Copy link
Copy Markdown
Owner

Summary

  • Bug: Clicking "Stop" during generation caused the AI to lose conversation history. Follow-up questions would start from scratch because the cancelled turn (user message + partial response) was discarded from the backend ConversationHistory.
  • Root cause: The !was_cancelled guard in ask_ollama prevented cancelled turns from being persisted to in-memory history, even though the frontend correctly displayed the partial response.
  • Fix: Removed the !was_cancelled check so cancelled turns are retained in context. The epoch guard still prevents stale writes after a reset.

Also verified that server-side request termination (Issue 1) already works correctly via CancellationToken + tokio::select! + HTTP connection drop.

Test plan

  • 78 backend tests pass
  • 257 frontend tests pass
  • 100% line coverage maintained (bun run test:backend:coverage)
  • bun run validate-build clean (zero errors)
  • Manual: start a generation, click Stop mid-stream, then ask a follow-up — model should retain context of the partial response

🤖 Generated with Claude Code

Previously, clicking Stop discarded the user message and partial
assistant response from the backend ConversationHistory. This caused
the model to lose all context from the cancelled turn, making
follow-up questions start from scratch.

Remove the `!was_cancelled` guard from the persistence condition so
cancelled turns are kept in the in-memory history. The epoch check
still prevents stale writes after a reset.

Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
@quiet-node quiet-node merged commit 3e6c846 into main Apr 4, 2026
0 of 3 checks passed
@quiet-node quiet-node deleted the fix/stop-button-context-retention branch April 4, 2026 03:19
quiet-node added a commit that referenced this pull request Apr 10, 2026
Previously, clicking Stop discarded the user message and partial
assistant response from the backend ConversationHistory. This caused
the model to lose all context from the cancelled turn, making
follow-up questions start from scratch.

Remove the `!was_cancelled` guard from the persistence condition so
cancelled turns are kept in the in-memory history. The epoch check
still prevents stale writes after a reset.

Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
quiet-node added a commit that referenced this pull request Apr 10, 2026
Previously, clicking Stop discarded the user message and partial
assistant response from the backend ConversationHistory. This caused
the model to lose all context from the cancelled turn, making
follow-up questions start from scratch.

Remove the `!was_cancelled` guard from the persistence condition so
cancelled turns are kept in the in-memory history. The epoch check
still prevents stale writes after a reset.

Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
quiet-node added a commit that referenced this pull request Apr 11, 2026
Previously, clicking Stop discarded the user message and partial
assistant response from the backend ConversationHistory. This caused
the model to lose all context from the cancelled turn, making
follow-up questions start from scratch.

Remove the `!was_cancelled` guard from the persistence condition so
cancelled turns are kept in the in-memory history. The epoch check
still prevents stale writes after a reset.

Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
This was referenced Apr 11, 2026
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.

1 participant