Skip to content

feat(assistant): edit and resend the last stopped message - #424

Draft
Zhangbo-cn wants to merge 1 commit into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/375-edit-resend
Draft

Zhangbo-cn wants to merge 1 commit into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/375-edit-resend

Conversation

@Zhangbo-cn

Copy link
Copy Markdown
Contributor

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 messages positionally.

Design decisions

revisionOf is the only new relationship field. The new user message carries it alongside model and runtime; the active path is derived by walking the chain, with non-terminal nodes considered superseded. No second supersededBy field, so there is one source of truth and no implicit ordering rules — the exact class of bug that positional slicing (messages[:-2]) produced.

expectedRevision guards concurrent writes. conversation.json keeps an incrementing revision; begin carries expectedRevision and a mismatch returns a conflict with the current revision. Validation order inside one transaction: revision → revisionOf validity → 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 stopped or interrupted, 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 inheritedJobs snapshot. commandId (the idempotency key) is always present; jobId is resolved from the project snapshot when the submission was actually accepted, so jobId: null means "this call never produced a job" rather than "unknown". The UI shows this in a collapsed section.

Client keeps one operation identity. pendingTurnId in sessionStorage (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.py parsed every stdout line as JSON, so a harness that prints a warning between events failed the whole turn. Claude Code does exactly this for deepseek-flash:

[claude-code:unrecognized_model] {"model":"deepseek-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 without type. 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.

Runtime Result Evidence
default (bundled OpenCode) passed created work\keep.txt, stop recorded stopped, revised turn replied NEW-MARK, context contained only the revised request
opencode passed same flow
deepseek (dsh) passed same flow once DEEPSEEK_API_KEY was present in the launching environment
claude partial replies correctly after the stdout fix, but responds too fast to reliably catch a mid-stream stop locally, so the stop-and-revise chain is unverified
codex blocked with a local shim injecting the provider, the CLI model listing comes back empty (CLI 未返回模型列表)
jiuwenswarm blocked a single turn exceeds a 900 s client timeout; its own trace ends with is_complete: true, so it completes but far too slowly to automate here

The 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, stale expectedRevision, 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.
  • Backend suite: 207 passed.
  • Frontend: 940 of 947 passed. The 7 failures are all in tests/browserHost.test.ts, where python3.exe resolves to the WindowsApps stub (exit 9009); none of them touch assistant code.
  • tests/test_native_runtime.py had two subprocess.TimeoutExpired failures under load; both pass when rerun alone.

Not done

  • CLI/Agent entry point for edit-and-resend, which the issue tracks separately.
  • Frontend tests for the composer fill and cancel paths beyond the request-shaping test.
  • Attachment and reference selections are covered only by the server-side test, not in a browser.
  • No browser run of the UI; the panel changes are type-checked and unit-tested, not visually verified.

Refs #375. Parent roadmap #261.

…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.
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

Two checks failed; neither comes from this change.

checks / browser (isolated) — only timeline node output fails:

locator.waitFor: Timeout 20000ms exceeded.
waiting for locator(.react-flow__edge[data-id^=publication:9f6f48a2-...:]) to be visible
at tests/browser/timeline_node_output.mjs:78

That test drives .cw-selection-toolbar → "Output video" and waits for the publication edge to appear after a rendered video is saved. It never opens the assistant panel. The other 13 browser checks in the same job passed, including browser (assistant). My CSS additions are all cw-assistant-* prefixed, so they cannot affect .react-flow__edge.

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 browser (isolated) that would settle it.

checks / checks is only the aggregate that reports the browser result; it failed 6 s in, right after printing the per-job table.

Everything else is green: python, frontend, static, browser (assistant), browser (voice), CodeQL python and javascript-typescript.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants