Skip to content

studiobench: refuse a streamed tail the corpus cannot deliver - #9659

Merged
danielhanchen merged 2 commits into
mainfrom
studiobench-tail-shortfall
Aug 25, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studiobench-tail-shortfall

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What this fixes

--stream-tail-chars N is documented as the only way to vary reply length in this tool. It silently under-delivered, and in a way that corrupted the rung label at the same time.

Two effects compound, and fixing only the one you notice leaves the other:

  1. The streamed tail is one corpus unit, and clipped_to returns the unit unchanged when the ask exceeds it (fixture/corpus.py, if chars >= self.chars: return self). Delivery is capped at that unit's size.
  2. Asking for more tail lowers that cap rather than raising it. A bigger tail shrinks seed_target, which moves the streamed turn to a lower index, and the corpus escalates in size. At the extreme the seeded prefix is evacuated entirely and the rung's thread goes with it.

Measured at 100K with a 400,000 character request, before this change:

quantity asked delivered
streamed reply 400,000 15,405 (3.9%)
thread total 397,755 18,122 (4.6%)

The cell still carried the r100K id that scoring/from_payload.py and report/build.py use as the rung key, so an 18,122 character thread was recorded, weighted and reported as the 100K rung.

The check that should have caught it goes quieter as the input gets worse. --assert-liveness returned 0 scene problems, 0 missed slots, exit 0, byte-identical to the default run, because a saturated tail drains faster than the film it was supposed to outlast. That is the shape of catalogued defect 13: a gate that cannot report the other answer is not a gate.

Delivery across the ladder, before and after

ok = accepted, and every accepted pair now lands within 10% of the request with the thread within 5% of the default. Every refused pair is one that previously under-delivered silently.

tail 1K 10K 100K 500K 1M
default 3,883 4,832 4,642 5,420 5,994
24,000 refused refused 23,831 23,803 23,749
48,000 refused refused 47,617 46,566 47,555
96,000 refused refused 95,762 94,892 94,941
200,000 refused refused refused 198,928 199,340
400,000 refused refused refused refused refused

Before, those refused cells returned 15,405 / 11,374 / 133,113 / 306,669 / 290,984 characters with no warning of any kind.

Why a mechanism predicate and not a tolerance

The guard keys on clipped_to's own early return, not on a percentage. The two ways a tail lands under its budget are different in kind and only one is a defect:

  • Block-boundary clipping loses at most one block, and it is load bearing: a character-aligned prefix can end inside a fence, and an unclosed fence is a different Streamdown path with a different cost.
  • Exceeding the unit loses everything above it and is unbounded.

A percentage bound cannot separate those, and a bound nobody can derive is an unacknowledged bias rather than a tolerance.

The default ladder is untouched

The guard is scoped to an explicit request. STREAM_TAIL_CHARS = 6_000 is a ceiling the small rungs are legitimately under (the 1K rung is 4,000 characters in total, less than one tail), and that shortfall is the rung being small rather than the corpus failing to answer. Default numbers do not move by a character at any rung.

Test coverage, and an honest note about it

test_studiobench_reply_axis.py already asserts the right property, reply within 10% and thread within 5%, but only at the 100K rung and only at 24,000 and 96,000. Re-running its own two assertions across the ladder, 10 of 15 (rung, tail) pairs failed them. The shipped test covered exactly the 2 that passed. A test can be right about the property and wrong about the coverage; the new file is the matrix.

Teeth confirmed by mutation, each restored from a byte snapshot with md5:

mutant result
guard deleted 12 failed
refuse every explicit request 9 failed
restore the wrong "ask for at most N" advice 1 failed
drop the thread-collapse clause from the message 1 failed
raise STREAM_TAIL_CHARS above the smallest unit 1 failed

One mutant is NOT caught and the test file says so. Dropping the stream_tail_chars is not None exemption leaves all selftests passing and the default ladder byte-identical, because STREAM_TAIL_CHARS (6,000) is below the smallest corpus unit (11,374), so the guard's other half cannot fire on the default path. That clause is defensive, not load bearing. Rather than fake coverage of an unreachable branch, test_the_default_exemption_is_currently_unreachable_and_says_so pins the premise, so a re-freeze with smaller units or a raised constant fails loudly and someone re-checks.

A wording bug this shipped with for one revision

The first draft of the refusal said "ask for at most 15,405 characters". That is confidently wrong: the ceiling rises as the request falls, because a smaller tail leaves a longer seeded prefix which draws the streamed turn from a larger unit. At 100K it would have told the reader to ask for at most 15,405 while 96,000 succeeds, a factor of six in the direction that makes someone abandon a measurement they could have taken. A refusal that names the wrong number is worse than a vaguer one. test_the_refusal_does_not_name_a_maximum_it_has_not_computed pins it.

No re-freeze is needed, and please do not do one by analogy

corpus_hash covers eight generator parameters plus each unit's sha256. STREAM_TAIL_CHARS is not among them, freeze() never reads it, and clipped_to produces a read-time prefix that never touches units.jsonl. Verified across tails from 6k to 200k: the hash stays 23cd2464.... Task #118's re-freeze was driven by manifest_unit_count, a different lever. This change is hash-neutral, so everything measured before it remains comparable.

A suspicion I checked and withdrew

While tracing this I suspected that nothing mechanically refuses to pool payloads taken at different tails, on the grounds that scoring/ab.py's COMPARABILITY_FIELDS does not mention stream_tail_chars. That was wrong and I am recording it rather than quietly dropping it. scoring/ab.py is an intra-payload backstop whose only caller builds both identities from one dict. The real cross-payload key is scoring/payload_rules.py, which does carry stream_tail_chars, and three gates refuse on it: --compare exits 1, floor_table.render raises, and --resume refuses under a changed tail. There is also an existing producer-in-the-loop test that enumerates the field list rather than hard-coding it. No change was needed and none was made.

Scope

This does not change what the rung ladder varies, and it is not a venue claim.

The ladder pins the streamed tail at 6,000 on every rung deliberately, and that pin should stay. It is a one-way fix: the tail originally grew with the rung, and it was pinned because at field cadence the stream drained in 811 s at 1M against a 135 s film, so every slot labelled "after the reply is complete" ran mid-generation. Scaling it back would also make analysis/fit.py's published exponent unidentifiable, since a tail proportional to the rung reports b = 1.00 for a purely reply-driven cost that never touches the thread, and fit.py reads b ~ 1 as "linear in thread length".

What this change does is make the orthogonal axis trustworthy, so that a reply-length measurement at a large rung either happens or fails loudly.

Testing

  • tests/studio/studiobench: 1442 passed.
  • ruff check tests/studio/studiobench: clean.
  • AST sweep for duplicate names in a single ImportFrom across the package: 0.
  • git status --porcelain diffed before and after the full test run: no stray files.

danielhanchen and others added 2 commits August 25, 2026 00:58
`--stream-tail-chars N` is the only way to vary reply length in this tool, and it
silently under-delivered. The tail is one corpus unit and `clipped_to` returns the
unit unchanged when the ask exceeds it, so delivery is capped at that unit's size.
Asking for more tail lowers that cap rather than raising it: a bigger tail shrinks
`seed_target`, which moves the streamed turn to a lower index, and the corpus
escalates in size.

Measured at 100K with a 400,000 character request: 15,405 characters streamed
(3.9%) on a thread of 18,122 against the rung's 397,755 (4.6%), still carrying the
`r100K` cell id that scoring and the report use as the rung key. `--assert-liveness`
returned 0 scene problems, 0 missed slots, exit 0, byte-identical to the default
run, because a saturated tail drains faster than the film it was meant to outlast.

The guard keys on `clipped_to`'s own early return rather than on a percentage,
because the two ways a tail lands under budget differ in kind: block-boundary
clipping loses at most one block and keeps a prefix from ending inside a fence,
while exceeding the unit is unbounded. The default ladder is untouched.

The existing reply-axis test asserts the right property at the 100K rung with
24,000 and 96,000 only. Across the ladder, 10 of 15 pairs failed its own two
assertions; it covered exactly the 2 that passed. The new test is the matrix.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c6decfe44

ℹ️ 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".

# The DEFAULT path is exempt on purpose: `STREAM_TAIL_CHARS` is a ceiling the small rungs are
# legitimately under (the 1K rung is 4,000 characters in total, less than one tail), and that
# shortfall is the rung being small rather than the corpus failing to answer.
if stream_tail_chars is not None and tail_target >= source.chars:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow tails equal to the source unit

Using >= rejects requests that the corpus can deliver exactly. For example, plan_rung(corpus, "100K", stream_tail_chars=133_113) selects unit 8, whose size is exactly 133,113 characters; the resulting thread would be 399,282 characters against the 400,000 target, yet this branch raises and even reports that the reply would be 100.0% of the request. Since clipped_to returns the complete unit when the sizes are equal, only requests strictly larger than source.chars should be refused.

Useful? React with 👍 / 👎.

Comment on lines +1038 to +1040
f"the reply would be {deliverable / requested:.1%} of the one asked for. Asking for more "
f"tail makes this worse rather than better, because the seeded prefix shrinks to pay for "
f"it and the streamed turn moves to a smaller unit -- here the thread would collapse to "

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid claiming larger tail requests always reduce capacity

The frozen unit sizes are jittered rather than monotonic, so moving to a lower source index does not necessarily select a smaller unit. At the 100K rung, a 119,000-character request selects unit 9 (118,955 characters) and is refused, but increasing the request to 133,000 moves it to unit 8 (133,113 characters) and succeeds. The message therefore sends users in the wrong direction when it says increasing the request necessarily makes matters worse and advises only lowering it; describe the non-monotonic selection instead.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit b0962ef into main Aug 25, 2026
29 checks passed
@danielhanchen
danielhanchen deleted the studiobench-tail-shortfall branch August 25, 2026 02:20
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