Skip to content

feat(headless): make Harbor adapters loadable under Pier - #1344

Merged
Astro-Han merged 5 commits into
mainfrom
feat/headless-pier-network-allowlist
Jul 22, 2026
Merged

Astro-Han merged 5 commits into
mainfrom
feat/headless-pier-network-allowlist

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #1343. Makes both Harbor agent adapters loadable and trial-functional under Pier ≥ 0.3.0 (Datacurve's Harbor fork used to run DeepSWE, where all 113 tasks set allow_internet = false), while leaving plain-Harbor 0.13.2 Terminal-Bench runs untouched. Three commits: missing Pier hooks, harness-tree selection, and the adjudicated cross-review hardening.

  1. Missing Pier hooks. Pier's trial executor calls agent.install_spec() (evaluated first — the immediate AttributeError) and agent.network_allowlist(); Harbor's base classes define neither. Both adapters now implement both:
    • MakaAgent: install_spec() → None (runtime install path unchanged); network_allowlist() → empty, valid only because the container makes no model calls. A single _container_makes_model_calls() predicate owns that invariant: only a cell-mode ai-sdk run without host-side provider configuration needs in-container egress and raises a RuntimeError naming the fixes (host-side config, backend=fake, or MAKA_HARBOR_MODE=task-run); host-side, fake, and task-run modes all get the empty allowlist. The in-container Node ≥ 22 bootstrap (reachable only for cell+fake) now collapses any failure into one diagnostic — its downloads are the adapter's only container-side network dependency and Pier non-internet containers are offline — instead of obscure curl/apt errors.
    • MakaKimiCodeAgent: install_spec() → None (toolchain pre-baked into the image, verified offline via sha256 + manifest fingerprint); network_allowlist() → exactly the model-endpoint host of MAKA_PROVIDER_PROXY_URL. No fallback domain: unset/empty/unparsable URLs raise the existing "Kimi Code requires the host provider proxy" error at allowlist time, and IPv6 literal endpoints raise an explicit unsupported-endpoint error (Pier's domain validator rejects :). This endpoint-shape validation is Pier-only — it lives behind the plain-Harbor early return in network_allowlist(), while _runtime_env() keeps main's contract and forwards the URL opaquely (IPv6 included), so Harbor 0.13.2's input domain is not narrowed. When the proxy port is outside {80, 443}, network_allowlist() warns on stderr instead of raising: Pier's Squid egress proxy for allow_internet=false tasks only allows those destination ports, but the adapter cannot see allow_internet and internet tasks ignore the allowlist.
  2. Parallel, type-incompatible package trees. The eval(headless): DeepSWE 1.1 discriminative-30 harness A/B — Maka vs Kimi Code and Codex CLI #1343 pilot then failed at Pier trial setup with a pydantic ValidationError: TrialResult.agent_info only accepts pier.models.trial.result.AgentInfo, but the adapters subclassed the compat harbor.* tree. New harness_compat.py selects the whole base-class tree at import time; both adapters import their harness symbols from it.

Tree-selection rule: prefer Pier whenever import pier succeeds

  • The plain-Harbor uv tool venv (~/.local/share/uv/tools/harbor, harbor 0.13.2) has no pier distribution — verified import pier fails — so every Terminal-Bench consumer keeps the harbor tree bit-for-bit. The only interpreter where both trees import is Pier's own venv, where the compat harbor.* tree is exactly what the pilot proved wrong.
  • The probe falls back to harbor only on ModuleNotFoundError naming pier itself (genuinely absent package). Any other failure inside pier's own import — broken install, missing dependency — re-raises at the probe, and a pier tree broken below the top level fails at first symbol resolution; falling back in those cases would silently rebuild the adapters on the compat tree that Pier's TrialResult rejects.
  • The CI Python-bridge contract in harbor-adapter.test.ts resolves its interpreter from the harbor launcher on PATH (plain 0.13.2 venv, no pier), so prefer-pier cannot change what it tests. No env switch: it would add a knob that fails closed when forgotten on the Pier side.
  • Symbols resolve lazily (PEP 562), so each adapter's transitive import surface stays exactly the names it declares — the per-adapter harness-stub smoke tests keep stubbing only the modules each adapter actually uses.

API-drift audit (harbor 0.13.2 vs pier 0.3.0, every symbol the adapters use)

Symbol Drift Impact
ExecResult none (stdout/stderr/return_code) —
BaseEnvironment.exec / upload_file / download_file same signatures —
CliFlag / EnvVar, with_prompt_template identical —
__init__, _get_env, _resolved_flags, _extra_env, model_name, logs_dir identical —
CLI-flag env_fallback resolution identical in 0.13.2 and pier (reads os.environ only; the extra_env-aware resolution is a harbor 0.20.0 feature) flags like backend must come from kwargs or process env, not --ae; tests use the kwarg path
EnvironmentPaths.agent_dir identical (drift only in skills/chmod helpers) —
AgentContext pier adds optional fields only —
trajectory models + format_trajectory_json import paths only —
to_agent_info() returns tree-local AgentInfo root cause; fixed by tree selection
install_spec() / populate_context_post_run() abstract on pier's BaseInstalledAgent both adapters define both
install() default body pier runs install_spec().steps both adapters fully override install()
_exec env handling pier wraps with environment.agent_process_env internal, inherited

Other files in the harbor dir (codex_agent.py, opencode_agent.py, opencode_title_harbor_agent.py, maka_verifier.py) still bind harbor.* directly: they are Terminal-Bench-only arms, and DeepSWE runs use each task's own verifier (the pilot trial config has no custom verifier import path). They would need the same treatment only if ever run under Pier.

Verification

  • packages/headless/harbor/tests/test_harness_compat.py under both interpreters (each test scrubs MAKA_* from os.environ and restores it, so operator shells cannot flip the contracts):
    • Pier venv: 6 passed, 0 skipped, 0 failed — the pilot-failure seam (to_agent_info() is pier...AgentInfo and passes TrialResult.agent_info pydantic assignment), the maka mode-mismatch raise plus the task-run empty-allowlist case, the kimi unset/IPv6 raises plus the port-warning contracts, the gate-free _runtime_env IPv6-forward case, the harbor fallback under meta-path poisoning, and the broken-pier re-raise (injected ModuleNotFoundError(name="socksio") propagates instead of falling back). Earlier run with MAKA_PROVIDER_PROXY_URL=https://example.invalid, MAKA_HOST_NO_AUTH=true, and MAKA_BACKEND=fake exported: all green (tests scrub MAKA_*).
    • Plain harbor 0.13.2 venv: 3 passed, 3 skipped, 0 failed (the gate-free _runtime_env case runs for real here); with MAKA_HARNESS_COMPAT_EXPECT=pier the missing pier coverage fails as intended (exit 1).
  • task-run repro under the Pier python: MAKA_HARBOR_MODE=task-run + MakaAgent(logs_dir=...).network_allowlist() → NetworkAllowlist [] (previously raised).
  • IPv6 regression repro under the harbor 0.13.2 python: MAKA_PROVIDER_PROXY_URL=http://[::1]:43210/v1 through _runtime_env() → KIMI_MODEL_BASE_URL=http://[::1]:43210/v1 forwarded opaquely (HEAD before this fix raised ValueError; now matches main).
  • Port checks under the Pier python: :8443 → host allowlisted + stderr warning naming the Squid 80/443 restriction; :443 → no warning; IPv6 → ValueError.
  • New TS wrapper tests in harbor-adapter.test.ts spawn the python contract under each interpreter (harbor launcher probe; pier launcher probe or MAKA_PIER_PYTHON, with MAKA_HARNESS_COMPAT_EXPECT=pier so skips cannot masquerade as green), self-skipping visibly when an interpreter is absent. Both ran on this machine.
  • Full @maka/headless suite in the worktree (npm run test -w @maka/headless): 1181 pass / 0 fail / 1 skip (source contracts on the install command — nvm install 22, /usr/local/nvm, NODE_MAJOR — still hold after the bootstrap wrap). npm run lint and npm run format:check clean.
  • Pier factory smoke through AgentFactory.create_agent_from_import_path + TrialResult.agent_info validation: maka (host-side) → allow.domains=[], pydantic OK; kimi (proxy URL set) → allow.domains=['api.kimi.com'], pydantic OK; maka without host-side config → RuntimeError at allowlist time; kimi without proxy URL → ValueError at allowlist time.
  • Plain-harbor smoke under the 0.13.2 venv: both classes subclass harbor.agents.installed.base.BaseInstalledAgent and to_agent_info() returns harbor's AgentInfo — Terminal-Bench path unchanged.
  • Network behavior code-traced in Pier: empty allowlist → _prepare_egress_proxy_compose returns early and the no-network compose applies; non-empty → filtered egress proxy for exactly those domains.
  • Not run: a full pier run with a live model — that is the eval(headless): DeepSWE 1.1 discriminative-30 harness A/B — Maka vs Kimi Code and Codex CLI #1343 pilot, tracked on the issue.

Known constraint / follow-up

Pier's write_docker_proxy_compose() (pier/environments/agent_setup.py) generates a Squid egress proxy with acl Safe_ports port 80 443 + http_access deny !Safe_ports for allow_internet=false tasks, verified against Pier 0.3.0 output. Our host provider proxy currently listens on a random high port, which Squid would silently deny on the first in-container model request of an offline Kimi trial. This branch surfaces the mismatch as a stderr warning at environment creation (raising would wrongly kill internet-enabled tasks, where the allowlist is ignored). Binding the provider proxy to 80/443 (or an internet task) is the actual fix and is handed off to the pier task-runner follow-up PR.

Astro-Han added a commit that referenced this pull request Jul 22, 2026
…n errors

Apply the adjudicated cross-review bundle for PR #1344:

- harness_compat: catch only ModuleNotFoundError naming pier itself; an
  ImportError raised inside pier's own __init__ (broken install, missing
  dependency) now re-raises instead of silently selecting the compat harbor
  tree, which would reproduce the TrialResult.agent_info pydantic failure.
