1 min lesson
Streaming edit application
Explain the order in "Streaming edit application", then say how you would verify the result.
Step 1 of 2
Streaming edit applicationapply model output as it arrives
The model streams tokens, so you can't wait for the full edit before showing anything. The danger is applying a partial edit and corrupting the buffer when the next chunk arrives. The safe pattern keeps a stable base and replaces a pending region on each chunk.
- 1Anchor a region. Pick the offset range the stream is rewriting and treat it as a single replaceable span.
- 2Buffer the partial. Accumulate streamed text; render it into the anchored region for preview without committing.
- 3Commit on completion. When the stream ends, apply one final, validated edit and clear the pending state. If the stream errors, drop the pending region - the base buffer was never mutated.
If your edits are reified objects, undo/redo is free: keep a stack of applied edits and their inverses. The inverse of {offset, length, text} is {offset, length: text.length, text: deletedText}. Mention this when asked about undo - it shows the data model was designed for it, not bolted on.
Don't apply streamed chunks directly into the live buffer offset-by-offset. A retry, a reorder or a truncated final chunk will leave half an edit in place. Keep the pending region separate and commit once.