Skip to content

📏 test: Hold a Long Agent Thread to Count Budgets - #18712

Draft
danny-avila wants to merge 2 commits into
devfrom
danny-avila/thread-count-budgets
Draft

danny-avila wants to merge 2 commits into
devfrom
danny-avila/thread-count-budgets

Conversation

@danny-avila

@danny-avila danny-avila commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Nothing in CI notices when a change makes a long conversation heavier. The costs fixed in #18551, #18555, #18571 and #18580 (a toolbar mounted in every row, a whole thread mounted in one commit, every row rendering on each streamed frame, a document listener per tooltip) were all found by hand with a profiler, after they had merged. Timing them in CI is not an option on shared runners: the same build measures two to five times slower when the machine is busy.

This adds two mock-lane scenarios that open a generated 250-row agent conversation and hold what it costs the page to budgets. Every figure is a count taken from the built client, so it comes out the same on a busy runner as on a quiet one, and a change that goes over one fails before it merges.

Budget What it counts Today Budget
opened Elements in the thread once it has mounted 23,015 24,150
read Elements in it after scrolling back through every row 28,631 30,050
step Rows added in one frame while the thread mounts 32 32
listeners Listeners on document and window after reading every row 263 276
frame Component renders in one streamed frame of a reply 59 or 74 80
around Of those, the renders outside every row 31 34
earlier Renders inside rows that were already there, over a whole reply 1,931 2,600

The conversation the scenarios open is new too. buildThread(rows) generates a thread with the shape of a real working session of about 250 rows (4,667 parts, 3,152 of them tool calls in the same mix of tools, grouped under activity labels and phases, with reasoning between them and user turns long enough to collapse). The same seed gives the same content on every machine, so two builds are measured against the same thread. It is also what a timing run on dev can open later, in place of an exported private chat.

Two of today's figures are costs the counts turned up, left as they are here and to be fixed separately, each fix lowering its budget:

  • frame is 74 instead of 59 once the reply's usage control (ℹ️ feat: Add Conversation Info and Message Usage #17968) has mounted: the control renders again on every streamed frame.
  • earlier is entirely the toolbars of the rows near the reader, rendered five or six times per send because they read the whole chat context for two of its fields.

How it works

e2e/specs/mock/
├── thread.ts                         # buildThread / seedThread: the generated conversation
├── counts.ts                         # the counts, read from the built client
└── scenarios/thread-budgets.spec.ts  # the budgets

Renders are counted through the hook React reports every commit to, which works on the production bundle: a stand-in installed before the bundle loads sees each component that rendered, and a render is attributed to a row when it is below that row's element. frame is the count more commits share than any other, since a reply is a few hundred commits and most of them write one frame of its text; a mean or a median moved with how the frames happened to batch.

A failing run reports every budget the change went over, not only the first, and every run prints what it measured:

thread budgets (measured/budget): opened 23015/24150, read 28631/30050, step 32/32, listeners 263/276
thread budgets (measured/budget): frame 74/80, around 31/34, earlier 1931/2600

Elements are counted inside the thread, and the scenarios clear the user's other conversations first. The first CI run of this pull request showed why: the sidebar there listed 24 conversations left by earlier specs, which added 445 elements and 72 window listeners (each listed conversation registers keydown, keyup and blur on the window through useShiftKey).

The seeded conversation carries the agent id a first turn on the provider saves. Without it the reply sent by the test is the turn that sets it, every row renders again for the conversation it now reads, and earlier measures the seed instead of the app.

Type of change

  • Tests / tooling / CI

Testing

Tested environments/configuration:

  • Chromium, mock e2e lane against the production client build, viewport 1280 x 800.

Automated tests:

  • thread-budgets.spec.ts: 17 runs of each scenario locally. The four document counts were identical in every run; around was 31 in every run; frame was 59 or 74 and earlier 1,635 or 1,931, all inside their budgets.

  • The budgets fail when they should. Against a build with five deliberate breaks (every toolbar mounted, the mount chunk unbounded, the row and message memos returning false, a keydown listener per row) both scenarios failed with:

    opened 29630/25200, read 29630/31100, step 234/32, listeners 513/276
    frame 2451/80, around 1666/34, earlier 210333/2600
    

    (Taken while elements were still counted over the whole document, hence the larger opened and read figures.)

    read holds there, as it should: it counts what every row weighs once read, which none of those breaks changed.

  • long-conversation-mount.spec.ts and offscreen-rows.spec.ts still pass beside it (16 scenarios in all).

On a hosted runner the first CI run read the same step and the same per-frame figures as locally (frame 74, earlier 1,635). opened depends on how many rows fit near the viewport, which follows font metrics, so it has 5% of headroom.

Screenshots / recordings

No user-facing change.

Risk / compatibility

Test-only. The two scenarios add about 40 seconds to the mock lane. A budget can fail a pull request for a cost it means to add; the README section says when to raise one and when to lower one.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors
  • User-facing or complex behavior is documented where necessary
  • Required dependency changes have been merged/published
  • Required documentation PR: N/A

This branch has not been deployed

No deployments
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.

1 participant