research29 min studyLesson 750 in Engineering

Stage recovery: preserve the visible token prefix under explicit assumptions

Separate cache recomputation from output replay, generation ownership, durable token records, and client deduplication.

On this page

What you’ll understand

  • Identify the state needed to continue an already visible generation.
  • State assumptions required for replay without duplicate visible tokens.
  • Distinguish cache frontier, sampled tokens, output commitment, and client acknowledgment.

A failed prefill before any output can often be recomputed, while a failed decoder after visible output must preserve a prefix the client has already seen. Replaying the prompt and sampling from scratch may produce a different continuation or duplicate earlier tokens. Define the continuity promise and the supporting state. The protocol below is an illustrative design with explicit durable-output, fenced-owner, and client-deduplication assumptions. Neither a KV connector completion callback nor an ordinary streaming connection supplies those guarantees by itself.

Recover logical generation state, not just a cache allocation

Bind recovery to request and generation identity, model and adapter versions, exact prompt tokens, accepted generated-token prefix, sampling configuration and relevant RNG state, stop and grammar state, penalties, and compatible cache representation. The cache’s covered input positions can lag a sampled or emitted token because a newly sampled token may enter the next model step before its KV is materialized. Record the actual next-input position and cache frontier instead of assuming one output token always equals one already stored cache position.

A compatible decoder can reconstruct missing KV by processing the exact known token prefix under the intended model and position semantics, but that consumes time and does not automatically reproduce every future floating-point or stochastic choice. Preserving already emitted token identities is a narrower claim than bitwise reproduction of an uninterrupted future stream. If necessary state or committed output records are unavailable, return the defined failure or restart signal rather than silently present a new generation as continuity of the old one. External tool side effects require their own idempotency contract.

kack≤ksent≤klogk_{\rm ack}\le k_{\rm sent}\le k_{\rm log}
This proposed prefix ordering assumes output token records are durably committed before send, sends form an ordered generation prefix, and acknowledgments identify that prefix. Counts are nonnegative sequence positions. The cache frontier is a different state variable, and this ordering alone does not implement exactly-once visible delivery.↔ Scroll wide equations horizontally.

Delivery uncertainty needs an output protocol

A server can send token five and fail before receiving its acknowledgment; the client may or may not already have displayed it. Resending by text alone can duplicate visible output, while skipping it can lose output for the client that never received it. One proposed solution uses immutable token records keyed by request, generation, and sequence, a durable replay source, and a client that deduplicates those identities over the claimed reconnect and crash scope. Server ownership must be fenced so an old decoder cannot append a conflicting record after recovery.

These assumptions need implementation evidence. An in-memory token buffer does not survive arbitrary process or node loss, and a transport acknowledgment need not mean the application durably recorded or displayed a token. Define client acknowledgment and retention, log completeness, conflict detection, and rollback behavior. A lost handoff acknowledgment should resolve the same authoritative generation and epoch, not create two emitting owners. Exactly-once visible output is therefore an end-to-end protocol claim with failure limits, not a property inferred from retrying a network write.

Tresume=Tdetect+Troute+Tload+Trecompute+TreconnectT_{\rm resume}=T_{\rm detect}+T_{\rm route}+T_{\rm load}+T_{\rm recompute}+T_{\rm reconnect}
This illustrative sequential recovery budget uses nonnegative durations in seconds and excludes overlap, repeated failures, and unlisted work. It estimates a resume boundary under specified state availability, not a guarantee of a preserved latency SLO or output trajectory.↔ Scroll wide equations horizontally.

Exercise failures around both handoff and emission

Test source failure during copying, destination failure after readiness, ownership-commit acknowledgment loss, decoder death after sampling but before log commitment, and failure after send but before client acknowledgment. Verify the surviving authority, cache and token frontiers, exact replay keys, and stale-owner rejection. If no output has been committed, a new internal attempt can still need the same public request identity and bounded retry budget. Once output is visible, it cannot be retracted by quietly changing the model, prompt, or generation identifier. Preserve the client’s observed prefix in the oracle.

The reliability lab provides only majority availability counts. Reset, explicitly set replicas five and unavailable one, predict four available and threshold three, then Play or Step. Compare a fresh Reset with replicas five and unavailable three explicitly set, giving two available. There are no KV shards, output logs, client acknowledgments, ownership fences, or reconnects in this model. A majority flag cannot establish the stated continuity promise or tell whether the exact required generation state survived.

Replay a committed token identity instead of sampling it again

Under the proposed durable-log-before-send protocol, generation g has immutable token records one through five. The client has acknowledged through four, but may already have displayed five when the connection fails. The client persistently deduplicates request/generation/sequence identities over this reconnect scope, and a fenced recovery owner can read the log.

  1. The replay interval after the acknowledged prefix is sequence five only. The recovery owner retrieves that committed token record rather than resampling a replacement token for the same key.

  2. If the client already displayed five, the repeated identical key is suppressed; if not, it displays that committed token once. This conclusion depends on the stated client and durable-record assumptions, not merely on an ordered transport.

  3. After resolving the prefix, the next new output record is sequence six under the same generation and fenced authority. Reconstruct any missing cache from the exact token prefix with the correct position state, and do not infer that emitted token five was already fully represented in KV.

The result

One committed record is replayed under an explicit deduplicating protocol. Without those assumptions, a lost acknowledgment creates unresolved visible-delivery ambiguity.

Explore the model

Interactive lab

Interactive lab · reliability

Replica availability does not prove stream continuity

Use independent Reset → explicitly set BOTH n and k → predict → Play/Step runs for (5,1) and (5,3), giving four and two available with threshold three. No generation state, KV frontier, durable output record, client deduplication, or recovery route is modeled.

Replica availability does not prove stream continuityA replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Current readings: Available replicas: 4 of 5; Majority needed: 3; Majority available?: Yes. All parameters are adjustable with the labeled controls below.Majority available · need 3 of 5Playback highlights fixed statesR1 · upR2 · upR3 · upR4 · upR5 · downCyan mark: majority threshold
AvailableUnavailableMajority threshold
Available replicas
4 of 5
Majority needed
3
Majority available?
Yes
t = 0 s

A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forContinuity depends on the exact state and end-to-end protocol that survive, not a generic majority count.

Check your understanding

A decoder fails after sending a token but before its acknowledgment arrives. What can prevent either loss or duplicate visible output under the proposed design?

Try it yourself

The client acknowledges through seven and the durable log contains through nine under the same proposed protocol. Which records are replay candidates? Separately, detection 0.2 s, routing 0.05 s, load 0.1 s, recomputation 0.4 s, and reconnect 0.05 s give what sequential resume budget?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Preserve committed token identities after the acknowledged prefix, then add the stated recovery components independently.

Compare with the solution

Sequences eight and nine are replay candidates; do not resample their contents. A client that already displayed either needs the stated persistent identity deduplication to suppress the duplicate. The sequential budget is 0.8 seconds. It excludes repeated failures and other work and does not prove a streaming-gap SLO or identical future sampling. Verify cache coverage and next-input position separately, and fail explicitly if the required durable records or ownership authority are unavailable.

Take it with you

  • Preserve exact committed token identities and generation state through recovery.
  • State durable-log, client-deduplication, and fencing assumptions for visible delivery.
  • Track cache, sampling, commitment, send, and acknowledgment frontiers separately.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.