Repository navigation
feat(assistant): edit and resend the last stopped message - #424
Zhangbo-cn wants to merge 1 commit 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: |
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.