Skip to content

fix(openclaw): retain model errors and capture ownership - #5119

Merged
giuliolovisotto merged 2 commits into
mainfrom
glovisotto/openclaw-session-outcomes
Nov 2, 2026
Merged

giuliolovisotto merged 2 commits into
mainfrom
glovisotto/openclaw-session-outcomes

Conversation

@giuliolovisotto

@giuliolovisotto giuliolovisotto commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

OpenClaw sandbox sessions attach every captured model attempt to its invocation, including rejected requests without a response ID. The provider sends the invocation ID as x-session-id; the rollout URL continues to identify the episode.

Model failures return a structured failed response with the original error, partial output, usage and ng_agent_outcome, allowing the environment to apply its configured policy:

  • HTTP failures retain model_request_error and the upstream status.
  • Connection errors, interrupted streams and the pinned CLI's idle-watchdog abort use model_transport_error.
  • Typed context-overflow errors, including a local precheck without a model request, use model_context_limit.

The adapter requires successful cleanup and a recognized CLI termination. A supervisor deadline remains an incomplete response; unrelated aborts, worker crashes and cleanup failures still raise. No separate public issue: these fixes address gaps reproduced by controlled harness probes. Conformance registration and regression coverage are isolated in stacked follow-up #5120.

The rebase preserves upstream Bash process supervision and MCP grant handling. The capture-ownership regression uses the renamed join_agent_model_calls helper through the public trajectory API; existing test callers use the same export.

Validation

On Linux ARM64 with OpenClaw 2026.6.11 / Node 22.19.0:

  • python -m pytest -o addopts= --import-mode=importlib responses_api_agents/openclaw_agent/tests -q: 494 passed, 1 skipped (the opt-in process-identity test).
  • On the test(conformance): include OpenClaw in P0 harness probes #5120 stack, HARNESS=openclaw python -m pytest -o addopts= --import-mode=importlib scripts/harness_conformance/tests tests/unit_tests/harness_capabilities -q: 412 passed, 2 skipped, including eight real-CLI error regressions.
  • python -m pytest -o addopts= --import-mode=importlib tests/unit_tests/test_public_api_facades.py tests/unit_tests/test_agent_outcome.py tests/unit_tests/trajectory/test_trajectory_record.py -q: 371 passed.
  • Full pre-commit checks passed; DCO and SSH commit signatures verified.
  • Fresh controlled P0 run: 8/8 scenarios passed with underscore tool-call IDs.
  • A real-model smoke completed two model calls and one shell tool, retained their evidence, wrote the expected file, and received verifier reward 1 with completed, unmasked evaluation.

The additional CLI regressions cover exhausted 429/500/503, connection reset, interrupted SSE, native idle timeout, provider context overflow and local context precheck. Raw socket faults intentionally bypass model capture and validate outcome delivery, not capture completeness.

Compatibility and benchmark impact

Structured outcomes allow environment policy to distinguish model failures from agent endpoint failures. Transport failures default to retry. Context overflow now follows the existing model_context_limit rule: an ungraded, nonretryable failure by default, configurable via agent_outcome_policy.by_failure_kind.model_context_limit. This includes provider context overflow formerly treated as a generic, verifiable HTTP 400. The original provider message and captured exchange remain available; no HTTP status is fabricated for a local precheck.

Runtime pins and legacy local execution are unchanged. The real-model smoke validates integration, not benchmark accuracy.

@giuliolovisotto giuliolovisotto added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Oct 27, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 27, 2026 13:56

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP — LGTM, no concerns found.

Reviewed all four changed files and traced terminal-error handling, runtime/cleanup failure precedence, capture ownership, and environment outcome-policy consumption. The regression cases cover preserved model failures and rejected-attempt ownership; the updated documentation matches the inspected behavior.

Static review only: tests and the external OpenClaw runtime were not executed. The PR supplies representative real-model smoke evidence and describes the scoring compatibility change.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

prokotg
prokotg previously approved these changes Oct 30, 2026
@giuliolovisotto

Copy link
Copy Markdown
Contributor Author

@prokotg Following up on the error-handling questions in your #5120 review: these cases had not been checked. I reproduced them with the pinned OpenClaw 2026.6.11 CLI and pushed bdd0364.

  • Exhausted HTTP 429/500/503: each makes three attempts, then returns a structured model_request_error with the correct status. Existing handling works; regression coverage is now in test(conformance): include OpenClaw in P0 harness probes #5120.
  • Connection reset and interrupted SSE: the CLI reports Connection error. / terminated. These were classified as unknown; they now use model_transport_error.
  • Model idle timeout: the CLI emits stopReason=aborted. The adapter previously raised HTTP 502; it now returns a structured transport outcome. Supervisor deadlines and unrelated aborts remain separate.
  • Context overflow: both provider-reported overflow and the local precheck now use the CLI's typed context_overflow evidence to report model_context_limit. The local precheck previously became a generic HTTP 502.

Context limits follow Gym's existing ungraded, nonretryable default, configurable to verify. This changes provider context overflow previously treated as generic HTTP 400; the original error is retained.

Validation: 466 adapter tests passed (2 skipped), all eight new real-CLI error regressions passed on the stack, 7/7 P0 scenarios passed, and the real-model tool/verification smoke passed. The raw socket fault probes validate outcome delivery and deliberately bypass model capture.

Could you re-review and approve this updated adapter commit if it looks good?

@giuliolovisotto
giuliolovisotto added this pull request to the merge queue Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41476681997

Merged via the queue into main with commit cd490bb Nov 2, 2026
55 of 58 checks passed
@giuliolovisotto
giuliolovisotto deleted the glovisotto/openclaw-session-outcomes branch November 2, 2026 16:37

This branch was previously deployed

1 inactive deployment
public — 8f603d6f Deployed Nov 2, 2026 by copy-pr-bot[bot] via release / finalize / notify #9096
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 bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants