Repository navigation
[codex] Expose agent harness selection decisions - #70750
100yenadmin wants to merge 1 commit into
Conversation
|
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 SummaryThis PR extracts the existing harness-selection logic into a new Confidence Score: 5/5Safe 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 No files require special attention.
|
| 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[]; | ||
| }; |
There was a problem hiding this 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.
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.There was a problem hiding this comment.
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 keepingselectAgentHarness()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. |
| 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. |
There was a problem hiding this comment.
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).
| 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. |
| 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. |
There was a problem hiding this comment.
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).
| 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. |
Summary
resolveAgentHarnessSelection(...)decision object for the existing embedded harness selector.AgentHarnessSPI and runtime behavior unchanged;selectAgentHarness(...)now delegates to the decision helper.runAgentHarnessAttemptWithFallback(...)so operators can see selected harness id, policy runtime/fallback values, selection reason, and candidate support results.codex/*vsopenai-codex/*routing without redesigning Pi/Codex harness selection.Scope Guard
upstream/mainto 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.tspnpm tsgo:core:testpnpm exec oxlint src/agents/harness/selection.ts src/agents/harness/selection.test.tspnpm exec oxfmt --check src/agents/harness/selection.ts src/agents/harness/selection.test.ts docs/plugins/sdk-agent-harness.md docs/plugins/codex-harness.mdnode scripts/run-vitest.mjs run --config test/vitest/vitest.full-core-support-boundary.config.ts test/scripts/lint-suppressions.test.tsgit diff --checkNotes
eb82cc910f.agents/harnesslogger is debug-enabled.supports(...)method is still called exactly once per candidate.