fix(chat): settle authoritative turns and make capabilities explicit
This commit is contained in:
@@ -3,7 +3,6 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -180,16 +179,6 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
// Reserve the activation before calling the external service. If the
|
||||
// process dies after the call but before the success checkpoint, a retry
|
||||
// must report the ambiguous operation rather than append the skill twice.
|
||||
// Preload the web chat's behavior brief before the first turn. This is
|
||||
// best effort: an older OpenCode build or another harness without the
|
||||
// experimental instruction surface still gets a usable chat.
|
||||
if instructions != "" {
|
||||
if instr, ok := broker.(chatInstructioner); ok {
|
||||
if err := instr.SetInstruction(ctx, session.ID, "pipelines.behavior", instructions); err != nil {
|
||||
log.Printf("chat %s preload instructions: %v", session.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := registry.AdvanceChatCreate(ctx, operationID, "created", "activating"); err != nil {
|
||||
chatCreateConflictError(request, err, write)
|
||||
return
|
||||
@@ -239,6 +228,24 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
session.Directory = resolved
|
||||
session.Tag = protocol.ChatSessionTagOperator
|
||||
session.Backend = backend
|
||||
// Setting a named instruction replaces it idempotently. Repeat on a retried
|
||||
// create so the reply reports an observed result, never a guessed success.
|
||||
session.InstructionStatus = "not_requested"
|
||||
if instructions != "" {
|
||||
session.InstructionStatus = "unsupported"
|
||||
if instr, ok := broker.(chatInstructioner); ok {
|
||||
err := instr.SetInstruction(ctx, session.ID, "pipelines.behavior", instructions)
|
||||
switch {
|
||||
case err == nil:
|
||||
session.InstructionStatus = "applied"
|
||||
case errors.Is(err, errChatInstructionsUnsupported):
|
||||
session.InstructionError = err.Error()
|
||||
default:
|
||||
session.InstructionStatus = "failed"
|
||||
session.InstructionError = err.Error()
|
||||
}
|
||||
}
|
||||
}
|
||||
response := protocol.Message{Type: protocol.ChatCreate, ID: request.ID, ChatSession: &session}
|
||||
// The same registry row is echoed on the list field so a client can splice it
|
||||
// into chat_sessions without a re-list. An ephemeral create has no listed row
|
||||
|
||||
Reference in New Issue
Block a user