Skip to content

Benchmark each reply's whole time and Leaf's share, with the harness waiting and working - #3387

Merged
max-sixty merged 17 commits into
mainfrom
agent-ad936791c59f7ff86
Oct 20, 2026
Merged

max-sixty merged 17 commits into
mainfrom
agent-ad936791c59f7ff86

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Max asked that the reply benchmark record both Leaf's share and the whole reply, and cover two cases: a comment that reaches a waiting harness and one that reaches a working harness. This change makes leaf-dev journey and leaf-dev response-times report both numbers for every reply. The whole reply is broken into its model calls. The note notes/user-feedback-responsiveness.md gets budgets for each number and case, a measured table on current main, and the model calls a small page change should take.

The benchmark

  • One home for a reply's breakdown. dev/leaf_dev/reply_phases.py splits the span from a comment's admission to its reply into phases. busy is the harness on other work before it takes the comment, delivery runs until the comment is in the agent's context, and the rest is model, tool and idle time between turns. reply_breakdown sums the phases into the whole reply and Leaf's share (delivery plus tool phases that run leaf). It also groups model phases into the model calls the harness made, each with the tool calls it issued. The journey's old turn_phases moved here.
  • Harness records carry turns and responses. Each harness's normalized record marks where a model response ended and where a turn started and ended, using the harness's own signals. Claude Code's transcript gives the last record of each message id, turnPosition, turn_duration and interruptedMessageId. Codex gives thread/tokenUsage/updated, turn/started and turn/completed. Pi gives turn_end, agent_start and agent_settled.
  • Two cases in every harness journey. journey.CASES names them. The release ask reaches a waiting harness. The mid-turn step now asks for the same small page change, naming a release of its own, while the harness runs the user's 25 s command. Each step requires a revision that names its release. Each sample says which comment asked for which case.
  • The table. uv run leaf-dev journey-chart --replies tabulates the kept samples by target and case.
  • Real pages. leaf-dev response-times adds the breakdown for inputs that Claude Code answered, reading the transcript it finds by session id. On real pages Leaf's share is an upper bound, because a shell command that runs leaf among slower work counts whole.

Readings on current main

Four Claude Code journeys and three each on Codex App Server and Pi, at this branch on main 23acce2b1. Seconds:

Harness Case Whole reply Leaf's share After the boundary Model calls
Claude Code waiting 21.9–45.2 1.1–8.7 21.9–45.2 4–8
Claude Code working 35.5–41.9 0.9–1.2 10.8–17.0 2–3
Codex App Server waiting 14.1–19.4 0.5–0.9 14.1–19.4 4–5
Codex App Server working 38.6–43.1 0.7–0.8 13.9–18.4 3
Pi waiting 31.0–33.0 1.0–1.5 31.0–33.0 8–10
Pi working 40.0–41.7 0.7–0.8 14.8–16.5 6

In the working case the harness was busy with the user's command for 24.5–25.2 s first, so the working budget counts from that boundary. Leaf's share was 0.5–1.5 s in 19 of 20 replies; the exception ran leaf page check --render. The model takes the rest. The proposed budgets are Leaf's share under 2 s in both cases, and a whole reply of Leaf's share plus two model calls. The note says which calls the replies spent beyond two: widget and registry lookups, and reference reads on a session's first comment. It also says why the two cases differ in more than the harness's state.

Codex App Server ran main's delivery after the revert of #3357 (#3362) and #3368: Leaf starts a turn for an idle task, and the tool hook delivers inline to a working one. Earlier batches on #3357's queue path, before #3368 and #3372 landed, showed the two calls those changes removed.

Review

An independent Codex review ran over three rounds against real transcripts and the kept runs. It found idle gaps counted as model time, an idle harness read as busy, local commands and compaction summaries starting turns, and end_turn blocks ending turns early. All of these are fixed and checked on the page it used. The remaining limit is on real pages: Leaf's share counts a whole shell command that runs leaf among other work. The note proposes that each leaf command record its own duration.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 15 commits October 20, 2026 13:32
…waiting and working

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…alls by the response that follows them

Codex App Server records the opened pickup when the agent acknowledges the
pointer its hook handed over, and reports each response's token usage after
the calls it started return; Pi's turn_end does the same.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A real page's reply can span the harness's idle time, and a comment admitted
to an idle harness is not one it was busy before. Each harness record now
marks where its turns start and end: busy needs a turn running at the
admission, a pointer the agent acknowledges ends delivery at the turn that
took it, and time between turns is idle rather than model time.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nd and Leaf's share as an upper bound

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	dev/leaf_dev/commands/response_times.py
… busy turn ended

Claude Code marks the input that starts a turn with turnPosition and ends
the turn with a turn_duration record once its Stop hooks let it stop; a
local command starts no turn, and a response's end_turn blocks don't end one.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ction's summary

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The working-case split can charge another tool's runtime to Leaf. _phases ends busy at the first tool_result, but Claude Code delivers pending input at PostToolBatch, after the batch's tools finish. With two tools already running when the comment arrives, one returning at 2 s and the other at 10 s, and pickup at 10.2 s, reply_breakdown reports 1 s busy and 8.2 s delivery. That 8.2 s becomes leafMs, even though Leaf has not handed the comment over. Keep the outstanding tool IDs at admission and end busy when the batch drains or the turn ends; a parallel-tool case would protect the benchmark's central Leaf-share reading.

…eturned

