Repository navigation
Description
Summary
Follow-up to #1599. That PR lets an in-flight cosmetic streaming edit settle (up to 3 s) before the finalize write in stream_prompt_blocks (crates/openab-core/src/adapter.rs). One residual risk was accepted for that PR and is tracked here: a stale ...<tail> preview can still become the visible message when the settle times out.
Residual risk
Two writers touch the same message: the cosmetic edit loop (preview edit A) and finalize (final edit B).
- Timeout path (>3 s). If A has not finished within
COSMETIC_EDIT_SETTLE_TIMEOUT,settle_cosmetic_edit_taskaborts and joins the task, then finalize sends B. A request that was already written to the wire cannot be recalled. A Slackchat.update, or a Discord edit that is being retried after a 429, may then land after B and leave the stale preview visible. - Gateway. openab → gateway ordering is fixed, because A and B travel over one WebSocket. For fire-and-forget platforms behind the gateway, the gateway's downstream HTTP calls have no ordering guarantee, so the same reordering can happen one hop later.
The impact is cosmetic (the full answer was produced, but the visible message shows a truncated preview), and it needs an HTTP edit that stalls for more than 3 s.
Correct re-write condition
If the final edit B was sent while any cosmetic edit A was still in flight, re-send B after A settles.
The order in which the responses arrive does not tell you the order in which the platform applied the edits. "A's response came back before B's" is not proof that B is the visible state, so the condition must be "A was in flight when B was sent", not a comparison of response times.
There is one case no local design can handle: the client times out on A (for example Slack's 30 s), and the platform applies A afterwards. The client cannot know whether A took effect.
Options
(a) Timeout-branch change only
On the timeout branch, do not abort A. Send B immediately, then re-send B once A settles (bounded, best effort).
- Small change, limited to
settle_cosmetic_edit_taskand the finalize call site. - The normal path (A settles within 3 s) does not change.
- The background task that waits for A and re-sends B outlives finalize, so it needs a bound and logging.
(b) Per-message writer task
One task per message is the only writer for that message. Cosmetic updates are latest-wins (keep only the newest, no queue). Finalize marks the message final and sends B without waiting for A; if A was in flight when B was sent, the writer re-sends B after A settles.
- Removes the two-writer race by construction, and replaces
settle_cosmetic_edit_taskand the 3 s constant. - Estimate: about 120–180 lines in
crates/openab-core/src/adapter.rsplus about 4–5 tests (about 150 lines, reusing theRecordingAdapterand paused-time setup from fix(streaming): avoid cosmetic edit race against finalize delivery #1599). Half a day to a day of work. No per-platform adapter changes. - The user may briefly see the old preview before the re-write.
Shared hard part
Both options must never re-write B after the placeholder message was deleted or replaced. Finalize has several branches where this happens:
- delete-and-resend when the reply contains a mention;
reply_to, which deletes the placeholder and posts a reply;- splitting a long answer into multiple messages, where the placeholder holds only the first chunk.
The re-write logic must know which of these happened and skip, or target the right message. Review should focus on this.
Acceptance criteria (proposal)
- When a cosmetic edit is still in flight at finalize and completes after the final edit, the visible message ends as the final content (deterministic paused-time test).
- No edit is sent to a placeholder after it was deleted or replaced, for each finalize branch above (tests).
- The normal path (A settles within 3 s) keeps the current single final write.
Activity
github-actions commentedon Nov 15, 2026
Thanks for the report! A maintainer will triage this shortly and apply the appropriate label. Once a type label is added, the issue will be re-validated automatically.