Repository navigation
Assert the preset sheet subscribes, not how the subscription is spelled - #11065
Conversation
main is red on Repo tests (CPU, studio): AssertionError: the preset sheet never subscribes to reasoningBudget, so a change to it does not re-render the component whose memos capture it It does subscribe. af4e98e made the selector conditional over several lines while still reading s.reasoningBudget, and both memo dependency lists still name the field, so the behaviour the test documents holds. What broke was the test requiring the literal (s) => s.reasoningBudget and counting the field at two fixed indentations. Parse the useChatRuntimeStore() selectors and the useMemo() dependency arrays and assert membership. Dropping the subscription or either dependency entry still fails; reformatting no longer does.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security review |
Two holes in the previous version, both from the Codex review. zustand compares the value a selector returns, not the properties it touched, so a selector naming the field in its condition and returning something else in every branch read the store without tracking the field and still passed. Split the selector body on its ternaries and require every result to depend on the field. And the regex hardcoded the parameter name `s`, so renaming it to `state` failed a refactor that changes nothing, which is the spelling sensitivity this was supposed to remove. The name now comes from the selector's own signature.
acd79ad to
a92a4d3
Compare
|
Both review rounds landed on
It also checks what the selector returns rather than what its text mentions. zustand re-renders on the returned value under @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01f9918afa
ℹ️ 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".
| elif depth == 0 and char == ":": | ||
| return _split_ternary(expression[question + 1 : index]) + _split_ternary( | ||
| expression[index + 1 :] | ||
| ) |
There was a problem hiding this comment.
Match the colon to its owning conditional
For an unparenthesized nested conditional in the true arm, this loop treats the nested conditional's colon as the outer conditional's colon because it tracks bracket depth but not conditional depth. For example, cond ? nested ? state.reasoningBudget : state.other : state.reasoningBudget is split into arms that both textually contain reasoningBudget, so _selector_reads returns true even though the state.other path does not depend on that field. Track nested ? operators while locating the matching : so this regression cannot pass the guard.
Useful? React with 👍 / 👎.
| results = _split_ternary(body) | ||
| return bool(results) and all( | ||
| re.search(rf"\b{parameter}\.{field}\b", result) for result in results | ||
| ) |
There was a problem hiding this comment.
Recognize return values derived through the condition
Requiring every result arm to mention the field rejects selectors that still return the field's value exactly. For example, (state) => state.reasoningBudget === -1 ? -1 : state.reasoningBudget is an identity selector and re-renders for every budget change, but this check rejects it because the first arm is a literal. That makes the new guard fail on a behavior-preserving selector refactor; account for constraints imposed by the condition or validate the selector's behavior instead of requiring a lexical field reference in every arm.
Useful? React with 👍 / 👎.
…icate A selector written as `s.budget != null ? s.budget : null` does track the field: the null arm is reached only when the field is null, so the returned value still moves when the field moves. Requiring every arm to name the field rejected it, which is the same brittleness this PR exists to remove. _split_ternary now pairs each result with the conditions governing it, and an arm counts when the field appears in the result or in a guard. `s.enabled ? s.budget : s.fallback` is still rejected: neither its guard nor its second arm mentions the budget, so the subscription does not follow it. It also unwraps a wholly parenthesised arm before scanning, so a nested ternary inside brackets is split instead of being matched as one blob of text. Added a case table over the predicate itself, since it is the part a refactor of the sheet walks into first. Mutations checked against the real sheet: a selector that reads the field and returns something else fails, a dropped memo dependency fails, and renaming the selector parameter to `state` stays green.
|
Pushed The A wholly parenthesised arm is now unwrapped before scanning, so a nested ternary inside brackets is split rather than matched as one blob of text. Added a case table over the predicate itself. Mutations against the real sheet: a selector that reads the field and returns something else fails, a dropped memo dependency fails, renaming the selector parameter to @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 117e7f40c9
ℹ️ 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".
| return bool(results) and all( | ||
| read.search(result) or any(read.search(guard) for guard in guards) | ||
| for result, guards in results |
There was a problem hiding this comment.
Reject selectors whose guards do not affect their results
When the field appears only in a guard, this accepts both arms regardless of what they return. For example, (s) => s.reasoningBudget ? s.other : s.other and even (s) => s.reasoningBudget === 1 ? null : null return True from _selector_reads, although their result never changes with the budget. Consequently, test_preset_sheet_reacts_to_a_reasoning_budget_change can remain green after the actual subscription is replaced by an unrelated or constant selector; a guard should justify an arm only when its constraint makes that arm's result track the field, rather than every guard mention counting automatically.
Useful? React with 👍 / 👎.
`a ? b ? c : d : e` has no brackets to raise the depth, so taking the first colon at bracket depth zero cut it into `a ? b` and `d : e`. The second piece was never split again, so a field named anywhere inside it looked like every arm returning it, and `cond ? nested ? s.budget : s.other : s.budget` passed the guard despite the `s.other` path not following the field. The scan for the matching colon now counts intervening `?` operators, skipping `??` and `?.` as the outer scan already does, and consumes one colon per open conditional before accepting its own. Case table gains the unbracketed nested shape in both directions, plus the identity selector `s.budget === -1 ? -1 : s.budget`, which the guard-aware rule already accepts.
|
Both agreed with, both fixed. Colon matching. Correct, and it was live. Return values derived through the condition. Same conclusion I reached independently before this review landed; Mutation-checked: restoring the first-colon behaviour fails the table, and dropping the condition allowance fails it too. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f77a68999
ℹ️ 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".
| naming = [names for names in dependency_lists if field in names] | ||
| assert len(naming) == 2, ( |
There was a problem hiding this comment.
Scope dependency checks to the capture memos
This counts the field across every useMemo in the sheet without verifying that the matching lists belong to hasUnsavedPresetChanges and currentLoadSummary. If the field is removed from currentLoadSummary but added to an unrelated memo—for example, [committedSeed, params, reasoningBudget]—len(naming) remains 2 and the test passes even though the summary is stale after a budget change. Associate each dependency list with its memo and check the two capture-dependent memos specifically.
Useful? React with 👍 / 👎.
Two holes, both of which left the guard green while the thing it guards was gone. A condition naming the field justified every arm unconditionally, so `s.budget ? s.other : s.other` and `s.budget === 1 ? null : null` counted as subscriptions although their result never moves. A guard can only justify an arm it is able to steer away from, so arms that all return the same expression are rejected before the guard is consulted. The dependency check counted the field across every useMemo in the sheet and asked for two. Moving it out of currentLoadSummary and into an unrelated memo kept the count at two, so a stale summary passed. Dependency lists are now keyed by the name each memo is bound to, and hasUnsavedPresetChanges and currentLoadSummary are each required to list the field. A rename of either is reported by name rather than passing quietly. Mutations: the field moved from currentLoadSummary to an unrelated memo fails, dropping the identical-arms rule fails, and renaming a capture memo fails with a message naming it.
|
Both agreed with and fixed in Guards that steer nothing. Correct, and it made the guard vacuous in exactly the way it was written to prevent: Memo scoping. Also correct, and your example is now a test. Dependency lists are keyed by the name each memo is bound to, and Mutations against the real sheet: moving @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6112529e54
ℹ️ 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".
| out, needle = [], "useChatRuntimeStore(" | ||
| start = source.find(needle) | ||
| while start != -1: | ||
| out.append(_balanced(source, start + len(needle) - 1)) | ||
| start = source.find(needle, start + 1) |
There was a problem hiding this comment.
Restrict selector discovery to the owning component
This scans every useChatRuntimeStore call in the file, including calls in separate components such as MaxToolCallsSlider. If ChatSettingsPanel's budget selector is changed to return another field while a later child component subscribes to reasoningBudget, any(_selector_reads(...)) remains true; only that child re-renders, so the parent's hasUnsavedPresetChanges and currentLoadSummary memos remain stale. Extract selectors from ChatSettingsPanel specifically rather than from the whole module.
Useful? React with 👍 / 👎.
| if all(read.search(result) for result, _ in results): | ||
| return True |
There was a problem hiding this comment.
Reject unused reads in block-bodied selectors
When a selector uses a block body, this treats the entire block as its returned value, so _selector_reads("(s) => { void s.reasoningBudget; return null; }", "reasoningBudget") returns true. Zustand actually receives null on every call and will not re-render the sheet when the budget changes, allowing the regression test to stay green after a broken block-bodied refactor. Parse the block's returned expressions or conservatively reject block bodies that are not understood.
Useful? React with 👍 / 👎.
Selector discovery scanned the whole module. The sheet holds several
components, and the ones after ChatSettingsPanel subscribe to the runtime
store too, so repointing the panel's selector at another field while a sibling
still named reasoningBudget left the guard green with the panel's memos stale.
Discovery now runs over the panel's own span, taken from its top-level
declaration up to the next one.
A block-bodied selector was read as one blob of text, so
`(s) => { void s.budget; return null; }` counted as a subscription although
zustand receives null every time. The block's return expressions are what is
checked now, with plain const and let bindings inlined first so naming the
value before returning it stays a refactor. A block whose returns cannot be
found is rejected rather than read as its own source.
Mutations: repointing the panel selector while MaxToolCallsSlider keeps the
subscription fails, and a block body that reads the field and returns null
fails.
|
Both agreed with and fixed in Component scoping. Correct, and your example is the one that mattered: Block bodies. Also correct. The body was treated as one blob of text, so Mutations against the real sheet: repointing the panel's selector while @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18a68f70a1
ℹ️ 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".
| if len({re.sub(r"\s+", "", result) for result, _ in results}) < 2: | ||
| return False |
There was a problem hiding this comment.
Compare selector result arms semantically
The new source-text comparison only removes whitespace, so equivalent arms such as (s) => s.reasoningBudget ? s.other : s["other"] are considered different. _selector_reads then lets the field-bearing guard justify both arms and returns True, although the selector always returns the same store value and a budget-only change cannot trigger a re-render. This fresh counterexample remains after the identical-arm fix; normalize equivalent property accesses or conservatively reject guards whose result arms cannot be shown to differ.
Useful? React with 👍 / 👎.
| signature = re.match(r"\s*\(?\s*([A-Za-z_$][\w$]*)\s*\)?\s*(?::[^=]*)?=>", selector) | ||
| if signature is None: | ||
| return False |
There was a problem hiding this comment.
Accept destructured selector parameters
This signature regex only accepts a single identifier parameter, so a behavior-preserving Zustand selector such as ({ reasoningBudget }) => reasoningBudget makes _selector_reads return False. Since destructuring is valid TypeScript and still subscribes the component to exactly this field, that routine refactor would make this guard fail and recreate the spelling-sensitive CI failure this change is intended to eliminate.
Useful? React with 👍 / 👎.
`({ reasoningBudget }) => reasoningBudget` is the same subscription written the
other way, and the signature match took a bare identifier only, so a routine
refactor would have made this guard red for a selector that tracks exactly the
field. The parameter is read as either shape now, through its local name when
the destructuring renames it, and a destructuring that does not take the field
is not a read of it.
Arms were compared with whitespace stripped and nothing else, so `s.other` and
`s["other"]` looked like a choice the guard steers, when the selector returns
the same store value either way. One access now has one spelling: bracketed
string access is rewritten to dot access before comparing.
That comparison also missed the trailing comma of the useChatRuntimeStore()
argument, which rides along on the last arm and made an arm differ from its
twin by punctuation. Separators are stripped with the whitespace.
Mutations: the panel's selector rewritten as a destructuring stays green, and
one rewritten to steer between two spellings of the same access fails.
|
Both agreed with and fixed in Destructured parameters. Correct, and squarely the thing this PR exists to prevent: Arm comparison. Also correct. Stripping whitespace and nothing else made Chasing your counterexample surfaced a second one in the same comparison: the trailing comma of the Mutations against the real sheet: the panel's selector rewritten as a destructuring stays green, and one rewritten to steer between two spellings of the same access fails. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c31a066b5
ℹ️ 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".
| collapsed = re.sub(r"\s+", "", expression).rstrip(",;") | ||
| return re.sub(r"\[['\"]([A-Za-z_$][\w$]*)['\"]\]", r".\1", collapsed) |
There was a problem hiding this comment.
Ignore comments when comparing selector arms
Fresh evidence after the bracket-access fix: _normalised retains comments, so (s) => s.reasoningBudget ? s.other : /* same value */ s.other produces two textually different arms and _selector_reads returns True. The selector actually returns s.other on both paths, so a budget-only update will not re-render the component and the regression guard can remain green; strip comments without altering string literals before comparing arms.
Useful? React with 👍 / 👎.
| returned = re.findall(r"\breturn\b([^;}]*)", block) | ||
| results = [result for expression in returned for result in _split_ternary(expression)] |
There was a problem hiding this comment.
Restrict return matching to the selector's function scope
Fresh evidence after the block-body fix: this regex also collects returns from nested functions. A valid selector such as (s) => { function normalize(v) { return v ?? -1; } return normalize(s.reasoningBudget); } is rejected because v ?? -1 is treated as another selector result that does not read the field, recreating the refactor-sensitive CI failure this change is meant to remove; analyze only returns belonging to the selector rather than nested function scopes.
Useful? React with 👍 / 👎.
A comment is not part of the value an arm returns, so `s.other` and
`/* same value */ s.other` compared as a choice the guard steers, when the
selector returns the same store value either way. Comments are stripped before
anything is compared, with string literals left alone.
Return matching took every `return` in a block body, including those belonging
to a function declared inside it. A helper's return is not what zustand
compares, so `{ function n(v) { return v ?? -1; } return n(s.budget); }` was
rejected for reading the field through a helper, which is the refactor
sensitivity this change exists to remove. Only returns in the selector's own
scope are collected now.
Mutations: a selector whose arms differ only by a comment fails, and one that
returns through a nested helper stays green.
|
Both agreed with and fixed in Comments in arms. Correct. A comment is not part of the value an arm returns, so Nested function returns. Also correct, and it was the refactor-sensitive direction: a helper's own return is not what zustand compares, so Mutations against the real sheet: a selector whose arms differ only by a comment fails, and one that returns through a nested helper stays green. A note on what this guard is and is not. It reads source text, so it answers "does every value this selector can return depend on the field" syntactically. It cannot prove the returned value is distinct for distinct field values, and a sufficiently indirect selector will defeat it. That limit is stated in the test's docstring. What it does buy is that the failure it was written for, a captured field the sheet neither subscribes to nor lists as a memo dependency, is caught without pinning one spelling. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3621328974
ℹ️ 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".
| if char == "{": | ||
| depth += 1 | ||
| elif char == "}": | ||
| depth -= 1 | ||
| elif depth == 0 and re.match(r"\breturn\b", block[index:]): |
There was a problem hiding this comment.
Include control-block returns in selector analysis
Brace depth also excludes returns inside ordinary control blocks, not just nested functions. For example, _selector_reads("(s) => { if (s.enabled) { return s.other; } return s.reasoningBudget; }", "reasoningBudget") returns True because the first return is skipped; replacing the real selector with that form would therefore leave this regression test green even though a budget-only change cannot re-render the sheet while enabled is true. Distinguish nested function bodies from blocks belonging to the selector itself.
Useful? React with 👍 / 👎.
…non-optional Backend CI on main has been red since unslothai#7701 (2ab07c9 and after) at `(Python 3.13, rest)`: three tests in tests/multi_account/test_chat_shared_resident.py read /status through FakeLlama, whose __getattr__ answers None for any runtime field it does not declare. unslothai#7701 added four non-Optional fields to _InferenceRuntimeFields (reasoning_budget, reasoning_budget_message and their requested_ twins), so InferenceStatusResponse fails validation with four None inputs and the route answers "Failed to get status". The fake declares the four with the real backend's defaults, as it already does for every other non-Optional runtime field. Test-only. RED/GREEN on 6731ba1: 3 failed / 2 passed before, 5 passed after. The other unslothai#7701 aftermath, the preset-sheet pin in tests/studio/test_chat_preset_load_config.py, is unslothai#11065. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012DRiTpjxAymRtv9p8Xr2kd
) `Backend CI` has been red on main since the reasoning-budget controls landed, with three multi-account tests answering `{"detail":"Failed to get status"}`, a message naming neither the field nor the cause. Four reasoning fields were added to `_InferenceRuntimeFields` and they are not Optional, which is right: `LlamaCppBackend.__init__` sets `_reasoning_budget = -1` and `_reasoning_budget_message = ""`, so the real backend never answers None for them. `_llama_runtime_fields` mirrors every field in that model off the backend, and the test doubles answered None for anything nobody set, so /status raised ValidationError and the route returned 500. The PR that added the fields is correct; the doubles were not. ## What changed `FakeLlamaCppBackend` carries the runtime surface /status mirrors, at the values `LlamaCppBackend.__init__` gives them. The same block was being re-declared by hand in the per-test fakes, which is what the shared double exists to end. Fields the real backend holds only as `_name` are declared under that name, so the double claims nothing production cannot read. The blanket `__getattr__` several fakes carried defeated that fallback: answering None for the public name hides the private slot that has the value. It lives on the shared double now, scoped to the names /status mirrors and taken from the model rather than listed. Everything else raises `AttributeError` as before, so `getattr(backend, name, default)` keeps its default; a blanket version broke `supports_tool_passthrough` defaulting to `supports_tools`, which Codex caught during review. Attributes the status route reads straight off the backend rather than through the model-field loop are declared too, at the real backend's initial values. ## Coverage The existing canary drives /chat/completions and never reaches this. A second one builds the /status runtime payload from the bare double and validates it, failing with the offending field in the message. Mutation-tested: removing the four reasoning fields reproduces the original break and the canary names all four; answering None instead of the private slot names the seven private-only fields; restoring the blanket fallback fails the video chat-completions tests. All nine files that use the double pass, 110 tests. `(Python 3.13, rest)` is green here, against red on main. The two remaining red jobs are inherited from main and fixed elsewhere: the studio shard by #11065, and the python shard's kaggle launcher flake by #11085.
Excluding returns by brace depth threw away more than nested functions: an `if`
or a `for` body is the selector's own scope, so `{ if (s.enabled) { return
s.other; } return s.budget; }` was read as always returning the budget, and a
selector that cannot re-render the sheet while `enabled` is true passed the
guard.
Nested function bodies are located by their own opener, `=> {` or a `function`
declaration, and only those are treated as another scope. Everything else counts.
Chasing that surfaced a second one: the binding inliner captured up to the first
`;`, which lands inside the body of a function-valued binding and substituted
the fragments. It now takes brace-free right-hand sides only, so `const f = (v)
=> { return v; }; return f(s.budget)` is left alone and read through the nested
function rule instead.
Mutations: an early return of another field from inside an if-block fails, and
the same shape returning the field from both paths stays green.
|
Agreed and fixed in Correct, and it was the worse direction of the two: excluding returns by brace depth threw away the selector's own control blocks along with nested functions, so your Chasing it surfaced a second defect in the same path. The binding inliner captured up to the first Mutations against the real sheet: an early return of another field from inside an if-block fails, and the same shape returning the field on both paths stays green. Four of these shapes are in the case table. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 205f9ec42b
ℹ️ 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".
| return all( | ||
| read.search(result) or any(read.search(guard) for guard in guards) | ||
| for result, guards in results |
There was a problem hiding this comment.
Require guards to track every field value change
Fresh evidence after the distinct-arm fix: (s) => s.reasoningBudget > 0 ? s.other : null is accepted because the arms differ and the guard mentions the field, but changing the budget from 1 to 2 leaves the selected result as s.other, so Zustand does not re-render and both capture memos remain stale. Merely steering between distinct arms is insufficient; a guard-only field reference should count only when its constraint makes each returned value track the field.
Useful? React with 👍 / 👎.
| start = source.find(needle) | ||
| while start != -1: | ||
| out.append(_balanced(source, start + len(needle) - 1)) | ||
| start = source.find(needle, start + 1) |
There was a problem hiding this comment.
Exclude commented calls from selector discovery
Fresh evidence beyond stripping comments inside selector arms: if the old subscription is commented out as // useChatRuntimeStore((s) => s.reasoningBudget) while the active selector is changed to another field, this scan still extracts the commented argument, and _without_comments cannot remove it because the comment marker was outside the extracted text. The later any(...) therefore stays green even though ChatSettingsPanel no longer subscribes to the budget; remove comments before discovering calls.
Useful? React with 👍 / 👎.
A condition naming the field says which arm is taken, not what the arms return, so `s.budget > 0 ? s.other : null` held the same result while the budget moved from 1 to 2 and the sheet never re-rendered. Some arm has to return the field now. Where one does, a guard naming it still accounts for the others, which is what keeps `s.budget != null ? s.budget : null` a subscription. Two cases in the table were wrong under that rule and are corrected rather than kept: `s.budget != null ? s.other : null` and `s.budget ? s.other : s.another` are both rejected, for the same reason. I had recorded them as subscriptions in earlier rounds; they are not. Comments come out before selectors are discovered, not only inside arms. A commented-out `// useChatRuntimeStore((s) => s.budget)` sitting beside a repointed live selector is still a call to a text scan, and the marker is outside the extracted argument so a later strip cannot reach it. The distinct-arms rule is gone; requiring an arm to return the field subsumes it. Mutations: a guard-only reference with neither arm returning the field fails, and commenting out the real subscription while repointing the live one fails.
|
Both agreed with and fixed in Guards do not carry the subscription. Correct, and this is the one that mattered. A condition naming the field says which arm is taken, not what the arms return, so Two entries I had put in the case table in earlier rounds are wrong under that rule, and they are corrected rather than grandfathered: The distinct-arms rule is gone, since requiring an arm to return the field subsumes it. Commented-out calls. Also correct, and the ordering is the whole point: the marker sits outside the extracted argument, so stripping inside the arms can never reach it. Comments now come out of the component body before any discovery runs. Mutations against the real sheet: a guard-only reference with neither arm returning the field fails, and commenting out the real subscription while repointing the live one fails. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb9753f76c
ℹ️ 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".
| return all( | ||
| read.search(result) or any(read.search(guard) for guard in guards) | ||
| for result, guards in results |
There was a problem hiding this comment.
Require every guarded subpath to track the field
Fresh evidence after the stated guard-only fix: _selector_reads("(s) => s.reasoningBudget != null ? (s.enabled ? s.reasoningBudget : s.other) : null", "reasoningBudget") still returns True. When enabled is false and the budget changes between two non-null values, the selector remains s.other, so the sheet does not re-render; the field-returning sibling arm cannot justify that path. Require each branch governed by a budget guard to track the budget on every reachable subpath rather than allowing one field-bearing result anywhere in the flattened list.
Useful? React with 👍 / 👎.
| results = [ | ||
| result | ||
| for expression in _own_scope_returns(block) | ||
| for result in _split_ternary(expression) | ||
| ] |
There was a problem hiding this comment.
Account for block selectors that fall through
For a selector such as (s) => { if (s.enabled) return s.reasoningBudget; }, the extracted results contain only the explicit field-bearing return, so this predicate reports a subscription. When enabled is false, however, the selector returns undefined, and a budget-only change keeps that result unchanged, leaving the component stale while the regression test remains green. Add the reachable implicit undefined result when a block body is not proven to return on every path.
Useful? React with 👍 / 👎.
|
Both correct, and both arrived as this merged. Fixed in #11089 rather than here. The guarded subpath. Right, and it defeats the rule I had just added: one arm returning the field was taken as licence for the outer guard to account for the rest, so the That also overturns another case I had recorded as a subscription: The fall-through. Also right. The extracted results held only the field-bearing return, so the Mutations against the real sheet: the nested guarded subpath fails, the falling-through block fails, and the same block returning the field on both paths stays green. |
…e rest (#11089) * ## Summary Two holes Codex found in #11065's selector predicate. The review landed at the moment that PR was merged, so they are fixed here rather than before it went in. Both let a broken refactor keep `test_preset_sheet_reacts_to_a_reasoning_budget_change` green. ## A guard cannot rescue a subpath it does not pin `(s) => s.reasoningBudget != null ? (s.enabled ? s.reasoningBudget : s.other) : null` passed. One arm returned the field, which was taken as enough to let the outer budget guard account for the rest. It is not: with `enabled` false, the budget moving between two non-null values leaves the result at `s.other` and the sheet does not re-render. Every path now either returns the field, or is reachable for only one value of it. Only a comparison that fixes the field at a literal on the branch taken counts, so `budget === -1` taken true and `budget != null` taken false both qualify, while `budget > 0` and a bare truthiness test qualify for nothing. Guards carry which way they fell for this reason. That also corrects a case I had recorded as a subscription in #11065: `{ const v = s.reasoningBudget; return v ? s.reasoningBudget : -1; }`. A budget of 0 and a budget of null both land on -1, so it does not track every change. It is a rejection now. ## A block that falls through returns undefined `(s) => { if (s.enabled) return s.reasoningBudget; }` passed, because the only extracted result was the field-bearing return. When `enabled` is false the selector returns `undefined`, which is as steady as any other constant. A block that is not a plain "last statement is an unconditional return" now contributes that path explicitly, including the unbraced `if (x) return y;` shape that looks like a final statement but is not. ## Verification 13 shapes checked directly, both new cases and eleven behaviours from #11065 that must not move. Mutations against the real sheet: the nested guarded subpath fails, the falling-through block fails, and the same block returning the field on both paths stays green. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Compare the literal against the field, not merely near it `_pins` asked two independent questions, whether the guard names the field and whether it compares something to a literal, so the two answers could come from different operands. `s.budget > 0 && s.mode === "x"` read as pinning the budget because the field matched one half and the literal the other, and every budget above zero still returned the same arm. The comparison is anchored to the field now, on either side of the operator. Polarity follows from that. Taken true, a conjunction still implies its parts, so `budget === -1 && mode === "x"` pins; a disjunction does not, so the same shape with `||` does not. Taken false, only the bare comparison pins, because negating `budget != null && mode === "x"` gives a disjunction that leaves the budget free. * Bind the pin to the selector's parameter, and to the value it fixes Two ways a pinned path was still dishonest. The comparison matched the field on any receiver, so `defaults.reasoningBudget === -1` read as a statement about the store while `s.reasoningBudget` moved underneath it. It is matched against the field read off the selector's own parameter now, with a lookbehind, because `s.reasoningBudget` otherwise matches inside `defaults.reasoningBudget`. Being reachable for one value of the field does not make a constant result honest: `s.budget === -1 ? 0 : s.budget` pins the first arm at -1 and returns 0, which is exactly what the other arm returns once the budget IS 0, so the -1 to 0 change produces no change at all. A pinned arm now has to return the value the field holds there, which is the literal it was pinned to. `_pins` became `_pinned_literal` for that: the branch reports which value it fixes rather than answering yes or no. Mutations: a comparison on another object's field fails, and a pinned arm returning a colliding constant fails. * Refuse a pin under negation, and bound the access on both sides `!(s.budget === -1)` was read as pinning the budget to -1, because the equality was found without regard to the Boolean context around it. The branch implies the opposite, and every transition among the other values keeps returning the same arm. A guard carrying a logical not is refused rather than interpreted. The reverse form of the comparison had a boundary before the access and none after, so `-1 === s.budgetExtra` matched on the `s.budget` prefix. Both ends are bounded now. Mutations: a negated equality fails, and a comparison against a longer field name that starts with this one fails. * Read the pinned literal whole, and require the equality to be a conjunct Two ways a guard could read as pinning a value it does not pin. The numeric alternative stopped at the first digit run, so `1e3` matched as `1` and `s.reasoningBudget === 1e3 ? 1 : s.reasoningBudget` passed: a budget of 1000 and a budget of 1 both return 1, which is the collision the check exists to catch. The pattern now spells exponent and radix forms and refuses to end mid-token. The equality only had to appear somewhere in the guard, so `(s.reasoningBudget === -1) === false` counted: that arm is taken for every budget except -1, the opposite of what the inner comparison reads as. The comparison now has to be one of the guard's top-level `&&` conjuncts, matched end to end, so an inner equality fed to another operator no longer pins anything. * Pin only on strict comparisons, and keep whitespace inside literals `==` relates a class of values to one literal rather than pinning the field to it: a message of "" and a message of "0" both satisfy `msg == 0`, so an arm returning 0 there holds still while the field moves between them. Only `===` and `!==` are read as pins now. That drops `s.reasoningBudget != null ? s.reasoningBudget : null`, which is false for null and undefined alike; the strict spelling of the same selector is still accepted. Normalisation stripped whitespace everywhere, including inside quoted literals, so a guard pinning the field to "a b" matched an arm returning "ab" and the collision it exists to catch read as a match. Whitespace is now only removed between tokens. * Find the last statement by bracket depth, not by the last semicolon A loop header carries its own semicolons, so taking the last one as the statement boundary hid the `for` from the fall-through check and `{ for (let i = 0; i < s.list.length; i++) return s.reasoningBudget; }` read as an unconditional return. An empty list falls through to undefined, which tracks nothing. Delimiters now count only at bracket depth zero. * Tighten the comments in the selector predicate Collapses the multi-line explanations on the internal helpers to what they need to say. No code change: comment_tools.py check reports comments only. * Read a parenthesised comparison as the comparison it is `(s) => (s.reasoningBudget === -1) ? -1 : s.reasoningBudget` was rejected: the conjunct arrives wrapped and the end-to-end match against it failed, so a reformatting of a selector this test accepts made it red. That is the class of guard this test replaced. Redundant outer parentheses are stripped before the match, one pair at a time and only when the opening one closes at the very end, so `(budget === -1) === false` keeps its meaning and is still refused. * Walk the block's statements instead of hunting the last return `{ if (s.enabled) return s.reasoningBudget; else return s.reasoningBudget; }` returns the field on every path, and the fall-through check invented an undefined path for it: it only recognised a trailing unconditional return, so an exhaustive if/else read as a block that can fall off the end. That is a semantics-preserving refactor of a selector this test accepts, failing it. The check now consumes the block's own statements. A return at that level ends it, a braced block is entered, and an if/else counts when both arms always return. A loop still never counts, since its body may not run at all. Consuming statements also binds `else` to the nearest `if`, which the regex could not, and keeps a helper declared mid-block from swallowing the return after it. * Read operators outside literals, and count an exhaustive switch Two legal refactors the predicate refused. A quoted literal is a value, not syntax, but `!`, `||` and `&&` were searched for across the whole guard, so a message spelling one of them made a selector that returns the field unchanged read as a guard carrying a negation or a disjunction. Those operators, and the bracket scan that splits conjuncts, now run against a copy with literal contents blanked out. A `switch` was consumed as a statement but never analysed, so an exhaustive one reported fall-through and the caller appended an undefined result that no path produces. A defaulted switch whose every arm returns now counts. Undefaulted does not, since a value matching nothing falls past the closing brace, and neither does a `break`, which leaves the switch with no value. * End the switch on an empty last arm, and compare pins by value An empty case falls into the next label, so it needs one: an empty LAST label leaves the switch instead, and `switch (s.mode) { default: return s.budget; case "x": }` returns undefined for mode "x". It is no longer read as exhaustive. Pins were compared as source text, so rewriting a literal broke them: `s.budget === 0x10 ? 16` returns the field unchanged for every budget and was refused, as were 1e3 against 1000 and 'x' against "x". Supported literals are canonicalised to the value they denote before the comparison, which leaves genuinely different values -- null against undefined, true against 1 -- apart. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read escapes, refuse a zero pin, and keep a nested switch's labels its own Three shapes the predicate got wrong. A backslash escapes the next character, but the literal patterns ended at the first matching quote, so a message containing an escaped quote cut the token short and a selector returning the field unchanged was refused. `budget === 0` is satisfied by -0 as well, so the branch holds two values, while zustand compares with Object.is, which tells them apart. An arm returning 0 there is stale across a -0 to 0 change, and the preset normaliser reaches -0 through Math.trunc, so this is a value the store can hold. Zero no longer pins. A nested switch has `case` labels of its own. Collecting them flat split the outer arms mid-brace and raised `unbalanced {` out of the predicate. Labels are now taken at the switch body's own bracket depth. * Let an arm fall through, and stop rejecting an unrelated negation Fall-through is not a property of empty arms. Any arm that neither returns nor breaks falls into the next label, so `case "x": sideEffect(); case "y": return s.budget;` reaches a return on every path and was being refused. A `break` still ends the switch carrying no value, and a last arm still has nothing to fall into. The guard checks searched the whole condition for `!` and `||`, so an ordinary extra condition was enough to lose the pin: `budget === -1 && !disabled` was refused for a negation that has nothing to do with the comparison. Both searches are gone. Requiring the comparison to match a top-level conjunct end to end already excludes a negated or disjoined one, because neither is a conjunct equal to the comparison itself. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Own the default, own the break, and keep a colon in a message out of the ternary Two of these let the predicate pass a selector that goes stale, which is the failure that matters here. The exhaustiveness check searched the whole body for `default:`, so a nested switch's default counted as the outer switch's. A mode matching no outer case falls straight past the closing brace. The default now has to be one of this switch's own labels. A `break` was located by bracket depth, which hides one inside a plain block. `if (stop) { break; }` leaves the switch just as plainly as a bare `break`. Only the statements that can absorb a break of their own are skipped now: a loop, a nested switch, a function body. Third, the ternary scan read raw source, so a colon inside a message was taken for the operator and a selector returning the field unchanged was refused. * Unwrap the guard before splitting it, and read escapes as the characters they spell A conjunction wrapped whole keeps its `&&` above depth zero, so `(budget === -1 && enabled)` was never split and the pin inside it never seen. The guard is unwrapped before the split now, which is the same treatment its conjuncts already got. A wrapped disjunction is still refused: unwrapping does not make `||` imply its parts. String literals were compared as source, so `"\\x61"` and `"a"` read as two values. Literals are decoded to the runtime string they denote before the comparison, covering \\xHH, \\uHHHH, \\u{...} and the usual single-character escapes, with an unrecognised escape standing for the character itself as JavaScript does. * Read try, do/while and surrogate pairs the way JavaScript does Three shapes a legal selector can take that the predicate refused. A `try` was split into clauses by the statement walker and never analysed, so one returning on every path read as a fall-through. It now counts when `finally` returns, or when both the attempt and its `catch` do. A `try` alone still does not: the throwing path is uncovered. `do` is the one loop whose body runs before its test, so `do { return x; } while (c);` always returns. `while` and `for` still do not count, since their bodies may not run at all. A surrogate pair is one character written the way JavaScript stores it, so the decoder now combines `\\uD83D\\uDE00` into the code point rather than leaving two halves. * Own the try clauses, and let a continue leave the switch Both of these let the predicate pass a selector that goes stale. `_try_always_returns` searched the whole statement for clauses, so a nested try/catch contributed its own and an inner body stood in for the outer one. A path falling out of the outer `try` then read as covered. The clauses are walked from the start of the statement now, so only this try's own count. An arm ending in `continue` does not fall into the next label: it jumps to the surrounding loop's test and leaves the switch. It is refused alongside `break`, with one difference that matters -- a nested switch absorbs a `break` but never a `continue`, which passes straight through it to the loop. * Count a loop that always enters, and read template literals A loop whose test is written as true always runs its body, so `for (;;) return s.budget;` and `while (true) return s.budget;` return on every path. They count now, unless the body can `break` out of the loop first, which puts the fall-through back. A test read off the store is still a condition, not a certainty. A template literal with no substitution is a constant like any other string, so a selector written with backticks is no longer refused. Two template patterns, which matters more than it looks: blanking has to pair backticks the way the source does, substitutions and all. A pattern that cannot match a template with ${} does not skip it, it pairs that template's closing backtick with the next one's opening backtick and blanks the operators in between. That is a false POSITIVE, not a rejection: the ternary stopped being split, and the whole expression read as one result that mentions the field. Blanking uses the permissive pattern; only the substitution-free form counts as a constant. * Trim the selector predicate's comments * Drop the unused _statement_start helper * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Let a continue end a single-pass loop, and read line continuations in literals * Refuse a selector with a regex, and skip properties named like keywords * Refuse a selector that returns a comparison, and inline only const bindings * Score the left operand of && and || as a path of its own * Split the left operand of && and || as well * Rewrite bracket access only outside string literals * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refuse a pin under a top-level || * Park string literals while reading a selector's structure * Inline a const only where it is referenced, and park literals inside substitutions * Leave a const uninlined when its name is bound again * Refuse a selector whose body binds the parameter's name again * Collapse whitespace around a member dot before reading the selector * State why ?? is not split, with the sheet's own selector as a case * Count only real loop and switch statements as jump absorbers * End a statement at do/while and at the next statement keyword without a semicolon * Score a comma expression's last operand, and strip comments in substitutions * Advance past a split operator by its own length * Read a return's expression by depth, and a line break after return as undefined * Refuse a selector that writes to its own parameter * Count destructuring and for-of heads as writes to the parameter * See through parentheses around a written parameter * Read binding patterns and parameter lists as balanced spans * Never take a labelled jump as absorbed * Read only the selector subset the test can prove, and refuse the rest * Take the field only as the value itself or a call argument * Refuse optional chaining, which can skip the read * Say in the failure that a refused spelling can be the cause --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: oobabooga <[email protected]>
…lothai#11076) `Backend CI` has been red on main since the reasoning-budget controls landed, with three multi-account tests answering `{"detail":"Failed to get status"}`, a message naming neither the field nor the cause. Four reasoning fields were added to `_InferenceRuntimeFields` and they are not Optional, which is right: `LlamaCppBackend.__init__` sets `_reasoning_budget = -1` and `_reasoning_budget_message = ""`, so the real backend never answers None for them. `_llama_runtime_fields` mirrors every field in that model off the backend, and the test doubles answered None for anything nobody set, so /status raised ValidationError and the route returned 500. The PR that added the fields is correct; the doubles were not. ## What changed `FakeLlamaCppBackend` carries the runtime surface /status mirrors, at the values `LlamaCppBackend.__init__` gives them. The same block was being re-declared by hand in the per-test fakes, which is what the shared double exists to end. Fields the real backend holds only as `_name` are declared under that name, so the double claims nothing production cannot read. The blanket `__getattr__` several fakes carried defeated that fallback: answering None for the public name hides the private slot that has the value. It lives on the shared double now, scoped to the names /status mirrors and taken from the model rather than listed. Everything else raises `AttributeError` as before, so `getattr(backend, name, default)` keeps its default; a blanket version broke `supports_tool_passthrough` defaulting to `supports_tools`, which Codex caught during review. Attributes the status route reads straight off the backend rather than through the model-field loop are declared too, at the real backend's initial values. ## Coverage The existing canary drives /chat/completions and never reaches this. A second one builds the /status runtime payload from the bare double and validates it, failing with the offending field in the message. Mutation-tested: removing the four reasoning fields reproduces the original break and the canary names all four; answering None instead of the private slot names the seven private-only fields; restoring the blanket fallback fails the video chat-completions tests. All nine files that use the double pass, 110 tests. `(Python 3.13, rest)` is green here, against red on main. The two remaining red jobs are inherited from main and fixed elsewhere: the studio shard by unslothai#11065, and the python shard's kaggle launcher flake by unslothai#11085.
…ed (unslothai#11065) `Repo tests (CPU, studio)` has been red on main since the reasoning-budget controls landed: FAILED tests/studio/test_chat_preset_load_config.py::test_preset_sheet_reacts_to_a_reasoning_budget_change AssertionError: the preset sheet never subscribes to reasoningBudget The sheet does subscribe. The guard required the literal `(s) => s.reasoningBudget` and counted the field at two fixed indentations, so writing the same subscription as a multi-line conditional turned it red. A guard a legal refactor breaks says nothing about the behaviour it guards. ## What it asserts now That every value the selector can return depends on the field, and that the two memos calling `capturePresetLoadConfig()` name it as a dependency. Not a spelling. The parameter name comes from the selector's own signature, and a destructured parameter is read through its local name. Bracketed string access is normalised to dot access, comments are stripped before anything is discovered or compared, and block bodies are read through their own returns, excluding functions declared inside them but not the selector's own control blocks. A condition naming the field is not on its own a subscription: it says which arm is taken, not what the arms return, so some arm has to return the field. Where one does, a guard naming it accounts for the rest, which is what keeps `s.budget != null ? s.budget : null` a subscription and rejects `s.budget > 0 ? s.other : null`. ## What it cannot do It reads source text. It cannot prove the returned value is distinct for distinct field values, and a sufficiently indirect selector will defeat it. That limit is recorded in the test's docstring rather than implied away. ## Coverage A case table over the predicate itself, since that is the part a refactor of the sheet walks into first. Mutations against the real sheet, all caught: a selector that reads the field and returns something else, a dropped memo dependency, the field moved from `currentLoadSummary` into an unrelated memo, a renamed capture memo, the panel's selector repointed while a sibling component keeps the subscription, a block body that reads and discards, arms differing only by a comment, an early return of another field from inside an if-block, a guard-only reference with neither arm returning the field, and the real subscription commented out beside a repointed live one. Renaming the selector parameter, destructuring it, naming the value before returning it, and returning through a nested helper all stay green.
…e rest (unslothai#11089) * ## Summary Two holes Codex found in unslothai#11065's selector predicate. The review landed at the moment that PR was merged, so they are fixed here rather than before it went in. Both let a broken refactor keep `test_preset_sheet_reacts_to_a_reasoning_budget_change` green. ## A guard cannot rescue a subpath it does not pin `(s) => s.reasoningBudget != null ? (s.enabled ? s.reasoningBudget : s.other) : null` passed. One arm returned the field, which was taken as enough to let the outer budget guard account for the rest. It is not: with `enabled` false, the budget moving between two non-null values leaves the result at `s.other` and the sheet does not re-render. Every path now either returns the field, or is reachable for only one value of it. Only a comparison that fixes the field at a literal on the branch taken counts, so `budget === -1` taken true and `budget != null` taken false both qualify, while `budget > 0` and a bare truthiness test qualify for nothing. Guards carry which way they fell for this reason. That also corrects a case I had recorded as a subscription in unslothai#11065: `{ const v = s.reasoningBudget; return v ? s.reasoningBudget : -1; }`. A budget of 0 and a budget of null both land on -1, so it does not track every change. It is a rejection now. ## A block that falls through returns undefined `(s) => { if (s.enabled) return s.reasoningBudget; }` passed, because the only extracted result was the field-bearing return. When `enabled` is false the selector returns `undefined`, which is as steady as any other constant. A block that is not a plain "last statement is an unconditional return" now contributes that path explicitly, including the unbraced `if (x) return y;` shape that looks like a final statement but is not. ## Verification 13 shapes checked directly, both new cases and eleven behaviours from unslothai#11065 that must not move. Mutations against the real sheet: the nested guarded subpath fails, the falling-through block fails, and the same block returning the field on both paths stays green. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Compare the literal against the field, not merely near it `_pins` asked two independent questions, whether the guard names the field and whether it compares something to a literal, so the two answers could come from different operands. `s.budget > 0 && s.mode === "x"` read as pinning the budget because the field matched one half and the literal the other, and every budget above zero still returned the same arm. The comparison is anchored to the field now, on either side of the operator. Polarity follows from that. Taken true, a conjunction still implies its parts, so `budget === -1 && mode === "x"` pins; a disjunction does not, so the same shape with `||` does not. Taken false, only the bare comparison pins, because negating `budget != null && mode === "x"` gives a disjunction that leaves the budget free. * Bind the pin to the selector's parameter, and to the value it fixes Two ways a pinned path was still dishonest. The comparison matched the field on any receiver, so `defaults.reasoningBudget === -1` read as a statement about the store while `s.reasoningBudget` moved underneath it. It is matched against the field read off the selector's own parameter now, with a lookbehind, because `s.reasoningBudget` otherwise matches inside `defaults.reasoningBudget`. Being reachable for one value of the field does not make a constant result honest: `s.budget === -1 ? 0 : s.budget` pins the first arm at -1 and returns 0, which is exactly what the other arm returns once the budget IS 0, so the -1 to 0 change produces no change at all. A pinned arm now has to return the value the field holds there, which is the literal it was pinned to. `_pins` became `_pinned_literal` for that: the branch reports which value it fixes rather than answering yes or no. Mutations: a comparison on another object's field fails, and a pinned arm returning a colliding constant fails. * Refuse a pin under negation, and bound the access on both sides `!(s.budget === -1)` was read as pinning the budget to -1, because the equality was found without regard to the Boolean context around it. The branch implies the opposite, and every transition among the other values keeps returning the same arm. A guard carrying a logical not is refused rather than interpreted. The reverse form of the comparison had a boundary before the access and none after, so `-1 === s.budgetExtra` matched on the `s.budget` prefix. Both ends are bounded now. Mutations: a negated equality fails, and a comparison against a longer field name that starts with this one fails. * Read the pinned literal whole, and require the equality to be a conjunct Two ways a guard could read as pinning a value it does not pin. The numeric alternative stopped at the first digit run, so `1e3` matched as `1` and `s.reasoningBudget === 1e3 ? 1 : s.reasoningBudget` passed: a budget of 1000 and a budget of 1 both return 1, which is the collision the check exists to catch. The pattern now spells exponent and radix forms and refuses to end mid-token. The equality only had to appear somewhere in the guard, so `(s.reasoningBudget === -1) === false` counted: that arm is taken for every budget except -1, the opposite of what the inner comparison reads as. The comparison now has to be one of the guard's top-level `&&` conjuncts, matched end to end, so an inner equality fed to another operator no longer pins anything. * Pin only on strict comparisons, and keep whitespace inside literals `==` relates a class of values to one literal rather than pinning the field to it: a message of "" and a message of "0" both satisfy `msg == 0`, so an arm returning 0 there holds still while the field moves between them. Only `===` and `!==` are read as pins now. That drops `s.reasoningBudget != null ? s.reasoningBudget : null`, which is false for null and undefined alike; the strict spelling of the same selector is still accepted. Normalisation stripped whitespace everywhere, including inside quoted literals, so a guard pinning the field to "a b" matched an arm returning "ab" and the collision it exists to catch read as a match. Whitespace is now only removed between tokens. * Find the last statement by bracket depth, not by the last semicolon A loop header carries its own semicolons, so taking the last one as the statement boundary hid the `for` from the fall-through check and `{ for (let i = 0; i < s.list.length; i++) return s.reasoningBudget; }` read as an unconditional return. An empty list falls through to undefined, which tracks nothing. Delimiters now count only at bracket depth zero. * Tighten the comments in the selector predicate Collapses the multi-line explanations on the internal helpers to what they need to say. No code change: comment_tools.py check reports comments only. * Read a parenthesised comparison as the comparison it is `(s) => (s.reasoningBudget === -1) ? -1 : s.reasoningBudget` was rejected: the conjunct arrives wrapped and the end-to-end match against it failed, so a reformatting of a selector this test accepts made it red. That is the class of guard this test replaced. Redundant outer parentheses are stripped before the match, one pair at a time and only when the opening one closes at the very end, so `(budget === -1) === false` keeps its meaning and is still refused. * Walk the block's statements instead of hunting the last return `{ if (s.enabled) return s.reasoningBudget; else return s.reasoningBudget; }` returns the field on every path, and the fall-through check invented an undefined path for it: it only recognised a trailing unconditional return, so an exhaustive if/else read as a block that can fall off the end. That is a semantics-preserving refactor of a selector this test accepts, failing it. The check now consumes the block's own statements. A return at that level ends it, a braced block is entered, and an if/else counts when both arms always return. A loop still never counts, since its body may not run at all. Consuming statements also binds `else` to the nearest `if`, which the regex could not, and keeps a helper declared mid-block from swallowing the return after it. * Read operators outside literals, and count an exhaustive switch Two legal refactors the predicate refused. A quoted literal is a value, not syntax, but `!`, `||` and `&&` were searched for across the whole guard, so a message spelling one of them made a selector that returns the field unchanged read as a guard carrying a negation or a disjunction. Those operators, and the bracket scan that splits conjuncts, now run against a copy with literal contents blanked out. A `switch` was consumed as a statement but never analysed, so an exhaustive one reported fall-through and the caller appended an undefined result that no path produces. A defaulted switch whose every arm returns now counts. Undefaulted does not, since a value matching nothing falls past the closing brace, and neither does a `break`, which leaves the switch with no value. * End the switch on an empty last arm, and compare pins by value An empty case falls into the next label, so it needs one: an empty LAST label leaves the switch instead, and `switch (s.mode) { default: return s.budget; case "x": }` returns undefined for mode "x". It is no longer read as exhaustive. Pins were compared as source text, so rewriting a literal broke them: `s.budget === 0x10 ? 16` returns the field unchanged for every budget and was refused, as were 1e3 against 1000 and 'x' against "x". Supported literals are canonicalised to the value they denote before the comparison, which leaves genuinely different values -- null against undefined, true against 1 -- apart. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read escapes, refuse a zero pin, and keep a nested switch's labels its own Three shapes the predicate got wrong. A backslash escapes the next character, but the literal patterns ended at the first matching quote, so a message containing an escaped quote cut the token short and a selector returning the field unchanged was refused. `budget === 0` is satisfied by -0 as well, so the branch holds two values, while zustand compares with Object.is, which tells them apart. An arm returning 0 there is stale across a -0 to 0 change, and the preset normaliser reaches -0 through Math.trunc, so this is a value the store can hold. Zero no longer pins. A nested switch has `case` labels of its own. Collecting them flat split the outer arms mid-brace and raised `unbalanced {` out of the predicate. Labels are now taken at the switch body's own bracket depth. * Let an arm fall through, and stop rejecting an unrelated negation Fall-through is not a property of empty arms. Any arm that neither returns nor breaks falls into the next label, so `case "x": sideEffect(); case "y": return s.budget;` reaches a return on every path and was being refused. A `break` still ends the switch carrying no value, and a last arm still has nothing to fall into. The guard checks searched the whole condition for `!` and `||`, so an ordinary extra condition was enough to lose the pin: `budget === -1 && !disabled` was refused for a negation that has nothing to do with the comparison. Both searches are gone. Requiring the comparison to match a top-level conjunct end to end already excludes a negated or disjoined one, because neither is a conjunct equal to the comparison itself. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Own the default, own the break, and keep a colon in a message out of the ternary Two of these let the predicate pass a selector that goes stale, which is the failure that matters here. The exhaustiveness check searched the whole body for `default:`, so a nested switch's default counted as the outer switch's. A mode matching no outer case falls straight past the closing brace. The default now has to be one of this switch's own labels. A `break` was located by bracket depth, which hides one inside a plain block. `if (stop) { break; }` leaves the switch just as plainly as a bare `break`. Only the statements that can absorb a break of their own are skipped now: a loop, a nested switch, a function body. Third, the ternary scan read raw source, so a colon inside a message was taken for the operator and a selector returning the field unchanged was refused. * Unwrap the guard before splitting it, and read escapes as the characters they spell A conjunction wrapped whole keeps its `&&` above depth zero, so `(budget === -1 && enabled)` was never split and the pin inside it never seen. The guard is unwrapped before the split now, which is the same treatment its conjuncts already got. A wrapped disjunction is still refused: unwrapping does not make `||` imply its parts. String literals were compared as source, so `"\\x61"` and `"a"` read as two values. Literals are decoded to the runtime string they denote before the comparison, covering \\xHH, \\uHHHH, \\u{...} and the usual single-character escapes, with an unrecognised escape standing for the character itself as JavaScript does. * Read try, do/while and surrogate pairs the way JavaScript does Three shapes a legal selector can take that the predicate refused. A `try` was split into clauses by the statement walker and never analysed, so one returning on every path read as a fall-through. It now counts when `finally` returns, or when both the attempt and its `catch` do. A `try` alone still does not: the throwing path is uncovered. `do` is the one loop whose body runs before its test, so `do { return x; } while (c);` always returns. `while` and `for` still do not count, since their bodies may not run at all. A surrogate pair is one character written the way JavaScript stores it, so the decoder now combines `\\uD83D\\uDE00` into the code point rather than leaving two halves. * Own the try clauses, and let a continue leave the switch Both of these let the predicate pass a selector that goes stale. `_try_always_returns` searched the whole statement for clauses, so a nested try/catch contributed its own and an inner body stood in for the outer one. A path falling out of the outer `try` then read as covered. The clauses are walked from the start of the statement now, so only this try's own count. An arm ending in `continue` does not fall into the next label: it jumps to the surrounding loop's test and leaves the switch. It is refused alongside `break`, with one difference that matters -- a nested switch absorbs a `break` but never a `continue`, which passes straight through it to the loop. * Count a loop that always enters, and read template literals A loop whose test is written as true always runs its body, so `for (;;) return s.budget;` and `while (true) return s.budget;` return on every path. They count now, unless the body can `break` out of the loop first, which puts the fall-through back. A test read off the store is still a condition, not a certainty. A template literal with no substitution is a constant like any other string, so a selector written with backticks is no longer refused. Two template patterns, which matters more than it looks: blanking has to pair backticks the way the source does, substitutions and all. A pattern that cannot match a template with ${} does not skip it, it pairs that template's closing backtick with the next one's opening backtick and blanks the operators in between. That is a false POSITIVE, not a rejection: the ternary stopped being split, and the whole expression read as one result that mentions the field. Blanking uses the permissive pattern; only the substitution-free form counts as a constant. * Trim the selector predicate's comments * Drop the unused _statement_start helper * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Let a continue end a single-pass loop, and read line continuations in literals * Refuse a selector with a regex, and skip properties named like keywords * Refuse a selector that returns a comparison, and inline only const bindings * Score the left operand of && and || as a path of its own * Split the left operand of && and || as well * Rewrite bracket access only outside string literals * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refuse a pin under a top-level || * Park string literals while reading a selector's structure * Inline a const only where it is referenced, and park literals inside substitutions * Leave a const uninlined when its name is bound again * Refuse a selector whose body binds the parameter's name again * Collapse whitespace around a member dot before reading the selector * State why ?? is not split, with the sheet's own selector as a case * Count only real loop and switch statements as jump absorbers * End a statement at do/while and at the next statement keyword without a semicolon * Score a comma expression's last operand, and strip comments in substitutions * Advance past a split operator by its own length * Read a return's expression by depth, and a line break after return as undefined * Refuse a selector that writes to its own parameter * Count destructuring and for-of heads as writes to the parameter * See through parentheses around a written parameter * Read binding patterns and parameter lists as balanced spans * Never take a labelled jump as absorbed * Read only the selector subset the test can prove, and refuse the rest * Take the field only as the value itself or a call argument * Refuse optional chaining, which can skip the read * Say in the failure that a refused spelling can be the cause --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: oobabooga <[email protected]>
Repo tests (CPU, studio)is red onmain, so every PR inherits it (seen on #11059, #11015 and #11013):The sheet is fine
af4e98e2f("add reasoning budget controls for llama.cpp models") is the last commit to touch the file, and it subscribes to exactly that field:Both memo dependency lists still name
reasoningBudgetandreasoningBudgetMessage, so a change to either still moves the Update button and the summary. The behaviour the test documents holds.The test was checking spelling
The first requires the selector to be one line with that exact text; making it conditional broke it. The second counts the field at two hardcoded indentations, so re-indenting either memo would break it too. Neither states the property, and a guard a legal refactor turns red says nothing about what it guards.
What it asserts now
The
useChatRuntimeStore(...)selectors and theuseMemo(...)dependency arrays are parsed with a balanced-bracket scan, and the test asserts the field is read by some selector and named by exactly two dependency lists.Mutation-tested against the regressions it exists for, with the sheet restored after each:
s.reasoningBudgetfails itNo product file changes.