#797·flue

Every durable append clones the whole reduced conversation state

Author: rikbrownCreated Sep 29, 2026Updated Sep 29, 2026

Summary

On @flue/runtime 2.1.1, ConversationRecordWriter.appendBatch calls reduceConversationRecords for each batch. That function calls cloneReducedInstanceState before it applies the records, so that an invalid record later in the batch leaves the accepted state intact. The clone copies every entry and block of the conversation (object spreads and a new Map per conversation), so each append costs O(entries + blocks) of the whole conversation, not O(records in the batch). Loads already use reduceConversationRecordsInPlace.

Measurement

Local benchmark with the 2.1.1 dist functions, Node 24, synthetic turns of 3 tool calls with 4 KB results each:

Turns Clone per append Fold checkpoint size
50 0.07 ms 1.1 MB
200 0.34 ms 4.5 MB
400 1.08 ms 9.1 MB

A response appends one batch per block start and end, per delta flush, and per tool call and result (#790 reports about 12 batches for a typical turn). The clone runs once per batch on the Durable Object's thread, and its cost grows linearly with the length of the conversation.

Proposed fix

Keep the failure atomicity, but without a whole-state copy:

  1. Validate every record of the batch against the current state first, then apply the batch in place with reduceConversationRecordsInPlace; or
  2. Copy on write: copy only the entries and blocks that the batch changes.

The writer adopts the new state only after store.append succeeds, so option 1 must also leave the state unchanged when the append fails (for example, apply after the append resolves).

Related: #790 (fold checkpoints stop advancing, so each load re-folds a growing suffix).