Repository navigation
[codex] refactor: execute selected harnesses through v2 lifecycle - #71238
100yenadmin wants to merge 11 commits into
Conversation
Greptile SummaryThis PR routes both Pi and plugin harness attempts through the new V2 lifecycle executor ( Confidence Score: 5/5Safe 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 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 AIThis 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 |
There was a problem hiding this comment.
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). |
|
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. |
Summary
Follow-up to #71222, #71096, and RFC #71004. This PR routes selected harness attempts through the V2 lifecycle executor instead of calling
runAttemptdirectly 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.
Review package links: #71196, #71197, #71201, #71220, #71222, #71223, #71224, #71238, #71239.
Local Architecture
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
runAgentHarnessV2LifecycleAttempt(...)insrc/agents/harness/v2.ts.runAgentHarnessAttemptWithFallback(...)to adapt the selected harness and execute through the V2 lifecycle.Maintainer Review Guide
src/agents/harness/v2.ts,src/agents/harness/selection.ts,src/agents/harness/v2.test.ts.thisbinding 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.tsgit diff --checkpnpm check:architectureThis PR is logically stacked after #71222. Until #71222 merges, GitHub may show that adapter foundation in the diff as well.