Skip to content

Anchor studio source slices on declarations, not on comment text - #10297

Merged
danielhanchen merged 5 commits into
mainfrom
fix-comment-slice-anchors
Sep 4, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
fix-comment-slice-anchors

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Repo tests (CPU) is red on main at 553fdf8b6, and so on every PR branched from it, with 93 failures out of 15,899:

93 failed, 15806 passed, 366 skipped in 682.76s

56  tests/studio/test_new_chat_context_recount.py
18  tests/studio/test_cancelled_turn_history_prune.py
13  tests/studio/test_token_count_prompt_parity.py
 3  tests/studio/test_model_picker_contracts.py
 1  tests/studio/test_multi_chat_prompt_queue_contract.py
 1  tests/studio/test_deep_research_frontend_contract.py
 1  tests/studio/test_chat_thread_read_consolidation.py

Almost all of them are one line in the harness:

tests/studio/_node_harness.py:44: in slice_between
    end = text.index(end_marker, start + len(start_marker))
E   ValueError: substring not found
    end_marker = '      // Block queue materialization before taking the cancellation snapshot.'

#10114 is right, and it changed no behaviour at all

studio/frontend carries no JS test runner, so these tests slice the real source verbatim into a node harness and run it. The slices are delimited by markers, and a lot of those markers were comments.

#10114 trimmed comments across 245 frontend files. That comment now reads

// Block queue materialization before taking the cancellation snapshot: a queue that appears while

and four others the tests named were removed outright. Not one line of behaviour moved, and 93 tests went red.

A comment is prose about the code, not the code. It is exactly the thing a maintainer is free to reword, and a comment-only PR is the clearest possible case of a change these tests should not be able to see. They failed the one kind of edit they should have been blind to.

The change

Anchor the slices on the declaration or statement the comment sat above, not on the comment. 29 anchors across 12 files, including ones that still happen to match today and would have broken on the next trim.

     return slice_between(
         read(RUNTIME),
         "          const confirmedStatus = await getInferenceStatus().catch(() => null);",
-        "      // Block queue materialization before taking the cancellation snapshot.",
+        "      const lifecycleLease = useChatRuntimeStore",
     )

Each replacement was checked against the source as it stood immediately before #10114, where the old markers still resolve, and required to sit on the same side of the same code with nothing but comments and whitespace between it and the marker it replaces. So every slice covers the same statements it covered before, and each new anchor occurs exactly once in the file it is read from.

slice_between now refuses a comment as an anchor rather than failing later with substring not found several frames away:

if marker.lstrip().startswith(("//", "/*")):
    raise AssertionError(
        f"{role} anchor is a comment, so rewording it breaks this test: {marker!r}"
    )

Re-syncing the literals is the obvious alternative and it is what the table below argues against: it gets main green today and goes red again on the next comment edit, which is the same edit #10114 made.

Verified by breaking it

Thirteen edits to studio/frontend, each run against the test file that reads it. Comment-only edits must pass, real regressions must still fail:

edit expected result
trim the anchor's own comment again pass pass
delete the anchor's comment entirely pass pass
delete the docblock above a slice end pass pass
add a new comment above an anchor pass pass
reword the compare-composer comment pass pass
delete the deep-research comment pass pass
reword the usage-examples comment pass pass
resident fast path stops recounting fail fail
refusal detection always returns false fail fail
fresh default keeps the slot count fail fail
deep research drops the tools gate fail fail
compare side 2 loses its lifecycle acquire fail fail
the compact thinking rule stops hiding fail fail

Three of those started out as bad mutations of mine that passed when they should have failed, which is the check working.

Next to what a plain re-sync of the literal would give, on the anchor that took 56 of the 93 down:

re-synced literal this change
baseline 58 passed 58 passed
that comment trimmed again 56 failed, 2 passed 58 passed

tests/studio: 7483 passed, 195 skipped. No source changes.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-04T13:03:42.922092Z 03f0264 Manual request
ℹ️ About Codex in GitHub

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

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

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

@chatgpt-codex-connector 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: 765f54c072

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

Comment thread tests/studio/_node_harness.py Outdated
and took 93 tests here down with it, none of which were about anything it changed.
Anchor on the declaration or statement the comment sits above instead.
"""
if marker.lstrip().startswith(("//", "/*")):

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 Reject JSX comment anchors too

When test_project_chat_view_switch._provider_jsx() passes its existing end marker " {/* The view stays mounted", this predicate does not recognize the JSX comment prefix and therefore permits the same brittle comment-based slicing this change is intended to prevent. Rewording or removing that comment will still break the test, so the validation should also reject JSX comments such as {/* ... */}.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, and I missed it: my scan looked for // and /* and never for {/*, so both the guard and the sweep had a hole exactly where JSX lives.

The guard now rejects {/* as well, and the two JSX-comment anchors that existed are converted:

  • test_project_chat_view_switch._provider_jsx() ends on {children}.
  • test_desktop_reliability_frontend_contract ends on the <DiffusionTrainPanel branch. Worth noting the naive choice was wrong there: {pageMode === "train" ? ( on its own first matches 3.4k characters BEFORE the comment, which would have quietly shortened the header slice rather than failing. Pinning the two lines together is unique and lands where the comment did.

Battery: rewording either JSX comment passes, while dropping {children} from the provider and flipping the images header's divider rule both fail.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 03f0264961

ℹ️ About Codex in GitHub

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

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

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

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

@danielhanchen
danielhanchen merged commit f5a14aa into main Sep 4, 2026
23 of 24 checks passed
@danielhanchen
danielhanchen deleted the fix-comment-slice-anchors branch September 4, 2026 13:37
danielhanchen added a commit that referenced this pull request Sep 4, 2026
#10297 fixed this properly: the studio slice tests now anchor on the
declaration each comment sat above, and slice_between refuses a comment
anchor outright rather than failing several frames later. Restoring the
comment text only re-synced the literals, which goes red again on the
next trim, as that PR sets out.

This returns the branch to its one job, the facts #10114 dropped.
Souravrajvi0 pushed a commit to Souravrajvi0/unsloth that referenced this pull request Sep 4, 2026
…rd (unslothai#10307)

`Repo tests (CPU)` was red on `main` at `99a83f6a6` and `a2a4143ce`, and so on PRs branched from them, on one test out of 15,899:

```
FAILED tests/studio/test_auth_form_input_count.py::test_auth_flow_routes_do_not_mount_global_settings
  assert 'if (!active || !mounted) return null;' in mount
```

unslothai#10237 gave `SettingsDialogMount` a second surface, so the single lazy-mount flag became two:

```diff
-  const [mounted, setMounted] = useState(open || monitorOpen);
-  if (!active || !mounted) return null;
+  if (!active || !(settingsMounted || monitorMounted)) return null;
```

That is right and it did not open the auth routes. `!active` still short-circuits, so an inactive mount still renders nothing, which is the whole of what this test is named for. The other two assertions in the test still match byte for byte, so the chain it protects, auth route to `active={false}` to nothing rendered, is intact at every link. The assertion had simply quoted the auth gate and the lazy-mount bookkeeping as one string.

## The change

Assert the property rather than a spelling: `SettingsDialogMount` must return null from its own top level on every inactive render. The guard is read as a parse, because a textual match is what got us here:

- Comments and string bodies are blanked first, in a same-length copy so indices still line up. The assertion this replaces matched `// if (!active || !mounted) return null;` just as happily as the live line, so the guard could have been struck out entirely and the test would have stayed green.
- The slice is the real function body. The signature is `({ active }: { active: boolean })`, so the body brace is found by walking the parameter list rather than taking the first brace after the name.
- Only statements directly in that body count, so `(active) => { if (!active) return null; }` cannot answer for the component.
- The condition must be a disjunction whose first operand is `!active`. A top-level `?` or `,` disqualifies it, since both bind looser than `||`: `!active || mounted ? false : true` and `!active || track(), active` each leave the disjunction as a discarded sub-expression and skip the return while inactive. `?.` and `??` are neither.
- `{ return null; }` is accepted alongside `return null;`, so a bracing pass does not go red for nothing.

This is the same shape as unslothai#10267, unslothai#10231, unslothai#10289 and unslothai#10297. The file had already reached that conclusion twice on its own, as "Lock the count, not the spelling, so a rename does not falsely fail" and "Lock the behaviour, not one spelling of it, so either form passes". This assertion had not had the treatment.

## Verified by breaking it

The predicate was checked directly against 15 conditions, all correct. Then fifteen edits to `settings-dialog-mount.tsx`, each run against the test, next to what a plain re-sync of the literal would give:

| edit | re-synced literal | this change |
| --- | --- | --- |
| baseline | passed | passed |
| both mount flags renamed | **failed** | **passed** |
| a third surface joins the mount | **failed** | **passed** |
| the operands reordered | **failed** | **passed** |
| back to a single flag, as before unslothai#10237 | **failed** | **passed** |
| optional chaining in the second operand | **failed** | **passed** |
| the guard braced by a formatter | **failed** | **passed** |
| the `!active` half dropped | failed | failed |
| `||` becomes `&&` | failed | failed |
| the whole guard deleted | failed | failed |
| the gate inverted to `active` | failed | failed |
| a ternary swallows the disjunction | failed | failed |
| a comma expression discards the disjunction | failed | failed |
| the guard moved into a nested callback | failed | failed |
| the guard survives only as a comment | **passed** | **failed** |

Six harmless forms pass where a re-sync goes red on all six, none of which touches the auth routes. Nine real regressions fail. The last row is the one that matters most: a re-sync, and the assertion that was there before it, both accept a guard that exists only as a comment.

`tests/studio`: 7483 passed, 195 skipped. No source changes. Staging CI green.
danielhanchen added a commit that referenced this pull request Sep 5, 2026
* Restore the facts the frontend comment trim reworded away

* Correct three restored facts that no longer matched the code

* Put back the comments the tests read as landmarks

Some tests locate a region of the frontend by indexing on a comment's
exact text, so to them a comment is an identifier and deleting one is
deleting a symbol. #10114 trimmed ten of them, and 71 tests in
tests/studio have been failing on main since it merged. Restored
verbatim from 7580935^, comments only.

Reflowing counts as deleting here. Most of these were not removed, they
were rewrapped onto one line or had a second line dropped, which reads
as harmless and breaks the lookup exactly the same way.

One was failing silently, which is worse. The deep research contract
splits the adapter on "// Project sources auto-scope" rather than
indexing it, and split does not raise when the marker is gone, it
returns the whole remainder. Four assertions were being checked against
about two thousand lines of unrelated source and passing. The suite was
green and proving nothing.

tests/studio: 7475 passed, 0 failed, from 7404 passed and 71 failed.

* Revert the anchor restorations, superseded by #10297

#10297 fixed this properly: the studio slice tests now anchor on the
declaration each comment sat above, and slice_between refuses a comment
anchor outright rather than failing several frames later. Restoring the
comment text only re-synced the literals, which goes red again on the
next trim, as that PR sets out.

This returns the branch to its one job, the facts #10114 dropped.
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