Skip to content

Have each leaf command record its own duration, and read Leaf's share from it - #3403

Merged
max-sixty merged 11 commits into
mainfrom
agent-ad936791c59f7ff86
Oct 21, 2026
Merged

max-sixty merged 11 commits into
mainfrom
agent-ad936791c59f7ff86

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Leaf's share of an agent's reply was read from the harness transcript: any tool call whose text named leaf counted whole. That was an upper bound, because a shell command that runs leaf among slower work counted entirely, and Codex and Pi pages got nothing. Now every leaf command records its own duration in the page it acted on, and leaf-dev response-times and leaf-dev journey read Leaf's share from those records. The transcript classifier is deleted.

The record

interaction_log.record_command appends one leaf_command observation to observations.jsonl as a command exits. It holds command (its words, such as response reply), started, durationMs, session and context.

  • Which pages. A command acts on the pages it names: an initialized page given as a PAGE argument (cli.resolve_dir), an answer reference's page (delivery.response_address), or every page a delivery it reads or acknowledges carries. Each notes its page with acting_on. page init, which creates or re-vendors a page, records nothing, so a refused or unchanged init still writes nothing to the page.
  • Timing. The time runs from the launcher's start, which includes bin/leaf's uv, when this process's parent runs python -m leaf with the same arguments. Otherwise, as for Codex's MCP tool or the sandbox bridge, it runs from the process's own start. On a scratch page, page check recorded 208.8 ms where /usr/bin/time read 220 ms.
  • What records nothing. A command that names no page, such as leaf wait watching a session's pages, records nothing. One that names a page and then waits, such as leaf wait --ack, records its own work when it starts waiting. Harness hooks don't pass through the CLI, and their time shows as delivery in the pickup receipts.
  • Failure and cost. Gathering or writing the record can't change a command's result. A sandbox that refuses the session record or a page drops the diagnostic, and each page's write fails alone. Recording costs about 7 ms per command.

Reading it

reply_phases.reply_breakdown takes the session's command records. Leaf's share is the time covered by delivery or a command, each moment counted once. A command counts when it started after the comment's admission (or, for a working harness, after the boundary where the harness took the comment) and before the reply, clipped at the reply's admission. response-times gives every answered input leaf_commands_s on any harness: the answering session's commands from the transcript's take boundary where available, otherwise from its opened pickup or admission, to its answer. Without a transcript, that fallback can miss commands run before the agent acknowledges a pointer it read itself. It also adds a leaf_commands summary row. The journey reads its claimant's records. One validation journey per harness recorded every command, including Codex's MCP-tool calls.

Tests

page interactions used to leave the diagnostics file byte-identical; it now leaves every existing record unchanged and appends its own. The Codex stream test removes the file setup now creates before making the path a directory.

Review

An independent Codex review ran over two rounds and found eight issues. All are fixed here: metadata collection could fail a command; overlapping commands counted twice; a reply by reference recorded into every page of its delivery; leaf wait --ack counted its wait; one unwritable page suppressed other pages' records; commands outside tool phases reduced other tool time; and the journey didn't filter by session.

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

max-sixty and others added 9 commits October 20, 2026 16:37
… removing its home

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A reply by reference records into its own page, not every page its
delivery carries; gathering the record can't fail the command; overlapping
commands and delivery count once; the journey reads its claimant's commands.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ge's record apart, and count a working reply's commands from its boundary

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.

leaf_commands_s includes Leaf work from the turn already running when a new comment arrives. For example, with the comment admitted at 1 s, a command running from 2–4 s, pickup at 5.2 s, and the answer at 12.5 s, leaf_commands_ms reports 2,000 ms for that command. The reply breakdown correctly excludes it as busy. This overstates the new per-input metric, especially for working inputs, and makes it disagree with leafCommandsMs for the same reply. Bound the summary to the point where the harness took the comment, or label and report it as admission-to-answer command time rather than Leaf's share of the reply.

…t's commands from where the harness took it

A refused or unchanged page init writes nothing to the page, as before; a
working harness's commands for its other work stay out of the input's
leaf_commands_s.

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.

leaf_commands_s now starts at the opened pickup, but the agent can run Leaf commands after the harness takes an input and before it records that pickup. reply_breakdown accounts for this when the agent reads and acknowledges a delivery itself. With admission at 1 s, the harness taking it at 5 s, a Leaf command from 7–8 s, pickup at 9.2 s, and an answer at 12.5 s, I get leaf_commands_s: 0 while leafCommandsMs: 1000 for the same reply. The new metric therefore omits Leaf work on this input. It needs the same take boundary as the reply breakdown; for harnesses without that boundary in their records, the summary should say what its pickup-based measurement covers.

…cript gives one

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit e6ce91d into main Oct 21, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-ad936791c59f7ff86 branch October 21, 2026 01:34
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