Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
fix(chat): replay the current mode's context when a resume falls back (#558)
crispinhu271b6084743fa9
diff --git a/internal/httpapi/assistant.go b/internal/httpapi/assistant.goindex eb4c0692..a406a575 100644--- a/internal/httpapi/assistant.go+++ b/internal/httpapi/assistant.go@@ -552,10 +552,7 @@ func (h *assistantHandlers) chat(c *gin.Context) {cliSessionID = newAssistantSessionID()}resume = false- prompt = fullPrompt- if switches > 0 {- prompt += "\n本轮之前的阶段已执行过操作。先核对工作区实际文件与状态,避免重复执行。"- }+ prompt = h.freshPhasePrompt(req, sourceRoot, switches)continue}if err != nil {diff --git a/internal/httpapi/assistant_resume_recovery.go b/internal/httpapi/assistant_resume_recovery.goindex d1a24b68..c9b9f51e 100644--- a/internal/httpapi/assistant_resume_recovery.go+++ b/internal/httpapi/assistant_resume_recovery.go@@ -8,6 +8,17 @@ import ("agentflow/internal/runtime")+// freshPhasePrompt rebuilds the full transcript for a fresh native session.+// req.workspaceMode follows the current phase, so a fallback after a handoff+// describes the new mode rather than the one the turn started in.+func (h *assistantHandlers) freshPhasePrompt(req assistantRequest, sourceRoot string, switches int) string {+ prompt := h.turnPrompt(req, sourceRoot, false)+ if switches > 0 {+ prompt += "\n本轮之前的阶段已执行过操作。先核对工作区实际文件与状态,避免重复执行。"+ }+ return prompt+}+// assistantResumeRejectedRe matches providers refusing a replayed native// journal: a 400/422, or the wording CodeBuddy and OpenAI-compatible// gateways use for a transcript whose structure they reject.diff --git a/internal/httpapi/assistant_resume_recovery_test.go b/internal/httpapi/assistant_resume_recovery_test.goindex b41cbe64..2b39e69c 100644--- a/internal/httpapi/assistant_resume_recovery_test.go+++ b/internal/httpapi/assistant_resume_recovery_test.go@@ -25,6 +25,30 @@ func TestHandoffPromptsAskForAShortAckInsteadOfSilence(t *testing.T) {}}+// A fallback after a handoff runs in the new mode's tool set, so the replayed+// context must describe that mode, not the one the turn started in.+func TestFreshPhasePromptFollowsCurrentMode(t *testing.T) {+ h := &assistantHandlers{}+ req := assistantRequest{Messages: []assistantMessage{{Role: "user", Content: "改一下文案"}}}+ platform := h.freshPhasePrompt(req, t.TempDir(), 0)+ req.workspaceMode = true+ workspace := h.freshPhasePrompt(req, t.TempDir(), 1)+ if !strings.Contains(platform, assistantPlatformExecutionReminder) || strings.Contains(platform, "工作区原生文件、补丁和命令直接执行") {+ t.Fatal("platform phase prompt does not describe platform mode")+ }+ if strings.Contains(workspace, assistantPlatformExecutionReminder) || !strings.Contains(workspace, "工作区原生文件、补丁和命令直接执行") {+ t.Fatal("workspace phase prompt still describes platform mode")+ }+ for _, prompt := range []string{platform, workspace} {+ if !strings.Contains(prompt, "改一下文案") {+ t.Fatal("fresh phase prompt lost the transcript")+ }+ }+ if strings.Contains(platform, "本轮之前的阶段已执行过操作") || !strings.Contains(workspace, "本轮之前的阶段已执行过操作") {+ t.Fatal("prior-phase note does not follow the handoff count")+ }+}+func TestHandoffOutlivesOldPhaseError(t *testing.T) {s := &AgentToolSession{}ctx := context.Background()