Skip to content

Type agent config upstream to fix ty unsound-assignment - #952

Merged
Sun Haoran (haoranpb) merged 5 commits into
mainfrom
ty/strict-unsound-assignment
Oct 8, 2026
Merged

Sun Haoran (haoranpb) merged 5 commits into
mainfrom
ty/strict-unsound-assignment

Conversation

@haoranpb

@haoranpb Sun Haoran (haoranpb) commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

What

Fix ty unsound-assignment by typing data where it is read, instead of annotating each place Any gets assigned.

  • config.yaml is parsed into a frozen pydantic AgentConfig (bcbench/types.py). The YAML shape is unchanged; each section is its own model (instructions/skills: ToggleConfig, agents: CustomAgentsConfig, mcp: McpConfig). Unknown keys are rejected at every level, toggles are StrictBool, and MCP servers are typed as either HttpMcpServer or StdioMcpServer; the reserved altool/bcmcp servers must be stdio/http.
  • mcp.py keeps its original flow, including updating the server entries in place. The changes are just dict lookups swapped for attribute access, plus isinstance narrowing in the two next(...) lookups.
  • JudgeConfig is now a pydantic model too. It reads judges.<name>.model with AliasPath, which replaces the hand-written checks and the cast.
  • Values from raw JSON keep explicit annotations: text: object and platform: object, narrowed with isinstance. One cast with a comment remains for re.Match.group(1), which typeshed types as str | Any. In evaluator/metrics.py, tool_usage is untyped bc-eval metadata, so it stays Any instead of being annotated as dict[str, int].

Behaviour changes

  • An invalid config now fails when the file is loaded, with a pydantic ValidationError. This covers test-generation input, MCP server type, <category>-template keys, judge models, misspelled or non-mapping sections, non-boolean toggles (e.g. enabled: "yes") and mistyped reserved MCP servers. The old "use hyphens" hint is gone, but the error still lists the valid values.
  • A missing instructions/skills/agents section now means disabled. Disabled plugins entries are still not validated.

Part of the stack that makes ty strict (all = "error") across the whole uv workspace. Each PR fixes one rule in Python code only; the config change lands in #956.

@haoranpb
Sun Haoran (haoranpb) added this pull request to stack #957 October 7, 2026 12:57
Comment thread src/bcbench/agent/shared/mcp.py Fixed
@github-code-quality

github-code-quality Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: Python

Python / code-coverage/pytest

The overall line coverage in commit c4b552f in the ty/strict-unsound-as... branch remains at 86%, unchanged from commit c30246c in the main branch.

Show a line coverage summary of the most impacted files.
File main c30246c ty/strict-unsound-as... c4b552f +/-
src/bcbench/eva...stgeneration.py 46% 41% -5%
src/bcbench/col...t_codereview.py 89% 88% -1%
src/bcbench/ope...p_operations.py 92% 91% -1%
src/bcbench/ope...n_operations.py 88% 87% -1%
src/bcbench/age...opilot/agent.py 74% 73% -1%
src/bcbench/age...claude/agent.py 77% 76% -1%
src/bcbench/eva...view_parsing.py 70% 70% 0%
src/bcbench/types.py 91% 92% +1%
src/bcbench/config.py 97% 98% +1%
src/bcbench/age...t/shared/mcp.py 92% 95% +3%

Updated October 08, 2026 11:48 UTC

@haoranpb
Sun Haoran (haoranpb) force-pushed the ty/strict-unsound-assignment branch from fb21caf to c624647 Compare October 7, 2026 13:46
@haoranpb Sun Haoran (haoranpb) changed the title Make Any boundaries explicit for ty unsound-assignment Type agent config upstream to fix ty unsound-assignment Oct 7, 2026
Comment thread src/bcbench/types.py
Comment thread src/bcbench/types.py
Comment thread src/bcbench/agent/shared/mcp.py Fixed
@haoranpb
Sun Haoran (haoranpb) force-pushed the ty/strict-unsound-assignment branch from c624647 to 6b71fe8 Compare October 8, 2026 09:01
Base automatically changed from ty/strict-type-arguments to main October 8, 2026 09:09
@haoranpb
Sun Haoran (haoranpb) force-pushed the ty/strict-unsound-assignment branch 2 times, most recently from f0c65ef to 6b1efe1 Compare October 8, 2026 09:23
Comment thread src/bcbench/agent/shared/mcp.py
@haoranpb
Sun Haoran (haoranpb) force-pushed the ty/strict-unsound-assignment branch 2 times, most recently from 179bf55 to dd289b1 Compare October 8, 2026 10:13
@haoranpb
Sun Haoran (haoranpb) marked this pull request as ready for review October 8, 2026 10:13
Copilot AI balanced review requested due to automatic review settings October 8, 2026 10:13

Copilot AI 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.

🟡 Changes recommended

Malformed nested sections and incompatible reserved MCP server types can pass loading and fail or silently disable features later.

3 open findings
What changed in this PR

Moves agent and judge YAML parsing into typed Pydantic models to support strict ty checking.

Changes:

  • Adds typed prompt, MCP, agent, and judge configuration models.
  • Updates consumers and tests to use typed attribute access.
  • Narrows remaining raw JSON and HTTP values.
File Description
src/​bcbench/​types.py Defines typed agent configuration models.
src/​bcbench/​config.py Converts judge configuration to Pydantic.
src/​bcbench/​agent/​shared/​mcp.py Uses typed MCP server variants.
src/​bcbench/​agent/​shared/​prompt.py Reads typed prompt settings.
src/​bcbench/​agent/​shared/​plugin.py Accepts typed agent configuration.
src/​bcbench/​agent/​shared/​mcp_gateway.py Types HTTP responses.
src/​bcbench/​agent/​copilot/​agent.py Loads typed configuration.
src/​bcbench/​agent/​claude/​agent.py Loads typed configuration.
src/​bcbench/​agent/​claude/​metrics.py Narrows raw transcript text.
src/​bcbench/​operations/​skills_operations.py Uses typed skills toggle.
src/​bcbench/​operations/​instruction_operations.py Uses typed instruction and agent toggles.
src/​bcbench/​operations/​setup_operations.py Narrows JSON platform values.
src/​bcbench/​evaluate/​testgeneration.py Reads test-generation mode from AgentConfig.
src/​bcbench/​evaluate/​review_parsing.py Narrows parsed review JSON.
src/​bcbench/​collection/​collect_codereview.py Narrows regex results.
evaluator/​metrics.py Retains untyped external metadata.
tests/​test_mcp_config.py Updates MCP fixtures for typed configuration.
tests/​test_custom_instructions.py Updates instruction fixtures.
tests/​test_copilot_prompt.py Updates prompt fixtures and file loading.
tests/​test_config.py Tests Pydantic judge validation.
tests/​test_agent_skills.py Updates skills fixtures.
tests/​test_agent_plugins.py Updates plugin fixtures and shipped-config loading.
tests/​test_testgeneration_validation.py Removes legacy direct YAML validation tests.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread src/bcbench/types.py Outdated
Comment thread src/bcbench/types.py Outdated
Comment thread src/bcbench/types.py

Copilot AI 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.

🔵 Needs a closer look

The prompt validator silently accepts and discards the unsupported templates key, delaying failure until prompt construction.

0 open findings

3 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Reject prompt.templates to prevent silent overwrite and later KeyError

src/​bcbench/​types.py:582

An explicit prompt.templates key is currently accepted but silently overwritten by the synthesized mapping. This bypasses the promised unknown-key validation, so the config loads successfully and build_prompt later fails with a KeyError for the missing category template. Reject this internal field in the pre-validator so YAML must keep using <category>-template keys.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Sun Haoran (haoranpb) and others added 5 commits October 8, 2026 13:23
Parse config.yaml into a validated, frozen AgentConfig model instead of
passing raw dicts around, so consumers use typed attributes and ty no longer
sees Any flowing into declared types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 70c54f79-d7a0-4cde-baf2-e53dfff3deb4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🟡 Changes recommended

Raw judge and PR-review sections still bypass the advertised nested-key validation.

1 open finding

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread src/bcbench/types.py
@haoranpb
Sun Haoran (haoranpb) force-pushed the ty/strict-unsound-assignment branch from accbc65 to c4b552f Compare October 8, 2026 11:46
@haoranpb
Sun Haoran (haoranpb) merged commit 6c9c1ac into main Oct 8, 2026
30 checks passed
@haoranpb
Sun Haoran (haoranpb) deleted the ty/strict-unsound-assignment branch October 8, 2026 11:51
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.

3 participants