Skip to content

fix(doctor): clear stale Codex session state - #77565

Merged
steipete merged 3 commits into
mainfrom
fix/doctor-stale-codex-session-state
May 5, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/doctor-stale-codex-session-state

Conversation

@steipete

@steipete steipete commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Move stale auto-created session route repair into core doctor as a generic session repair path.
  • Let bundled plugins define static route-state ownership metadata through doctor-contract-api, with Codex owning only IDs/prefixes rather than repair code.
  • Clear stale auto-created model/runtime/auth/CLI bindings during doctor --fix, while leaving explicit user choices for manual review.
  • Switch the kitchen-sink plugin canary to @latest so prerelease coverage does not drift on every package publish.
  • Bump the root axios override to 1.16.0 to clear the new high-severity production dependency audit advisory.

Verification

  • pnpm test src/plugins/doctor-contract-registry.test.ts src/commands/doctor-session-state-providers.test.ts extensions/codex/index.test.ts test/scripts/plugin-prerelease-test-plan.test.ts -- --reporter=dot
  • node scripts/pre-commit/pnpm-audit-prod.mjs --audit-level=high
  • pnpm crabbox:run -- --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --idle-timeout 90m --ttl 240m --timing-json --shell -- "env CI=1 NODE_OPTIONS=--max-old-space-size=4096 OPENCLAW_TEST_PROJECTS_PARALLEL=6 OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=900000 pnpm check:changed" (tbx_01kqtsftvsxv7t3dtn2f83s1td, exit 0)

Refs #68615.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: L maintainer Maintainer-authored PR labels May 4, 2026
@clawsweeper

clawsweeper Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge.

Summary
The PR adds a plugin-owned doctor session-state repair contract and Codex implementation, wires it into doctor state integrity, and updates tests, docs, and changelog for stale Codex session cleanup.

Reproducibility: yes. source-level. A session configured for openai-codex/gpt-5.4 under PI with stale agentHarnessId: "codex" and codex-cli bindings reaches routeAllowsOwnerState and skips the cleanup branch.

Next step before merge
Protected maintainer-labeled PR with blocking review findings; the author or maintainer should update the branch and request re-review.

Security
Cleared: The diff extends doctor/plugin contract loading and docs/tests without new dependencies, workflows, package resolution changes, lifecycle hooks, or secret-handling expansion.

Review findings

  • [P2] Separate provider routes from runtime cleanup — src/commands/doctor-session-state-providers.ts:187-191
  • [P2] Regenerate the Plugin SDK API baseline — src/plugin-sdk/runtime-doctor.ts:20
Review details

Best possible solution:

Keep the plugin-owned repair direction, make route allowance state-kind aware so PI provider state does not preserve stale native runtime/harness/CLI bindings, then regenerate the SDK API baseline and rerun the targeted doctor/Codex tests plus changed gate.

Do we have a high-confidence way to reproduce the issue?

Yes, source-level. A session configured for openai-codex/gpt-5.4 under PI with stale agentHarnessId: "codex" and codex-cli bindings reaches routeAllowsOwnerState and skips the cleanup branch.

Is this the best way to solve the issue?

No. The repair seam is maintainable, but the current predicate is too coarse and the new public SDK export needs its baseline regenerated.

Full review comments:

  • [P2] Separate provider routes from runtime cleanup — src/commands/doctor-session-state-providers.ts:187-191
    Because this returns true for any configured owner provider, a PI route such as openai-codex/gpt-5.4 makes the scanner skip stale native Codex state. That leaves agentHarnessId: "codex" and codex-cli bindings in place even though openai-codex/* is documented as the PI OAuth provider route, not the native runtime.
    Confidence: 0.9
  • [P2] Regenerate the Plugin SDK API baseline — src/plugin-sdk/runtime-doctor.ts:20
    This new public export changes the openclaw/plugin-sdk/runtime-doctor API surface, but the PR does not update docs/.generated/plugin-sdk-api-baseline.sha256. The repo's Plugin SDK API check hashes exported symbols and will report baseline drift until the hash is regenerated and committed.
    Confidence: 0.84

Overall correctness: patch is incorrect
Overall confidence: 0.9

What I checked:

  • PR state and protected label: GitHub API shows the PR is open, not draft, head 3310a0507373f13d94ac2fd2aec14b3b7c42f1f3, mergeable=true, and labeled maintainer, so it should stay open for maintainer handling. (3310a0507373)
  • Current main lacks the new repair hook: Searching current main found no new doctor session-state repair symbols, so this PR is not obsolete on main. (44a10ceea2a8)
  • Provider/runtime conflation remains in the PR: routeAllowsOwnerState returns true when any configured model ref uses an owner provider id, which lets an openai-codex/* PI route suppress cleanup of stale native Codex harness and CLI bindings. (src/commands/doctor-session-state-providers.ts:187, 3310a0507373)
  • Test fixture preserves the bad mixed state: The added test expects no repair when configuredModelRefs includes openai-codex/gpt-5.4 under runtime pi, even though the entry still has agentHarnessId: "codex" and codex-cli bindings. (src/commands/doctor-session-state-providers.test.ts:179, 3310a0507373)
  • Docs define openai-codex/* as PI provider route: Current docs say openai-codex/* is Codex subscription auth through PI, while native Codex execution is openai/* plus agentRuntime.id: "codex". Public docs: docs/providers/openai.md. (docs/providers/openai.md:31, 44a10ceea2a8)
  • Plugin SDK baseline was not updated: The PR adds a public type export from openclaw/plugin-sdk/runtime-doctor, but the PR head's docs/.generated/plugin-sdk-api-baseline.sha256 is unchanged from current main; repo policy requires API baseline/export checks for SDK surface changes. (src/plugin-sdk/runtime-doctor.ts:20, 3310a0507373)

Likely related people:

  • steipete: Recent main history covers doctor state integrity, plugin cache/registry boundaries, Codex runtime routing docs, and the Codex app-server harness surface involved here. (role: recent maintainer and Codex/plugin-runtime owner; confidence: high; commits: c5bc4b689264, f43a184103b6, 6d4f65c9d41b; files: src/commands/doctor-state-integrity.ts, src/plugins/doctor-contract-registry.ts, docs/concepts/agent-runtimes.md)
  • pashpashpash: Recent commits introduced/refined the documented split between openai-codex/* PI provider routing and native Codex runtime selection, and also touched current Codex plugin behavior. (role: Codex runtime documentation and recent Codex maintainer; confidence: medium; commits: 42ec7a868fe8, 6cfe810402d0, 9fb90f3d2921; files: docs/concepts/agent-runtimes.md, docs/plugins/codex-harness.md, extensions/codex/index.ts)
  • vincentkoc: Recent history touches Plugin SDK leaf type surfaces, plugin runtime capture, and Codex/runtime docs adjacent to the public SDK and route-cleanup contract in this PR. (role: adjacent plugin SDK/runtime maintainer; confidence: medium; commits: 74e7b8d47b18, 5f3b8b41004c, 88ea3d839bbb; files: src/plugin-sdk/runtime-doctor.ts, src/plugins/doctor-contract-registry.ts, docs/concepts/agent-runtimes.md)
  • gumadeiras: Recent merged work lazy-loaded doctor plugin paths in the same doctor contract registry area extended by this PR. (role: doctor plugin registry contributor; confidence: medium; commits: 66add9fcd96a; files: src/plugins/doctor-contract-registry.ts)

Remaining risk / open question:

  • No execution validation was run in this read-only review; the blocking functional issue is source-inspected.
  • Public commit status for the PR head currently reports no statuses, so merge should still wait for the normal targeted tests, SDK API check, and changed gate.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 44a10ceea2a8.

Re-review progress:

@steipete
steipete force-pushed the fix/doctor-stale-codex-session-state branch 2 times, most recently from 33cb592 to 3310a05 Compare May 5, 2026 00:20
@steipete
steipete marked this pull request as ready for review May 5, 2026 00:20

@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: 3310a05073

ℹ️ 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".

@@ -0,0 +1,12 @@
import type { DoctorSessionRouteStateOwner } from "openclaw/plugin-sdk/runtime-doctor";

export const sessionRouteStateOwners: DoctorSessionRouteStateOwner[] = [

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 Badge Load the Codex doctor contract from npm installs

When Codex is installed as the official external npm plugin, this new contract is emitted by the plugin runtime build under dist/doctor-contract-api.js, while resolveContractApiPath() only probes <rootDir>/doctor-contract-api.{js,ts,...} and <rootDir>/contract-api.... Because the manifest registry uses the package root as rootDir, openclaw doctor --fix will never discover sessionRouteStateOwners for the npm-installed Codex plugin, so stale Codex session routing state remains uncleared on the main external-plugin install path; please either probe the dist/ sidecar or package/copy a root sidecar.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the fix/doctor-stale-codex-session-state branch from 3310a05 to ef32882 Compare May 5, 2026 00:29
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts docker Docker and sandbox tooling labels May 5, 2026

@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: ef32882796

ℹ️ 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".

const current = currentMutableStore[key];
if (
current &&
applySessionRouteStateRepair({ entry: current, repair, now: repairedAt })

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 Badge Revalidate the session entry before applying repairs

If openclaw doctor --fix runs while the gateway is active, the session can change between the initial scan/confirmation and this updateSessionStore mutation. The mutator reloads the current store, but it applies the previously computed repair without checking that the current entry still has the same auto Codex state; for example, a user could select a Codex model/runtime in the interim and this stale auto model override repair would still delete the new providerOverride/modelOverride fields. Re-scan or validate the current entry inside the writer before clearing fields.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the fix/doctor-stale-codex-session-state branch from ef32882 to 3211a06 Compare May 5, 2026 00:40

@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: 3211a06bc0

ℹ️ 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 on lines +293 to +297
if (
params.entry.authProfileOverrideSource === "auto" &&
ownsPrefixedValue(authProfilePrefixes, params.entry.authProfileOverride)
) {
addReason(reasons, "auto auth profile override");

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 Badge Clear auto auth profiles with custom IDs

When an auto-selected profile ID does not start with one of the owner prefixes (for example a user-defined Codex profile named work whose store entry has provider openai-codex), this condition never records auto auth profile override, so doctor --fix can clear the stale Codex model/runtime/CLI state but leave authProfileOverride and authProfileOverrideSource: "auto" behind. Auth profile IDs are looked up as arbitrary keys in the auth-profile store, not guaranteed provider-prefixed, so this misses valid stale Codex auth state for custom profile names.

Useful? React with 👍 / 👎.

@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: 67d989a35e

ℹ️ 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".


const explicitOwnedOverride =
directOverrideIsOwned && directOverrideSource !== undefined && directOverrideSource !== "auto";
if (!routeAllowsOwner && !explicitOwnedOverride) {

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 Badge Clear pinned runtime separately from provider route

When the current config still includes a Codex-owned provider (for example as a fallback) but no longer uses the Codex runtime, routeAllowsOwner is true, so this block never evaluates agentHarnessId or the Codex CLI bindings for cleanup. That leaves agentHarnessId: "codex" in the session, and src/agents/command/attempt-execution.ts resolves that stored value before the configured runtime, so later message-channel runs remain pinned to Codex even after the runtime default moved away. Consider checking runtime-owned state against runtimeIds independently from provider-owned model refs.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant