Skip to content

fix(schema): handle field named 'required' in strict mode - #6240

Open
user-Param wants to merge 1 commit into
browser-use:mainfrom
user-Param:fix/6209-schema-optimizer-required-field
Open

user-Param wants to merge 1 commit into
browser-use:mainfrom
user-Param:fix/6209-schema-optimizer-required-field

Conversation

@user-Param

@user-Param user-Param commented Oct 30, 2026 •

Copy link
Copy Markdown

Fixes #6209 - SchemaOptimizer was skipping field names literally named 'required' due to an overbroad check in . The fix removes the key check since recursing into the 'required' array (list of strings) is a no-op, and correctly handles user fields named 'required'.


Summary by cubic

Fixes the strict-mode schema optimizer so user fields named required containing nested models are still processed (regression for #6209).

  • The optimizer previously skipped any dict/list value under a key named required, treating it as the schema's required array; iterating schema.values() recurses into every dict/list value, and recursing into the actual required list of strings is a no-op.
  • Adds a regression test covering a nested model under a field named required.

Written for commit ab11bf2. Summary will update on new commits.

View guided diff

@mintlify

mintlify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit ab11bf2.

Approve preview

@CLAassistant

CLAassistant commented Oct 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


def-Param seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.

View guided diff | Re-trigger cubic

@user-Param

Copy link
Copy Markdown
Author

@gregpr07 Could you please review this PR? All tests pass and the fix addresses a real issue. Thank you!

@r266-tech

Copy link
Copy Markdown
Contributor

Thanks for addressing #6209. I found two review points before merge:

  1. The current diff only changes browser_use/llm/schema.py and browser_use/tokens/service.py; it does not add the regression test described in Bug: SchemaOptimizer skips strict-mode required for a nested model under a field named "required" #6209. Please add a focused test with a nested model field literally named required, asserting that the nested optional property is present in that object's required list (and that the sibling field behaves the same). This would pin the failure mode without relying only on the implementation change.

  2. The clean_old_caches(keep_count=0) change is unrelated to the schema bug and has no test or linked issue in this PR. Please split it into a separate PR, or explain the intended scope and add a targeted test for its keep_count semantics. Keeping this PR focused will make the Bug: SchemaOptimizer skips strict-mode required for a nested model under a field named "required" #6209 fix easier to review.

@user-Param

Copy link
Copy Markdown
Author

Thanks for the review, @r266-tech!

  1. Regression test added — Added test_optimizer_handles_field_named_required_in_strict_mode which creates a model with a field literally named required containing a nested model, and asserts that the nested optional property is present in that object's required list (and that the sibling field behaves the same). All 4 schema optimizer tests pass.

  2. clean_old_caches(keep_count=0) — This change is in a separate PR (fix(tokens): handle keep_count=0 in clean_old_caches to remove all matching caches #6239, fix(tokens): handle keep_count=0 in clean_old_caches), not in this PR. PR fix(schema): handle field named 'required' in strict mode #6240 only touches browser_use/llm/schema.py. The clean_old_caches change has its own PR and issue (Bug: clean_old_caches(keep_count=0) retains every pricing cache #6235).

The PR is now focused solely on the schema fix (#6209) with a regression test. Ready for re-review.

@user-Param

Copy link
Copy Markdown
Author

Thanks for the review, @r266-tech!

Update on both points:

  1. Regression test for Bug: SchemaOptimizer skips strict-mode required for a nested model under a field named "required" #6209 — Added test_optimizer_handles_field_named_required_in_strict_mode to tests/ci/models/test_llm_schema_optimizer.py. Creates a model with a field literally named required containing a nested model, asserts the nested optional property is present in that object's required list (and that the sibling field behaves the same). All 4 schema optimizer tests pass.

  2. clean_old_caches(keep_count=0) — This change is already in a separate PR (fix(tokens): handle keep_count=0 in clean_old_caches to remove all matching caches #6239, fix(tokens): handle keep_count=0 in clean_old_caches), not in this PR. PR fix(schema): handle field named 'required' in strict mode #6240 only touches browser_use/llm/schema.py. I've now also added 4 targeted tests for the keep_count semantics in PR fix(tokens): handle keep_count=0 in clean_old_caches to remove all matching caches #6239 (browser_use/tokens/tests/test_clean_old_caches.py), covering keep_count=0, keep_count=N, keep_count > file count, and keep_count=1.

PR #6240 is now focused solely on the schema fix (#6209) with a regression test. PR #6239 has its own targeted tests. Ready for re-review.

…e#6209)

The _make_strict_compatible loop skipped dict/list values under a key
named 'required' (thinking it was the schema's required array). When a
user field is literally named 'required' and contains a nested model,
that nested model's properties were never processed for strict mode.

Changed the loop to iterate over schema.values() instead of
schema.items(), so every dict/list value is recursed into regardless of
its key name.

Also adds regression test test_optimizer_handles_field_named_required_in_strict_mode.

Fixes browser-use#6209.
@user-Param
user-Param force-pushed the fix/6209-schema-optimizer-required-field branch from d8edf42 to ab11bf2 Compare November 1, 2026 22:07
@user-Param

Copy link
Copy Markdown
Author

Thanks for the review, @r266-tech!

Both points addressed:

  1. Regression test added — Added test_optimizer_handles_field_named_required_in_strict_mode which creates a model with a field literally named required containing a nested model, and asserts that the nested optional property is present in that object's required list (and that the sibling field behaves the same). All 4 schema optimizer tests pass.

  2. clean_old_caches split — The clean_old_caches(keep_count=0) change was already in a separate PR (fix(tokens): handle keep_count=0 in clean_old_caches to remove all matching caches #6239). I've also added 4 targeted tests for its keep_count semantics in PR fix(tokens): handle keep_count=0 in clean_old_caches to remove all matching caches #6239 (browser_use/tokens/tests/test_clean_old_caches.py), all passing.

This PR now contains only the schema fix (#6209) + regression test. Ready for re-review.

@user-Param

Copy link
Copy Markdown
Author

@r266-tech

Copy link
Copy Markdown
Contributor

Re-reviewed exact head ab11bf2. The change is now limited to _make_strict_compatible and the regression test. Recursing into the required keyword list is a no-op because its entries are strings, while a nested schema under a user field named required is now visited.

The test covers both the required-named nested field and its sibling, and asserts the exact nested required members. The current hosted models/test_llm_schema_optimizer, code-style, and type-checker checks all pass. Both points from my earlier review are addressed; I have no remaining findings on this head.

This branch has not been deployed

No deployments
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.

Bug: SchemaOptimizer skips strict-mode required for a nested model under a field named "required"

3 participants