[feat] assistant: accept a follow-up message while a turn is still running / 运行中插入补充消息

Đang mở
#379 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, typescript
Lĩnh vực
api, backend, devtools, frontend

Hướng nghiên cứu

Start with the submit guard and conversation state in apps/api/src/opendirector_api/agent.py, then trace RunEvents and the stop path. Read src/backend/chat.ts and src/canvas/useAssistantChat.ts for the client stream and composer flow, plus packages/core/src/opendirector/agent/runtime.py for runtime capabilities. The acceptance criteria define done: queued messages persist, run once in order after the current turn, and remain recoverable across stop, failure, reload, and restart.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area:agent

Parent roadmap: #261. Related work: edit and resend after stopping #375, conversation management #247, turn/tool/job/receipt correlation #372.

Summary / 摘要

While a reply is streaming, the assistant cannot accept a supplementary instruction. The composer replaces Send with Stop, Enter is silently dropped, and the API answers any second submission for the same project with 409 当前工程已有回复正在执行。. The draft survives, but it cannot be delivered until the turn ends. A user who remembers a missing constraint while the Agent is working must either interrupt the turn (discarding work) or wait and hope the result is not already wrong.

本 issue 描述一个已复现的能力缺口,并提出分层方案:运行中提交的补充消息进入投递队列,当前轮结束后在同一对话里自动续跑(P0,对所有 runtime 生效);在此基础上,对具备原生输入通道的 harness 提供同轮插入(P1,逐个 runtime 实测后再开放)。

Current behavior (verified)

Reproduction: pytest + TestClient, one turn held open through the existing disconnect_turn helper (the run keeps going after the SSE connection closes), then a second submission while active[project_id] is populated. Observed on 9d08bf5a:

PROBE second turn -> 409 {'detail': '当前工程已有回复正在执行。', 'code': 'operation_rejected'}
PROBE draft save -> 200
PROBE messages before/after -> 2 2
PROBE queued markers -> ['complete', 'streaming']
PROBE follow-up routes -> []
Layer Location Behavior
Submit guard apps/api/src/opendirector_api/agent.py:291-297 POST /turns takes a per-project admission lock, sees project_id in active, raises ProjectError('当前工程已有回复正在执行。', 409)
Composer src/canvas/AssistantPanel.tsx:729-746 chat.sending replaces the submit button with the stop button; there is no queued/insert affordance
Keyboard src/canvas/useAssistantChat.ts:436 send() returns early while submitting.current is set, so Enter during a turn is a silent no-op
Picker state src/canvas/AssistantPanel.tsx:703,712,719 agent, skill and model pickers are disabled while chat.sending
Stream shape src/backend/chat.ts:72-79 ChatEvent ends at end; status has complete/streaming/stopped/interrupted, no queued
Route surface apps/api/src/opendirector_api/agent.py no queue, retract or follow-up endpoint exists; conversation switching is also refused while running
Design statement docs/architecture/agent-runtime.md "同一工程同时只接受一个回复运行" — the single-run guarantee is intentional, not a bug

The single-run guarantee is worth keeping: it is what keeps runtime sessions, active, the conversation file and the tool ledger consistent. What is missing is a place for input that arrives during a run.

Goal and scope

Let a user submit a supplementary message at any time, and deliver it without losing it, without breaking the single-run guarantee, and with an explicit, inspectable result.

  • P0 — queued follow-up, universal. A submission during a run is persisted immediately as a user message in queued state, shown in the conversation, and dispatched as the next turn in the same conversation once the current turn reaches a terminal state. Works for every runtime, including those whose process takes exactly one prompt.
  • P1 — same-turn steering, per runtime. Where the harness exposes an input channel while it runs (streaming stdin, session server, ACP extension), deliver the text into the running turn and mark it as applied to that turn. Gated on measured capability, not on documentation.
  • Out of scope: multi-project parallelism, multi-Agent, reordering or editing the running prompt, and rewriting the runtimes into a duplex protocol.

