Skip to content

ADR-0083: A turn shows its progress: phase, thinking, and an estimated count

Status: Accepted, amended by ADR-0085 (the tokens folded under the strip), and by ADR-0086 (the fall-back line), and by ADR-0092 (the strip is the one sign that a turn works) Date: 2026-10-27 Deciders: Alex Nodeland Amends: ADR-0053 (what streams, and the three dots before it; a call's arguments and result, and what Copy copies), ADR-0080 (the strip over a turn)

Context

The owner watched a turn for five minutes and saw three dots. artifactr streams every part the model produces, text, thinking and a tool call's arguments as they are generated (artifactr ADR-0007, docs/artifactr/guides/live-output.md), but client's store kept only text_delta, and the chat drew dots until the first word of text. A reasoning model, or a tool call whose arguments run to kilobytes, is minutes of apparent silence: "It's also been working for 5 mins but I see no progress. I should be able to switch the model, see token counts for input, output, cache as the content streams. I should see thinking if available and stream token by token text where possible. Sitting and waiting for 5 mins is unacceptable."

The store had three further faults. Text accumulated across every text part of a turn, so what the model wrote before a tool call ran into the reply. Each delta told every listener at once, so a stream of two hundred deltas a second was two hundred renders of the thread. And a run's end wiped its text, so a turn that failed, or was stopped, took what it had written with it. On a reconnect, the server replays up to 1,024 of a running run's frames (FanoutChannel), and the store would have appended them to what it already had.

This record is the chat's half of the streaming design: what the UI shows from the frames that exist today. Exact token counts, the model that answered, and cache awareness need new fields from artifactr and are later phases; the strip is built so they plug in.

Decision

  • The store keeps what a run is doing. A Run has live: its phase (starting, thinking, tool or writing), the tool being prepared or the latest running and how many run, the characters of its arguments so far, the model's thinking, the milliseconds spent in thinking parts that have ended, every character the model has produced this turn, and when the phase began and the last frame came, by the browser's clock. part_started sets the phase, and so does a delta whose part's start was lost; tool_called says a tool runs, tool_returned that one fewer does, and the model is waited on again once none, run_paused the same; a resumed run, on its answer and on its new turn's run_started, starts afresh, its text included: the words before its question aren't the reply. apply takes the clock as a parameter, Date.now() by default, so a test is deterministic.
  • A new response's text replaces the old. pydantic-ai numbers the parts of each model response from 0. A part of any kind whose index is at or below the last part's begins a new response, and the reply is that response's text: its first text part replaces what the model wrote before its tool call, which isn't the reply, as the posted message, which is result.output, won't hold it; from the moment the tool call's part starts, that text is stale, and the chat fades it. Within one response, a second text part goes on from the first. Text that arrives after message_posted, late, isn't kept, until a new part starts.
  • The listeners hear once per frame. The store applies each live frame as it arrives and tells its listeners on the next animation frame, once for however many frames came in between; any other change tells them at once, which also delivers what was put off. A hidden tab draws no frames, so a tenth of a second's wait tells them where no frame has.
  • A reconnect starts live output over. Protocol gains welcome(state, frame), which the store calls as a connection is welcomed without a reset, before the replay: artifactr's resets every running run's text and live, so the frames the server sends again show nothing twice; and it seeds, from the welcome's active_runs, every run the server says is running that the store doesn't hold, so the frames that reach the store before the replay reaches the run's run_started, or that come to a store that joined at the head (fromHead) and replays nothing, aren't dropped; run_started, when it comes, keeps what such a run has streamed. A frame buffer that overflowed loses its oldest frames (1,024 kept), so the head of a long text may be missing after a reconnect: the store marks the run truncated when the first frame after a welcome isn't a part's start, or the frames since reach the buffer's size, and the chat shows "…" before the words; how long a thinking part took before the welcome isn't known, and the disclosure says "Thought", with no length; a turn that ends mid-thought counts that part up to its last frame. A failed or stopped turn keeps what it streamed only in the store that saw it: a reconnect while it ran starts it over, and a reload loses it, as live output is never stored. An offset per delta, or a snapshot on watch, is artifactr's to add (phase B).
  • What streamed outlives a failure. run_ended keeps the text and thinking of a run that failed or was stopped; message_posted clears both, as the posted message is the reply, and a completed run has posted it. threadLog puts a partial entry before a failed turn's notice, at the same place, and Streaming draws it quietly, dimmed; a stopped turn, with or without anything streamed, is followed by Stopped, "Stopped here." as a line of the log.
  • Memory is bounded. Text and thinking keep their last 65,536 characters each; past that, the start goes, and truncated says so. Engines keep a string built by appending as a rope, flattened once when it is read, so appending a delta is cheap; the run object is new with every frame regardless. A run's thinking is held for the run's life and goes with its reply.
  • The strip says what the turn is doing. Beside its status, a line reads "Waiting on the model", "Thinking", "Preparing a create_app call, 12 KB", "Running create_app" (or "Running create_app and 1 more", for calls in parallel) or "Writing the reply"; after twenty seconds without a frame, ", 40 s since the last output" joins it, counting. The clock stays. Stop stays while the run works, where artifactr:stop_run allows. How a turn ended, the log says, which announces what joins it: its reply, its failure's notice, which is live for a turn that fails while the page is open, whoever started it, or "Stopped here.", a line of the log's own after what a stopped turn had streamed, or alone.
  • Thinking is folded under the words. Where the model shows its thinking, Streaming has a disclosure above the bubble, "Thinking…" while it thinks and "Thought for 12 s" after, closed by default, holding the thinking as preformatted text and the line "Thinking isn't kept: it goes when the page does." Everyone who can see the thread sees it (the owner's decision); it is never stored, never sent anywhere, and goes with the run's reply.
  • A token count, estimated. In the strip, under its status and its phase, as chips in the badge's style with tabular figures, "in ~1,000" and "out ~101", each named in full for a screen reader ("Input tokens, estimated: 1,000"), wrapping as whole chips: the characters of the thread's messages before the turn over four, which is a floor, as the system prompt, the tools and their results aren't counted, and the characters the model produced over four. The strip is one row: its status, the phase and the elapsed time as a quiet line under it on the same left edge, then the chips; Stop on the right, centred. The chips come with the add-on, which the thread loads as it opens, so the strip may grow by a line as they arrive; the load ahead makes that rare. On a narrow phone the buttons wrap under the strip's column rather than squeeze it. The estimate is a rough guide, said to be one, never a tokenizer. Amended by phase C: once a model request has ended, artifactr's usage frame (artifactr ADR-0096) gives the provider's counts, and the store keeps its total in live.usage, replaced by run_ended's; the chips are then exact, "in 1,030" with no "~", named "Input tokens: 1,030", with "cached N" and "cache write N" for the prompt cache and "reasoning N" only where they aren't 0, and the model that answered, as its response names it, in quiet text after them, named "Model: glm-4.7" for a screen reader; a usage frame is no output, so the idle count goes on through it; a resumed run's count starts afresh; until then the estimate stands. A welcome starts the count over with the rest of the live output, and the server sends the run's latest count again.
  • What is announced. The streaming item is aria-live="off" inside the log, so nothing of what grows, words, thinking or the disclosure's label, is announced; the posted message is. The strip has one role="status", kept through the add-on's loading, which says how the run goes and what it does, "Working: Writing the reply", on a change and at most every three seconds, with ", nothing for a while" once the idle count begins; the clock, the idle count and the token line are never live. The disclosure is a button with aria-expanded; the focus never moves by itself; the three dots stay still under reduced motion, as before.
  • A call's parts, formatted. The owner read a create_app call's arguments on a phone: one line of JSON with a page of HTML escaped inside it. Open, a call's Arguments and Result each have a toggle in their header, beside Copy, Formatted or Raw, two buttons pressed as chosen, where the value is a JSON object or array; a scalar, or a value that isn't JSON, has none. Formatted lays the JSON out with its keys quiet before their values, nested values indented, and a string that holds lines, or more than a line's worth, as a block of its own under its key, wrapped to the box: as code, in a block of the add-on's own labelled with its language and with Copy, where its key's words name one (html, css, js, ts, py, sql, md, or code, source, src, script for code of no named language; description names nothing, as script is no word of it) or its first lines read as one (<!doctype, import … from '…', def), and as plain preformatted text otherwise. Nothing of a value is run or parsed as HTML, and the characters that would change the direction of what follows show as their escapes. Raw is the value exactly as the run recorded it. A value the run cut short is closed where it stopped, a number or word cut at its end dropped as unknowable, or cut back to its last comma or bracket outside any string, so what parses is shown, under "Cut short: values at the end may be incomplete."; one past 200,000 characters, deeper than 50, or of more than 5,000 values, or that parses no way, is shown raw with a note; where a number has sixteen digits or more, or an exponent, a note says the browser may have rounded it and Raw has it as recorded; before the add-on loads, such a value is shown as recorded rather than indented, as indenting parses it. Copy copies what is shown: the JSON indented under Formatted, as before, and the recorded text under Raw. Each part keeps its own choice; the latest is the default for the next part opened, kept in the browser as portalr:tool-call-view ("raw", or nothing), in this tab: another tab reads it as it opens a call. It is the json-view add-on, loaded as a call is first opened, which takes the kit's region and Copy from its caller rather than importing them, as the bundle would otherwise split them into chunks shared with the chat, for the budget's sake; it keeps the choice in its own few lines rather than stored-setting, and highlights nothing, for the same reason.
  • An add-on that failed to load is tried again. Offline, or across a deploy that replaced its chunk, an add-on's import fails once and useLoaded remembers it: the strip tries the streaming add-on again as the next run starts, a call the json-view add-on as it is opened again; and a thread's page loads the streaming add-on as it opens (prefetchStreaming), so the first turn's phase doesn't wait on a round trip.
  • Bytes. The app's initial budget had 1,279 gzipped bytes to spare. The store's additions and the chat's own (aria-live, the disclosure, the kept partial text) fit; the phase's wording, the throttled status and the token line are the streaming add-on (ui/src/on-demand/streaming.tsx), loaded as the first run streams, with a budget of its own, 1,100 bytes, raised to 1,300 by phase C for the exact chips, the cache and reasoning chips and the model (1,248 bytes as built; what each costs, and what was kept small, is in artifactr ADR-0096's consequences); the store's usage reducer cost the initial 70 bytes, 203,431 of 203,500 as measured. The add-on imports nothing the chat doesn't hold already: an import of Disclosure from it made the bundler split Base UI's collapsible into chunks shared with the chat, which cost 1.7 KB of the initial for nothing. The disclosure is in chat.tsx for that reason. What its summary says once the model has thought, and for how long, is the add-on's (Thought); until it loads, "Thinking…". Until the add-on has loaded, the status says the run's status alone. The json-view add-on has a budget of its own, 2,800 bytes (the owner's decision): first set at 2,000, it grew past that with what review asked of it (a cut value's repair, the caps on depth and count, the long-number note, the per-part toggle and its kept choice, the direction escapes), and none of those could go without breaking what this record promises.

Options considered

Option For Against
The phase from the existing frames (chosen) No wire change; lands now A tool's arguments are counted, not read; no exact tokens
A phase event from artifactr One source of truth A new event for what the frames already say
Coalesce in the store, per animation frame (chosen) One render per frame for the whole thread A later path in Stream
Throttle in Streaming alone Touches no shared code The thread still renders per delta
A text part at or below the last index starts over (chosen) Keeps a response's several text parts; drops a tool call's preface Relies on pydantic-ai numbering from 0 per response
Reset on every text part Simplest Drops a response's earlier text parts
Reset on welcome (chosen) Replay idempotent today A buffer that overflowed loses the head
De-duplicate by offset Exact Needs an offset the frames don't carry yet (phase B)
Thinking as preformatted text (chosen) Cheap; nothing to parse mid-stream No Markdown in thinking
Thinking through Markdown Headings and lists where a model writes them Another streaming parser per delta
Phase wording in an add-on (chosen) Fits the budget; one chunk, cached The first turn's phase line waits a round trip
Raise the initial budget Everything in the first load The owner's ceiling, and a precedent

Consequences

  • Easier: a reader sees that the model is thinking, what call it is preparing and how much of it, and when nothing has come for a while; a stopped or failed turn keeps what it wrote; a reconnect shows nothing twice.
  • Harder: apply takes the clock as a parameter for a run's phase, Date.now() unless a test gives it. The estimate counts characters of messages alone: tool results, system prompts and attachments aren't in it, so it is a floor, said as "at least".
  • Harder: the strip's row of tokens is kept from the start, so the strip holds a line that says nothing yet.
  • Harder: the thinking is held in memory for the run's life, and a model that thinks for pages holds pages; it goes with the reply.
  • Deferred to artifactr (phase B): an offset per delta or a snapshot on watch, usage on a stopped or failed run_ended, an idle watchdog. To phase C: exact counts from UsageUpdate. To phases D and E: the model picker and the cache hint, beside the token line.
  • The streaming text's aria-live="off" and the strip's one status are held by tests: mutating the text adds no live region, and the status excludes the clock.

Action items

  1. client: Live on Run, applyLive, welcome, kept partial text, the store's later telling.
  2. ui: Streaming's disclosure and ended, RunStrip's status, Said and Doing in the streaming add-on; a call's Formatted and Raw in the json-view add-on.
  3. app: partial entries in threadLog; the thread's history for the estimate.
  4. Phase C: exact counts from UsageUpdate and RunEnded.usage.