Skip to content

[codex] refactor: share harness terminal outcome classification - #71239

Closed
100yenadmin wants to merge 4 commits into
openclaw:mainfrom
electricsheephq:contract-first/outcome-policy-resolver
Closed

100yenadmin wants to merge 4 commits into
openclaw:mainfrom
electricsheephq:contract-first/outcome-policy-resolver

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #71096 and RFC #71004. This PR moves terminal harness outcome classification out of the Codex app-server event projector and into the lightweight openclaw/plugin-sdk/agent-harness-runtime surface.

Codex now consumes the same shared helper for empty, reasoning-only, and planning-only terminal turns instead of owning a local duplicate classifier.

RuntimePlan Package Context

This is the outcome-policy ownership rung. Terminal classification is high-risk because it drives GPT-5 fallback behavior. The package goal is to make that policy OpenClaw-owned and shared before further Pi/Codex refactors.

flowchart TD
  RFC["#71004 RFC"] --> Base["#71096 RuntimePlan merged"]
  Base --> Harness["#71222/#71238 Harness V2 lifecycle"]
  Harness --> This["#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 Events as Codex app-server events
  participant Projector as Event projector
  participant Shared as agent-harness-runtime classifier
  participant Result as EmbeddedRunAttemptResult
  participant Fallback as OpenClaw fallback chain

  Events->>Projector: assistant/reasoning/planning/tool/error signals
  Projector->>Shared: classify terminal outcome
  Shared-->>Projector: empty | reasoning-only | planning-only | undefined
  Projector->>Result: agentHarnessResultClassification
  Result->>Fallback: fallback eligibility signal
Loading

Why This PR Exists

The RuntimePlan/RFC path is about preventing Pi and Codex from silently forking OpenClaw-owned policy. Terminal outcome classification is one of the highest-risk policies because it decides whether GPT-5 empty/planning-only/reasoning-only terminal results can advance the fallback chain.

What Changed

  • Added classifyAgentHarnessTerminalOutcome(...) to src/plugin-sdk/agent-harness-runtime.ts.
  • Added SDK-level unit coverage for in-flight turns, prompt errors, intentional silent replies (NO_REPLY), whitespace-only text, planning-only, reasoning-only, and empty outcomes.
  • Replaced Codex app-server local classification logic with the shared helper.
  • Narrowed the classifier return type to the embedded terminal classification union.
  • Kept event projection, app-server lifecycle, and fallback policy behavior unchanged.

Maintainer Review Guide

  • Highest-signal files: src/plugin-sdk/agent-harness-runtime.ts, extensions/codex/src/app-server/event-projector.ts.
  • Check behavior equivalence with the removed Codex-local classifier.
  • Check NO_REPLY remains intentional silent output and does not trigger fallback.
  • Check whitespace-only assistant text remains fallback-eligible.
  • Check prompt errors, including empty-string errors, block classification.

What Did Not Change

Verification

  • ./node_modules/.bin/vitest run src/plugin-sdk/agent-harness-runtime.test.ts --config test/vitest/vitest.unit-fast.config.ts
  • ./node_modules/.bin/vitest run extensions/codex/src/app-server/outcome-fallback-runtime-contract.test.ts --config test/vitest/vitest.extensions.config.ts
  • ./node_modules/.bin/oxlint --tsconfig tsconfig.oxlint.core.json src/plugin-sdk/agent-harness-runtime.ts src/plugin-sdk/agent-harness-runtime.test.ts extensions/codex/src/app-server/event-projector.ts
  • git diff --check
  • pnpm check:architecture

This is one ownership-boundary extraction: Codex uses shared OpenClaw terminal outcome policy.

Copilot AI review requested due to automatic review settings April 24, 2026 20:08
@greptile-apps

greptile-apps Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extracts the terminal harness outcome classifier (classifyTerminalResult) from the Codex app-server event projector into a shared SDK function (classifyAgentHarnessTerminalOutcome) in src/plugin-sdk/agent-harness-runtime.ts. The logic is preserved exactly — only the parameter types are slightly widened (reasoningText/planText become string | null | undefined) to accommodate future callers, and optional chaining handles those additions. The Codex call site continues to pass plain string values, so no behavioral change occurs.

Confidence Score: 5/5

Safe to merge — pure refactor with no behavioral changes and matching unit test coverage.

All findings are P2 or lower. The extracted function is logically identical to the removed local one; types at the call site are compatible; the new SDK type is a proper superset of the removed local type alias; and tests cover all documented classification branches including in-flight, prompt-error, NO_REPLY, planning-only, reasoning-only, and empty.

No files require special attention.

Reviews (1): Last reviewed commit: "refactor: share harness terminal outcome..." | Re-trigger Greptile

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

This PR extracts Codex’s terminal harness outcome classification logic into the shared lightweight openclaw/plugin-sdk/agent-harness-runtime surface so that Codex and other harness adapters consume the same OpenClaw-owned policy that drives fallback behavior.

Changes:

  • Added classifyAgentHarnessTerminalOutcome(...) (and input type) to the plugin SDK runtime surface.
  • Added unit tests covering terminal classification scenarios (in-flight, prompt error, NO_REPLY, planning-only, reasoning-only, empty).
  • Replaced Codex app-server’s local classifier with the shared SDK helper.

Reviewed changes

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

File Description
src/plugin-sdk/agent-harness-runtime.ts Introduces the shared terminal-outcome classifier and its input type.
src/plugin-sdk/agent-harness-runtime.test.ts Adds unit coverage for the new classifier behavior.
extensions/codex/src/app-server/event-projector.ts Removes local classification logic and calls the SDK helper when building EmbeddedRunAttemptResult.

Comment thread src/plugin-sdk/agent-harness-runtime.ts Resolved
Comment thread src/plugin-sdk/agent-harness-runtime.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 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/plugin-sdk/agent-harness-runtime.ts Resolved
Comment thread src/plugin-sdk/agent-harness-runtime.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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

@steipete this series of gpt /codex optimizations ready for review.
Review package links: #71196, #71197, #71201, #71220, #71222, #71223, #71224, #71238, #71239.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants