Skip to content

Studio tests: count the work in the prose-call amortization test instead of timing it - #16315

Merged
danielhanchen merged 1 commit into
mainfrom
fix-stripper-call-amortized-count
Oct 31, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-stripper-call-amortized-count

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

studio/backend/tests/test_streaming_stripper.py::test_prose_containing_the_word_call_is_still_amortized failed in (Python 3.13, a-f) on #16311, a frontend-only PR:

AssertionError: incremental cost grew 5.7x vs the reference's 8.6x on prose containing the word 'call'

The test timed 300 and then 1200 tokens once each and required the stripper's growth to stay under half of the reference strip's growth. Both measurements take a few milliseconds (about 1 ms and 4 ms locally), so on a loaded runner the linear code read 5.7x and the quadratic reference only 8.6x, where 4x and 16x are expected. The code under test is unchanged on main. The timing was what flaked.

Change

The test now counts work in the same way test_scan_is_amortized_not_quadratic above it already does. It counts the characters handed to _first_sentinel and to StreamingMarkupStripper._full_strip, and it also asserts that the prose comes back unchanged on every token. The counts are deterministic:

300 tokens 1200 tokens growth
main 13,132 51,832 (2.7 per buffer character) 3.9x
_first_sentinel returning every bare call unconfirmed 722,400 11,529,600 (600 per buffer character) 16.0x

The assertion requires under 8x growth and at most 8 characters of work per buffer character.

Verification

  • The new test passes on main, and the whole file passes 67/67 three times under -n 4.
  • Sabotage: with the confirmation in _first_sentinel removed, so that any bare call counts as a sentinel, the test fails with work grew 16.0x for 4x the tokens (722400 -> 11529600 characters over a 19200-character buffer). That is the regression the test was written for in Studio: stop rescanning the whole answer on every streamed token #8538.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T17:10:56.421281Z fee1ab8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: fee1ab8364

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit e5f465e into main Oct 31, 2026
@danielhanchen
danielhanchen deleted the fix-stripper-call-amortized-count branch October 31, 2026 17:15
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