Skip to content

refactor(agent): move Kilo, Pi and OpenClaw to the outcome ladder - #5875

Draft
yaoyu-33 wants to merge 2 commits into
feat/agent-outcome-ladderfrom
refactor/outcome-ladder-kilo-pi-openclaw
Draft

yaoyu-33 wants to merge 2 commits into
feat/agent-outcome-ladderfrom
refactor/outcome-ladder-kilo-pi-openclaw

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Stacks on #5870 (the shared outcome ladder). Review the diff against feat/agent-outcome-ladder; it touches only these three adapters.

What changed and why

Kilo, Pi and OpenClaw each decided their own response status, chose between a 500, a bare 502 and a 200, and wrote ng_agent_outcome by hand. Each now reads its harness's own evidence into a RunEvidence and returns finish_response(response, evidence, session=...) with HTTP 200. The parsers and classify_outcome() stay in the adapters. Only lifecycle failures still raise.

Kilo (responses_api_agents/kilocode_agent/app.py)

  • _lifecycle_failure() is split out of _runtime_failure(): a missing receipt, a supervisor error, unconfirmed termination, an unconfirmed task-environment plugin or required MCP server, a runner that failed before Kilo, or a Kilo that could not start. These still raise (agent_route_failed 500).
  • _run_evidence() maps Kilo's event stream and exit to RunEvidence. "Model replied" means the same as before: any output or any tokens.
  • classify_outcome() now also reads ContextOverflowError (a context limit) and a retryable APIError without statusCode (model_transport_error), the same rules the OpenCode adapter uses. These names come from Kilo 7.4.15's bundled code; no live Kilo run has shown them yet.
  • retry_deadline_before_reply=True: Kilo retries an unreachable model without emitting events, so a deadline before any reply stays retried (failed unknown now, a 500 before).
  • An error event is the run's error only when Kilo exits 0 or 1. Kilo exits 1 on a terminal APIError; any other exit is the worker's own failure.
  • The local /v1/responses path uses the same ladder, because it shares _response_from_events().

Pi (responses_api_agents/pi_agent/app.py)

  • The status logic, _reported_model_error() and report_outcome() are gone. A supervisor error, or required MCP tools that never started (exit 78), still raise.
  • Pi's final model error is the outcome even after a nonzero exit: Pi stopped on that error.
  • An empty length reply is an output-limit stop (model_limit="output", incomplete_details=max_output_tokens). Pi 0.80.2 does not count the default vLLM length path (an empty completion with zero usage) as an overflow, so that path was already incomplete, not a 500. When Pi's own classifier (outcome.mjs) calls a length reply an overflow, the run is a context limit whatever its exit.
  • An aborted reply outside a deadline is no usable result. Pi aborts only on SIGTERM, which exits 143, so this path is not expected in practice.

OpenClaw (responses_api_agents/openclaw_agent/app.py)

  • The CLI's typed context_overflow envelope sets context_limit=True, whatever the exit code (decision 1). It used to need the exit-code gate.
  • The FailoverError exit gate still decides whether an assistant model error is the run's outcome.
  • The bare HTTPException(502) for a response without an outcome is gone. A run with no usable result answers 200 agent_run_error. A supervisor error or a missing receipt raises a typed agent_route_failed 500.
  • The two MCP-grant 502s (probe failure, and a required grant that did not connect in the run) are unchanged: they are setup failures, not run outcomes.

All three adapters now follow the ladder's model_request_rejected rule (decision 4). With it, they pass the conformance model_error check as #5870 updated it.

The adapter READMEs describe the new outcomes. Tests that pinned the old behaviour are updated, and each says why in its name or a comment.

Score and disposition changes

