← Back to Pull requests

Chat: Edit and Regenerate work on the session authority (bugfix) #476

Closed
unknown closed this pull request without merging on Nov 25, 2026 01:17 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 09:57 UTC
Author

Edit a prompt and Regenerate a reply (both ChatSession.rewind) on a session-authority gateway. The legacy path sends what it sent before.

1. Edit and Regenerate on a session-authority gateway

Before: on a gateway whose gateway.ready has session_authority: true (the gateway-hosted Webapp listener), prompt.submit takes a closed set of keys. The one request a rewind sent was refused, so Edit and Regenerate did nothing:

prompt.submit {session_id, text, truncate_before_row_id, confirm_truncate, confirm_empty_truncate, submission_id}
-> {"code": 4001, "message": "invalid_params", "data": {"reason": "invalid_params", "fields": ["truncate_before_row_id", "confirm_truncate", "confirm_empty_truncate"]}}

Now, as Hermes Desktop does there (splitRewindSubmit in apps/desktop/src/api/canonical-protocol.ts, v0.23.3):

1. session.mutate with operation: "rewind", payload: {target_message_id: <the prompt's row>}, a request_id, and the session's expected_revision and expected_generation (the same fences branching uses since #469).
2. A plain prompt.submit with the new text and no truncation keys.

What happens when it doesn't go:

  • The cut is refused (revision_conflict, stale_generation, session_busy, or a row the gateway can't place): nothing was written. The chat goes back as it was, says why, and reloads the transcript. A fence refusal's current revision and generation are kept for the next try. It is not sent again by itself, unlike a branch: what changed elsewhere may be turns the cut would throw away.

  • The prompt fails after the cut is made (the two are separate requests there): the chat shows the cut, and the prompt stays under it, marked, to send again with one tap. Turned down, it's "not received"; with no answer, it's the usual "check before you resend".
  • Two more things were needed for a prompt sent in this session, both found against the real gateway:

  • prompt.submit there answers before the prompt's row is written, with no user_row_id, so the prompt had no row to cut at until the chat was opened again. It now goes with a submission_id of its own and takes its row from its turn's message.complete (persisted_turn.user_row_id, matched by submission_id).

  • The authority answers every prompt.submit "queued", one that starts a turn too. With a quick turn, message.start arrives before that reply is read, and the prompt stayed "Queued · sends after this task" for good, with no Edit or Regenerate. A prompt that starts a turn there is no longer marked queued; one sent mid-turn still is.
  • 2. The legacy path is unchanged

    Off the session authority a rewind still sends one prompt.submit with exactly session_id, text, truncate_before_row_id, confirm_truncate and confirm_empty_truncate, as before. (A first version of this PR also sent confirm_deep_truncate there; that was taken out in review: no hermes-agent from v0.22.0 to v0.23.4 enforces it, DEEP_TRUNCATE_ENFORCED = False, and it is a separate change.)

    A session authority that answers session.mutate with -32601 has nothing to fall back to (its prompt.submit refuses the truncation keys): the chat stays as it was, no prompt goes, and it says the gateway can't cut a chat back. Every authority version in the supported window has session.mutate rewind with target_message_id.

    How it was tested

    Unit tests (ChatSessionTest): the authority rewind sends session.mutate then a prompt.submit with only session_id, text and submission_id; each refusal; -32601; the prompt failing after the cut, refused or with no answer; a cut with no answer; the row from message.complete; the "queued" race. Edit, Regenerate and a cut at the first prompt are each tested in both modes, with the exact keys of each request. The CI command and :desktopApp:compileKotlinJvm pass locally.

    Raw JSON-RPC probes against local test gateways with a fake model:

    | Gateway | Result |
    |---|---|
    | v0.23.3 Webapp listener (session authority) | Old request: 4001 invalid_params as above. session.mutate rewind: stale revision → revision_conflict and stale generation → stale_generation, both with the current fences; mid-turn → session_busy; a row that isn't a prompt → invalid_params, field target_message_id. None changed the stored rows. With the right fences the rows from the target on are gone, and the plain prompt.submit writes the new prompt. |

    Version × mode matrix (supported window v0.22.0 to v0.23.4; Edit of an earlier prompt with a later turn, Regenerate of the last reply, Edit of the first prompt; the old request on the authority; a stale fence and a cut row):

    | Version | Legacy (hermes dashboard) | Session authority |
    |---|---|---|
    | v0.22.0 | contract validator + live probe: pass | none in this version |
    | v0.22.3 | contract validator + live probe: pass | contract validator + rewind payload validator: pass; not live (its authority listener is loopback-only with control-socket tickets, no Webapp listener) |
    | v0.22.7 | contract validator + live probe: pass | contract validator + payload validator + live probe on the Webapp listener: pass |
    | v0.23.4 | contract validator + live probe: pass | contract validator + parse_mutation + live probe on the Webapp listener: pass |

    In the app (Dev build on an emulator, signed in to the v0.23.3 Webapp listener), checking the gateway's stored rows after each step:

  • A prompt sent in this session shows no "Queued" and its reply has Regenerate.

  • Regenerate of the last reply: its prompt and reply are replaced.

  • Regenerate of an earlier reply: the confirm dialog ("discard 4 later messages"), then the chat ends at the regenerated turn.

  • Edit of the first prompt after that (two rewinds in a row, so the second used the first's receipt fences): the chat is the edited prompt and its reply.
  • These app checks were made before review; the review changes (legacy request back to as before, the -32601 message) were checked by unit tests and the probes above, not again in the app.

    Not proved in the app: the legacy path (probe and unit tests only), and the failure paths on the authority (refusals and a prompt failing after the cut), which are covered by unit tests and the probe's refusal shapes. The fake model makes no tool calls, so a rewind over a turn with tool steps wasn't tried on a device.

    Overlap

    #473 also edits ChatSession.rewind (it wraps the body in the send lock). Here the request itself for the authority moved out into mutateRewind, and the changes inside rewind are a few lines around that call and in its error handling, so whichever merges second has a small conflict there.

    ROADMAP: "edit-and-resend as a rewind" moved from the open session-authority item to the Regenerate/Edit item.

    Review follow-ups (rebased on master)

    Two fixes from a fresh-context review, each with a test that fails without it:

  • 8d5b71be A prompt edited or regenerated on the session authority now goes with a submission_id it keeps, so its turn's message.complete gives it its row even when the transcript can't be read afterwards, and the execution_generation the prompt.submit reply gives is kept for the next stop, approval or cut.

  • 4568610a If that turn ends before the prompt.submit reply is read, the row it got is no longer wiped by the reply (which has no user_row_id on the authority), as the send path already does.
  • In the app on this head's code (Dev build on an emulator, local test gateways with a fake model, stored rows checked after each step):

    | Gateway | master | this PR |
    |---|---|---|
    | v0.22.3 session authority (its gateway-hosted listener, bound to a reachable port for the test) | Regenerate: invalid_params, nothing changes | Regenerate (reopened chat and same-session prompt), Edit of the first prompt, Regenerate right after an edit: all cut and resend |
    | v0.23.4 session authority (Webapp listener) | Regenerate: invalid_params | Regenerate, Edit of an earlier prompt with a later turn (confirm dialog, "discard 2 later messages"), Regenerate after it, and after another client cut the chat |
    | v0.23.4 legacy (hermes dashboard) | works | still works: Regenerate and Edit of an earlier prompt |

    Once on v0.22.3, the first Regenerate after reinstalling the app was refused as "changed somewhere else" and went through on the next tap. I couldn't make it happen again in 6 more tries (relaunches, a gateway restart, quick taps).

    Version × mode probe on this head's requests (raw JSON-RPC, the exact params rewind sends): v0.22.0 legacy; v0.22.3, v0.22.7 and v0.23.4 in both modes. All pass: on the authority the old one-request rewind is refused with 4001, stale revision and generation are refused with the current fences, a reply's row is refused (field: target_message_id), refusals leave the rows as they were, message.complete names the prompt's row by submission_id, and Edit of an earlier prompt, Regenerate of the last reply and Edit of the first prompt leave the expected rows. Off the authority the same three cuts work with the unchanged legacy keys.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Giton22 Review duration: 2360m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #476"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%