- MakaAgent.network_allowlist: an empty allowlist is only correct when the
  container makes no model calls; raise a RuntimeError naming the fix when
  backend=ai-sdk runs without host-side provider configuration, so the trial
  fails at environment creation instead of opaque in-container network errors.
- MakaKimiCodeAgent: drop the api.kimi.com fallback and centralize proxy-URL
  parsing in _provider_proxy_host(), shared by network_allowlist() and
  _runtime_env(); unset/empty/unparsable URLs raise the existing host-proxy
  error at allowlist time, and IPv6 literal endpoints raise an explicit
  unsupported-endpoint error (pier's domain validator rejects ':').
- Tests: cover broken-pier re-raise, the maka mode-mismatch raise, and the
  kimi unset/IPv6 raises; count skips separately from passes; support
  MAKA_HARNESS_COMPAT_EXPECT=pier to fail instead of skip when expected pier
  coverage is unavailable. harbor-adapter.test.ts now runs the python contract
  under both interpreters (harbor launcher probe, pier launcher probe or
  MAKA_PIER_PYTHON), self-skipping visibly when one is absent.
- Add -> None / Optional return annotations on install_spec and
  network_allowlist in both adapters.
Astro-Han added a commit that referenced this pull request Jul 22, 2026
…ilures diagnosable

Apply the adjudicated fresh-eye review items for PR #1344:

- MakaAgent.network_allowlist no longer rejects MAKA_HARBOR_MODE=task-run:
  the guard collapses into a single _container_makes_model_calls() predicate
  (cell mode + backend!=fake + no host-side config). task-run always runs the
  model on the host and only bridges tool commands into the container, so the
  empty allowlist is correct there; the mismatch error now also names task-run
  as a way out.
- The in-container Node >= 22 bootstrap (reachable only for cell+fake under
  the new guard) runs in a child bash so first-failure semantics survive the
  || guard, and any failure collapses into one diagnostic naming the cause
  (downloads need network; Pier non-internet containers are offline) and the
  ways out, instead of obscure curl/apt errors. No IS_PIER branching; both
  trees behave identically.
- test_harness_compat: scrub MAKA_* keys from os.environ per test (restored
  afterwards; MAKA_HARNESS_COMPAT_EXPECT stays visible as the runner's own
  control) so exported operator variables like MAKA_PROVIDER_PROXY_URL or
  MAKA_HOST_NO_AUTH cannot flip the contracts; add the task-run case locking
  the allowlist fix.
Astro-Han added a commit that referenced this pull request Jul 22, 2026
…rn on Squid-blocked ports

Apply the second adjudicated fresh-eye bundle for PR #1344:

- _runtime_env restores main's plain-Harbor contract: it only requires
  MAKA_PROVIDER_PROXY_URL and MAKA_PROVIDER_PROXY_TOKEN to be non-empty and
  forwards the URL opaquely, IPv6 included. The IPv6 rejection comes from
  Pier's NetworkAllowlist domain validator (rejects ':'), a Pier-only
  constraint, so endpoint-shape validation moves entirely behind the plain-
  Harbor early return in network_allowlist(); Pier still fails early because
  execution calls network_allowlist at environment creation.
- network_allowlist now also parses the proxy port and warns on stderr when
  it is outside {80, 443}: Pier's Squid egress proxy for allow_internet=false
  tasks only allows those destination ports (Safe_ports acl in
  pier/environments/agent_setup.py), so a random high-port proxy is silently
  unreachable in offline tasks. Warn, do not raise - the adapter cannot see
  allow_internet, and internet tasks ignore the allowlist. Binding the
  provider proxy to 80/443 belongs to the pier task-runner follow-up.
- Tests: the :8443 case now asserts the warning and restates the Squid
  constraint; the portless case asserts silence; a new gate-free case runs
  under both trees and locks the opaque IPv6 forward through _runtime_env.
Pier (Datacurve's Harbor fork) asks each agent for install_spec() and
network_allowlist() when building a trial environment; plain Harbor 0.13.2
defines neither on its base classes, so both MakaAgent and MakaKimiCodeAgent
raised AttributeError under Pier before any task could run.

Add both hooks with a guarded NetworkAllowlist import so the modules still
import under plain Harbor (Terminal-Bench). install_spec() returns None (both
adapters install/verify at runtime, not at build time). MakaAgent uses an empty
allowlist (host-side LLM, tools bridged in, container needs no egress);
MakaKimiCodeAgent allowlists only the model endpoint host derived from
MAKA_PROVIDER_PROXY_URL, defaulting to api.kimi.com, since its toolchain is
pre-baked and verified offline.

Add a self-runnable behavior test covering both the Pier-importable shapes and
the pier-absent import path (meta-path poisoning).
…time

The DeepSWE pilot failed at pier trial setup with a pydantic ValidationError:
pier 0.3.0's TrialResult.agent_info only accepts pier.models.trial.result.
AgentInfo, but the adapters subclassed the (type-incompatible, parallel)
harbor tree, so to_agent_info() returned harbor's AgentInfo.

Add harness_compat.py, which prefers the pier.* tree whenever `import pier`
succeeds and falls back to harbor.* otherwise. The importing process is always
the harness runner itself, so pier importability identifies the runner exactly:
the plain-Harbor 0.13.2 uv tool venv (Terminal-Bench, and the CI Python-bridge
contract in harbor-adapter.test.ts) cannot import pier, and inside pier's venv
the compat harbor tree is never the right choice. Symbols resolve lazily
(PEP 562) so each adapter's transitive import surface stays exactly the names
it asks for, which keeps the per-adapter harness-stub smoke tests intact.

API-drift audit harbor 0.13.2 vs pier 0.3.0 for every symbol the adapters use:
ExecResult, BaseEnvironment.exec/upload_file/download_file, CliFlag/EnvVar,
with_prompt_template, _get_env/_resolved_flags/_extra_env, EnvironmentPaths.
agent_dir, trajectory models, and format_trajectory_json are shape-identical;
AgentContext only gains optional fields. Pier makes install_spec() and
populate_context_post_run() abstract on BaseInstalledAgent - both adapters
already define both.

Extend the tests to lock the pilot-failure seam (to_agent_info() is pier's
AgentInfo under pier) and the harbor-tree fallback, and rename them to match
the widened scope.
…n errors

Apply the adjudicated cross-review bundle for PR #1344:

- harness_compat: catch only ModuleNotFoundError naming pier itself; an
  ImportError raised inside pier's own __init__ (broken install, missing
  dependency) now re-raises instead of silently selecting the compat harbor
  tree, which would reproduce the TrialResult.agent_info pydantic failure.
- MakaAgent.network_allowlist: an empty allowlist is only correct when the
  container makes no model calls; raise a RuntimeError naming the fix when
  backend=ai-sdk runs without host-side provider configuration, so the trial
  fails at environment creation instead of opaque in-container network errors.
- MakaKimiCodeAgent: drop the api.kimi.com fallback and centralize proxy-URL
  parsing in _provider_proxy_host(), shared by network_allowlist() and
  _runtime_env(); unset/empty/unparsable URLs raise the existing host-proxy
  error at allowlist time, and IPv6 literal endpoints raise an explicit
  unsupported-endpoint error (pier's domain validator rejects ':').
- Tests: cover broken-pier re-raise, the maka mode-mismatch raise, and the
  kimi unset/IPv6 raises; count skips separately from passes; support
  MAKA_HARNESS_COMPAT_EXPECT=pier to fail instead of skip when expected pier
  coverage is unavailable. harbor-adapter.test.ts now runs the python contract
  under both interpreters (harbor launcher probe, pier launcher probe or
  MAKA_PIER_PYTHON), self-skipping visibly when one is absent.
- Add -> None / Optional return annotations on install_spec and
  network_allowlist in both adapters.
…ilures diagnosable

Apply the adjudicated fresh-eye review items for PR #1344:

- MakaAgent.network_allowlist no longer rejects MAKA_HARBOR_MODE=task-run:
  the guard collapses into a single _container_makes_model_calls() predicate
  (cell mode + backend!=fake + no host-side config). task-run always runs the
  model on the host and only bridges tool commands into the container, so the
  empty allowlist is correct there; the mismatch error now also names task-run
  as a way out.
- The in-container Node >= 22 bootstrap (reachable only for cell+fake under
  the new guard) runs in a child bash so first-failure semantics survive the
  || guard, and any failure collapses into one diagnostic naming the cause
  (downloads need network; Pier non-internet containers are offline) and the
  ways out, instead of obscure curl/apt errors. No IS_PIER branching; both
  trees behave identically.
- test_harness_compat: scrub MAKA_* keys from os.environ per test (restored
  afterwards; MAKA_HARNESS_COMPAT_EXPECT stays visible as the runner's own
  control) so exported operator variables like MAKA_PROVIDER_PROXY_URL or
  MAKA_HOST_NO_AUTH cannot flip the contracts; add the task-run case locking
  the allowlist fix.
…rn on Squid-blocked ports

Apply the second adjudicated fresh-eye bundle for PR #1344:

- _runtime_env restores main's plain-Harbor contract: it only requires
  MAKA_PROVIDER_PROXY_URL and MAKA_PROVIDER_PROXY_TOKEN to be non-empty and
  forwards the URL opaquely, IPv6 included. The IPv6 rejection comes from
  Pier's NetworkAllowlist domain validator (rejects ':'), a Pier-only
  constraint, so endpoint-shape validation moves entirely behind the plain-
  Harbor early return in network_allowlist(); Pier still fails early because
  execution calls network_allowlist at environment creation.
- network_allowlist now also parses the proxy port and warns on stderr when
  it is outside {80, 443}: Pier's Squid egress proxy for allow_internet=false
  tasks only allows those destination ports (Safe_ports acl in
  pier/environments/agent_setup.py), so a random high-port proxy is silently
  unreachable in offline tasks. Warn, do not raise - the adapter cannot see
  allow_internet, and internet tasks ignore the allowlist. Binding the
  provider proxy to 80/443 belongs to the pier task-runner follow-up.
- Tests: the :8443 case now asserts the warning and restates the Squid
  constraint; the portless case asserts silence; a new gate-free case runs
  under both trees and locks the opaque IPv6 forward through _runtime_env.
@Astro-Han
Astro-Han force-pushed the feat/headless-pier-network-allowlist branch from fe6d05b to 9eac360 Compare July 22, 2026 14:34
@Astro-Han
Astro-Han merged commit 6a2951c into main Jul 22, 2026
3 checks passed
@Astro-Han
Astro-Han deleted the feat/headless-pier-network-allowlist branch July 22, 2026 14:45
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