Repository navigation
feat(assistant): edit and resend the last stopped message - #424
Zhangbo-cn wants to merge 2 commits into
Conversation
…ab#375) A stopped turn can be revised in place: the new attempt records the turn it replaces, so the active path follows that chain instead of slicing messages positionally. Project changes and accepted jobs are preserved, and a snapshot of the replaced attempt's tool records rides on the new turn. Server: - Turn gains revisionOf and expectedRevision; conversation.json keeps an incrementing revision so a stale view cannot overwrite a newer one. - active_messages() replaces the positional slicing that fed the runtime context; the superseded request and its partial reply leave the active path but stay in history. - Validation inside the begin transaction: expected revision, then the target turn, then its terminal status, then the duplicate id. - inherited_jobs() keeps the idempotency key for every replaced call and resolves the job record when one was accepted. Client: - Editing a stopped message fills the composer with its text, references and skills, and leaves the conversation untouched until the server accepts. - pendingTurnId in sessionStorage keeps one operation identity across retries of an uncertain edit. - Inherited jobs render in a collapsed section. Also tolerate plain-text stdout from a harness: Claude Code prints an unrecognized-model warning between JSON events, which failed the whole turn on a parse error.
|
Two checks failed; neither comes from this change.
That test drives I read this as a timing flake on a 20 s wait after video rendering. I cannot rerun the job myself (no admin rights), so if a maintainer can rerun
Everything else is green: |
|
On the new CodeQL alert: I cannot see the alert details — To narrow it down, here is what the diff can and cannot contain. The TypeScript changes are type declarations plus React render code, all escaped by React; there is no store.setItem(`opendirector.chat.revision.${conversationId}`, id)That is an operation identity, not a credential, and it lives in The Python changes read So I would expect the alert to be a false positive or to sit in code I did not touch, but I am guessing without the rule id. Happy to fix it once I know what it points at. |
|
@yefuyou — your boundary matches what I built, and #374 is already on What matches. The original user message id stays the turn id, and the new attempt gets its own id, so the two never mix. Refresh links are a separate field ( job.agentRunId == revision_of # same filter as turn_jobs()
agent_command_id(turn, call_id) # same derivationWhere I diverged. Rather than let the new attempt query "inheritedJobs": [{"commandId": "...", "callId": "...", "name": "...",
"jobId": "..."|null, "status": "...", "asset": {...}|null}]
My reason was that the composer needs to show what the previous attempt already submitted before resending, and a snapshot makes that a single read with the message. The cost is duplication: if a Job's status changes after the snapshot, the snapshot is stale and only the endpoint is authoritative. The question. Do you want the snapshot kept, or removed in favour of the client calling Your point that the endpoint does not decide reuse-or-resubmit also matches: nothing in my change auto-reuses. The snapshot is informational; the decision stays with the attempt. |
1 similar comment
|
@yefuyou — your boundary matches what I built, and #374 is already on What matches. The original user message id stays the turn id, and the new attempt gets its own id, so the two never mix. Refresh links are a separate field ( job.agentRunId == revision_of # same filter as turn_jobs()
agent_command_id(turn, call_id) # same derivationWhere I diverged. Rather than let the new attempt query "inheritedJobs": [{"commandId": "...", "callId": "...", "name": "...",
"jobId": "..."|null, "status": "...", "asset": {...}|null}]
My reason was that the composer needs to show what the previous attempt already submitted before resending, and a snapshot makes that a single read with the message. The cost is duplication: if a Job's status changes after the snapshot, the snapshot is stale and only the endpoint is authoritative. The question. Do you want the snapshot kept, or removed in favour of the client calling Your point that the endpoint does not decide reuse-or-resubmit also matches: nothing in my change auto-reuses. The snapshot is informational; the decision stays with the attempt. |
|
Thanks for checking this with me. From the #374 Turn → Job lineage side, my recommendation is option B: keep the existing That keeps message revisions ( For how the inherited Job information should appear in the composer, I'd defer to the product/UX direction for #375. This is my architectural preference rather than a decision on the final UI. |
|
Request: review on the current base, not a retry of the 2026-11-21 attempt — @FayeSpica, would you take this one? Background, since the red CI was not caused here:
I have merged Two reasons not to retry the old attempt instead:
The isolated suite is also intermittent on this runner: main's own Release checks passed at 2026-11-22T16:06Z before #441, and two other branches in the same window failed different isolated cases with bare timeouts ( Local checks after the merge: What I am asking for:
|
Draft: server and UI slice for #375, with the runtime verification results recorded below.
What this does
A stopped turn can be edited and resent in place. The new attempt records the turn it replaces, and the active conversation path is derived by following that chain rather than by slicing
messagespositionally.Design decisions
revisionOfis the only new relationship field. The new user message carries it alongsidemodelandruntime; the active path is derived by walking the chain, with non-terminal nodes considered superseded. No secondsupersededByfield, so there is one source of truth and no implicit ordering rules — the exact class of bug that positional slicing (messages[:-2]) produced.expectedRevisionguards concurrent writes.conversation.jsonkeeps an incrementingrevision;begincarriesexpectedRevisionand a mismatch returns a conflict with the current revision. Validation order inside one transaction: revision →revisionOfvalidity → target turn terminal status → duplicate message id.Scope stays on the newest turn. Editing is offered only for the newest user message whose reply is
stoppedorinterrupted, and a turn can only be revised once.The session is rebuilt from the revised history. The old native session is discarded and the original working directory is kept, uniformly across runtimes.
Accepted jobs are carried forward. The new turn gets an
inheritedJobssnapshot.commandId(the idempotency key) is always present;jobIdis resolved from the project snapshot when the submission was actually accepted, sojobId: nullmeans "this call never produced a job" rather than "unknown". The UI shows this in a collapsed section.Client keeps one operation identity.
pendingTurnIdinsessionStorage(keyed by conversation) is reused when retrying an uncertain edit, and cleared on acceptance.Changes
apps/api/src/opendirector_api/agent.py—Turn.revisionOf/expectedRevision,active_messages(),revision_error(),inherited_jobs(), revision counter, transactional validation.packages/core/src/opendirector/agent/native.py— tolerate plain-text stdout outside the harness event protocol (see below).src/backend/chat.ts,src/canvas/chatTurnRequest.ts,src/canvas/useAssistantChat.ts,src/canvas/AssistantPanel.tsx,assistant-panel.css— editing state, composer fill, inherited jobs, copy in en-US and zh-CN.An unrelated defect fixed on the way
native.pyparsed every stdout line as JSON, so a harness that prints a warning between events failed the whole turn. Claude Code does exactly this fordeepseek-flash:The user saw "Agent 执行失败,请检查后端日志。" while the log held nothing useful. Unparseable lines are now recorded in the trace and skipped, and
text_events()ignores frames withouttype. This is what made the Claude Code path usable at all; without it that runtime cannot run an unrecognized model. It is arguably a separate PR — happy to split it out.Verification
Run on Windows with a local server driven over HTTP: create a project, send a turn that writes a file, send a follow-up and stop it mid-reply, then edit and resend.
work\keep.txt, stop recordedstopped, revised turn repliedNEW-MARK, context contained only the revised requestDEEPSEEK_API_KEYwas present in the launching environmentCLI 未返回模型列表)is_complete: true, so it completes but far too slowly to automate hereThe codex and jiuwenswarm entries are upstream CLI and environment limits, not revision-logic failures. I could not produce continuation evidence for them.
Test status:
tests/test_assistant_revision.py— 10 passed. Covers the chain-derived active path, rejecting an unrelated or non-newest turn, single revision, staleexpectedRevision, concurrent running turn (real 409), reload, attachment preservation through a real upload, and the job snapshot.tests/test_agent_citations.py— includes a regression test for the plain-text stdout case.tests/browserHost.test.ts, wherepython3.exeresolves to the WindowsApps stub (exit 9009); none of them touch assistant code.tests/test_native_runtime.pyhad twosubprocess.TimeoutExpiredfailures under load; both pass when rerun alone.Not done
Refs #375. Parent roadmap #261.