Skip to content

[codex] refactor: centralize runtime plan tool policy - #71220

Closed
100yenadmin wants to merge 4 commits into
openclaw:mainfrom
electricsheephq:contract-first/runtime-plan-tool-policy-dedupe
Closed

100yenadmin wants to merge 4 commits into
openclaw:mainfrom
electricsheephq:contract-first/runtime-plan-tool-policy-dedupe

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #71096 and RFC #71004. This PR centralizes the RuntimePlan-first tool normalization and diagnostics policy into one helper used by both Pi and Codex app-server paths.

Runtime behavior is intended to be equivalent: RuntimePlan wins when present, and the legacy provider-schema fallback remains intact when no plan is available.

RuntimePlan Package Context

This is the first production dedupe rung after the contract and forwarding proofs. It removes duplicate OpenClaw-owned tool-policy reassembly from Pi and Codex without adding new hooks or changing the harness SPI.

flowchart TD
  RFC["#71004 RFC"] --> Base["#71096 RuntimePlan merged"]
  Base --> Proofs["#71196/#71197/#71201 contract + forwarding + observability proofs"]
  Proofs --> This["#71220 shared RuntimePlan tool policy helper"]
  This --> HarnessFoundation["#71222 Harness V2 adapter"]
  HarnessFoundation --> HarnessExecution["#71238 selection executes via V2 lifecycle"]
  This --> Transcript["#71223 transcript policy resolver"]
  Transcript --> Alias["#71224 embedded-runner alias"]
  HarnessExecution --> Outcome["#71239 shared terminal outcome classifier"]
Loading

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

Local Architecture

flowchart TD
  Plan["AgentRuntimePlan.tools"] --> Helper["normalizeAgentRuntimeTools\nlogAgentRuntimeToolDiagnostics"]
  Legacy["Legacy provider schema normalization"] --> Helper
  Helper --> Pi["Pi embedded attempt"]
  Helper --> Codex["Codex app-server dynamic tools"]
  Helper --> Diagnostics["strict/downgrade diagnostics"]
Loading

Why This PR Exists

Tool policy was one of the clearest examples of Pi/Codex policy drift: each path knew how to prefer RuntimePlan when present and fall back to legacy normalization, but the branches were duplicated. This PR keeps the behavior but makes the ownership boundary explicit.

What Changed

  • Added src/agents/runtime-plan/tools.ts as the shared RuntimePlan-first tool-policy adapter.
  • RuntimePlan normalization and diagnostics route through plan.tools when present.
  • Legacy provider schema normalization and diagnostics remain the fallback.
  • Pi embedded attempt and Codex app-server dynamic tool setup now call the same helper.
  • Re-exported the helper through plugin-sdk/agent-harness-runtime for Codex extension consumption.

Maintainer Review Guide

  • Highest-signal files: src/agents/runtime-plan/tools.ts, src/agents/pi-embedded-runner/run/attempt.ts, extensions/codex/src/app-server/run-attempt.ts.
  • Check RuntimePlan precedence is preserved.
  • Check no legacy no-plan path was removed.
  • Check helper tests cover both RuntimePlan and fallback branches, including diagnostics.

What Did Not Change

Verification

  • ./node_modules/.bin/vitest run src/agents/runtime-plan/tools.test.ts --config test/vitest/vitest.agents.config.ts
  • ./node_modules/.bin/vitest run src/agents/pi-embedded-runner/run.attempt-param-forwarding.test.ts --config test/vitest/vitest.agents.config.ts
  • ./node_modules/.bin/vitest run extensions/codex/src/app-server/run-attempt.test.ts --config test/vitest/vitest.extensions.config.ts
  • ./node_modules/.bin/oxlint --tsconfig tsconfig.oxlint.core.json src/agents/runtime-plan/tools.ts src/agents/runtime-plan/tools.test.ts src/plugin-sdk/agent-harness-runtime.ts extensions/codex/src/app-server/run-attempt.ts src/agents/pi-embedded-runner/run/attempt.ts
  • git diff --check
  • pnpm check:architecture

Local broad pnpm check:changed has previously hit unrelated repository type/dependency drift; focused RuntimePlan tool-policy checks are the intended merge signal for this slice.

@100yenadmin
100yenadmin marked this pull request as ready for review April 24, 2026 19:16
Copilot AI review requested due to automatic review settings April 24, 2026 19:16
@greptile-apps

greptile-apps Bot commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR centralizes the duplicated runtimePlan?.tools.normalize(...) ?? normalizeProviderToolSchemas(...) and if (runtimePlan) { logDiagnostics } else { logProviderToolSchemaDiagnostics } patterns into two shared helpers (normalizeAgentRuntimeTools, logAgentRuntimeToolDiagnostics) in src/agents/runtime-plan/tools.ts. Both Pi embedded and Codex app-server callers are migrated. The refactor is behaviorally equivalent: RuntimePlan takes precedence when present, legacy fallback is intact, and env defaults to process.env when not supplied (matching prior call sites). The new helpers are re-exported through plugin-sdk/agent-harness-runtime so the Codex extension can consume them from its existing harness-runtime surface.

Confidence Score: 5/5

Safe to merge — pure refactor with no behavioral change and passing tests.

All findings are P2 or lower. The behavioral equivalence is clear from the diff, the logic is covered by the new tests (three cases), and the Codex diagnostic omission is intentional (no prior call existed). No correctness or security concerns found.

No files require special attention.

Reviews (2): Last reviewed commit: "refactor: centralize runtime plan tool p..." | Re-trigger Greptile

Comment thread src/agents/runtime-plan/tools.test.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

Centralizes the RuntimePlan-first tool policy (normalization + diagnostics) behind a shared helper so Pi embedded attempts and the Codex app-server adapter don’t each maintain their own RuntimePlan/legacy fallback branches.

Changes:

  • Added normalizeAgentRuntimeTools and logAgentRuntimeToolDiagnostics helper functions that prefer runtimePlan.tools.* when available and fall back to legacy provider schema normalization/diagnostics otherwise.
  • Updated Pi embedded attempt tool setup and diagnostics logging to use the shared helper.
  • Updated Codex app-server dynamic tool building to use the same helper, and re-exported the helper from plugin-sdk/agent-harness-runtime.

Reviewed changes

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

Show a summary per file
File Description
src/plugin-sdk/agent-harness-runtime.ts Re-exports the shared tool-policy helpers for extension consumption.
src/agents/runtime-plan/tools.ts New shared adapter implementing RuntimePlan-first tool normalization + diagnostics with legacy fallback.
src/agents/runtime-plan/tools.test.ts Adds focused unit coverage for RuntimePlan routing vs legacy fallback behavior.
src/agents/pi-embedded-runner/run/attempt.ts Switches embedded attempt tool normalization and diagnostics to the shared helper.
extensions/codex/src/app-server/run-attempt.ts Switches Codex dynamic tool normalization to the shared helper via plugin-sdk runtime surface.

@100yenadmin
100yenadmin marked this pull request as draft April 24, 2026 19:20
@100yenadmin
100yenadmin marked this pull request as ready for review April 24, 2026 19:46

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 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines 732 to 736
const runtimePlanModelContext = {
workspaceDir: effectiveWorkspace,
modelApi: params.model.api,
model: params.model,
};

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

runtimePlanModelContext is now unused after switching to normalizeAgentRuntimeTools / logAgentRuntimeToolDiagnostics. It should be removed (or passed into the helper) to avoid unused-local lint/typecheck failures.

Copilot uses AI. Check for mistakes.

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 6 out of 6 changed files in this pull request and generated no new comments.

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 6 out of 6 changed files in this pull request and generated no new comments.

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 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/agents/runtime-plan/tools.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 6 out of 6 changed files in this pull request and generated no new comments.

@100yenadmin 100yenadmin changed the title refactor: centralize runtime plan tool policy [codex] refactor: centralize runtime plan tool policy 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 extensions: codex size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants