FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Versioned Editing for AI Assistant Responses

Let readers correct assistant text through versioned edits that preserve the original answer, editor attribution, citation state, and conflict recovery.

Freshness: current•12 min read•AI User Experience and Human-AI Interaction
Full Technical Reference Document

Mental model

An inline correction should create a new, attributable response revision rather than silently mutate the model's original output. Bind each edit to the response ID and revision the user opened, require a completed snapshot or explicit stream-stop action, and commit with a compare-and-swap check. Keep the original, edited text, editor identity, and citation state linked so stale saves cannot overwrite newer answers.

Define the edit transaction

The visible answer is not the generation itself. It is a presentation of one response object that may contain text, citations, refusal status, and tool events. An edit therefore needs an explicit target: response ID, response revision, editor, and the exact text or patch being submitted. Treat an edit as a new application revision with its own audit event. Preserve the model output as the parent so a user correction never masquerades as text generated by the model.

Start editing from a stable snapshot. If tokens are still arriving, either disable the edit control until the response-completed event or let the user stop generation and record that decision before opening the editor. Otherwise the arriving stream can overwrite the user's draft or append text to the version they believed they were changing. A saved edit should not alter provider-side response data; it changes the application's rendered revision.

On save, the server checks that the caller can edit the response, the response is in an editable state, and the supplied base revision is still current. Perform that comparison and append the new revision in one transaction. A client-side check alone has a race: another tab or background regeneration can save after the check but before the write. If the compare-and-swap fails, return a conflict and keep the user's draft locally. Offer a side-by-side comparison or explicit merge; never silently use last-write-wins.

Idempotency matters when a save response is lost. Give each edit submission an operation ID and record it with the revision. Retrying the same operation returns the already-created revision, while a second intentional edit gets a new operation ID. Keep the audit event small but useful: actor ID, response ID, base and resulting revision, timestamp, operation ID, and whether cited ranges were retained, remapped, or invalidated. Avoid copying sensitive content into analytics logs.

Preserve citations and attribution

Text replacement can move or invalidate citation offsets. Store citation relations against claim IDs or anchored ranges in a specific revision, not raw positions that are assumed to survive edits. If a patch overlaps a cited claim, mark that relation for review or rebuild it from the new revision. The edited text may be helpful, but the previous source does not automatically support the replacement wording.

Make the editor status visible: “AI response,” “Edited by you,” and “Source links need review” express separate facts. A correction should not inherit a model confidence value as if that value assessed the corrected text. If the product lets users undo, undo should create another revision pointing to the prior content, preserving an audit trail rather than deleting the edit history.

Theory

Let rr be the current server revision and e.basee.base the revision the editor opened. Let B(e.text)B(e.text) be the UTF-8 byte length of the submitted text and Bmax⁡B_{\max} the product's storage limit in bytes. Accept only a non-empty edit within that limit whose base revision still matches:

commit⁡(e,r)={r+1,e.base=r∧0<B(e.text)≤Bmax⁡conflict⁡,e.base≠rinvalid⁡,B(e.text)=0∨B(e.text)>Bmax⁡\operatorname{commit}(e,r)= \begin{cases} r+1, & e.base=r \land 0 < B(e.text) \leq B_{\max} \\ \operatorname{conflict}, & e.base \neq r \\ \operatorname{invalid}, & B(e.text)=0 \lor B(e.text)>B_{\max} \end{cases}

For example, two browser tabs open response revision 17. Tab A saves a 64-byte correction first, creating revision 18. Tab B then submits its draft with base revision 17. The server returns a conflict instead of changing revision 18. Tab B keeps its unsaved text and can compare it with the new answer. Counting UTF-8 bytes also bounds storage for multi-byte text; JavaScript string length alone counts UTF-16 code units and is not a byte limit.

Failure modes and misconceptions

FailureWhy it occursSafer behavior
A slow save overwrites a newer answerClient checks the revision before a separate writeCompare and append atomically on the server
Stream output replaces a draftEditing starts before the response reaches a terminal eventFreeze a completed snapshot or record an explicit stop
A citation remains beside changed wordingThe edit moved or replaced its claimInvalidate or re-review overlapping citation relations
Retry creates duplicate editsThe client lost the first acknowledgementPersist an operation ID and make retries idempotent
Edited content looks model-authoredThe UI hides the author and parent revisionLabel the edit and retain the original response revision

Immediate persistence gives clear recovery but may add a network round trip to each save. A local draft feels responsive, but it is not durable until the server confirms the new revision. Keep drafts visible during a conflict, announce the save state in a polite status region, and do not move focus away from the editor when a response completes in the background.

Trade-offs

An append-only revision chain makes undo, attribution, and incident review straightforward, but stores more data and needs retention rules. A compact patch log saves space, yet reconstructing a response requires replaying edits in order and preserving the exact base version. Choose a retention policy that keeps enough history for user recovery and governance without copying private answer text into general analytics. The editor should clearly distinguish a local draft from a durable server revision.

Decision scenario

Two reviewers opened response revision 12. Reviewer A saves a correction and receives revision 13. Reviewer B's tab still contains a different useful edit based on revision 12, and its changed sentence overlaps a citation range. Return a conflict, preserve Reviewer B's draft, and show revision 13 beside it. Require an explicit merge or rebase against revision 13; after that choice, invalidate or re-review the overlapping citation before presenting the merged response as sourced.

Learning outcomes

  • Describe the response ID, base revision, and operation ID required for an edit transaction.
  • Explain how atomic compare-and-swap prevents stale drafts from overwriting newer responses.
  • Identify when a correction must invalidate or re-review an attached citation.

Implementation

The client sends the base revision and a unique operation ID. The server endpoint still has to enforce authorization, byte limits, idempotency, and compare-and-swap in a database transaction.

typescript
type EditCommand = {
responseId: string;
baseRevision: number;
operationId: string;
text: string;
};
​
type EditResult =
| { kind: "saved"; revision: number }
| { kind: "conflict" };
​
export async function submitResponseEdit(command: EditCommand): Promise<EditResult> {
const bytes = new TextEncoder().encode(command.text).byteLength;
if (bytes === 0 || bytes > 16_384) {
throw new RangeError("Edited response must be between 1 and 16384 UTF-8 bytes");
}
const response = await fetch("/api/response-edits", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(command),
});
if (response.status === 409) return { kind: "conflict" };
if (!response.ok) throw new Error("Could not save the response edit");
const result = (await response.json()) as { revision: number };
return { kind: "saved", revision: result.revision };
}
Select a completed response revision
Edit an attributed local draft
Validate base revision and byte limit
Append the edit with compare-and-swap
Render the saved revision and citation status
Conceptual teaching model synthesized from:human-ai-guidelines,openai-responses-streaming-events,openai-api-reference
Reflect before revealing the guide

Prerequisites & Related Concepts (2)

Private notes

0 words
Recommended Free Track
Free · Verifiable Credential

FS-501AI Evaluation and Reliability

Turn product intent and risk into representative evaluations release gates traces service targets and continuously improving regression evidence.

17 concepts~22h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.

Next