Skip to content

Feat/issue 298/preserve context - #326

Merged
theantichris merged 2 commits into
mainfrom
feat/issue-298/preserve-context
Aug 31, 2026
Merged

theantichris merged 2 commits into
mainfrom
feat/issue-298/preserve-context

Conversation

@theantichris

Copy link
Copy Markdown
Owner

Closes #298

@theantichris theantichris self-assigned this Aug 31, 2026
Copilot AI lite review requested due to automatic review settings August 31, 2026 22:05
@theantichris theantichris added the enhancement New feature or request label Aug 31, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in theantichris Aug 31, 2026
@theantichris theantichris moved this from Backlog to In review in theantichris Aug 31, 2026
@theantichris
theantichris merged commit 862bb3a into main Aug 31, 2026
5 checks passed
@theantichris
theantichris deleted the feat/issue-298/preserve-context branch August 31, 2026 22:06
@github-project-automation github-project-automation Bot moved this from In review to Done in theantichris Aug 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

RunTurn can panic on nil inputs and can commit an assistant message even if the chat implementation returns a non-assistant role, potentially diverging session history from the returned response.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Implements a small orchestration boundary for multi-turn chat by introducing a turn-level helper that constructs outbound history and commits messages to the session only on success, aligning with Issue #298’s “preserve context across turns” and “no fabricated assistant responses on failure” requirements.

Changes:

  • Replaces ad-hoc prompt/session mutation in the CLI path with conversation.RunTurn.
  • Adds conversation.ChatFunc and conversation.RunTurn to centralize turn orchestration and commit semantics.
  • Adds unit tests asserting correct outbound message ordering across two turns and ensuring failures/cancellation don’t mutate session history.
File summaries
File Description
main.go Uses conversation.RunTurn and shared conversation.ChatFunc instead of mutating session directly.
internal/conversation/turn.go Introduces RunTurn orchestration helper that builds outbound history and commits user+assistant on success.
internal/conversation/turn_test.go Adds multi-turn and failure/cancellation tests for outbound message sequence and session immutability on errors.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +3 to +27
import (
"context"
"fmt"
)

// ChatFunc requests one assistant response for an ordered message history.
type ChatFunc func(context.Context, string, []Message) (Message, error)

// RunTurn sends a user prompt with the session history and commits the
// user-assistant exchange only when chat succeeds. Any returned error leaves
// the session unchanged.
func RunTurn(ctx context.Context, session *Session, model string, prompt string, chat ChatFunc) (Message, error) {
messages := session.Messages()
messages = append(messages, Message{Role: RoleUser, Content: prompt})

response, err := chat(ctx, model, messages)
if err != nil {
return Message{}, fmt.Errorf("run conversation turn: %w", err)
}

session.AppendUser(prompt)
session.AppendAssistant(response.Content)

return response, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

M2.C2: Preserve context across multiple turns

2 participants