User flow and rules

  • While a turn runs, the composer stays writable and Enter submits. The send action becomes "queue for the next turn" (P0) or offers "insert into this turn" when the runtime declares steering support (P1).
  • A queued message appears immediately in the transcript, above the streaming reply's continuation, with a queued marker, its position, and a retract action. Queueing is a commit: the text leaves the draft, and the draft content is preserved in the message.
  • The running turn keeps its original prompt. A queued message is context for the next turn only, and the next turn sees the finished reply of the previous one. The UI states this, so a user does not believe the current answer already reflects the addition.
  • When a turn ends and the queue is non-empty, the next turn starts automatically on the same stream, so the transcript never shows a stopped chain between two turns.
  • Multiple queued messages are delivered in submission order, one turn each, unless the user merges them explicitly.
  • Stop acts on a chain, not a single turn: stopping cancels the running turn and leaves queued messages in cancelled state with a Resend action. Interrupting must never silently consume a supplement. A per-turn continue action is offered separately.
  • A failed turn stops the chain and keeps the queue intact for an explicit retry. Automatic continuation after an error is not allowed.
  • After a process restart, queued messages survive and are offered for continuation instead of being replayed automatically.
  • Idempotency: resubmitting the same message id while queued returns the existing queue entry rather than a duplicate or a conflict; the conflict response remains for a message id that is already part of a turn.
  • Every state (queued, dispatched, applied to a running turn, cancelled, failed) is visible in the conversation after a reload and through the Agent/CLI entry points.

Implementation impact

Reuse conversation persistence, turn submission, RunEvents replay and the stop path; add the minimum queue record and stream continuation.

  • Backend: extend Conversations (apps/api/src/opendirector_api/agent.py:61) with a per-conversation queue and the queued/cancelled message states; replace the single-turn active entry with a chain entry that owns RunEvents; add POST /assistant/messages (submit-or-queue), DELETE for a queued message, a chain-scoped event stream with a replay cursor, and explicit stop scope.
  • Events: add seq per chain, message events for queue changes, and nextTurnId on end so a client knows the stream continues instead of treating end as final. Keep the existing end shape valid for clients that ignore the new fields.
  • Frontend: src/canvas/useAssistantChat.ts (submit while running, continue the follower across turns, queue state and retract), src/canvas/AssistantPanel.tsx (composer stays enabled, queued marker and retract, stop semantics), src/backend/chat.ts (event and status types), src/i18n/messages/zh-CN/assistant.ts and src/i18n/messages/en-US/assistant.ts (bilingual, delivered together).
  • Runtime layer: add a declared capability to RuntimeSpec in packages/core/src/opendirector/agent/runtime.py (e.g. supportsSteering: bool = False) and surface it through runtime_catalog() / GET /assistant/runtimes, so the UI never offers an insert the harness cannot honor. No runtime switches to steering without a measured probe.

Acceptance criteria

  • Submit during a streaming turn; the text is persisted immediately, visible as queued, and executed as the next turn after the current one ends, without a second client action.
  • The running turn receives exactly its original prompt; the next turn receives the queue in order with the previous reply in context.
  • Queue two or three messages during one turn; all are delivered exactly once, in order, with no duplicate turn and no lost message.
  • Retract a queued message before dispatch; it never reaches a runtime and the transcript shows it as withdrawn.
  • Stop during a turn with a queued message; the turn stops, the queued message becomes cancelled, is not auto-run, and can be resent.
  • A turn that fails leaves the queue intact for an explicit retry; no automatic continuation.
  • Reload, disconnect and process restart preserve queue state and never replay a delivered message.
  • Duplicate submission of the same message id produces one queue entry and one turn.
  • Steering, where enabled for a runtime, delivers the supplement into the running turn and the reply reflects it; when it is not supported the UI offers queueing instead of failing late.
  • Both locales cover every new string, and the UI states whether the supplement applies to this turn or the next.

Decisions to confirm

  1. Default queue semantics when a turn ends: auto-continue (proposed) versus a visible "continue" prompt.
  2. Multiple queued messages: one turn per message (proposed) versus coalescing consecutive submissions into the next turn.
  3. Stop scope: chain-wide with cancelled queue entries (proposed) versus turn-only where the queue continues.
  4. Whether a queued message should also be included in a P1 steering-capable turn automatically, or only when the user picks "insert into this turn".
Ngôn ngữ chính
TypeScript
Star
119
Fork
16
Merge trung bình
16 giờ 13 phút
Pull request đã merge (30 ngày)
195

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ThinkFlowLab/OpenDirector

Tất cả issue của ThinkFlowLab/OpenDirector

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.