Repository navigation
studiobench: a window's stream-cost integrity is about one response - #9609
Conversation
`StreamCostInstrument.close` refuses a window whose opening buffer held half a frame AND which then counted that frame. That pair is the thing that actually makes the denominator wrong: characters delivered before the window opened, counted inside it. The two halves were read at two different scopes. `pending` lives on the per-decoder state; `carriedFlushes` was page-global on `S`, so any decoder could move the counter that was supposed to be about that one buffer. `send_turn` follows `stop_generation` in all three shipped schedules, and `stop_generation` exists to cut a socket mid-frame. So the abort's orphaned half frame was routinely paired with a carried flush produced by the NEW response's own split, and a window that had delivered every one of its characters was refused for a buffer that never flushed. Measured against the real instrument in Chromium rather than argued: a two-chunk reply after an abort delivers all 13 of its characters inside the window and is refused, while the same traffic with no abort in front of it is accepted. A refused window is dropped outright, and reads go ragged exactly when the renderer is jammed, so the loss falls on the most expensive windows. That is the flattering direction on cost per character. ## What changed `carriedFlushes` moves onto the decoder's own state beside `pending`, and `wireIntegrity(id)` answers about a NAMED decoder whose id `open` records and `close` passes back. Named rather than compared at the two ends, and that distinction is the whole fix. A same-id-at-both-ends check gets the important case wrong: the response pending at the open can complete its carried frame INSIDE the window and then be replaced as the active decoder before the close, and an id comparison would see two different ids, discard exactly the carry it is looking for, and accept a window whose denominator really is wrong. Asking about the named decoder answers regardless of who is active now. Two details that would otherwise bite later. The sentinel `active` is built by the same constructor as a real decoder state rather than by hand, or a window opening before the first stream reads `undefined` where it wants zero. And the id map holds integers and no `TextDecoder` reference, so it cannot defeat the WeakMap scoping the previous fix introduced; it is bounded on the same discipline as `MAX_PENDING_CHARS`. No payload key changes. `decoder_id` is an argument between `streamcost.py` and `streamcost.js` and never reaches a row, so `INTERFACES.md` has nothing to add and the reasoning lives in the instrument. ## Tests Three new, and the second and third are the ones that matter: - the fragmented response after an abort is scoreable - the counter is shown still to MOVE, asked of the decoder that owns the split, so the first test cannot pass against an instrument that has simply stopped counting carried flushes, which would take the genuine straddle refusal down with it - a frame that really did straddle the window open still refuses its window, with another decoder active at the close, which is the case the rejected id-comparison fix would break Mutation: put the counter back on a page-global and the first fails with `assert 1 == 0` on `wire_carried_frames_counted_in_window`. Four existing exact-dict assertions gain the new key, on the same tolerance idiom they already use for `carried_flushes` beside it. `pytest tests/studio/studiobench -q`: 1301 passed, up from 1298. `ruff` clean. Follow-up to #9439, where this was accepted as a real residual on the fix made in that PR and deliberately left open.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe690726d0
ℹ️ 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".
| pending_chars: active.pending.length + heldMarkerChars(), | ||
| // WHICH decoder the two numbers above are about, so the close can ask about the same one. | ||
| decoder_id: active.id, |
There was a problem hiding this comment.
Preserve the owner of a held marker fragment
When a new decoder has emitted only a partial data: marker at window open, pending_chars includes that decoder's markerHold, but decoder_id still names the previously active decoder (or the sentinel). If the new decoder completes its frame inside the window, its carried counter increments, while close() queries the unrelated ID and observes a zero delta; with no residual or parse failure, the window is incorrectly marked scoreable even though its denominator includes a frame that began before the window. Return integrity ownership for the held marker as well, or otherwise track every pending owner's carried count.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced the mechanism exactly as described and it does not reach the consequence, so no change here.
Driven in chromium: decoder A completes a frame, the response ends, decoder B's first chunk is dat. At the open pending_chars=3 and decoder_id=2, which is A, so B's carried flush inside the window is invisible and the window closes scoreable. That part is right.
The window is scoreable correctly, though. markerTail is at most four characters of the literal data: and setMarkerTail is only ever reached on the branch where pending is empty, so a held fragment carries ZERO denominator characters. In that run reply_chars_delta came out 5 for hello, every character of it delivered after the open. The refusal exists for a buffer whose characters were delivered before the window and counted inside it, and that case is a real pending half frame, which lives on the decoder that is active by construction, is named by decoder_id, and still fires (test_a_window_that_opens_on_a_half_delivered_frame_is_not_scoreable).
Widening ownership to the marker holder would refuse that window instead. Pinned in f2a27da as test_a_marker_fragment_held_at_the_open_does_not_cost_the_window_its_reading, which goes red under exactly that change (decoder_id: (markerHold || active).id) while the other 24 stay green.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
StreamCostInstrument.closerefuses a window whose opening buffer held half a frame ANDwhich then counted that frame. That pair is the thing that actually makes the denominator
wrong: characters delivered before the window opened, counted inside it. The two halves
were read at two different scopes.
pendinglives on the per-decoder state;carriedFlusheswas page-global on
S, so any decoder could move the counter that was supposed to be aboutthat one buffer.
send_turnfollowsstop_generationin all three shipped schedules, andstop_generationexists to cut a socket mid-frame. So the abort's orphaned half frame was routinely paired
with a carried flush produced by the NEW response's own split, and a window that had
delivered every one of its characters was refused for a buffer that never flushed.
Measured against the real instrument in Chromium rather than argued: a two-chunk reply
after an abort delivers all 13 of its characters inside the window and is refused, while
the same traffic with no abort in front of it is accepted. A refused window is dropped
outright, and reads go ragged exactly when the renderer is jammed, so the loss falls on the
most expensive windows. That is the flattering direction on cost per character.
What changed
carriedFlushesmoves onto the decoder's own state besidepending, andwireIntegrity(id)answers about a NAMED decoder whose idopenrecords andclosepassesback.
Named rather than compared at the two ends, and that distinction is the whole fix. A
same-id-at-both-ends check gets the important case wrong: the response pending at the open
can complete its carried frame INSIDE the window and then be replaced as the active decoder
before the close, and an id comparison would see two different ids, discard exactly the
carry it is looking for, and accept a window whose denominator really is wrong. Asking
about the named decoder answers regardless of who is active now.
Two details that would otherwise bite later. The sentinel
activeis built by the sameconstructor as a real decoder state rather than by hand, or a window opening before the
first stream reads
undefinedwhere it wants zero. And the id map holds integers and noTextDecoderreference, so it cannot defeat the WeakMap scoping the previous fixintroduced; it is bounded on the same discipline as
MAX_PENDING_CHARS.No payload key changes.
decoder_idis an argument betweenstreamcost.pyandstreamcost.jsand never reaches a row, soINTERFACES.mdhas nothing to add and thereasoning lives in the instrument.
Tests
Three new, and the second and third are the ones that matter:
first test cannot pass against an instrument that has simply stopped counting carried
flushes, which would take the genuine straddle refusal down with it
decoder active at the close, which is the case the rejected id-comparison fix would break
Mutation: put the counter back on a page-global and the first fails with
assert 1 == 0onwire_carried_frames_counted_in_window.Four existing exact-dict assertions gain the new key, on the same tolerance idiom they
already use for
carried_flushesbeside it.pytest tests/studio/studiobench -q: 1301 passed, up from 1298.ruffclean.Follow-up to #9439, where this was accepted as a real residual on the fix made in that PR
and deliberately left open.