The main column comes from code reading at acb67734cc (the base of #5870), with main's policy. (t) marks a row that a test on main also pins; this PR updates those tests where the row changes. Actions: verify = graded, retry = episode retried up to the attempt cap, fail = neither. Rows marked changed change disposition.

Harness Event main this PR
Kilo context overflow, ContextOverflowError (propagate flag on) 500 → retry 200 incomplete → verify changed (decision 1)
Kilo context overflow, default vLLM length path 200 incomplete → verify 200 incomplete (max_output_tokens) → verify
Kilo deadline before any reply 500 → retry (t) 200 failed unknown → retry
Kilo deadline after a reply 200 incomplete → verify; 500 → retry if an error event preceded it (t) 200 incomplete → verify changed for the error-event case (rare: Kilo exits on a terminal error)
Kilo no usable result (nonzero exit, no output) 500 → retry (t) 200 failed agent_run_error → retry
Kilo persistent 429/5xx (APIError with status) 200 failed model_request_error N → retry (t) same
Kilo transport failure (APIError, retryable, no status) 500 → retry 200 failed model_transport_error → retry
Kilo 401 before any reply 200 failed model_request_error 401 → fail 200 failed model_request_rejected → fail
Kilo other 4xx before any reply (400) 200 failed model_request_error 400 → verify (t) 200 failed model_request_rejected → fail changed (decision 4)
Kilo refusal no refusal signal: completed → verify same
Pi context overflow (error reply Pi calls an overflow) 200 incomplete → verify (t) same
Pi overflow whose compaction call failed 200 failed unknown → retry (t) same
Pi default vLLM length path (empty length, zero usage) 200 incomplete → verify 200 incomplete (max_output_tokens) → verify
Pi empty length reply Pi calls an overflow, then a nonzero exit 500 → retry 200 incomplete → verify changed (decision 1)
Pi deadline before any reply 200 incomplete → verify same
Pi deadline after a reply 200 incomplete → verify; 500 → retry if the last reply was an error Pi was not retrying (t) 200 incomplete → verify changed for the error case
Pi no usable result (nonzero exit, no reply, non-terminal reply) 500 → retry (t) 200 failed agent_run_error → retry
Pi aborted reply outside a deadline, exit 0 200 incomplete → verify (t) 200 failed agent_run_error → retry changed (not expected in practice)
Pi persistent 429/5xx or transport 200 failed classified → retry (t) same; also after a nonzero exit or a promised retry (500 → retry before)
Pi 401 before any reply 200 failed model_request_error 401 → fail (t) 200 failed model_request_rejected → fail
Pi other 4xx before any reply (400) 200 failed model_request_error 400 → verify (t); 500 → retry after a nonzero exit (t) 200 failed model_request_rejected → fail changed (decision 4)
Pi refusal graded as the answer same
OpenClaw context overflow (typed envelope), exit 0 or FailoverError 200 failed model_context_limit → fail on main's policy (t) 200 incomplete → verify changed (decision 1)
OpenClaw context overflow, any other exit bare 502 → retry 200 incomplete → verify changed (decision 1)
OpenClaw output limit (length) 200 incomplete → verify (t) 200 incomplete (max_output_tokens) → verify
OpenClaw deadline before or after a reply 200 incomplete → verify (t) same
OpenClaw no usable result (another nonzero exit, a non-transport abort, no terminal reply) bare 502 → retry (t) 200 failed agent_run_error → retry
OpenClaw supervisor error or missing receipt bare 502 → retry (t) typed agent_route_failed 500 → retry
OpenClaw persistent 429/5xx 200 failed model_request_error N → retry (t) same
OpenClaw transport (Connection error., terminated, idle-timeout abort) 200 failed model_transport_error → retry (t) same
OpenClaw 401 before any reply 200 failed model_request_error 401 → fail 200 failed model_request_rejected → fail
OpenClaw other 4xx before any reply (400, 413, 422) 200 failed model_request_error → verify (t) 200 failed model_request_rejected → fail changed (decision 4)
OpenClaw refusal graded as the answer same

For OpenClaw's context overflow, #5870 alone already grades the failed model_context_limit response: it makes model_context_limit: verify the policy backstop. Against #5870, this PR changes the response from failed to incomplete and removes ng_agent_outcome; the disposition is the same. Against main, the score changes.

A 4xx after a model reply keeps model_request_error with its status: 400, 413 and 422 are graded, and 401, 403 and 404 fail.

Overlaps

Validation

  • Unit tests on macOS, with the primary venv and this worktree on PYTHONPATH: responses_api_agents/{kilocode_agent,pi_agent,openclaw_agent}/tests, scripts/harness_conformance/tests and tests/unit_tests/agents/test_outcome_ladder.py. Result: 1304 passed, 113 skipped (Linux-only and pinned-CLI tests), 2 failed. Both failures are test_runtime_dependencies.py::test_opensandbox_sdk_is_available_in_agent_environment (Pi and OpenClaw), which fails without this PR too: this venv has no opensandbox module.
  • New tests:
    • Kilo: test_outcome_ladder_reads_kilo_events (context overflow, length stop, deadline after a reply with an error event, transport failure) and test_run_evidence_reads_replies_limits_and_exit.
    • Pi: test_empty_length_reply_is_an_output_or_context_limit.
    • OpenClaw: test_context_overflow_is_graded_as_incomplete, which also covers exit 1 without FailoverError.
  • pre-commit run --files <touched files>: passed.
  • Not run: scripts/harness_conformance/tests/test_openclaw_errors.py (Linux CI with HARNESS=openclaw and the pinned CLI; its context cases are updated to expect a graded incomplete row), and the pinned Pi 0.80.2 / OpenClaw tests, which skip here.

Smoke evidence

Harness conformance scenarios on a Linux host, run as a scripted-model smoke with no real model. Gym's real vllm_model sits in front of a scripted upstream, and the Environment Server's action is computed from each response under the default policy.

No episode had an execution error.

Scenario Kilo Code Pi OpenClaw
model_error (400 before a reply) failed model_request_error 400 → verify ⇒ failed model_request_rejected → fail same same
context_overflow 500 → retry ⇒ 200 incomplete → verify incomplete → verify, unchanged failed model_request_error 400 → verify, unchanged (see below)
context_overflow_length incomplete → verify, unchanged same same
deadline_before_reply 500 → retry ⇒ 200 failed unknown → retry (transitional rule) incomplete → verify, unchanged same as Pi
deadline_after_reply incomplete → verify, unchanged same same
harness_no_result 500 → retry ⇒ 200 failed agent_run_error → retry 500 → retry ⇒ same 502 → retry ⇒ same
model_401 failed model_request_error 401 → fail ⇒ failed model_request_rejected → fail same same
model_503 500 → retry ⇒ 200 failed unknown → retry (see below) failed model_request_error 503 → retry, unchanged same as Pi

Disposition changes: Kilo Code 2 (model_error, context_overflow), Pi 1, OpenClaw 1. Every 5xx on A becomes HTTP 200 on B.

Findings this PR does not change:

  • OpenClaw's context overflow is still failed model_request_error 400 after a reply. It should be incomplete (decision 1). fix(openclaw): preserve replay identity and startup timeout outcomes #5379 makes OpenClaw's context overflow incomplete, and its two context tests pass on its head (c739747a1a). Whichever of the two PRs lands second keeps that rule.
  • Kilo Code retries a 503 without a limit of its own (decision 6): 327 attempts in 37 s, until the run deadline. The deadline comes before any reply, so the transitional rule answers failed unknown, which is retried. The action matches; the outcome kind (unknown, not model_request_error 503) does not.
  • Kilo Code leaves a 943 MB session directory per episode under /tmp/nemo-gym-kilo-sessions, on both sides.

Compatibility

Callers that relied on a 500 or 502 from these adapters for "no usable result" now get a 200 failed response with agent_run_error, which the default policy in #5870 retries. Custom policies that map model_context_limit or a 400 model_request_error see the changed rows above.

🤖 Generated with Claude Code

Each of these adapters decided its own response status, chose between a
500, a bare 502 and a 200, and wrote ng_agent_outcome by hand. They now
read their harness's evidence into a RunEvidence and return
finish_response(response, evidence) with HTTP 200; only lifecycle failures
(a supervisor error or a missing receipt, an unconfirmed plugin or required
MCP server, a runner that never started Kilo) still raise.

Kilo: classify_outcome also reads ContextOverflowError (context limit) and a
retryable APIError without a status (model_transport_error), as the OpenCode
adapter does. A nonzero exit or a run without output answers 200 failed
agent_run_error instead of a 500. A deadline before any model reply keeps
today's retry (retry_deadline_before_reply), because Kilo retries an
unreachable model silently.

Pi: a nonzero exit, no reply, or a non-terminal last reply answers 200 failed
agent_run_error instead of a 500. Pi's final model error is the outcome even
after a nonzero exit. An empty length reply is an output-limit stop, or a
context limit when Pi's own classifier calls it an overflow, whatever the
exit. An aborted reply outside a deadline is no usable result.

OpenClaw: the CLI's typed context overflow is graded as incomplete, whatever
its exit (it was failed model_context_limit, and a 502 when the exit gate
did not hold). A run without a usable result answers 200 failed
agent_run_error instead of a bare 502; a supervisor failure raises a typed
agent_route_failed 500. The FailoverError exit gate still decides whether a
model error is the run's outcome.

The ladder's model_request_rejected rule applies to all three: a 4xx other
than 408/425/429 before any model reply is no longer graded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 9, 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.

…-kilo-pi-openclaw

Keeps this branch's OpenClaw context-limit test over the base's interim update
of the test it replaces.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 05d5556d Deployed Nov 9, 2026 by yaoyu-33 via release / finalize / notify #11153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior support User questions, support, or maintenance requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants