Skip to content

[codex] Expose agent harness selection decisions - #70750

Closed
100yenadmin wants to merge 1 commit into
openclaw:mainfrom
electricsheephq:feat/harness-selection-observability
Closed

100yenadmin wants to merge 1 commit into
openclaw:mainfrom
electricsheephq:feat/harness-selection-observability

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Expose a pure resolveAgentHarnessSelection(...) decision object for the existing embedded harness selector.
  • Keep the existing AgentHarness SPI and runtime behavior unchanged; selectAgentHarness(...) now delegates to the decision helper.
  • Add structured debug logging from runAgentHarnessAttemptWithFallback(...) so operators can see selected harness id, policy runtime/fallback values, selection reason, and candidate support results.
  • Document the observability path for diagnosing codex/* vs openai-codex/* routing without redesigning Pi/Codex harness selection.

Scope Guard

  • This is the follow-up architecture/observability slice after PR [codex] Harden GPT-5.4 runtime paths #70743. It intentionally does not repeat the GPT-5.4 runtime fixes already implemented there.
  • No provider routing, fallback behavior, app-server lifecycle, or public wire format changes.
  • Rebased onto current upstream/main to clear the old support-boundary base-drift failure.

Validation

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents.config.ts src/agents/harness/selection.test.ts
  • pnpm tsgo:core:test
  • pnpm exec oxlint src/agents/harness/selection.ts src/agents/harness/selection.test.ts
  • pnpm exec oxfmt --check src/agents/harness/selection.ts src/agents/harness/selection.test.ts docs/plugins/sdk-agent-harness.md docs/plugins/codex-harness.md
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.full-core-support-boundary.config.ts test/scripts/lint-suppressions.test.ts
  • git diff --check

Notes

  • Current head: eb82cc910f.
  • The debug record is emitted only when the agents/harness logger is debug-enabled.
  • Auto-mode tests assert each plugin supports(...) method is still called exactly once per candidate.

Copilot AI review requested due to automatic review settings April 23, 2026 19:41
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M r: too-many-prs Auto-close: author has more than twenty active PRs. labels Apr 23, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because the author has more than 10 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

@greptile-apps

greptile-apps Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extracts the existing harness-selection logic into a new resolveAgentHarnessSelection function that returns an observable AgentHarnessSelectionDecision (selected harness, policy, reason, and per-candidate support results), while keeping selectAgentHarness as a backward-compatible thin wrapper. It also adds a structured debug log in runAgentHarnessAttemptWithFallback and documents the new diagnostic path in two plugin guides. Behavior is fully preserved.

Confidence Score: 5/5

Safe to merge — behavior-preserving refactor with good test coverage; only minor style concerns remain.

No P0/P1 issues found. The two flagged items are both P2: a redundant intermediate .map in the auto-selection path and the unexported AgentHarnessPolicy type used inside a public type. Neither affects correctness or runtime behavior.

No files require special attention.

Comments Outside Diff (1)

  1. src/agents/harness/selection.ts, line 138-151 (link)

    P2 Redundant intermediate .map before .filter

    The intermediate .map on line 138 copies harness.harness → harness and harness.support → support, but those are exactly the same fields already present in each candidates element. The remap doesn't transform anything, so it can be dropped entirely.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/harness/selection.ts
    Line: 138-151
    
    Comment:
    **Redundant intermediate `.map` before `.filter`**
    
    The intermediate `.map` on line 138 copies `harness.harness` → `harness` and `harness.support` → `support`, but those are exactly the same fields already present in each `candidates` element. The remap doesn't transform anything, so it can be dropped entirely.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/harness/selection.ts
Line: 138-151

Comment:
**Redundant intermediate `.map` before `.filter`**

The intermediate `.map` on line 138 copies `harness.harness` → `harness` and `harness.support` → `support`, but those are exactly the same fields already present in each `candidates` element. The remap doesn't transform anything, so it can be dropped entirely.

```suggestion
  const supported = candidates
    .filter(
      (
        entry,
      ): entry is {
        harness: AgentHarness;
        support: AgentHarnessSupport & { supported: true };
      } => entry.support.supported,
    )
    .toSorted(compareHarnessSupport);
```

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: 40-53

Comment:
**`AgentHarnessPolicy` type is unexported but used in a public type**

`AgentHarnessSelectionDecision` (exported) contains a `policy: AgentHarnessPolicy` field, but `AgentHarnessPolicy` itself is not exported. Callers who receive an `AgentHarnessSelectionDecision` can read the object fine at runtime, but they cannot name or annotate variables of type `AgentHarnessPolicy` without casting. Exporting the type makes the public API fully self-contained.

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

Reviews (1): Last reviewed commit: "feat: expose agent harness selection dec..." | Re-trigger Greptile

Comment on lines +40 to +53
export type AgentHarnessSelectionDecision = {
harness: AgentHarness;
policy: AgentHarnessPolicy;
selectedHarnessId: string;
selectedHarnessLabel: string;
selectedReason:
| "pinned"
| "forced_pi"
| "forced_plugin"
| "forced_plugin_missing_pi_fallback"
| "auto_plugin"
| "auto_pi_fallback";
candidates: AgentHarnessSelectionCandidate[];
};

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.

P2 AgentHarnessPolicy type is unexported but used in a public type

AgentHarnessSelectionDecision (exported) contains a policy: AgentHarnessPolicy field, but AgentHarnessPolicy itself is not exported. Callers who receive an AgentHarnessSelectionDecision can read the object fine at runtime, but they cannot name or annotate variables of type AgentHarnessPolicy without casting. Exporting the type makes the public API fully self-contained.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/harness/selection.ts
Line: 40-53

Comment:
**`AgentHarnessPolicy` type is unexported but used in a public type**

`AgentHarnessSelectionDecision` (exported) contains a `policy: AgentHarnessPolicy` field, but `AgentHarnessPolicy` itself is not exported. Callers who receive an `AgentHarnessSelectionDecision` can read the object fine at runtime, but they cannot name or annotate variables of type `AgentHarnessPolicy` without casting. Exporting the type makes the public API fully self-contained.

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

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 adds an observability seam around embedded agent-harness selection so operators can understand why a run routed to the PI harness vs a plugin harness (e.g., Codex), without changing the underlying selection behavior.

Changes:

  • Refactors harness selection to produce an AgentHarnessSelectionDecision (selected harness + policy + candidate metadata) while keeping selectAgentHarness() as the simple API.
  • Emits a structured debug log ("agent harness selected") during embedded runs, capturing selection inputs and outcomes.
  • Adds tests covering the new decision object (including “no duplicate supports() probes”) and updates docs describing how to use the diagnostics.

Reviewed changes

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

File Description
src/agents/harness/selection.ts Introduces resolveAgentHarnessSelection(), decision/candidate types, and debug logging for embedded selection.
src/agents/harness/selection.test.ts Adds coverage for the new decision object and ensures supports() is invoked exactly once per candidate in auto mode.
docs/plugins/sdk-agent-harness.md Documents the new structured debug record for diagnosing harness routing.
docs/plugins/codex-harness.md Documents using the debug record to spot codex/* vs openai-codex/* prefix mistakes.

Comment on lines +54 to +57
structured `agent harness selected` record. It includes the selected harness id,
policy runtime/fallback values, and the support result for each registered
plugin harness, which makes prefix mistakes (`openai-codex/*` vs `codex/*`)
visible without changing runtime behavior.

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

This section implies the agent harness selected debug record always includes support results for each registered plugin harness. In the current implementation, support results are only evaluated/logged in runtime === "auto"; pinned/forced selection paths omit supported/reason fields to avoid extra probes. Please adjust the wording to reflect that (or change the code if you want support probes in non-auto modes).

Suggested change
structured `agent harness selected` record. It includes the selected harness id,
policy runtime/fallback values, and the support result for each registered
plugin harness, which makes prefix mistakes (`openai-codex/*` vs `codex/*`)
visible without changing runtime behavior.
structured `agent harness selected` record. It includes the selected harness id
and policy runtime/fallback values; when selection runs in `runtime: "auto"`,
it also logs the support result for each registered plugin harness. That makes
prefix mistakes (`openai-codex/*` vs `codex/*`) visible without changing
runtime behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +113 to +115
harness id, selection reason, and every plugin candidate's support reason. This
is the safest way to diagnose why a `codex/*` model used the Codex harness while
an `openai-codex/*` model stayed on the PI compatibility path.

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

The doc says the debug agent harness selected record includes "every plugin candidate's support reason", but the implementation only records support results when runtime === "auto" (forced/pinned paths intentionally skip supports() and candidates won’t have supported/reason). Please update this wording to clarify it’s only populated in auto-selection mode (or adjust the implementation to always probe if that’s desired).

Suggested change
harness id, selection reason, and every plugin candidate's support reason. This
is the safest way to diagnose why a `codex/*` model used the Codex harness while
an `openai-codex/*` model stayed on the PI compatibility path.
harness id, and selection reason. In `auto` mode, it also includes every
plugin candidate's support reason. This is the safest way to diagnose, in
`auto` mode, why a `codex/*` model used the Codex harness while an
`openai-codex/*` model stayed on the PI compatibility path.

Copilot uses AI. Check for mistakes.
@openclaw-barnacle openclaw-barnacle Bot removed the r: too-many-prs Auto-close: author has more than twenty active PRs. label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants