Skip to content

[codex] refactor: execute selected harnesses through v2 lifecycle - #71238

Closed
100yenadmin wants to merge 11 commits into
openclaw:mainfrom
electricsheephq:contract-first/harness-v2-selection-execution
Closed

100yenadmin wants to merge 11 commits into
openclaw:mainfrom
electricsheephq:contract-first/harness-v2-selection-execution

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #71222, #71096, and RFC #71004. This PR routes selected harness attempts through the V2 lifecycle executor instead of calling runAttempt directly from selection.

The harness registry and selection policy stay unchanged. Selected V1 harnesses are adapted to V2, then executed as prepare -> start -> send -> resolveOutcome -> cleanup.

RuntimePlan Package Context

This is the lifecycle execution rung. #71222 introduced the V2 adapter shape; this PR puts that shape on the selected-harness hot path so future cleanup, telemetry, session policy, and outcome classification have one execution boundary.

flowchart TD
  RFC["#71004 RFC"] --> Base["#71096 RuntimePlan merged"]
  Base --> Adapter["#71222 Harness V2 adapter"]
  Adapter --> This["#71238 selection executes through V2 lifecycle"]
  This --> Outcome["#71239 shared terminal outcome classifier"]
  Base --> ToolPolicy["#71220 shared tool policy"]
  ToolPolicy --> Transcript["#71223 transcript resolver"]
  Transcript --> Alias["#71224 embedded-runner alias"]
Loading

Review package links: #71196, #71197, #71201, #71220, #71222, #71223, #71224, #71238, #71239.

Local Architecture

sequenceDiagram
  participant Selection as Harness selection
  participant Adapter as adaptAgentHarnessToV2
  participant V2 as runAgentHarnessV2LifecycleAttempt
  participant Harness as Selected harness

  Selection->>Adapter: selected AgentHarness
  Adapter-->>Selection: AgentHarnessV2
  Selection->>V2: execute lifecycle
  V2->>Harness: prepare
  V2->>Harness: start
  V2->>Harness: send
  V2->>Harness: resolveOutcome
  V2->>Harness: cleanup
Loading

Why This PR Exists

#71004 calls out that Codex should own its model-loop lifecycle, while OpenClaw should own runtime policy and lifecycle boundaries. This PR does not move ownership into Codex; it gives OpenClaw one bounded lifecycle wrapper around selected Pi/plugin harness execution while preserving the existing registry and fallback semantics.

What Changed

  • Added runAgentHarnessV2LifecycleAttempt(...) in src/agents/harness/v2.ts.
  • Updated runAgentHarnessAttemptWithFallback(...) to adapt the selected harness and execute through the V2 lifecycle.
  • Preserved existing plugin-failure behavior: plugin harness failures are surfaced, not replayed through Pi.
  • Added lifecycle tests for ordered prepare/start/send/outcome/cleanup.
  • Added cleanup coverage for send/outcome/start failures and cleanup-failure surfacing after success.
  • Preserved existing V1 adapter compatibility.

Maintainer Review Guide

  • Highest-signal files: src/agents/harness/v2.ts, src/agents/harness/selection.ts, src/agents/harness/v2.test.ts.
  • Check selection decision logic is unchanged; only execution after selection is routed through V2.
  • Check plugin failure behavior remains non-fallback-to-Pi.
  • Check cleanup is best-effort on failure and does not mask the original harness error.
  • Check V1 harness this binding and optional hooks remain compatible.

What Did Not Change

Verification

  • ./node_modules/.bin/vitest run src/agents/harness/v2.test.ts src/agents/harness/selection.test.ts --config test/vitest/vitest.agents.config.ts
  • ./node_modules/.bin/oxlint --tsconfig tsconfig.oxlint.core.json src/agents/harness/v2.ts src/agents/harness/selection.ts src/agents/harness/v2.test.ts src/agents/harness/selection.test.ts
  • git diff --check
  • pnpm check:architecture

This PR is logically stacked after #71222. Until #71222 merges, GitHub may show that adapter foundation in the diff as well.

Copilot AI review requested due to automatic review settings April 24, 2026 20:05
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Apr 24, 2026
@greptile-apps

