Skip to content

[feat] assistant: Edit and resend the last user message after stopping #375

Open

Description

@FayeSpica

Parent roadmap: #261. Related work: conversation management #247 and turn/tool/job/receipt correlation #372.

Goal and scope

After stopping an Agent turn, let users edit its originating user message and resend it in the same conversation. Preserve earlier conversation context, attachments and project references.

User flow and rules

  • Wait for the turn to reach a terminal state before enabling Edit and resend on its originating user message.
  • Open the original text, attachments and reference selections in the composer. Allow editing, cancellation and submission; retain the draft on failure.
  • Resending creates a new attempt linked to the original message and stopped turn. Preserve the original text, partial reply, tool calls and execution records for inspection.
  • Build the new runtime context from the conversation before the edited message plus its revised content. Exclude the superseded request and stopped reply from the active conversational path. Ensure native runtime session state follows the same context.
  • Existing project changes and accepted jobs remain authoritative. Expose their current outcomes to the new attempt so it can reuse results or query ongoing/unknown work before submitting again.
  • Keep stop-response, orchestration stop and accepted-job cancellation semantics explicit. Editing and resending does not roll back project changes or cancel accepted jobs.
  • Validate conversation revision and active-turn state on submission. Concurrent edits or a newly active turn return an actionable conflict.
  • Initial scope covers the last user message associated with the stopped turn. Earlier-message editing requires separate scope.

Implementation impact

Reuse conversation persistence, drafts, turn submission and stop services. Add the minimal revision/attempt relationship needed for history and context selection. Provide a shared edit/resend operation for UI and Agent/CLI access with discoverable help. Verify adapter-specific session rewind, branching or reconstruction against actual runtime capabilities.

Acceptance criteria

  • Stop a streaming turn, edit its user message and resend with earlier context, attachments and references preserved.
  • The new attempt receives the revised request once; the superseded request and partial reply do not leak into active context.
  • Original and revised attempts remain inspectable after reload and project reopening.
  • Cancel editing and simulate save/submission failures without losing the original message or draft.
  • Reject stale revisions and concurrent active turns without duplicate attempts; retry an uncertain submission using the original operation identity.
  • Exercise a turn that already changed the project or accepted a generation job. Preserve those facts and avoid automatic duplicate generation.
  • Verify supported Default, OpenCode, OpenJiuwen, Codex and dsh runtime paths with actual continuation/context evidence; document any unsupported path explicitly.
  • Verify equivalent shared-operation behavior through UI and Agent/CLI, and complete English/Chinese interactions.

Decisions to confirm

Choose how the UI displays original and revised attempts while keeping execution history accessible.

Activity

  1. added
    help wantedExtra attention is needed
    type:featNew capability or behaviour
    area:agentAgent runtime, assistant chat and tools
    area:harnessHarness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH)
    on Nov 16, 2026
  2. Zhangbo-cn commented on Nov 17, 2026

    @Zhangbo-cn
    Contributor

    I would like to take this one. Before writing code I read the current paths and measured one assumption, because it changes how much of the acceptance list is actually new work. Two questions at the end need your call.

    Native session resume invalidates itself, measured

    Excluding the superseded pair from the active path is enough to make every native runtime rebuild from authoritative history. The reuse predicate in context.py:42 requires an exact message count:

    if saved['selection'] == selection and saved['messages'] == len(self.messages) - 1:

    Driving the real RunContext with no CLI and no model:

    turn 1 (no session yet)            context=1 resume=None
    turn 2 normal (pair kept)          context=3 resume=engine-session-1
    turn 2 resend (pair excluded)      context=1 resume=None
    turn 3 after resend                context=3 resume=engine-session-2
    

    So a resend returns None from native_session_id(), and native.py:177-181 then rebuilds the conversation from full history. The turn after the resend resumes normally against the new session, so this does not leave the conversation permanently unable to resume. OpenCode, Codex, Claude and dsh all read the same predicate through native.py:177; JiuwenSwarm reads it through jiuwenswarm.py:143.

    One consequence to decide on rather than hide: session_directory is only computed when session_id exists (native.py:178), so for Codex, Claude and dsh a resend also drops the reused work directory and starts a fresh one (reuse_workspace becomes false at native.py:192). Files the stopped turn published as assets are unaffected; uncommitted scratch files in that workspace are not carried over. I would document this as intended rather than add workspace-rewind logic, unless you want the workspace preserved.

    If that reading is right, acceptance item 7 becomes "show that all five paths take the rebuild branch" instead of implementing per-adapter rewind, which is a unit test on the predicate plus one stub-endpoint end-to-end run.

    What already satisfies the list

    • Concurrent active turn: agent.py:348 and the re-check at :470 already return 409.
    • Retrying an uncertain submission under the original identity: resending the same message id raises 409 at agent.py:134.
    • Original attempt stays inspectable: traces are keyed by turn id (<turn>.model.jsonl, <turn>.<runtime>.jsonl), and a resend needs a new turn id anyway, so the old files are untouched.
    • Project changes and accepted jobs are not rolled back: there is no rollback path to suppress.
    • Terminal-state gating: stopped and interrupted already exist and AssistantPanel.tsx:489 already renders them.

    The genuinely new work is the edit/resend operation itself, the active-path exclusion, and draft retention on failure.

    Two questions

    1. Where does the revision relationship live? Messages in conversation.json are a flat array whose entries carry no parent or revision link today. I can add a minimal link on the message entries, or wait for #372's turn_id → call_id → jobId correlation model and hang it off that. #372 (@yefuyou) and #247 (@MrDongsls) both modify this same file, so whoever lands first sets the shape. I would rather not introduce a second relationship concept — which of the two do you want this to follow?

    2. Is the display decision settled? Your "Decisions to confirm" asks how original and revised attempts appear. I do not want to guess at information architecture and rework it in review. If you have a preference (inline superseded-and-collapsed, versions behind the user message, or something else), I will build that.

    Proposed slice

    Assuming you are fine with it: Default runtime plus the UI, covering the edit/resend operation, active-path exclusion, stale and concurrency rejection, and draft retention, with bilingual copy. Tests go through the existing --assistant-fixture server so no paid provider is involved, and each test is mutation-checked against the pre-fix revision.

    I would leave out of this PR, as separate scope: the Agent/CLI entry point for acceptance item 8, since cli.py has no assistant or conversation command group at all today (the seven groups are asset canvas job model project timeline video), so that is a new surface rather than a flag; and editing any message other than the last, which your scope note already defers.

    If you would rather have the CLI side in the same change, say so and I will include it.

  3. yefuyou commented on Nov 17, 2026

    @yefuyou

    Thanks for the detailed investigation, @Zhangbo-cn! I'm working on #372 in PR #374 and wanted to clarify the boundary so this doesn't block your implementation.

    #374 persists the originating Agent turn ID and tool-call ID on accepted generation Jobs, and adds a read-only lookup at GET /api/creation/projects/{project_id}/assistant/turns/{turn_id}/jobs. It does not change conversation.json or introduce a message-revision/attempt model.

    For edit-and-resend, my suggestion is to keep a minimal revision link on the conversation message/new attempt, rather than attach message revisions to the Job lineage. They answer different questions: "which message/attempt revises which?" versus "which turn submitted this Job?" The original user message ID is already used as the turn ID in the current submission path, so #375 can retain that ID and look up the original turn's accepted Jobs through #374 once it lands.

    One important limit: the endpoint makes existing Jobs and their outcomes discoverable, but it does not automatically decide whether a revised attempt should reuse work or submit a new generation. That decision stays with the edit/resend flow.

    This should let the two changes evolve independently. No need to wait for #374 to define the conversation revision structure. Happy to help if you encounter a concrete integration gap.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agentAgent runtime, assistant chat and toolsarea:harnessHarness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH)help wantedExtra attention is neededtype:featNew capability or behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions