Skip to content

Fix main: read the settings route's contract off its parse tree, not its text - #9591

Merged
danielhanchen merged 2 commits into
mainfrom
fix-contract-grep-reflow
Aug 23, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix-contract-grep-reflow

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Repo tests (CPU) has been red on main since #9492 (1f475d7), on
tests/studio/test_model_picker_contracts.py::test_the_backfill_fills_in_fields_rather_than_skipping_known_keys.
Every open PR inherits it. Run 32659798911.

What actually broke

The rule the test guards did not change. #9492 added a third name,
mirrors_server_tuning, to the model_dump(exclude = {...}) set in
update_openai_auto_switch_override. The formatter then split that set one name
per line, and this assertion stopped matching:

route = _read_backend("routes/settings.py")
assert '"remove", "fill_absent_fields"' in route

route is the raw source text of studio/backend/routes/settings.py, so the
two names now have a newline and sixteen spaces between them. Both are still
excluded, and write modes still stay out of saved_fields. #9492 is correct
here and the test was stale.

Why not just re-pin the literal

This is the third failure of this exact shape on main in as many days: #9579
sliced setup.sh at a keyword that had been demoted from if to elif, and
#9578 compared two clock origins. Pinning a new literal only moves the next one
into the future. A test that has to be re-edited whenever a set literal is
reflowed is not testing the thing it names.

The fix

The frontend greps in this file have no parser to hand. The backend does. Three
helpers read the rule out of settings.py's AST:

  • _model_dump_exclusions returns the names the one model_dump(exclude = ...)
    in a given function leaves out. Exactly one such call is required, or the
    answer would be a union across calls and a name dropped from the call that
    matters could hide behind another.
  • _annotated_field returns the annotation and literal default of a pydantic
    field, so "declared as a bool defaulting to False" is asserted as that rather
    than as a substring.
  • _forwarded_keywords returns the keyword arguments passed as
    name = payload.name, which is the part the storage layer depends on.

Each raises rather than returning empty when it cannot find what it was pointed
at, so a renamed handler or field reddens here instead of passing vacuously.

Anti-vacuity evidence

One mutation at a time against settings.py, running the repaired test:

Mutation Result
unmodified main pass
"fill_absent_fields" dropped from the exclude set fail
the exclude set reflowed onto one line, reordered pass
the payload field defaulted to True fail
fill_absent_fields no longer forwarded to the db call fail
the route handler renamed fail
the payload field renamed fail

The reflow is the case that caused this outage and is now the only one that
stays green. Every mutation that actually breaks the contract still reddens.

Local run

tests/studio/test_model_picker_contracts.py: 187 passed, was 186 passed and 1
failed. No production code is touched by this PR.

The second failure on the same run, (Python 3.13) / Backend tests, is a
different root cause and is fixed separately.

`Repo tests (CPU)` has been red on main since #9492 (1f475d7) on
test_the_backfill_fills_in_fields_rather_than_skipping_known_keys. The rule the
test guards did not change. #9492 added a third name to the
`model_dump(exclude = {...})` set in `update_openai_auto_switch_override`, the
formatter then split the set one name per line, and

    assert '"remove", "fill_absent_fields"' in route

no longer matched, because `route` is the raw source text of
studio/backend/routes/settings.py and the two names now have a newline and
sixteen spaces between them. Both names are still excluded. Nothing about the
write-mode-is-not-a-saved-field rule moved.

This is the third failure of this shape on main in as many days (#9578, #9579),
so pinning a new literal only moves the next one into the future. A test that
has to be re-edited whenever a set literal is reflowed is not testing the thing
it names.

The frontend greps in this file have no parser to hand. The backend does. Three
helpers read the rule out of settings.py's AST instead:

- `_model_dump_exclusions` returns the names the one `model_dump(exclude = ...)`
  in a given function leaves out. Exactly one such call, or the answer would be
  a union and a name dropped from the call that matters could hide behind
  another.
- `_annotated_field` returns the annotation and literal default of a field on a
  pydantic model, so "declared as a bool defaulting to False" is asserted as
  that rather than as a substring.
- `_forwarded_keywords` returns the keyword arguments passed as
  `name = payload.name`, which is the part the storage layer depends on.

Each raises rather than returning empty when it cannot find what it was pointed
at, so a renamed handler or field reddens here instead of passing vacuously.

Verified by mutation against the repaired test, one at a time on settings.py:

| Mutation                                          | Result |
|---------------------------------------------------|--------|
| unmodified main                                    | pass   |
| `"fill_absent_fields"` dropped from the exclude set| fail   |
| the exclude set reflowed onto one line, reordered  | pass   |
| the payload field defaulted to True                | fail   |
| `fill_absent_fields` no longer forwarded to the db | fail   |
| the route handler renamed                          | fail   |
| the payload field renamed                          | fail   |

The reflow is the case that caused this outage and is now the only one that
stays green; every mutation that actually breaks the contract still reddens.

Local: `tests/studio/test_model_picker_contracts.py` 187 passed, was 186 passed
1 failed. No production code changed.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4a0e6e3fd6

ℹ️ 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 8625c2e into main Aug 23, 2026
23 of 24 checks passed
@danielhanchen
danielhanchen deleted the fix-contract-grep-reflow branch August 23, 2026 20:39
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