greptile-apps Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR routes both Pi and plugin harness attempts through the new V2 lifecycle executor (prepare → start → send → resolveOutcome → cleanup), replacing the scattered runAttempt direct calls and extracting applyHarnessResultClassification into a standalone module with a correctness fix (stale non-ok classification is now cleared when classification resolves to "ok"). Existing plugin-failure logging and Pi fallback behaviour are preserved, and the test suite covers ordered lifecycle phases, cleanup error handling in both failure and success paths, V1 adapter compatibility, and this-binding for optional hooks.

Confidence Score: 5/5

Safe to merge; all findings are P2 style and observability notes with no present defects.

The behavioral change for V1 harnesses is equivalent to the old code — V1 cleanup is always a no-op and the test suite validates all four lifecycle paths. The two P2 comments (silent cleanup error swallowing on the failure path, and missing await on the Pi branch) are non-blocking and do not affect current correctness.

No files require special attention; v2.ts and selection.ts are the main changed files and both are in good shape.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/harness/v2.ts
Line: 98-106

Comment:
**Cleanup errors on failure path are silently dropped**

When `send` (or `resolveOutcome`) throws, the inner catch swallows the cleanup error entirely via `void cleanupError` — no log, no metric, nothing. For the current V1 no-op cleanup this is harmless, but the comment acknowledges future telemetry intent. Even a `console.warn` or importing the subsystem logger here would make cleanup regressions visible before telemetry lands, especially once a real V2 native harness is registered and its `cleanup` can throw.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/harness/selection.ts
Line: 192-194

Comment:
**Missing `await` on the Pi lifecycle call**

The plugin path directly below uses `return await runAgentHarnessV2LifecycleAttempt(...)` so that rejections are caught by the surrounding `try/catch`. The Pi branch uses `return runAgentHarnessV2LifecycleAttempt(...)` (no `await`), which works today because the returned Promise propagates correctly through the `async` function — but the asymmetry is easy to misread as intentional skipping of error handling. Adding `await` here would make the two paths visually consistent and future-proof the branch against any outer `try/catch` added later.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "refactor: execute selected harnesses thr..." | Re-trigger Greptile

Comment thread src/agents/harness/v2.ts Resolved
Comment thread src/agents/harness/selection.ts Resolved

Copilot AI 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.

Pull request overview

Routes agent harness execution through the new Harness V2 lifecycle seam so that selected harness attempts run as a single bounded prepare -> start -> send -> resolveOutcome -> cleanup flow, instead of invoking runAttempt directly from selection. This supports the broader RuntimePlan effort by centralizing lifecycle/telemetry/session-policy concerns behind one execution boundary.

Changes:

  • Added a V2 lifecycle runner (runAgentHarnessV2LifecycleAttempt) and V1→V2 adapter (adaptAgentHarnessToV2).
  • Updated harness selection execution (runAgentHarnessAttemptWithFallback) to execute the selected harness via the V2 lifecycle.
  • Added unit tests for lifecycle ordering and cleanup behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/agents/harness/v2.ts Introduces V2 lifecycle contract + V1 adapter and a lifecycle attempt runner.
src/agents/harness/result-classification.ts Centralizes result classification/annotation logic used by the V2 adapter.
src/agents/harness/selection.ts Routes selected harness attempts through the V2 lifecycle runner (removes inline classification helper).
src/agents/harness/v2.test.ts Adds lifecycle and adapter behavior tests (ordering, cleanup, classification forwarding).

Comment thread src/agents/harness/v2.test.ts Resolved
@100yenadmin
100yenadmin requested a review from Copilot April 24, 2026 20:21

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/agents/harness/v2.ts Resolved
@100yenadmin
100yenadmin requested a review from Copilot April 24, 2026 20:51

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/agents/harness/v2.ts Resolved

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/agents/harness/v2.ts Resolved

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/agents/harness/v2.ts Resolved
Comment thread src/agents/harness/v2.ts Resolved

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@100yenadmin 100yenadmin changed the title refactor: execute selected harnesses through v2 lifecycle [codex] refactor: execute selected harnesses through v2 lifecycle Apr 25, 2026
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Superseded by #71722, which consolidates the RuntimePlan/Harness package into one review PR and preserves this PR's commits via cherry-pick -x. Keeping this PR as review/history evidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants