Skip to content

refactor(hle): migrate web-tool presets to agent sessions - #5953

Draft
yaoyu-33 wants to merge 66 commits into
mainfrom
codex/hle-web-tools-agent-migration
Draft

yaoyu-33 wants to merge 66 commits into
mainfrom
codex/hle-web-tools-agent-migration

Conversation

@yaoyu-33

Copy link
Copy Markdown
Contributor

This migrates the HLE-Diamond web-tools preset added in #5176 from opencode_sandboxed_agent to opencode_agent, and adds a pi_agent preset using the same tools and judge. The Environment Server owns the resources and agent sessions, grants the two MCP web tools, runs verification, and closes the sessions.

Targets rshahbazyan/hle-web-tools on top of #5176; the diff contains only this migration. No separate issue is needed for this focused follow-up.

Changes

  • Use single_agent_turn_legacy to adapt the existing dataset rows to agent sessions. The judge exposes no direct HTTP tools; hle_tools supplies web_search and web_fetch through MCP.
  • Add hle_diamond/pi_hle_tools through Gym's harness composition, retaining the dataset, blocklist, tool-session ownership, and grading.
  • Add optional sandbox_reasoning_effort to OpenCode's session config so the HLE preset continues requesting high effort. Unset preserves the adapter's default.
  • Document offline runtime requirements, a dedicated local Docker override, and migration impact.

Compatibility and benchmark impact

These presets now use the session adapters' output limits, compaction, status reporting, and cleanup. The previous pilot does not establish score parity. Restricted OpenCode runs additionally need a pinned plugin-dependency bundle; Pi runs need a prepared Pi 0.85.1 runtime. Pi retains its existing limitation: thinking: high does not transmit a reasoning_effort field through this provider path.

Validation

All verification ran on the workstation.

  • 436 tests passed, covering HLE configuration, OpenCode sandbox extensions, web tools, and single-agent environment orchestration:
    PYTHONPATH=. RAY_TMPDIR=/tmp .venv/bin/python -c 'import tests.helpers.single_agent_turn; import pytest; raise SystemExit(pytest.main(["resources_servers/equivalence_llm_judge/tests/test_hle_diamond.py", "responses_api_agents/opencode_agent/tests/test_sandbox_extensions.py", "resources_servers/hle_web_tools/tests/test_app.py", "environment_servers/single_agent_turn/tests/test_app.py", "--import-mode=importlib", "-q", "--disable-warnings", "--tb=short", "-o", "addopts="]))'
  • pre-commit run --all-files passed using Python 3.13; focused Ruff lint and formatting checks also passed.
  • Two real-model smoke rollouts passed, one per harness, using nvidia/nemotron-3.5-super-vl-120b-a12b for policy and HLE-format judging. Each called both web tools, returned the fixture answer, received reward 1, and removed its sandbox. Each made three policy calls; OpenCode's captured calls requested high reasoning effort.

The smoke used a synthetic question, a deterministic Tavily API fixture, and unrestricted Docker networking. Live Tavily, restricted-network execution, HLE accuracy, and the full test suite remain unvalidated; this PR stays draft. Rollout details are also recorded in the benchmark README.

rimashahbazyan and others added 30 commits October 26, 2026 15:36
… blocklist over MCP

Add resources_servers/hle_web_tools, a tool server that implements section 3 of
centerforaisafety/hle docs/evaluation-with-tools.md (commit 22ed307): exactly two
MCP tools, web_search (at most 20 results) and web_fetch (Markdown capped at
60,000 characters with a truncation indicator, no media payloads), with Tavily as
the search and extraction backend and the keys held server-side. The pinned
upstream docs/blocklist.json is shipped byte-exact and digest-checked at start;
all seven rule families are enforced with the protocol's semantics, plus query
refusal for blocked site: domains and verbatim question spans (8 consecutive
words, configurable; the question arrives through /seed_session), fetch-URL
checks after percent-decoding archive and proxy wrappers, title-and-Markdown
re-checks of fetched and cached pages, and a log line per blocked call naming
the family and rule.

Add benchmarks/hle_diamond/opencode_hle_tools.yaml, the OpenCode preset with this
server as its only tool server, document it and the residual Tavily-backend
difference in the Diamond README, and extend the Diamond preset tests to it.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…uestion

The plain POST /web_search route stays served next to /mcp under Gym's MCP
exposure, and a call without the rollout's cookie or token lands in a fresh
session that carries no question, so the verbatim-span rule was silently
skipped (probe: the same 8-word query refused with the rollout cookie, served
with no cookie and no token). Fail closed instead: web_search refuses any
session that was not seeded with a question under the new
require_seeded_question flag (default on), logged as family=unseeded_session;
a seed without a question says its searches will be refused. The other
families already applied on the direct route, and web_fetch has no
session-dependent rule.

Add the model-free test (seed, then a cookie-less POST /web_search is refused
and the backend is never called; the flag off restores the old behaviour),
and reword the module docstring and both READMEs to describe the enforced
behaviour rather than claiming the agent reaches the server only over MCP.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
…uestion

A session now keeps the question it was seeded with: a retried seed with the
same words is served again, a seed that would change or drop the question
answers HTTP 409 (ResourcesSessionConflictError), so a caller holding a
session cannot swap the verbatim-span check out from under it. QuestionSpans
keeps a SHA-256 of the normalized words, never the text, to tell the two
apart.

This does not close the fresh-session path: /seed_session is unauthenticated
and network_access model_and_tools admits the whole tool-server host, so a
sandbox can seed a new session with a question of its choice and search from
it without the span rule. The server README and the opencode_reference.yaml
header now state that residual and what closing it needs (an authenticated
seed channel the sandbox never sees).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
(cherry picked from commit 27187af4bc522d498ca64039b14570f41434aae2)
Resolved benchmarks/hle_diamond/README.md: the Tests block keeps main's
opencode_sandboxed_agent/tests/test_hle_reference_image.py line (#5177)
and adds this branch's resources_servers/hle_web_tools/tests/test_app.py.
resources_servers/equivalence_llm_judge/tests/test_hle_diamond.py merged
without conflict; both sides' additions are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
main moved the modules this server imported (nemo_gym.base_resources_server,
nemo_gym.server_utils names, nemo_gym.mcp_auto_exposure) and serves the old
paths only through deprecation shims removed in nemo_gym 0.10.0. Rewritten
with scripts/migrate_imports.py to the public API (nemo_gym.client,
nemo_gym.server_runtime) and, for the MCP test, the defining module, as
the other servers on main do; the README names the new request path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
opencode_reference.yaml and the README's Reference preset section, both
from main (#5177), said the reference preset would switch to the
hle_web_tools server once it existed. This branch adds that server, so
the sentence would turn into an unfulfilled promise on merge. The
reference preset keeps the Tavily tools here; the wording now names
opencode_hle_tools as the preset that runs hle_web_tools (on the science
image) and leaves running it on the reference image and egress policy to
a follow-up change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
A key pool whose keys Tavily all rejects (401, 432, 433) spun forever in
the key-selection loop without an await, freezing the worker's event
loop: one configured key, a key listed twice, or two distinct rejected
keys were enough. A rejected key also spent the transient retry budget,
so [bad, bad, bad, good] with three attempts never reached the good key.

The pool is now deduplicated when the backend is built, rejected keys
move on without spending an attempt, the next key comes from a bounded
helper over the keys still accepted, and the call raises a RuntimeError
naming the status once every key is rejected. Transient failures keep
their backoff and budget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
web_search read Tavily's payload unguarded: a body that is not an
object, `results: null`, a non-object item or a non-string title or
content raised AttributeError or TypeError and reached the model as an
HTTP 500. web_fetch had the same `results: null` gap and rendered a
non-string raw_content as page text.

Both tools now read the results list through one guarded helper.
web_search answers a malformed body with a "Search failed" tool error,
skips non-object items and treats non-string title and content as
empty; web_fetch reports any malformed body, item or raw_content as
"Fetch failed", and guards failed_results the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
CI's changed-server step runs ng_test with should_validate_data=true,
which requires data/example.jsonl (5 rows), data/example_metrics.json and
data/example_rollouts.jsonl, plus an agent with an example dataset in the
server config; hle_web_tools had none of them.

Following resources_servers/tavily_search: the config gains a
simple_agent with an example dataset behind a single_agent_turn_legacy
environment server over direct HTTP, example.jsonl holds 5 synthetic
general-knowledge rows (no HLE text, each marked by a placeholder field)
whose tools are web_search and web_fetch with the server's own schemas,
example_metrics.json comes from gym dataset collate in
example_validation mode, and example_rollouts.jsonl holds placeholder
rows since no live model or Tavily call was made. The server stays
verified: false. The README says so, and the update-readme-table hook
adds the server to the environment list now that its config has an
agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
Seeded questions and the page cache are per process, so with
num_workers > 1 a rollout's seed and its searches could land in
different workers; the module also defines no worker app, so such a
launch fails to start. Rather than add the multi-worker entrypoint
footer, the README states the single-worker requirement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
The URL check certified URLs it had not fully checked and matched the
page-level families on the raw string only. Now url_block:

- refuses as malformed_url any URL longer than 4,096 characters, with a
  backslash, whitespace or control character, or with any @ in the
  authority (an empty https://@host included);
- fails closed when candidate expansion stops with candidates unexplored,
  at the 64-candidate cap or after the original plus four rounds, so 63
  decoy query values or a fourth decoded form no longer hide a target;
- runs url_prefixes and serp_url_patterns on a canonical form as well
  (IDNA lower-cased host, trailing dot, userinfo and default port
  dropped, dot segments resolved), so :443, a trailing dot or /x/../
  no longer evade a prefix;
- treats every *.archive.org host as a wrapper and reads https:/,
  https:/// and https: remainders as https://;
- reads wrapped and decoded URLs the way WHATWG fetchers do (backslash
  as /, tab and newlines deleted);
- takes each embedded http(s):/ up to the next one instead of through a
  lookahead to the end of the string, so extraction is linear.

site: operands are read as host characters only, so (site:a OR
site:b), site:a|site:b and site:b, yield bare hosts, and an operand
whose IDNA encoding fails is refused instead of skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
Fetched content was sanitized and cut at max_cached_page_chars before
the content families ran, so a blocked span past 500,000 characters was
served and cached, and a cache cap below max_fetch_chars served a cut
page as truncated=False. Now:

- a fresh page is checked against url_patterns and
  patterns_case_sensitive on the provider's raw Markdown, before data
  URIs are removed or anything is cut, and on the sanitized Markdown;
  a refused page is never cached;
- the scan is bounded: a page longer than max_page_chars (new,
  default 1,000,000) is refused unread as oversized_page, and the regex
  work runs in a worker thread instead of on the event loop;
- max_cached_page_chars no longer cuts the page: a longer page is
  served whole but not cached, so cache-hit rechecks see the complete
  sanitized Markdown;
- data URIs with media-type parameters or a percent-encoded payload are
  removed too, the payload stops at the Markdown destination's end so
  following prose is kept, and every repetition is bounded so the
  regex stays linear (the unbounded suggested form is quadratic);
- the heading fallback for the title is linear on long blank runs
  (100,000 characters took 42 s) and drops a closing # sequence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
…oses

A typed seed (an Environment Server's resources_session_id, episode_id,
task_id and task_data) kept only the question, so the same ID could be
seeded or closed for another episode or task, and a seed replayed after a
close recreated a searchable session. Typed seeds are now validated as
ResourcesSeedSessionRequest, their episode and task are recorded next to
the question, and seed and close go through ResourcesSessionFence, as in
example_single_tool_call: a conflicting seed or close answers 409, and a
seed after its session closed is refused for the retry window. The
identity map shares the 10,000-session cap with the questions and is
evicted with them. Legacy Agent seeds are unchanged.

The test runs check_resources_session_contract with keeps_state=True.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
A seed whose question has no word characters ("?!", or an empty user
message) was stored as seeded with span_words=0, which disabled the
verbatim-span rule while require_seeded_question still saw a seeded
session. extract_question now returns None for such text (the question
field falls back to the last user message first), so the session stays
unseeded and its searches fail closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
…tion

Past MAX_SESSION_QUESTIONS (10,000) seeded sessions the least recently
seeded one was dropped silently, and its later searches were refused as
unseeded_session with nothing pointing at the cause. The eviction now logs
a WARNING naming the session and the cap. The test lowers the cap to one
and also checks that the question and the episode binding leave together.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
blocklist.json is an unmodified copy of docs/blocklist.json from
centerforaisafety/hle at 22ed3074b1e7b134bcbc09028d0ba320839b0655, which
is MIT (Copyright (c) 2025 centerforaisafety). The JSON stays byte-exact
for its digest check, so the upstream LICENSE at that revision is
reproduced unchanged in the sibling LICENSE-HLE, the file gets a row and
a note under Vendored Components in ATTRIBUTIONS.md, and the server
README gains a Licensing section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
Both READMEs called the Tavily backend the one residual difference from
upstream's wrapper, and the Diamond section said a session not seeded
with the question is refused "so the span rule cannot be skipped". Both
overstate the policy: /seed_session is unauthenticated, so a sandbox
process can seed a fresh session with a question of its choice and
search from it; the 409 on re-seeding covers existing sessions only, and
the session and MCP-token signing key derives from public config.

The server README now names that residual in its own paragraph, the
Diamond section lists it next to the backend as the second residual, the
fail-closed sentences are scoped to unseeded sessions, and the server
README's dangling pointer to the Diamond "Reference preset" section now
points at "Upstream web tools", where the residual is listed. Closing it
needs an authenticated seed channel; both READMEs carry the marker
TRACKING_ISSUE_TBD for the tracking issue, to be replaced by its number
before push.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
The core unit tests require every resources server to ship a task_data.py,
and the committed example rows to validate against it. hle_web_tools had
none, so TestSchemaPresence and TestRepoDataMatchesSchemas failed.

Declare both keys the example rows carry: the optional question that
/seed_session reads, and the placeholder note that marks the rows as
synthetic. Keeping the note in the data makes each row say what it is;
the schema records that the server never reads it.

tests/unit_tests/test_task_data.py: 2 failed, 421 passed before;
425 passed after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
normalize_hostname used Python's IDNA 2003 codec, which leaves code
points unassigned in Unicode 3.2 unmapped. Browsers (WHATWG URL) and
yarl, which aiohttp uses, map a host with UTS #46 first, so
https://sc\U0001f130le.com/leaderboard was allowed by the policy but
fetched as scale.com. The same held for lastexam.ai and arxiv.org
spelled with such letters.

Map a non-ASCII host with idna.uts46_remap (non-transitional, no STD3
rules) before the existing encode, and declare idna, already installed
through aiohttp and yarl, as a direct requirement. IDN hosts that are
ordinary (例え.jp) keep their punycode form.

Test: one row in the URL refusal table; it fails before this change
(allowed, extract awaited) and passes after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
url_shape_problem refuses an unparseable URL only at the outer level.
For a wrapped or decoded candidate, _single_url_block returned None when
urlsplit or IDNA raised, which skipped every family for it. Python
rejects https://[::1]@scale.com/leaderboard ("'scale.com' does not
appear to be an IPv4 or IPv6 address"), while browsers, httpx and
urllib3 read it as host scale.com, so a redirector carrying it in
?u= was served.

Refuse such a candidate as malformed_url instead. The realistic URL list
from review (48 URLs) shows no new refusal.

Test: one row in the URL refusal table; fails before (served), passes
after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… spelled

A scheme-less remainder became a candidate only when it matched an
ASCII-only host regex, which rejects a trailing dot after the TLD,
userinfo and full-width or ideographic-dot hosts. So
web.archive.org/web/2024/scale.com./leaderboard and
web.archive.org/web/2024/[email protected]/leaderboard were served, as was
?u=scale.com./leaderboard on a redirector.

A wrapper fetches its remainder (and Google's cache its cache: target)
whatever the spelling, so read each as https://<remainder> and let
urlsplit and normalize_hostname decide the host. Other query values
still need a scheme or a leading hostname, which may now end with a dot.
The README also records the malformed_url refusal of an unparseable
wrapped URL from the previous commit.

Test: three rows in the URL refusal table; all three fail before
(served) and pass after. The realistic URL list from review shows no
new refusal.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…order

The eight openreview.net prefixes carry ?id=<paper>. As plain string
prefixes they match one exact parameter order, so
openreview.net/pdf?&id=46UGfq8kMI and openreview.net/pdf?x=1&id=...
were served although a server reads both as pdf?id=46UGfq8kMI, and the
id appears in no url_patterns rule.

Keep the string-prefix check and add a second reading for a prefix with
a query: its path must prefix the URL's path, and each of its key=value
pairs must be among the URL's parsed query pairs (a value as a prefix),
in any order. This only adds matches to the upstream semantics.

Test: two rows in the URL refusal table; both fail before (served) and
pass after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
remove_dot_segments kept // runs, so arxiv.org//abs/2605.02442,
arxiv.org/abs//2605.02442, arxiv.org/%2Fabs/... and the Wayback form
of the first were served, and 2605.02442 has no url_patterns rule to
catch them. Servers with nginx's default merge_slashes serve such paths
as the single-slash page.

Collapse runs of / in the canonical form. It is used for prefix and SERP
matching only; the fetched URL is unchanged.

Not changed: export.arxiv.org and /format/, /src/ and /e-print/ paths of
2605.02442 are gaps in the pinned upstream list, not in its matching.

Test: one row in the URL refusal table; fails before, passes after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hecks

question_words ran \w+ over str.casefold() with no normalization, so a
query that repeats 8 words of the question in full-width or mathematical
letters, with a zero-width space or soft hyphen inside a word, with a
combining accent, or joined by underscores was served. The query
patterns had the same gap: humanity<U+00AD>s last exam was not matched.
Search engines fold all of these back to the plain words.

Words are now runs of letters and digits ([^\W_]+) after NFKC with
format characters (Cf) removed and combining marks stripped; the
question and the query go through the same function. url_patterns,
patterns_case_sensitive and site: operands are checked on the query as
written and as folded. Look-alike letters from another script (Cyrillic
o) are still not folded; the README says so.

Test: test_presentation_variants_of_a_blocked_query_are_refused, five
rows, one per mechanism (NFKC, Cf, combining mark, underscore, a pattern
with a soft hyphen); all five fail before and pass after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit was made before ruff-format wrapped this row; no
behavior change.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Result titles come from the provider with no length bound, and
_TITLE_SEPARATOR_RE (\s+ before a separator) backtracked over every
blank of a run, quadratic in its length: a 20,000-blank title took
3.9 s and a 50,000-blank one 26.6 s of web_search on the event loop.
Each separator also added a variant up to the full title length, so a
title of 'a | ' * 2,000 cost 1.1 s.

Start the separator match only at the first blank of a run, and cut a
title longer than 1,000 characters (with an ellipsis) before it is shown
or checked against answer_title_patterns. url_patterns and
patterns_case_sensitive still see a result's whole title, which is
linear.

The same cap applies to the fetched page's Title: line. That title,
taken from the heading when the provider sends none, was not counted
against max_fetch_chars, so one fetch could return about 960,000
characters.

Tests: test_long_result_titles_are_checked_in_linear_time (a blank run
and a separator chain, both 20,000 characters) fails before (about 5 s)
and passes after; the 60,000-character cap test gains a heading-derived
title case, which fails before (the 100,000-character title is shown
whole) and passes after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
5142f52 turned a decoded body of the wrong shape into a tool error,
but a 200 whose body does not decode still escaped: a gateway's HTML
page raised aiohttp's ContentTypeError and a cut-off JSON body raised
JSONDecodeError, and both reached the caller as a server error.

Return None from the transport for such a body, so the existing
"Search failed: ... malformed response" and "Fetch failed for <url>"
paths answer it. It is not retried: a 200 is not a transient status.

Test: two rows (HTML body, cut-off JSON) in the parametrized
malformed-payload test, through the real transport with a stubbed
request; both fail before (the exception propagates) and pass after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… spends it

test_rejected_keys_do_not_spend_the_retry_budget only bounded the total
number of requests, which the pre-fix code also met. Two real
regressions survived it: a rejected key spending an attempt, and key
selection that no longer wraps round to the current key.

Replace it with the mixed case: keys key-one, key-two and two attempts;
Tavily answers 401, 429, 200. The call must succeed after trying
key-one, key-two, key-two with one backoff sleep.

Fails on app.py from 498e34b (before eb466ec: "Tavily HTTP 429 on
/search after 2 attempts"), on the spend mutant (same error) and on the
no-wrap mutant (TypeError); passes on HEAD.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Untyped Agent seeds share the 10,000-session cap with typed sessions.
When eviction dropped a live typed session's episode binding, a later
seed of that ID for another episode returned 200 and bound it, where
the resources-session contract requires 409; the session's question
was already gone.

When the cap forgets a typed session, mark its ID closed by its bound
episode in the session fence. A later seed of the ID then gets 409, and
a close from its own episode is still accepted. The README states that
the cap must exceed the peak number of open rollouts.

Test: test_sessions_past_the_cap_are_forgotten_with_a_warning now seeds
the forgotten ID for another episode and expects 409; it fails before
(DID NOT RAISE) and passes after.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rdless fallback

Three regressions survived the session tests:
- a close naming another episode of a live typed session was not
  checked (the contract checks it only for a closed session), so
  disabling that 409 deleted the session's question unnoticed;
- holds_state looked only at the question table, so a close that kept
  the episode binding passed;
- the wordless-question row used the question field, which either of the
  two guards refuses alone, so dropping the extract_question gate for the
  last-user-message fallback passed.

The contract test now counts the binding as held state and closes a live
session with another episode (409, question and binding kept). The
wordless case also seeds a last user message of "?!" with no question
field.

Fails on: the close-conflict mutant (200 != 409), the close-keeps-binding
mutant ("close left state"), the gate mutant and app.py from 16cd8c0
(wordless message seeded); passes on HEAD.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
rimashahbazyan and others added 24 commits November 6, 2026 12:34
…ke ASCII quotes

Follow-up to review thread 4405604730 (site: operand parsing). Typographic
quotes and guillemets were neither openers nor excluded from the operand,
and NFKC does not fold them, so site:“scale.com” became the punycode host
xn--scale-hw3b.xn--com-9o0a, which is hostname-shaped and matches no
domain: the query was served with no refusal and no audit line. A
trailing ” survived as well (site:scale.com” became scale.xn--com-9o0a),
since trailing punctuation is stripped after IDNA encoding.

The operand regex now treats ‘ ’ ‚ ‛ “ ” „ ‟ « » ‹ › like " and ': they may
open the operand and end it. The opener run is now repeatable, so stacked
openers (site:((scale.com)), site:«“scale.com”») no longer stop the match.

Before (HEAD app.py, new rows): site:“scale.com”, site:scale.com” and
site:((scale.com)) are served. After: each is refused as domains;
site:example.org, site:“example.org” and site:en.wikipedia.org/wiki/Foo_(bar)
are still served; 101 passed.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…WSP as a word break

Follow-up to review thread 4398612299 (span-rule folding, e075400). Two
spellings still got an 8-word question span or a blocked query past both
readings of format characters:

- Mixing a zero-width space between words with a soft hyphen inside one
  ("How<ZWSP>many ... no<SHY>nvanishing", "H<SHY>LE<ZWSP>leaderboard"):
  each reading treats every format character the same way, so each one
  breaks. Unicode word segmentation (UAX #29) splits at U+200B and ignores
  U+00AD, and reads both as [how, many, ..., nonvanishing].
- Hangul fillers (U+3164, U+115F, U+FFA0; default-ignorable, category Lo)
  inside a word ("no<HF>nvanishing", "Hum<HF>anity's Last Exam",
  "H<HF>LE leaderboard"): only category Cf was folded, and NFKC maps the
  filler to U+1160, still a letter.

fold_text now treats every Default_Ignorable_Code_Point (ranges from
DerivedCoreProperties, since unicodedata has no such property) like a
format character, and the checks read text three ways: all removed, all
as a space, and as word segmentation does (U+200B a space, the rest
removed). The readings apply to the question n-grams, the query's words,
and the query forms the text families and site: operands see.

Before (HEAD app.py, new rows in the presentation-variant table): the four
rows mixed-format-characters, mixed-format-pattern, hangul-filler and
hangul-filler-pattern are served. After: each is refused with its family;
105 passed. Seeding a 2.24 MB non-ASCII question takes 1.6 s instead of
1.1 s (ASCII: 0.49 s, unchanged); unbounded seed size is already part of
the unauthenticated-seed residual.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ged before dots

Follow-up to review thread 4405604669 (equivalent spellings, 25f0c7f).
The canonical form resolved dot segments and then collapsed slash runs, so
arxiv.org/abs/x//%2e%2e/2605.02442 became arxiv.org/abs/x/2605.02442 and
was fetched. httpx and urllib3 send that path unchanged, and nginx with its
default merge_slashes collapses the run first and then resolves the dots:
a throwaway nginx 1.26.3 serves /abs/2605.02442 for it (whether arxiv's
front end does the same is not verified).

The URL-shaped families now see both orders: dots then slashes (as before)
and slashes then dots (nginx).

Before (HEAD app.py, new URL-table row): arxiv.org/abs/x//%2e%2e/2605.02442
is allowed. After: refused as url_prefixes; arxiv.org/abs/x/2605.02442 and
example.org/a//../b stay allowed; 106 passed.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lank run

Follow-up to review thread 4405604713 (e10df7a capped shown titles). The
answer-title check ran on the title already cut at 1,000 characters, so a
result titled "Quiz answers" + 5,000 blanks + "| Site" lost its separator
to the cut and was kept, although the model is shown "Quiz answers ...".
Before the cap it was dropped.

title_variants now takes the whole title: the title as shown, plus the
title up to each separator that starts within the first 1,000 characters,
however long the separator's blank run. Each variant stays at most 1,000
characters, so the check stays linear (1,000,000-character titles: under
0.04 s). An answer phrase that lies wholly past the cut is neither shown
nor checked; the README says so.

Before (HEAD app.py, new row padded-separator): kept. After: dropped;
107 passed.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lout

Review threads 4398612339 (LRU eviction) and 5680046430 (HOLD summary).
The README said the cap "must exceed the peak number of rollouts open at
once". That holds only for a harness that closes its sessions: OpenCode
seeds with its run body and never closes, so held sessions add up, and a
running rollout's question is forgotten once more than 10,000 later seeds
reach the server, however few rollouts are open at once (probe with the cap
at 2: A forgotten after B and C seed, with at most 2 open).

The README also said a seeded session keeps its question "for its whole
life", but only typed seeds check the fence: a forgotten Agent (untyped)
session, or a closed typed ID, takes a later untyped seed through its
cookie with another question (HTTP 200). The README and the comment in
_install_question now say so, and that this, like an unauthenticated seed
flood past the cap that makes other rollouts' searches fail closed, is the
same unauthenticated-seed residual as a sandbox-seeded fresh session.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review thread 4398612357 (data URIs). The README named the 16-parameter
bound only, but the regex also caps the type and subtype at 127 characters,
each parameter name at 127 and each value at 256: a data URI with one
parameter value of 257 characters is not matched and is served whole. The
bounds are what keep the scan linear, so the code is unchanged; the README
and the regex comment now state them and that a URI past them is left in
place.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…runs on the loop

The README described the page-check pool (b132980) without its cost or
its scope. Measured at this head, with the Tavily transport stubbed:

- The pool is created on the first page check and starts workers on
  demand, up to two. Each worker imports the server module afresh and sits
  at about 240 MB RSS, the size of the server process, and the first fetch
  takes about 1.8 s against 0.002 s afterwards.
- web_search's per-result URL, title and snippet checks still run on the
  event loop: one result whose title (or snippet) is 1,000,000 characters
  of 抱抱脸 holds the loop 4.2-4.4 s. Whether Tavily ever returns a title or
  snippet that long is not verified.

Both are now stated next to the pool description; the code is unchanged.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The configuration table omitted tavily_base_url, the one config field it
  did not list.
- The quoted multi-worker refusal hard-coded hle_tools, the Diamond
  preset's instance name; refuse_unsupported_num_workers prints the
  instance's own name (hle_web_tools for configs/hle_web_tools.yaml).
- "The checks below need TAVILY_API_KEY" pointed at Example data and Tests,
  which are model-free and pass with the key unset; the key is needed for
  live runs of the preset.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…residual

The Diamond README's residual said the 409 on re-seeding does not cover a
new session. It does not cover a session the server's cap has forgotten
either: an untyped seed through that session's cookie installs another
question (HTTP 200). The server README says so since 0cd8d9c; this keeps
the two residual descriptions consistent.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring the branch up to date with 79 main commits since 045284c.

Resolutions:
- README.md: git merged the environment table without a textual
  conflict. To be sure the row is generated, the table was reset to
  main's version and regenerated with scripts/update_env_list.py. The
  only difference from main is the generated "Hle Web Tools" row.
- No other file changed on both sides.

Main's managed environment lock files (#4837) delete every component
requirements.txt and forbid new ones. The migration of
resources_servers/hle_web_tools to pyproject.toml and uv.lock follows
in a separate commit.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's #5083 split ResourcesSessionFence into ResourcesSessionLocks,
which runs a session's seed and close one at a time, and
ResourcesSessionFences, which refuses a seed after its close until the
close retry window ends. The old name no longer exists, so the server
failed to import after the merge.

Map each call onto the new API without changing behaviour: locked() on
the locks, and raise_if_fenced(), get() and fence() on the fences in
place of raise_if_closed(), closed_episode() and mark_closed(). The base
config already requires a positive close retry window, so the new
constructor's check adds no refusal.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's #4837 moved every component from requirements.txt to a committed
uv project and lock, and its component dependency tests now refuse a
server that still ships requirements.txt or lacks either file.

Move the server's two requirements, nemo-gym[dev] and idna>=3.7, into a
pyproject.toml that copies the shared resolver policy, as
scripts/component_locks.py expects. The lock was seeded from the
calendar server's lock, which has the same Gym dependencies, so it pins
the same versions as the other component locks (idna 3.10, mcp 1.29.0)
instead of a fresh resolve that would move mcp, fastapi and others to
new major or minor releases.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since the timestamp-less Wayback reading was added, every /web/<first>/...
path was read both ways, so an ordinary timestamped snapshot also yielded
the candidate https://<timestamp>/<url>, which names no page. Each Wayback
layer then cost one to three extra candidates and more decode rounds, and a
URL at the edge of MAX_URL_CANDIDATES or MAX_URL_DECODE_ROUNDS was refused
as malformed_url where it was served before (four timestamped layers around
a percent-encoded page, or a snapshot of a page with thirty URL-valued query
values).

Add the second reading only when the first segment is not timestamp-shaped
(digits with an optional two-letter modifier such as id_ and an optional
star, or a bare star), which no hostname is. /web/scale.com/x, /web/2024/...,
/web/2024id_/... and /web/*/... keep their readings. Candidate counts return
to what they were before the second reading existed: two for a plain
timestamped snapshot. A URL-table row pins the four-layer case as served.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… reading

QuestionSpans took its span length from the "removed" reading of the
question but built n-grams of that length from the "space" and "word_break"
readings too. A question under the threshold whose ignorable characters
(a variation selector, a zero-width space, a Hangul filler) sit inside a word
has more words in the "space" reading than in the "removed" one, so
fragments of a single word became blocked n-grams and a query that merely
contained such a fragment as a word of its own was refused, against the
README's "protected as a whole". No local HLE-Diamond question has fewer
than 8 words or readings that differ, so this is a correctness note.

Give each reading its own span length min(threshold, words in that reading)
and check the distinct lengths longest first, returning the matched length
so the refusal rule and the log name the span that actually matched rather
than the "removed" reading's length. A test seeds a one-word question with
an ignorable character inside the word in two spellings, serves a query
repeating one fragment, and refuses the whole question in each spelling
with the matched length in the log.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
title_variants tried the capped title (with its cut marker) and the title
before each separator that starts within the first MAX_TITLE_CHARS
characters. A separator starting exactly at the cut was excluded, and the
cut marker made the end-anchored answer_title_patterns miss a phrase that
ends exactly there, so a title whose text before " | Site" is exactly 1,000
characters and ends in "Quiz answers" was kept and rendered as shown,
while the same title one character shorter was dropped.

Add the shown text without its cut marker as a variant whenever the title
is capped, so the check covers exactly what the model sees. Every variant
stays at most MAX_TITLE_CHARS long, so the linear bound holds. A row in the
title table pins the separator-at-cut case as dropped.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…actly

The eviction loop pops the oldest session as soon as the table holds
MAX_SESSION_QUESTIONS + 1 entries, so a running rollout's question is gone
when the 10,000th later session is seeded, not after "more than 10,000
later seeds". A retried seed of a held session only moves it to the end,
so the count is of distinct later sessions, not of seed requests. The log
line ("more than %d seeded sessions are held") was already right.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The README and the app comment attributed the third ignorable reading to
UAX #29 word segmentation in a sentence that names Hangul fillers among
the characters it removes. UAX #29 classes U+3164, U+FFA0, U+115F and
U+1160 as ALetter, letters it keeps; only format and extend characters
are skipped by WB4, and U+200B is a break. Say what the reading does and
where it follows the standard, and that the fillers are dropped because
NFKC_Casefold drops them. The range list is introduced as including
points outside category Cf rather than lying outside it, since most of the
listed ranges are Cf, and as listed with adjacent ranges merged.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…icate row

The site:scale.com” row is the only one that catches an implementation
reading typographic quotes as a balanced pair only, so it stays, with a
comment saying what it pins. The hangul-filler-pattern row never failed
without hangul-filler (the set membership) or soft-hyphen-pattern (the
pattern path's folding) failing too, since both paths call the same
fold_text and text_block folds nothing itself, so it is dropped.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… release path

main's AGENTS.md (since #5083) asks session code, tests and docs to use the
names in the key-terminology glossary and add no synonyms. The glossary
retires "typed session", "typed seed" and "Environment Server session" for
"episode session" and "episode seed", "untyped seed" for "agent-run seed",
"retry window" for "close retry window", and "free" for "release". This
branch kept the old names in comments, the 422 detail for a malformed
episode seed, a test name and fixture ID, docstrings and the README; the
merge adapted the code to the split locks and fences but not the words.

Rename them throughout. The README also said only a /close_session frees a
slot before the cap evicts it: the checkpoint controller's retire of an
attempt (retire_session_state) releases every session that attempt seeded
too, whatever seed created it, and does not fence the ID, so say so. The
"![untyped](data:...)" fixture is test data about data URIs and stays.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ssue

The unauthenticated /seed_session residual is now tracked in
#5845. Both READMEs point at it in place of the
TRACKING_ISSUE_TBD placeholder.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ools

Brings in 42 commits from main (bd6f5f0..363af5e), including #5709
(centralized resources lifecycle and verification ownership), #5551 (MCP
tools of extra tool servers granted to session agents), #5763 (HLE agent
loop bounded with max_steps 1) and #5446 (gym list environments).

Only README.md overlapped textually; the environment table was
regenerated with scripts/update_env_list.py and the Hle Web Tools row is
preserved.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…workers

The README and multiple_workers_unsupported_reason said a rollout's seed and
its searches could reach different workers. Session routing (since #3905, and
restated by #5709 in the add-benchmark skill) pins a resources request by its
cookie session_id and an MCP call by its token sid to the owning worker, so
session-ID-keyed state is not what stops a multi-worker launch. What does:
app.py defines no module-level app for uvicorn workers to import, and the
URL-keyed page cache and the page-check pool are per process. Reword both and
make the refusal test assert the new reason and the absence of the old one.
Behaviour is unchanged: num_workers > 1 is still refused before uvicorn starts.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers labels Nov 16, 2026
Base automatically changed from rshahbazyan/hle-web-tools to main November 17, 2026 18:07

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

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants