Skip to content

[codex] refactor: keep runtime plan type contracts leaf-safe - #71196

Closed
100yenadmin wants to merge 10 commits into
openclaw:mainfrom
electricsheephq:contract-first/runtime-plan-contract-closure
Closed

100yenadmin wants to merge 10 commits into
openclaw:mainfrom
electricsheephq:contract-first/runtime-plan-contract-closure

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the merged RuntimePlan implementation (#71096) and the umbrella RFC (#71004). This PR keeps src/agents/runtime-plan/types.ts as a leaf structural contract layer instead of allowing it to import concrete OpenClaw runtime policy modules.

No runtime behavior changes.

RuntimePlan Package Context

This PR is part of the post-#71096 RuntimePlan hardening package. The package goal is to make OpenClaw-owned policy explicit and shared before larger runner splits or naming cleanup happen.

flowchart TD
  RFC["#71004 RFC: contract-first Pi/Codex runtime"] --> Base["#71096 merged RuntimePlan implementation"]
  Base --> P71196["#71196 leaf-safe RuntimePlan contracts"]
  P71196 --> P71197["#71197 RuntimePlan reaches harness attempts"]
  P71197 --> P71201["#71201 RuntimePlan observability coverage"]
  P71201 --> P71220["#71220 shared tool policy helper"]
  P71220 --> P71222["#71222 additive Harness V2 adapter"]
  P71222 --> P71238["#71238 selection executes via V2 lifecycle"]
  P71220 --> P71223["#71223 transcript policy resolver split"]
  P71223 --> P71224["#71224 embedded-runner alias barrel"]
  P71238 --> P71239["#71239 shared terminal outcome classifier"]
Loading

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

Why This PR Exists

AgentRuntimePlan is supposed to sit below both Pi and Codex. The builder can wire concrete policy to existing OpenClaw helpers, but the type contract itself should not depend upward on auto-reply, config, plugin runtime model, Pi fallback helper, transcript policy, or prompt-mode implementation modules.

If those imports creep back into types.ts, the contract layer stops being a stable seam and future refactors can recreate the coupling that #71004/#71096 are trying to remove.

Local Architecture

flowchart LR
  Types["runtime-plan/types.ts\nleaf structural contracts"]
  Build["runtime-plan/build.ts\nconcrete wiring adapter"]
  Pi["Pi embedded runner"]
  Codex["Codex app-server adapter"]
  Concrete["Existing concrete OpenClaw policy modules"]

  Types --> Build
  Build --> Pi
  Build --> Codex
  Build --> Concrete
  Concrete -. forbidden import .-> Types
Loading

What Changed

  • Replaced concrete internal imports in runtime-plan/types.ts with local structural RuntimePlan contract types.
  • Kept concrete casts and wiring in runtime-plan/build.ts, where adapter policy belongs.
  • Added topology guard coverage proving runtime-plan/types.ts does not import concrete runtime policy modules.
  • Added compatibility tests so copied scalar/structural contracts drift loudly instead of silently.

Maintainer Review Guide

  • Highest-signal file: src/agents/runtime-plan/types.ts.
  • Check that types.ts stays structural and leaf-safe; concrete helper imports should remain in build.ts.
  • Check the topology guard is broad enough to catch both barrel and file imports.
  • This PR intentionally accepts structural copies with compatibility tests instead of importing the upstream source unions.

What Did Not Change

Verification

  • ./node_modules/.bin/vitest run src/agents/runtime-plan/types.test.ts --config test/vitest/vitest.agents.config.ts
  • ./node_modules/.bin/vitest run src/agents/runtime-plan/build.test.ts --config test/vitest/vitest.unit-fast.config.ts
  • ./node_modules/.bin/vitest run src/agents/runtime-plan/types.compat.test.ts src/agents/runtime-plan/build.test.ts --config test/vitest/vitest.unit-fast.config.ts
  • pnpm check:architecture
  • ./node_modules/.bin/oxlint --tsconfig tsconfig.oxlint.core.json src/agents/runtime-plan/types.ts src/agents/runtime-plan/build.ts src/agents/runtime-plan/types.test.ts src/agents/runtime-plan/types.compat.test.ts src/agents/runtime-plan/build.test.ts
  • git diff --check

Local broad pnpm check:changed has previously hit unrelated repository type/dependency drift; this PR's targeted topology, unit, lint, and architecture checks are the intended merge signal.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 24, 2026
@100yenadmin
100yenadmin marked this pull request as ready for review April 24, 2026 18:59
Copilot AI review requested due to automatic review settings April 24, 2026 18:59
@greptile-apps

greptile-apps Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR decouples runtime-plan/types.ts from concrete OpenClaw modules by replacing six upstream imports with local structural contract types and a new topology guard test. The concrete imports migrate to build.ts, which casts between the structural and concrete types at the adapter boundary. The structural copies (AgentRuntimeThinkLevel, AgentRuntimeFailoverReason, AgentRuntimePromptMode) are verbatim matches of their upstream sources; AgentRuntimeModel is an all-optional structural approximation; and AgentRuntimeConfig = unknown trades compile-time config safety for decoupling — all intentional trade-offs documented in the PR description.

Confidence Score: 5/5

Safe to merge — no runtime behavior changes and all concrete logic remains intact in build.ts.

All findings are P2: the topology guard gap (barrel imports) and union-drift risk are maintenance concerns rather than current defects. The structural type copies are accurate, the adapter casts in build.ts are consistent, and the refactor correctly achieves its stated goal.

types.test.ts — topology guard patterns could be tightened to cover barrel imports

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/runtime-plan/types.test.ts
Line: 11-16

Comment:
**Topology guard misses barrel imports**

Each regex requires a trailing slash (e.g. `from "../../auto-reply/"`) and therefore silently passes for a bare barrel import like `from "../../auto-reply"` (no trailing slash). If someone later adds `import type { ThinkLevel } from "../../auto-reply"`, `from "../../config"`, or `from "../../plugins"` the guard will not fire — the coupling re-enters undetected. A small tweak to the patterns (e.g. `from "../../auto-reply(?:/|")`) or adding a separate assertion for each bare directory would close this gap.

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/runtime-plan/types.ts
Line: 6-28

Comment:
**Hand-rolled union copies can silently drift from upstream sources**

`AgentRuntimeThinkLevel`, `AgentRuntimeFailoverReason`, and `AgentRuntimePromptMode` are verbatim copies of `ThinkLevel`, `FailoverReason`, and `PromptMode` respectively (confirmed by reading the source files). There is currently no compile-time enforcement that these copies stay in sync. If `ThinkLevel` gains a new member (e.g. `"ultra"`) the contract type becomes more restrictive than the concrete implementation without any compiler error or test failure, so callers using the new level via the plan API would get a type error while the underlying runtime accepts it fine. Consider a `satisfies` / assignability check in a shared utility or a comment citing the source to make the coupling explicit.

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

Reviews (1): Last reviewed commit: "refactor: keep runtime plan types leaf-s..." | Re-trigger Greptile

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

Hardens the AgentRuntimePlan type layer by keeping src/agents/runtime-plan/types.ts as a leaf “structural contract” module (no imports from concrete OpenClaw runtime policy modules), while keeping concrete wiring/adaptation in runtime-plan/build.ts.

Changes:

  • Replaced concrete internal type imports in runtime-plan/types.ts with local structural contract types (think level, prompt mode, model, reply payload, config, failover reason).
  • Updated runtime-plan/build.ts to reintroduce concrete types locally and cast/adapt where needed.
  • Added a topology guard test to prevent runtime-plan/types.ts from importing concrete runtime policy modules.

Reviewed changes

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

File Description
src/agents/runtime-plan/types.ts Converts runtime plan types into leaf-safe structural contracts by removing upward imports.
src/agents/runtime-plan/build.ts Keeps concrete policy wiring here via local type imports and casts to concrete runtime types.
src/agents/runtime-plan/types.test.ts Adds a guard test intended to enforce leaf-safety of the contract layer.

Comment thread src/agents/runtime-plan/types.ts Resolved
Comment thread src/agents/runtime-plan/build.ts Resolved
Comment thread src/agents/runtime-plan/build.ts Resolved
Comment thread src/agents/runtime-plan/types.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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

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

Comment thread src/agents/runtime-plan/build.ts Resolved
Comment thread src/agents/runtime-plan/types.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 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/agents/runtime-plan/types.test.ts Resolved
Comment thread src/agents/runtime-plan/build.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 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/agents/runtime-plan/build.ts Resolved
@100yenadmin

Copy link
Copy Markdown
Contributor Author

@steipete gpt 5.4 / runner

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8410458d08

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d9cbd0e8e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/runtime-plan/types.test.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ebd39b1ba0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

@100yenadmin 100yenadmin changed the title refactor: keep runtime plan type contracts leaf-safe [codex] refactor: keep runtime plan type contracts leaf-safe 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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants