Skip to content

feat: consolidate shared harness code in harnesses.utils - #2482

Merged
mikasenghaas merged 2 commits into
mainfrom
feat/harness-utils
Aug 31, 2026
Merged

feat: consolidate shared harness code in harnesses.utils#2482
mikasenghaas merged 2 commits into
mainfrom
feat/harness-utils

Conversation

@mikasenghaas

@mikasenghaas mikasenghaas commented Aug 31, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #2454: the building blocks that standalone chat programs share were spread over verifiers.v1.mcp.client, harnesses/standalone.py, and a monolithic minimal/program.py. This PR gathers them in a new verifiers.v1.harnesses.utils package and removes harnesses.minimal entirely:

  • mcp.py — the bundleable MCP client helpers (mcp_client, connect_mcp, call_mcp, mcp_content_to_chat_content, with_retry), moved from verifiers/v1/mcp/client.py.
  • compaction.py — tool-output bounding and context compaction (markers, thresholds, discover_threshold, truncate_tool_output, Compactor), extracted from minimal/program.py.
  • core.py — the chat call, local tools (bash/edit/search), the interception hook, the chat loop (run_chat_loop), plus argument parsing, assembly, and the __main__ entry point (inert on package import; the entry point once the module ends the bundled script), extracted from minimal/program.py.
  • launch.pylaunch_chat_program; bundle_program(program, *modules), which generalizes inline_mcp_client to splice any utils modules into a PEP 723 program (moved from standalone.py); and CHAT_PROGRAM_SOURCE, the shared Null/Bash program built as bundle_program(<PEP 723 metadata>, mcp, compaction, core) — the program text is only the metadata block.

The browser_use program keeps its own program file and bundles mcp only. Cross-module references inside bundled code stay TYPE_CHECKING-guarded, resolved by the flat bundle at runtime — same pattern the programs already used.

Housekeeping picked up along the way:

  • verifiers.v1.mcp keeps the host-side server infrastructure (Toolset, serve*, SharedToolServer) and no longer re-exports the client helpers — re-exporting from the new location would import the whole harnesses package during mcp's own import. The one runtime consumer (tasksets/nemo_gym/toolset.py) imports from the new home.
  • Drops a duplicated CONTEXT_OVERFLOW_MARKERS tuple that a merge left in minimal/program.py.
  • Narrows the .gitignore core-dump pattern from core.* to core.[0-9]* (it swallowed harnesses/utils/core.py).
  • run_chat_loop returning (instead of the loop's old early return from main()) means the interception tool_client is now closed on the null overflow path too.

No behavior changes otherwise: the bundled program is the same logic, reordered.

Verification

  • CHAT_PROGRAM_SOURCE and the browser_use bundle compile.
  • The bundled chat program runs in a fresh isolated uv env (uv run --no-project bundled.py --help executes all spliced module-level code against the declared script deps and reaches the __main__ entry point).
  • verifiers.v1 and tasksets.nemo_gym.toolset import cleanly; ruff + unit tests pass.

Note

Consolidate shared harness code into harnesses.utils package

  • Moves MCP client, compaction utilities, and launch helpers into the new verifiers/v1/harnesses/utils package, deleting the old harnesses/minimal package
  • Introduces bundle_program in launch.py to replace inline_mcp_client; builds a shared CHAT_PROGRAM_SOURCE constant used by the Bash, Null, and Browser-use harnesses
  • Extracts run_chat_loop from main in core.py and moves all compaction logic into compaction.py
  • Updates all harness imports to pull from the new utils modules instead of minimal and standalone
  • Behavioral Change: verifiers/v1/mcp.__init__ no longer re-exports client helpers (call_mcp, connect_mcp, mcp_client, mcp_content_to_chat_content, with_retry); any imports of those names from verifiers.v1.mcp will fail at runtime — update imports to verifiers.v1.harnesses.utils.mcp

Macroscope summarized fa2e316.

The building blocks that standalone chat programs share were spread
over verifiers.v1.mcp.client, harnesses/standalone.py, and a monolithic
minimal/program.py. Gather them in verifiers.v1.harnesses.utils:

- mcp.py: the bundleable MCP client helpers (from mcp/client.py)
- compaction.py: tool-output bounding and the Compactor (from
  minimal/program.py)
- core.py: the chat call, local tools, interception hook, and chat
  loop (from minimal/program.py)
- launch.py: launch_chat_program and bundle_program, which generalizes
  inline_mcp_client to splice any utils modules into a PEP 723 program
  (from standalone.py)

minimal/program.py shrinks to argument parsing and assembly. The
verifiers.v1.mcp package keeps the host-side server infrastructure and
no longer re-exports the client helpers (re-exporting would import the
whole harnesses package during mcp's own import). Drops a duplicated
CONTEXT_OVERFLOW_MARKERS tuple left by a merge, and narrows the
.gitignore core-dump pattern to core.[0-9]* so it stops swallowing
core.py.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mikasenghaas mikasenghaas changed the title refactor: consolidate shared harness code in harnesses.utils feat: consolidate shared harness code in harnesses.utils Aug 31, 2026
@mikasenghaas
mikasenghaas marked this pull request as ready for review August 31, 2026 21:33
@macroscopeapp

macroscopeapp Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This refactor changes the shared harness execution bundle and removes the existing verifiers.v1.mcp client exports and module path, which can break downstream imports. The compatibility impact and restructuring of production evaluation infrastructure warrant human review.

You can add or adjust custom eligibility rules. Learn more.

core.py now carries the argument parsing, assembly, and __main__
entry point - inert on package import, the entry point once the
module ends the bundled script. The program text is reduced to the
PEP 723 metadata block, built as CHAT_PROGRAM_SOURCE in launch.py,
and the harnesses.minimal package is gone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Reply with the summary as plain text. Do not call any tools - summarize from the conversation as it stands."""

POST_COMPACTION_FRAMING = """Another language model started to solve this problem and produced \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure I like this. is this based on anything?

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.

think codex, let me double chec

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.

Yes - it's Codex's compaction template, taken verbatim. The framing here is https://github.com/openai/codex/blob/c4350b4ca2a5/codex-rs/prompts/templates/compact/summary_prefix.md#L1 (word-for-word identical), and CHECKPOINT_COMPACTION_PROMPT above is https://github.com/openai/codex/blob/c4350b4ca2a5/codex-rs/prompts/templates/compact/prompt.md#L1-L9 plus our trailing no-tool-call line.

Comment thread .gitignore
raise
return completion, messages

async def compact(self, messages: list[dict]) -> list[dict]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so if there is an overflow during compaction, it just tries again COMPACTION_ATTEMPTS many times, yes?

wonder if we should progressively truncate the middle each time there is a failed compaction attempt

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.

yes, this is what it currently does. can decide this in diff pr - this one just moves file

@mikasenghaas
mikasenghaas merged commit 23f2cec into main Aug 31, 2026
13 checks passed
@mikasenghaas
mikasenghaas deleted the feat/harness-utils branch August 31, 2026 23:30
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.

2 participants