Claude Code hands pending input over at PostToolBatch, once the batch drains,
so the boundary is where no call is out, not the first result. Re-deriving
the 20 replies the note reports from their evidence gives the same numbers.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interrupted earlier turn can leave a tool_use without a tool_result: claude_code_records maps interruptedMessageId to turn_end without synthesizing a result. drained() keeps that old ID in out across the next turn_start, so it misses the next batch's actual drain. In a normalized sequence with the old turn ending at 2 s, the new tool running from 4–6 s, a comment at 5 s, and pickup at 6.2 s, reply_breakdown reports 0 ms busy and 1,200 ms delivery instead of 1,000 ms busy and 200 ms delivery. This inflates the benchmark's central leafMs reading. Reset outstanding IDs when a new turn begins, and cover an interrupted prior turn in the timing case.

Comment thread dev/leaf_dev/reply_phases.py Resolved
@max-sixty
max-sixty merged commit d91b67b into main Oct 20, 2026
5 checks passed
@max-sixty
max-sixty deleted the agent-ad936791c59f7ff86 branch October 20, 2026 23:35
max-sixty added a commit that referenced this pull request Oct 21, 2026
…3411)

The reply benchmark compared a waiting harness and a working one, but
the working ask came second in the same session. It had read Leaf's
references already and only added a release to the record the first ask
had built. Now each journey runs one case, chosen with `leaf-dev journey
TARGET --case waiting|working`. In both cases the small page change is
the fresh session's first comment, so the two start from the same page
and context.

## The benchmark

- **Two cases on one ask.** With `--case working`, the release ask is
sent while the user's own turn runs its 25 s shell command
(`Terminal.work`, which each harness module implements once and reuses
in its steps). The sample records its `case`.
- **The `mid-turn` step asks a question again.** It checks delivery
mid-turn, as before #3387. The `CASES`/`markers` machinery and the
second page-change ask are deleted.
- **The table.** `journey-chart --replies` groups samples by target and
case. `--since ISO` reads every sample kept since that time, for a batch
whose commits leave the plugin unchanged. This batch straddled a
`response-times`-only commit.

## Readings

Two journeys per harness and case, 18:10–18:42 PT, load average 5–19 on
18 cores, with Leaf's share read from each command's own record (#3403).
Seconds:

| Harness | Case | Whole reply | Leaf's share | After the boundary |
Model calls |
| --- | --- | --: | --: | --: | --: |
| Claude Code | waiting | 12.4–13.3 | 0.7 | 12.4–13.3 | 3 |
| Claude Code | working | 42.8–60.7 | 0.6–0.8 | 18.1–36.0 | 3–8 |
| Codex App Server | waiting | 18.4–33.0 | 0.4–0.5 | 18.4–33.0 | 4–5 |
| Codex App Server | working | 51.1–56.3 | 0.8 | 26.3–31.8 | 4–5 |
| Pi | waiting | 34.1–40.0 | 1.2–1.3 | 34.1–40.0 | 8–9 |
| Pi | working | 51.3–56.0 | 0.9–1.0 | 26.5–31.3 | 7–9 |

Leaf's share was 0.4–1.3 s in all twelve replies. Once the harness had
the comment, neither case was consistently quicker. The wait for the
boundary, the user's own 24.5–24.9 s command, made the difference in the
whole reply. The note (`notes/user-feedback-responsiveness.md`, "A small
page change's reply") gives the per-call detail and replaces the earlier
same-session table.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 22, 2026
Benchmark a reply by its time, attributed to where it went

The reply benchmark now measures the time from the user's comment to the
agent's reply and attributes all of it, each moment once, instead of
counting model calls. This follows Max's decision #40 on the overnight
report: a count of model calls is a noisy proxy for the time the user
waits, so the benchmark and the note's budgets are now in seconds.

`reply_phases.reply_breakdown` splits a reply into:

- Leaf's share: delivery, Leaf's commands, and now Leaf's hooks where
the harness times them;
- the harness's own work before each request;
- the model's wait for the stream's first output and its generation,
with each response's output tokens;
- the agent's other tools, the harness's busy time and idle time.

Each harness's record supplies a different part of this:

- **Claude Code**: the journey reads its debug log. It pairs each first
byte with its request by the elapsed time the log line states, so a
prompt-suggestion stream running alongside isn't mistaken for the main
thread's. The transcript gives each response's output tokens.
- **Pi**: the first stream event and output tokens come from its RPC
events.
- **Codex App Server**: its hook durations and per-response token usage
come from App Server notifications. App Server reports no request or
stream start, so Codex's model time stays unsplit.

The journey now breaks the release reply down once, after the session
ends, from its whole record. The call that replied keeps its tokens, and
reading Claude Code's transcript while it is still being written can no
longer fail the journey on a partial line.

`leaf-dev journey-chart --replies` prints a table with one column per
target and case. Each part shows its mean and its share of the whole
reply, and the parts add up to it. Model calls and output tokens remain
only as diagnostic rows.

`notes/user-feedback-responsiveness.md` now carries:

- a fresh batch of 18 journeys, three per harness and case;
- which parts each harness gives exactly and which are inferred or
missing;
- budgets in seconds: whole reply under 15 s, Leaf's share under 2 s.

In waiting replies the model took 82–92% of the time, mostly generation:
Claude Code generated at about 100 tokens a second, nearly all of it
thinking. Leaf's hooks took 1.0–1.6 s a reply on Claude Code and Codex;
nothing counted them before this change.

The TODO entry asking what the reply budget counts is removed: the
budget counts the whole reply. The website journey test's fake
`run_journey` and its expected sample were stale against #3387 and
#3403. They now take `commands` and expect `case`.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants