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.

feat(chatbot): show the model a subagent reports running on

testerc11f6b49c3d6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e690806..27e29087 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@ Platform releases use `vX.Y.Z` tags and publish `ghcr.io/tencent/loopforge`. Loo
## Unreleased
-- 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 Agent call named for the subagent (the `model` argument, for example `lite` or a model ID), 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; replies saved before this change show the model of their reply.
+- 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/chatbot/src/activity.js b/chatbot/src/activity.js
index c107e082..76f7769e 100644
--- a/chatbot/src/activity.js
+++ b/chatbot/src/activity.js
@@ -17,6 +17,12 @@ export function mergeActivity(previous = [], events = []) {
host = { id: event.parent, kind: "tool", tool: "Agent", detail: "", text: "", startedAt: at };
steps.push(host);
}
+ // The model the subagent reports it runs on, whatever the dispatch
+ // asked for (an alias such as "lite", or nothing).
+ if (event.kind === "agentModel") {
+ if (event.model) host.ranModel = event.model;
+ continue;
+ }
const child = { ...event, parent: undefined };
if (child.kind === "agentText") child.kind = "text";
host.children = mergeActivity(host.children || [], [{ data: child, sequence }]);
@@ -278,10 +284,12 @@ export const resumeMissed = (step) =>
// collectSubagents lists every subagent of a conversation, newest last. A
// dispatch that resumed an earlier agent joins it, so one entry holds every
// task that agent was given.
-// A subagent runs on the model its dispatch named, else on the model of the
-// reply that dispatched it; a live dispatch has no saved reply yet and uses
-// liveModel, the model the running reply was sent with. agent.model is the
-// latest dispatch's, agent.models[step.id] each dispatch's.
+// A subagent shows the model it reported running on (step.ranModel). Before
+// it reports, and for replies saved before that was recorded, it falls back
+// to the model its dispatch named, else the model of the reply that
+// dispatched it; a live dispatch has no saved reply yet and uses liveModel,
+// the model the running reply was sent with. agent.model is the latest
+// dispatch's, agent.models[step.id] each dispatch's.
export function collectSubagents(messages = [], liveSteps = [], liveModel = "") {
const agents = [];
// messageIndex is the saved reply that holds the dispatch; a live one has
@@ -296,7 +304,7 @@ export function collectSubagents(messages = [], liveSteps = [], liveModel = "")
if (step.agentId) agent.agentId = step.agentId;
agent.role = step.role || agent.role;
agent.subagent = step.subagent || agent.subagent;
- const model = String(step.model || replyModel || "").trim();
+ const model = String(step.ranModel || step.model || replyModel || "").trim();
if (model) agent.models[step.id] = model;
agent.model = model || agent.model;
agent.dispatches.push(step);
diff --git a/chatbot/tests/subagents.test.jsx b/chatbot/tests/subagents.test.jsx
index 823e8392..839c3b99 100644
--- a/chatbot/tests/subagents.test.jsx
+++ b/chatbot/tests/subagents.test.jsx
@@ -105,6 +105,31 @@ describe("dispatched subagents", () => {
]);
});
+ test("a subagent shows the model it reported running on", () => {
+ const dispatch = (id, extra = {}) => ({ kind: "tool", id, tool: "Agent", detail: id, subagent: "Explore", ...extra, at });
+ const ran = (parent, model) => ({ kind: "agentModel", parent, model, at });
+ const steps = mergeActivity([], events(dispatch("c1", { model: "lite" }), ran("c1", "hy4flash"), { kind: "text", parent: "c1", text: "done", at }));
+ // The report stays out of the subagent's own steps.
+ expect(steps[0].ranModel).toBe("hy4flash");
+ expect(steps[0].children.map((child) => child.kind)).toEqual(["text"]);
+ const agents = collectSubagents(
+ [
+ {
+ role: "assistant",
+ model: "deepseek-v4.1-flash",
+ activity: [dispatch("c1", { model: "lite" }), ran("c1", "hy4flash"), { kind: "toolDone", id: "c1", agentId: "agent-aaa", at }],
+ },
+ ],
+ // A live subagent that reported before its dispatch event arrived.
+ mergeActivity([], events(ran("c2", "deepseek-v4.1-flash-ioa"), dispatch("c2"))),
+ "glm-5.3-flash-ioa",
+ );
+ expect(agents.map((agent) => [agent.key, agent.model])).toEqual([
+ ["agent-aaa", "hy4flash"],
+ ["c2", "deepseek-v4.1-flash-ioa"],
+ ]);
+ });
+
test("the 子 Agent card and its session show the model it ran on", async () => {
const messages = [
{ role: "user", content: "补单测" },
diff --git a/internal/domain/assistant.go b/internal/domain/assistant.go
index 49638af6..8ab9cdf4 100644
--- a/internal/domain/assistant.go
+++ b/internal/domain/assistant.go
@@ -35,9 +35,10 @@ type AssistantActivityEvent struct {
Subagent string `json:"subagent,omitempty"`
Role string `json:"role,omitempty"`
AgentID string `json:"agentId,omitempty"`
- // Model is the model an Agent dispatch asked its subagent to run on. It
- // is empty when the subagent inherits the model of the reply that
- // dispatched it.
+ // Model is the model an Agent dispatch asked its subagent to run on
+ // (empty when it inherits the reply's model). An "agentModel" event,
+ // whose Parent is the dispatch, carries the model the subagent reported
+ // it actually ran on, which also resolves aliases such as "lite".
Model string `json:"model,omitempty"`
// Input is the task an Agent dispatch hands the subagent and Output the
// report it returns; the side panel shows them like an SOP node session.
diff --git a/internal/httpapi/assistant_activity.go b/internal/httpapi/assistant_activity.go
index cc7660a3..dddeb4f9 100644
--- a/internal/httpapi/assistant_activity.go
+++ b/internal/httpapi/assistant_activity.go
@@ -29,7 +29,7 @@ func (l *assistantActivityLog) add(event assistantStreamEvent) {
defer l.mu.Unlock()
l.appendTextLocked(event)
return
- case "thinkingStart", "thinking", "tool", "toolDone", "status", "agentText":
+ case "thinkingStart", "thinking", "tool", "toolDone", "status", "agentText", "agentModel":
default:
return
}
diff --git a/internal/httpapi/assistant_resume_recovery.go b/internal/httpapi/assistant_resume_recovery.go
index ef3cc7a8..50f9f14b 100644
--- a/internal/httpapi/assistant_resume_recovery.go
+++ b/internal/httpapi/assistant_resume_recovery.go
@@ -35,7 +35,7 @@ var assistantResumeRejectedRe = regexp.MustCompile(`(?i)(must end with a user me
// with none of these executed nothing and can safely start over.
func assistantPhaseProgress(ev assistantStreamEvent) bool {
switch ev.Kind {
- case "tool", "toolDone", "toolEnd", "text", "answer", "agentText", "draftStart", "draftDelta", "thinking", "thinkingStart":
+ case "tool", "toolDone", "toolEnd", "text", "answer", "agentText", "agentModel", "draftStart", "draftDelta", "thinking", "thinkingStart":
return true
}
return false
diff --git a/internal/httpapi/assistant_stream.go b/internal/httpapi/assistant_stream.go
index ad30600e..b5c1a887 100644
--- a/internal/httpapi/assistant_stream.go
+++ b/internal/httpapi/assistant_stream.go
@@ -17,8 +17,10 @@ type assistantStreamFilter struct {
lastTool string
lastDetail string
seenTools map[string]string
- answer string
- thinking string
+ // agentModels is the model each dispatch's subagent last reported.
+ agentModels map[string]string
+ answer string
+ thinking string
}
func (f *assistantStreamFilter) accept(ev assistantStreamEvent) bool {
@@ -46,6 +48,16 @@ func (f *assistantStreamFilter) accept(ev assistantStreamEvent) bool {
return ev.ID != ""
case "thinking":
return appendStreamText(&f.thinking, ev)
+ case "agentModel":
+ // Every line of a subagent names its model; forward a change only.
+ if ev.Parent == "" || ev.Model == "" || f.agentModels[ev.Parent] == ev.Model {
+ return false
+ }
+ if f.agentModels == nil {
+ f.agentModels = map[string]string{}
+ }
+ f.agentModels[ev.Parent] = ev.Model
+ return true
default:
return ev.Text != "" || ev.Tool != ""
}
@@ -146,6 +158,9 @@ func assistantLineEvents(line string) []assistantStreamEvent {
// Set on lines a sub-agent (Agent/Task tool) produced.
ParentToolUseID string `json:"parent_tool_use_id"`
Message struct {
+ // Model is the model that produced this message. On a subagent's
+ // line it is the model the subagent actually runs on.
+ Model string `json:"model"`
Content []struct {
Type string `json:"type"`
ID string `json:"id"`
@@ -183,6 +198,10 @@ func assistantLineEvents(line string) []assistantStreamEvent {
switch evt.Type {
case "assistant":
var out []assistantStreamEvent
+ if model := strings.TrimSpace(evt.Message.Model); subAgent && model != "" {
+ // assistantStreamEvents puts it under the dispatch (Parent).
+ out = append(out, assistantStreamEvent{Kind: "agentModel", Model: truncateRunes(model, 128)})
+ }
for _, block := range evt.Message.Content {
switch block.Type {
case "thinking":
diff --git a/internal/httpapi/assistant_stream_filter_test.go b/internal/httpapi/assistant_stream_filter_test.go
index 139c83a1..6928e8e9 100644
--- a/internal/httpapi/assistant_stream_filter_test.go
+++ b/internal/httpapi/assistant_stream_filter_test.go
@@ -87,3 +87,24 @@ func TestAssistantStreamFilterToolEndsReplyDraft(t *testing.T) {
t.Fatal("draft delta kept after a tool event")
}
}
+
+// Each subagent line names its model; only the first and a change pass, per
+// dispatch.
+func TestAssistantStreamFilterForwardsEachSubagentModelOnce(t *testing.T) {
+ var f assistantStreamFilter
+ for _, step := range []struct {
+ ev assistantStreamEvent
+ want bool
+ }{
+ {assistantStreamEvent{Kind: "agentModel", Parent: "c1", Model: "deepseek-v4.1-flash-ioa"}, true},
+ {assistantStreamEvent{Kind: "agentModel", Parent: "c1", Model: "deepseek-v4.1-flash-ioa"}, false},
+ {assistantStreamEvent{Kind: "agentModel", Parent: "c2", Model: "deepseek-v4.1-flash-ioa"}, true},
+ {assistantStreamEvent{Kind: "agentModel", Parent: "c1", Model: "glm-5.3-flash-ioa"}, true},
+ {assistantStreamEvent{Kind: "agentModel", Parent: "", Model: "glm-5.3-flash-ioa"}, false},
+ {assistantStreamEvent{Kind: "agentModel", Parent: "c3"}, false},
+ } {
+ if got := f.accept(step.ev); got != step.want {
+ t.Fatalf("accept(%+v) = %v, want %v", step.ev, got, step.want)
+ }
+ }
+}
diff --git a/internal/httpapi/assistant_subagents_test.go b/internal/httpapi/assistant_subagents_test.go
index 9c97acae..68c3901c 100644
--- a/internal/httpapi/assistant_subagents_test.go
+++ b/internal/httpapi/assistant_subagents_test.go
@@ -362,6 +362,15 @@ func TestSubagentStreamEventsCarryTheirDispatch(t *testing.T) {
t.Fatalf("%s: dispatch=%+v, want model %q", input, got, want)
}
}
+ // A subagent's line reports the model it actually runs on, under its
+ // dispatch; Main Bot's own lines do not.
+ ran := assistantStreamEvents(`{"type":"assistant","parent_tool_use_id":"call-1","message":{"model":"deepseek-v4.1-flash-ioa","content":[{"type":"text","text":"ok"}]}}`)
+ if len(ran) != 2 || ran[0].Kind != "agentModel" || ran[0].Model != "deepseek-v4.1-flash-ioa" || ran[0].Parent != "call-1" {
+ t.Fatalf("subagent line=%+v", ran)
+ }
+ if main := assistantStreamEvents(`{"type":"assistant","message":{"model":"deepseek-v4.1-flash-ioa","content":[{"type":"text","text":"ok"}]}}`); len(main) != 1 || main[0].Kind != "answer" {
+ t.Fatalf("main line=%+v", main)
+ }
if got := labelRoleSubagent(dispatch[0], []roleSubagent{{Role: domain.AgentDefinition{ID: "qa", Name: "测试工程师"}}}); got.Role != "测试工程师" {
t.Fatalf("role label=%q", got.Role)
}