Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8410 fix(qoder): run chat turns on Qoder Cloud Agents (#9726)
Shi Peipei77c17eb3610d
diff --git a/apps/docs/content/docs/daemon-runtimes.mdx b/apps/docs/content/docs/daemon-runtimes.mdxindex e5602b167d..3172e9463f 100644--- a/apps/docs/content/docs/daemon-runtimes.mdx+++ b/apps/docs/content/docs/daemon-runtimes.mdx@@ -294,7 +294,7 @@ On the Qoder Cloud Agents page, administrators can edit the connection and reposRuns beyond the concurrency limit wait in the queue. A follow-up on the same issue continues the agent's previous Qoder session when it is idle. An agent can set a default repository, used when the issue's project has none. The agent is asked to push a branch named after the issue identifier and to prefix the pull request title with it, so the pull request is linked to the issue.-This first version supports issue runs, progress reporting, cancellation, and recovery from a persisted run journal. Configure models, tools, and skills in Qoder. Interactive chat, local directories, attachments, and creating agents in Qoder Cloud Agents from Multica are not supported. The Runtimes page separates remote runtimes from connected computers.+This first version supports issue runs, chat, progress reporting, cancellation, and recovery from a persisted run journal. Configure models, tools, and skills in Qoder. Local directories, attachments, and creating agents in Qoder Cloud Agents from Multica are not supported. The Runtimes page separates remote runtimes from connected computers.For standalone bridge setup and operational limitations, see the [Qoder runtime README](https://github.com/multica-ai/multica/blob/main/server/cmd/qoder-runtime/README.md).diff --git a/apps/docs/content/docs/daemon-runtimes.zh.mdx b/apps/docs/content/docs/daemon-runtimes.zh.mdxindex 97faadb150..3e04ac6b18 100644--- a/apps/docs/content/docs/daemon-runtimes.zh.mdx+++ b/apps/docs/content/docs/daemon-runtimes.zh.mdx@@ -295,7 +295,7 @@ Qoder Cloud Agents 通过远端会话执行分配的任务。Multica 服务端超出并发上限的任务会排队等待。同一任务的后续运行会在上一会话空闲时继续使用该 Qoder 会话。智能体可以设置默认仓库,在任务所属项目未绑定仓库时使用。智能体会被要求以任务标识命名分支,并在 PR 标题前加上任务标识,以便 PR 自动关联到任务。-首版支持任务运行、进度同步、取消和基于持久化记录的恢复。模型、工具和 skill 在 Qoder 中配置;暂不支持交互聊天、本地目录、附件,也不支持从 Multica 创建远端 Qoder Cloud Agents 智能体。运行时页面分别展示远端运行时和电脑。+首版支持任务运行、聊天、进度同步、取消和基于持久化记录的恢复。模型、工具和 skill 在 Qoder 中配置;暂不支持本地目录、附件,也不支持从 Multica 创建远端 Qoder Cloud Agents 智能体。运行时页面分别展示远端运行时和电脑。独立桥接进程的配置与限制见 [Qoder runtime README](https://github.com/multica-ai/multica/blob/main/server/cmd/qoder-runtime/README.md)。diff --git a/packages/core/agents/draft.test.ts b/packages/core/agents/draft.test.tsindex 85d35d9cde..3ba99d01d8 100644--- a/packages/core/agents/draft.test.ts+++ b/packages/core/agents/draft.test.ts@@ -340,7 +340,7 @@ it("drops settings a Qoder runtime cannot run from a draft started elsewhere", (expect(request.model).toBeUndefined();expect(request.thinking_level).toBeUndefined();expect(request.service_tier).toBeUndefined();- expect(request).not.toHaveProperty("conversation_starters");+ expect(request.conversation_starters).toEqual([{ label: "Plan", prompt: "Plan it" }]);expect(request).not.toHaveProperty("custom_args");const local = buildCreateAgentRequest({ draft: current, runtimeId: "runtime-1", runtimeProvider: "codex" });diff --git a/packages/core/agents/draft.ts b/packages/core/agents/draft.tsindex dcf0118ae4..448dd5c877 100644--- a/packages/core/agents/draft.ts+++ b/packages/core/agents/draft.ts@@ -227,11 +227,10 @@ export function buildCreateAgentRequest(options: {const { runtimeId, runtimeProvider, template, duplicateSource } = options;const qoder = runtimeProvider === QODER_PROVIDER;// The Qoder bridge refuses skills and execution overrides, and the form- // hides them (plus conversation starters) once Qoder is chosen.+ // hides them once Qoder is chosen.const draft: AgentDraft = qoder? {...options.draft,- conversationStarters: [],model: "",thinkingLevel: "",serviceTier: "",diff --git a/packages/views/agents/components/agent-detail-inspector.starters.test.tsx b/packages/views/agents/components/agent-detail-inspector.starters.test.tsxindex 5151e3c3b5..a5c24bcf00 100644--- a/packages/views/agents/components/agent-detail-inspector.starters.test.tsx+++ b/packages/views/agents/components/agent-detail-inspector.starters.test.tsx@@ -100,13 +100,13 @@ describe("AgentDetailInspector conversation starters", () => {);});- it("offers neither starters nor a chat preview for a Qoder agent", () => {+ it("offers starters and a chat preview for a Qoder agent", () => {renderInspector({runtime: { id: "runtime-1", provider: "qoder_cloud" } as AgentRuntime,});- expect(screen.queryByText("Conversation starters")).toBeNull();- expect(screen.queryByText("New chat preview")).toBeNull();+ expect(screen.getByText("Conversation starters")).toBeInTheDocument();+ expect(screen.getByText("New chat preview")).toBeInTheDocument();});it("omits the editor on a backend that does not persist starters", () => {diff --git a/packages/views/agents/components/agent-detail-inspector.tsx b/packages/views/agents/components/agent-detail-inspector.tsxindex 7cbe061f8f..36a0f8e00d 100644--- a/packages/views/agents/components/agent-detail-inspector.tsx+++ b/packages/views/agents/components/agent-detail-inspector.tsx@@ -147,12 +147,12 @@ export function AgentDetailInspector({// A Qoder agent is bound to an agent in Qoder Cloud Agents, and the model lives there. Moving// between Qoder and any other runtime would need a different configuration// the server either rejects or the bridge refuses, so neither direction is- // offered here. It also never opens a chat, so nothing chat-facing applies.+ // offered here.const qoderRuntime = runtime?.provider === "qoder_cloud";const conversationStartersEnabled = useConfigStore((state) => state.agentConversationStartersSupported,);- const showStarters = conversationStartersEnabled && !qoderRuntime;+ const showStarters = conversationStartersEnabled;const startersComplete = starters.every((item) => item.label.trim() && item.prompt.trim(),);@@ -415,19 +415,17 @@ export function AgentDetailInspector({</SettingsSection></div>- {qoderRuntime ? null : (- <SettingsSection- title={t(($) => $.conversation_starters.preview_label)}- className="hidden @4xl:sticky @4xl:top-0 @4xl:block"- >- <NewChatPreview- name={name.trim() || agent.name}- description={description}- avatarUrl={agent.avatar_url ?? null}- starters={showStarters ? starters : []}- />- </SettingsSection>- )}+ <SettingsSection+ title={t(($) => $.conversation_starters.preview_label)}+ className="hidden @4xl:sticky @4xl:top-0 @4xl:block"+ >+ <NewChatPreview+ name={name.trim() || agent.name}+ description={description}+ avatarUrl={agent.avatar_url ?? null}+ starters={showStarters ? starters : []}+ />+ </SettingsSection></div></div>);diff --git a/packages/views/agents/create/agent-configuration-panel.tsx b/packages/views/agents/create/agent-configuration-panel.tsxindex e23be12d06..25bffd0616 100644--- a/packages/views/agents/create/agent-configuration-panel.tsx+++ b/packages/views/agents/create/agent-configuration-panel.tsx@@ -158,7 +158,7 @@ export function AgentConfigurationPanel({/></div></DraftFieldRow>- {conversationStartersSupported && !qoderRuntime ? (+ {conversationStartersSupported ? (<DraftFieldRowcompact={compact}align="start"diff --git a/server/cmd/qoder-runtime/README.md b/server/cmd/qoder-runtime/README.mdindex 0f36d08a1f..876cfc706f 100644--- a/server/cmd/qoder-runtime/README.md+++ b/server/cmd/qoder-runtime/README.md@@ -100,10 +100,11 @@ GitHub integration links the pull request back to the issue.connections, at most 10) execute at once per bridge; further tasks stayqueued in Multica. Deploy one instance per configuration with its dedicatedpersistent state volume; this is not an HA service.-- A follow-up run on the same issue continues the agent's previous Qoder session- when that session is idle, uses the same Qoder agent and environment, and no- other run is using it. Otherwise a fresh session starts with the current issue- and triggering/coalesced comment context. Do not send additional messages+- A follow-up run on the same issue, or the next turn in the same chat,+ continues the agent's previous Qoder session when that session is idle, uses+ the same Qoder agent and environment, and no other run is using it. Otherwise+ a fresh session starts with the current issue and triggering/coalesced comment+ context, or with the current chat message. Do not send additional messagesdirectly to a bridge-owned session while its run is active.- Progress uses cursor-paginated persisted events, polled every three seconds.Event IDs and opaque page cursors are tracked separately. A turn is successful@@ -136,9 +137,9 @@ GitHub integration links the pull request back to the issue.## Current boundaries-This is an issue-execution PoC. Chat, squad coordination, local directories,-attachments, arbitrary Git hosts, tag/commit checkout, full comment-history-hydration, interactive tool approval, custom client-side tools, terminal access,+This is a PoC for issue runs and chat turns. Squad coordination, local+directories, attachments (on issues and chat messages), arbitrary Git hosts,+tag/commit checkout, full comment-history hydration, interactive tool approval, custom client-side tools, terminal access,file transfer and billing/usage conversion are not implemented. Set up a QoderAgent that can execute autonomously with its configured tools. `requires_action`ends the Multica run as failed with the stop reason; approvals are not granted@@ -217,7 +218,7 @@ first. Stopping keeps Qoder Cloud Agents/repository credentials for a later Savestandalone bridge for the same connection alongside the managed service. Whenmigrating, stop the standalone bridge at idle before saving the managed config.-This does not add chat support, session continuation, or delivery validation:+This does not add delivery validation:The end of a turn in Qoder Cloud Agents remains execution completion, not proof that a PR was created.diff --git a/server/internal/qoderruntime/bridge_test.go b/server/internal/qoderruntime/bridge_test.goindex 0f6cb9ff12..c795a2f232 100644--- a/server/internal/qoderruntime/bridge_test.go+++ b/server/internal/qoderruntime/bridge_test.go@@ -235,6 +235,50 @@ func TestIssueRun(t *testing.T) {t.Fatal("credential persisted")}}+func TestChatRun(t *testing.T) {+ h := setup(t)+ ctx := context.Background()+ h.task.IssueID = ""+ h.task.ChatSessionID = "chat-1"+ h.task.ChatMessage = "Introduce yourself"+ if err := h.b.step(ctx); err != nil {+ t.Fatal(err)+ }+ if h.failure != nil || !strings.Contains(h.prompt, "Introduce yourself") || !strings.Contains(h.prompt, "Audience: direct room.") || strings.Contains(h.prompt, "pull request") {+ t.Fatalf("incorrect chat prompt: %s (failure %#v)", h.prompt, h.failure)+ }+ h.finish("end_turn")+ if err := h.b.step(ctx); err != nil {+ t.Fatal(err)+ }+ if h.complete["session_id"] != "sess_1" || !strings.Contains(fmt.Sprint(h.complete["output"]), "Tests passed") {+ t.Fatalf("result: %#v", h.complete)+ }+}+func TestChatAudience(t *testing.T) {+ for _, tc := range []struct{ channel, chatType, want string }{+ {"", "", "Audience: direct room."},+ {"slack", "p2p", "Audience: direct room."},+ {"slack", "group", "Audience: group room; not private"},+ {"feishu", "", "Audience: unknown."},+ } {+ if got := chatAudience(tc.channel, tc.chatType); !strings.Contains(got, tc.want) {+ t.Errorf("chatAudience(%q, %q) = %q, want %q", tc.channel, tc.chatType, got, tc.want)+ }+ }+}+func TestChatAttachmentsFailBeforeExecution(t *testing.T) {+ h := setup(t)+ h.task.IssueID = ""+ h.task.ChatSessionID = "chat-1"+ h.task.ChatMessageAttachments = []daemon.ChatAttachmentMeta{{ID: "att-1"}}+ if err := h.b.step(context.Background()); err != nil {+ t.Fatal(err)+ }+ if h.creates != 0 || !strings.Contains(fmt.Sprint(h.failure["error"]), "attachments") {+ t.Fatalf("chat attachment ignored: %#v", h.failure)+ }+}func TestAmbiguousSubmitReconcilesAfterRestart(t *testing.T) {h := setup(t)h.lostSend = truediff --git a/server/internal/qoderruntime/claim.go b/server/internal/qoderruntime/claim.goindex ec67c8ad9e..926a0a3082 100644--- a/server/internal/qoderruntime/claim.go+++ b/server/internal/qoderruntime/claim.go@@ -10,6 +10,10 @@ type claimedTask struct {WorkspaceID string `json:"workspace_id"`IssueID string `json:"issue_id"`ChatSessionID string `json:"chat_session_id,omitempty"`+ ChatMessage string `json:"chat_message,omitempty"`+ ChatAttachments []json.RawMessage `json:"chat_message_attachments,omitempty"`+ ChatChannelType string `json:"chat_channel_type,omitempty"`+ ChatType string `json:"chat_type,omitempty"`IsLeaderTask bool `json:"is_leader_task,omitempty"`AuthToken string `json:"auth_token,omitempty"`RemoteMCPConnections []json.RawMessage `json:"remote_mcp_connections,omitempty"`diff --git a/server/internal/qoderruntime/prompt.go b/server/internal/qoderruntime/prompt.goindex 95fb15e31c..a79e322f07 100644--- a/server/internal/qoderruntime/prompt.go+++ b/server/internal/qoderruntime/prompt.go@@ -15,8 +15,9 @@ func (b *Bridge) prepare(ctx context.Context, t *claimedTask) (*run, error) {if t.RuntimeID != b.state.RuntimeID || t.WorkspaceID != b.cfg.WorkspaceID {return nil, fmt.Errorf("claim identity does not match bridge")}- if t.IssueID == "" || t.ChatSessionID != "" || t.IsLeaderTask {- return nil, fmt.Errorf("Qoder bridge currently supports issue runs only")+ chat := t.ChatSessionID != ""+ if (t.IssueID != "") == chat || t.IsLeaderTask {+ return nil, fmt.Errorf("Qoder bridge currently supports issue and chat runs only")}if !strings.HasPrefix(t.AuthToken, "mat_") {return nil, fmt.Errorf("claim is missing a task-scoped credential")@@ -35,28 +36,20 @@ func (b *Bridge) prepare(ctx context.Context, t *claimedTask) (*run, error) {return nil, err}r.AgentID = binding.AgentID- taskAPI := *b.multica- taskAPI.token = t.AuthToken- var issue struct {- Title string `json:"title"`- Description string `json:"description"`- Attachments []json.RawMessage `json:"attachments"`- }- if err := taskAPI.call(ctx, http.MethodGet, "/api/issues/"+url.PathEscape(t.IssueID), nil, &issue); err != nil {- return nil, fmt.Errorf("read issue: %w", err)- }- if len(issue.Attachments) > 0 {- return nil, fmt.Errorf("issue attachments are not supported by the Qoder bridge")- }var p strings.Builder- p.WriteString("Complete the following Multica issue in your Qoder environment. Return a final summary including code changes, tests and branch/PR/MR links when available. This bridge does not expose a local Multica daemon.\n")- if t.PriorSessionID != "" {- r.PriorSessionID = t.PriorSessionID- p.WriteString("This is a follow-up on the same issue. If the earlier conversation is not in your context, rely on the issue and comments below.\n")- }- fmt.Fprintf(&p, "\nRun: %s\nIssue: %s\n\n%s\n\n%s\n", t.ID, t.IssueIdentifier, issue.Title, issue.Description)- if t.IssueIdentifier != "" {- fmt.Fprintf(&p, "\nWhen you change code, push a new branch named %s (never the default branch), open a pull request whose title starts with \"%s: \", and put the pull request link in your final summary. Multica links the pull request to this issue through that identifier.\n", BranchName(t.IssueIdentifier, issue.Title), t.IssueIdentifier)+ if chat {+ if len(t.ChatAttachments) > 0 {+ return nil, fmt.Errorf("chat attachments are not supported by the Qoder bridge")+ }+ p.WriteString("You are chatting with a user of a Multica workspace. Reply directly to their message; your final message is shown to them as your reply. This bridge does not expose a local Multica daemon.\n")+ p.WriteString(chatAudience(t.ChatChannelType, t.ChatType))+ if t.PriorSessionID != "" {+ r.PriorSessionID = t.PriorSessionID+ p.WriteString("This continues an earlier conversation. If it is not in your context, answer from the message below.\n")+ }+ fmt.Fprintf(&p, "\nRun: %s\n\nUser message:\n%s\n", t.ID, t.ChatMessage)+ } else if err := b.issuePrompt(ctx, t, r, &p); err != nil {+ return nil, err}if t.Agent != nil {fmt.Fprintf(&p, "\nAgent instructions:\n%s\n", t.Agent.Instructions)@@ -114,6 +107,46 @@ func (b *Bridge) prepare(ctx context.Context, t *claimedTask) (*run, error) {return r, nil}+// chatAudience mirrors the local daemon's chat audience line: a group reply is+// not private to its sender, and an IM chat of unknown type never defaults to+// private. Kept local so the bridge stays independent of the daemon packages.+func chatAudience(channelType, chatType string) string {+ switch {+ case chatType == "group":+ return "Audience: group room; not private; unseen members may read replies.\n"+ case chatType == "p2p" || channelType == "":+ return "Audience: direct room.\n"+ default:+ return "Audience: unknown.\n"+ }+}++func (b *Bridge) issuePrompt(ctx context.Context, t *claimedTask, r *run, p *strings.Builder) error {+ taskAPI := *b.multica+ taskAPI.token = t.AuthToken+ var issue struct {+ Title string `json:"title"`+ Description string `json:"description"`+ Attachments []json.RawMessage `json:"attachments"`+ }+ if err := taskAPI.call(ctx, http.MethodGet, "/api/issues/"+url.PathEscape(t.IssueID), nil, &issue); err != nil {+ return fmt.Errorf("read issue: %w", err)+ }+ if len(issue.Attachments) > 0 {+ return fmt.Errorf("issue attachments are not supported by the Qoder bridge")+ }+ p.WriteString("Complete the following Multica issue in your Qoder environment. Return a final summary including code changes, tests and branch/PR/MR links when available. This bridge does not expose a local Multica daemon.\n")+ if t.PriorSessionID != "" {+ r.PriorSessionID = t.PriorSessionID+ p.WriteString("This is a follow-up on the same issue. If the earlier conversation is not in your context, rely on the issue and comments below.\n")+ }+ fmt.Fprintf(p, "\nRun: %s\nIssue: %s\n\n%s\n\n%s\n", t.ID, t.IssueIdentifier, issue.Title, issue.Description)+ if t.IssueIdentifier != "" {+ fmt.Fprintf(p, "\nWhen you change code, push a new branch named %s (never the default branch), open a pull request whose title starts with \"%s: \", and put the pull request link in your final summary. Multica links the pull request to this issue through that identifier.\n", BranchName(t.IssueIdentifier, issue.Title), t.IssueIdentifier)+ }+ return nil+}+// Repository is a GitHub repository and optional branch mounted into a session.type Repository struct {URL string `json:"url"`diff --git a/server/internal/qoderruntime/state.go b/server/internal/qoderruntime/state.goindex fc4cfb64cc..198f9c49f0 100644--- a/server/internal/qoderruntime/state.go+++ b/server/internal/qoderruntime/state.go@@ -21,7 +21,8 @@ type journal struct {Run *run `json:"run,omitempty"`}type run struct {- // PriorSessionID is the session of this agent's previous run on the issue.+ // PriorSessionID is the session of this agent's previous run on the same+ // issue or chat.// An idle prior session is continued instead of creating a new one.PriorSessionID string `json:"prior_session_id,omitempty"`Continued bool `json:"continued,omitempty"`