Skip to content

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.

fix(assistant): let a turn keep the issue it linked from its @-mention (#1005)

Robert06228f0eeeac770e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27e29087..de2189a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@ Platform releases use `vX.Y.Z` tags and publish `ghcr.io/tencent/loopforge`. Loo
## Unreleased
+- 「创建并去对话澄清」 sends again. The first message of the new conversation @-mentions the requirement, and the turn links that issue to the conversation while starting; the start then compared the conversation it read before linking and refused its own link with 「关联需求已更新,请重新发送」 every time. The same happened to any later message that @-mentioned an issue in a conversation without a linked issue. A turn now accepts the issue it linked itself; a conversation rebound to another issue while the turn starts is still refused.
+
- A conversation's 子 Agent shows the model it ran on: its row in the artifacts list reads 「已完成 · 模型 …」, the header of an opened subagent names the model next to its status, and each dispatch in 会话过程 notes 「模型 · …」 under the task it was given. The model is the one the subagent reports running on: its first line in the CLI stream is saved as an `agentModel` activity event under the dispatch, so an alias such as `lite` shows the model it resolved to. Until it reports, and for replies saved before this change, the panel falls back to the model the Agent call named (the `model` argument), else the model of the reply that dispatched it, which the subagent inherits; a dispatch still running uses the model the running reply was sent with. Activity events of an Agent call carry the new `model` field only when the call named one.
- The built-in backend, frontend and defect-fix SOPs gain a 「发起 MR」 node between 人工验收 and 交付汇总 (#717). It commits the work branch, pushes it and opens an MR/PR against the run's target branch, then records the link, branches and commit SHA in `mr-body.md`. Its command gate checks every writable repository of the run: one with commits beyond the target branch fails while it has uncommitted changes, while its checkout is off the run's work branch, or until `git ls-remote origin` shows that work branch at HEAD. A repository the run left unchanged is skipped. A second gate of the new mode `mr` has the engine look the MR up on the host with the same lookup delivery tracking uses (GitHub and Gongfeng): every writable repository whose work branch on origin carries commits beyond the target branch needs an MR from that work branch into that target branch that carries the pushed tip: an open one whose head is the tip (or whose host reports no head), or a merged one whose head is the tip. An agent that reports pass without opening an MR, opens it against the wrong branch, or leaves only an earlier merged MR on a reused work branch does not reach 交付汇总. The lookup runs as the run: on GitHub with the Git token the run pushed with (its responsible user's), falling back to the Owner of the run's own project; on Gongfeng through the run project's MCP as the responsible user. A repository bound to several projects is no longer checked as whichever project bound it first, and a failed lookup names the identity it used. A host the platform cannot query (an SSH repository, a failed lookup) goes straight to a person. `mr` gates take no commands, and the role editor keeps them when a role is saved. The gates retry once with their feedback and then wait for a person, so a run no longer succeeds with every source change left in a workspace that is reclaimed right after success. Run-scoped commands now get `AGENTFLOW_WORK_BRANCHES` (one `dir<TAB>work branch<TAB>target branch` line per writable repository) and repository-scoped commands get `AGENTFLOW_WORK_BRANCH` and `AGENTFLOW_BASE_BRANCH`; the target branch is the one frozen into the run, including a requirement's release branch and a scheduled SOP's integration branch. 交付汇总 no longer pushes or opens a PR itself. Runs without a bound repository still deliver from the task workspace. New installs get the new templates from the seed. Existing installs keep their templates until an operator runs `migrations/033_generic_sop_mr_node.sql` by hand (see docs/deployment.md); it rewrites a template only while its node graph and 交付汇总 position are the shipped original and its 交付汇总 prompt only while unedited. SOPs already adopted into a project are copies and keep their old graph. The product SOP delivers documents only and is unchanged.
- A conversation reply that is still running keeps running through a slow heartbeat. A poll, the conversation list, a follow-up message or a steer used to record it as interrupted after 45 seconds without a stored heartbeat; the process then cancelled the CLI and the next message failed with 「工作区正在使用或保存,请稍后重试」 for up to 15 minutes. Reads of a turn this process executes no longer reap it, and an unchanged heartbeat on MySQL no longer counts as a lost turn. On MySQL a heartbeat's age is measured on the database clock that stamped it, so skew between an API host and MySQL neither reaps a live turn nor keeps a dead one; whether a lease holder stopped renewing is likewise judged from `run_workspace_checkpoints.lease_renewed_at`, stamped on the database clock, not from another replica's `lease_until`. When a turn whose process died is reaped, the workspace lease it recorded is released if nothing renewed it for 45 seconds, so the next message starts at once; a lease another turn took, one still renewed on another replica, and a background save are kept. `migrations/032_assistant_generation_workspace_lease.sql` adds the three columns by hand; startup AutoMigrate adds them too.
diff --git a/internal/httpapi/assistant.go b/internal/httpapi/assistant.go
index 7476ce10..7ac91305 100644
--- a/internal/httpapi/assistant.go
+++ b/internal/httpapi/assistant.go
@@ -65,6 +65,10 @@ type assistantRequest struct {
SpaceID string `json:"spaceId,omitempty"`
workspaceToken string
contextText string
+ // linkedIssueID is the issue this turn itself linked to the conversation
+ // while preparing its context (an @-mentioned issue), so starting the
+ // turn does not mistake that link for a concurrent rebinding.
+ linkedIssueID string
// roles are the project's roles plus shared roles mentioned in the
// conversation; each is written to the CLI home as a native subagent.
roles []roleSubagent
diff --git a/internal/httpapi/assistant_generation.go b/internal/httpapi/assistant_generation.go
index 03de8956..115b7371 100644
--- a/internal/httpapi/assistant_generation.go
+++ b/internal/httpapi/assistant_generation.go
@@ -152,7 +152,13 @@ func (h *assistantHandlers) startGeneration(c *gin.Context) {
}
}
g := domain.AssistantGeneration{StartedAt: time.Now().UTC(), ActorID: user.ID, ActorName: user.LoginName, ID: newAssistantSessionID(), SessionID: req.SessionID, UserID: ownerID, ProjectID: req.ProjectID, Status: "running", Events: []domain.AssistantGenerationEvent{}, MessageCount: len(req.Messages)}
- pending := assistantConversation{ExecutionTarget: req.ExecutionTarget, ID: req.SessionID, Shared: old.Shared, ProjectID: req.ProjectID, IssueID: old.IssueID, Model: req.Model, Effort: req.Effort, Executor: req.Executor, RunID: req.RunID, Messages: req.Messages, TitleEdited: old.TitleEdited, TitleGenerated: old.TitleGenerated}
+ // The issue this turn linked from its @-mention is the conversation's
+ // issue now; any other change since old was read is still refused.
+ issueID := old.IssueID
+ if issueID == "" && req.linkedIssueID != "" {
+ issueID = req.linkedIssueID
+ }
+ pending := assistantConversation{ExecutionTarget: req.ExecutionTarget, ID: req.SessionID, Shared: old.Shared, ProjectID: req.ProjectID, IssueID: issueID, Model: req.Model, Effort: req.Effort, Executor: req.Executor, RunID: req.RunID, Messages: req.Messages, TitleEdited: old.TitleEdited, TitleGenerated: old.TitleGenerated}
if old.TitleEdited || old.TitleGenerated {
pending.Title = old.Title
} else {
diff --git a/internal/httpapi/assistant_mention_issue_test.go b/internal/httpapi/assistant_mention_issue_test.go
new file mode 100644
index 00000000..5b51d6a3
--- /dev/null
+++ b/internal/httpapi/assistant_mention_issue_test.go
@@ -0,0 +1,83 @@
+package httpapi
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "testing"
+
+ "agentflow/internal/domain"
+)
+
+// "创建并去对话澄清" opens a new conversation whose first message @-mentions
+// the requirement. The browser saves the empty conversation first, so the
+// turn links the mentioned issue to it while starting; that link must not be
+// mistaken for a concurrent rebinding and reject the turn. The link does not
+// depend on how the requirement is delivered, so every SOP choice of the
+// new-requirement dialog is covered.
+func TestFirstTurnMentioningAnIssueLinksItAndStarts(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ issue domain.Issue
+ }{
+ {"bound SOP", domain.Issue{WorkflowID: "generic-backend-delivery"}},
+ {"SOP chosen later", domain.Issue{}},
+ {"no SOP", domain.Issue{SOPMode: domain.IssueSOPNone}},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ h, u := workbenchFixture(t)
+ h.generate = func(context.Context, string, domain.User) (string, error) {
+ return `{"message":"好的","drafts":[]}`, nil
+ }
+ issue := tc.issue
+ issue.ID, issue.ProjectID, issue.Title = "clarify-issue", "workbench", "test1"
+ if err := h.repo.PutIssue(issue); err != nil {
+ t.Fatal(err)
+ }
+ if err := h.repo.PutAssistantSession(u.ID, domain.AssistantSession{ID: "clarify-chat", ProjectID: "workbench"}); err != nil {
+ t.Fatal(err)
+ }
+ body, _ := json.Marshal(map[string]any{
+ "sessionId": "clarify-chat",
+ "projectId": "workbench",
+ "messages": []domain.AssistantMessage{{
+ Role: "user",
+ Content: "@test1 aaaa",
+ References: []domain.AssistantReference{{Type: "issue", ID: "clarify-issue", Name: "test1", ProjectID: "workbench"}},
+ }},
+ })
+ c, rec := workbenchContext(u, "POST", "/api/assistant/generations", bytes.NewBuffer(body))
+ h.startGeneration(c)
+ if rec.Code != 202 {
+ t.Fatalf("start: %d %s", rec.Code, rec.Body.String())
+ }
+ s := waitForCompletedGeneration(t, h, u.ID, "clarify-chat")
+ if s.IssueID != "clarify-issue" {
+ t.Fatalf("mentioned issue not linked: %q", s.IssueID)
+ }
+ })
+ }
+}
+
+// Rebinding the conversation to another issue while a turn starts is still
+// refused, so the turn never runs against a context it did not read.
+func TestTurnRefusesAConcurrentIssueRebinding(t *testing.T) {
+ h, u := workbenchFixture(t)
+ for _, id := range []string{"first-issue", "other-issue"} {
+ if err := h.repo.PutIssue(domain.Issue{ID: id, ProjectID: "workbench", Title: id}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := h.repo.PutAssistantSession(u.ID, domain.AssistantSession{ID: "rebind-chat", ProjectID: "workbench"}); err != nil {
+ t.Fatal(err)
+ }
+ stale, _ := h.repo.AssistantSession(u.ID, "rebind-chat")
+ if _, err := h.repo.SetAssistantSessionIssue(u.ID, "rebind-chat", "other-issue", stale.UpdatedAt); err != nil {
+ t.Fatal(err)
+ }
+ g := domain.AssistantGeneration{ID: "rebind-generation", SessionID: "rebind-chat", UserID: u.ID, ProjectID: "workbench", Status: "running"}
+ pending := domain.AssistantSession{ID: "rebind-chat", ProjectID: "workbench", IssueID: stale.IssueID, Messages: []domain.AssistantMessage{{Role: "user", Content: "hi"}}}
+ if err := h.repo.BeginAssistantGeneration(g, pending); err == nil {
+ t.Fatal("a turn started over a concurrent issue rebinding")
+ }
+}
diff --git a/internal/httpapi/assistant_workbench.go b/internal/httpapi/assistant_workbench.go
index bd967a31..424c4c1a 100644
--- a/internal/httpapi/assistant_workbench.go
+++ b/internal/httpapi/assistant_workbench.go
@@ -1365,5 +1365,6 @@ func (h *assistantHandlers) linkMentionedIssue(req *assistantRequest, user domai
if !linked {
return ""
}
+ req.linkedIssueID = issueID
return "需求 " + issueID + " 已设为本会话的关联主需求。"
}