Skip to content

fix(doctor): preserve codex context metadata#90507

Closed
sahibzada-allahyar wants to merge 3 commits into
openclaw:mainfrom
sahibzada-allahyar:fastino-90448-codex-context-fallback
Closed

fix(doctor): preserve codex context metadata#90507
sahibzada-allahyar wants to merge 3 commits into
openclaw:mainfrom
sahibzada-allahyar:fastino-90448-codex-context-fallback

Conversation

@sahibzada-allahyar

@sahibzada-allahyar sahibzada-allahyar commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #90448 — the doctor migration that folds a legacy openai-codex provider into the canonical openai provider dropped the per-model context metadata (contextWindow / contextTokens / maxTokens). This carries that metadata forward.

  • Preserve contextWindow / contextTokens / maxTokens (context-only; transport fields like baseUrl/api/headers stay excluded) when copying legacy openai-codex model rows into openai.
  • Lint/type hygiene: brace a guard clause and use const for a never-reassigned binding in the migration, and switch the migration tests to optional chaining / explicit casts so they pass both tsgo (no possibly-undefined access) and oxlint (no unnecessary type assertions).

Real Behavior Proof

Behavior addressed: The openai-codex → openai doctor migration carried only id/name into canonical openai model rows, losing context metadata for existing users with legacy openai-codex model entries (#90448). After this change the migration copies the full context metadata and removes the legacy provider.

Real environment tested: OpenClaw source checkout on macOS (arm64), Node v26, pnpm 11.2.2, branch fastino-90448-codex-context-fallback. Drove the real migration entry (LEGACY_CONFIG_MIGRATIONS_RUNTIME_MODELSmodels.providers.openai-codex->models.providers.openai) against a legacy config object — not a mock.

Exact steps or command run after this patch:

pnpm exec tsx --conditions=browser -e "load the migration entry, call apply() on a raw config whose legacy openai-codex provider has a gpt-5.5 row carrying context metadata, then print the resulting openai models and the change log"

Evidence after fix: Copied output:

AFTER openai.models = [{"id":"gpt-5.5","contextWindow":200000,"contextTokens":200000,"maxTokens":8192}]
has openai-codex still?  false
changes: ["Copied models.providers.openai-codex.models[].gpt-5.5 → models.providers.openai.models[].gpt-5.5.","Removed models.providers.openai-codex because models.providers.openai already exists."]

Observed result after fix: The legacy gpt-5.5 row is migrated into openai with its contextWindow (200000), contextTokens (200000), and maxTokens (8192) intact, and the legacy openai-codex provider is removed. Previously the context metadata was dropped on this path.

What was not tested: A full openclaw doctor --fix run over a real on-disk user config was not executed; the migration logic itself is exercised here against the real migration entry on this branch, and the focused suites pass.

Regression coverage

node scripts/run-vitest.mjs src/commands/doctor/shared/legacy-config-migrate.test.ts src/commands/doctor/shared/legacy-config-migrations.runtime.models.test.ts --reporter=dot
# Test Files  2 passed (2)
# Tests  119 passed (119)

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 5, 2026
@clawsweeper

clawsweeper Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR is superseded by a broader, clean, proof-positive migration PR that covers the same context-metadata preservation plus the provider-level budget, scoped model-id, and stale session-state cases this branch does not cover.

Canonical path: Close this dirty narrow branch and review or land the broader clean doctor/update migration in #90451 as the canonical fix.

So I’m closing this here and keeping the remaining discussion on #90451.

Review details

Best possible solution:

Close this dirty narrow branch and review or land the broader clean doctor/update migration in #90451 as the canonical fix.

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

Yes, source-level. Current main resolves OpenAI/Codex context config through canonical openai, and Codex source shows the 272000 default that legacy context overrides need to avoid.

Is this the best way to solve the issue?

No, this branch is not the best landing path. The narrower dirty branch is superseded by a clean canonical PR that handles model-scoped metadata, provider-level budgets, scoped ids, and stale session refs without adding runtime legacy readers.

Security review:

Security review cleared: The diff changes doctor migration code and tests only; it does not add dependency, workflow, credential, network, package, or code-execution surface.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md was read fully and applied; no scoped AGENTS.md exists under src/commands, and the only maintainer note is Telegram-specific. (AGENTS.md:13, ebb9c6a013b5)
  • Current runtime lookup uses canonical openai config: Current main resolves configured context caps from the selected provider's model rows first and then provider-level contextTokens/contextWindow, which is why migration shape and scoping are compatibility-sensitive. (src/agents/context.ts:271, ebb9c6a013b5)
  • This PR is dirty and not rebaseable: The live PR API reports this branch as mergeable=false, rebaseable=false, mergeable_state=dirty, while maintainer_can_modify is true. (214c00a496d4)
  • Superseding PR is viable: The related canonical PR is open, clean, rebaseable, maintainer-editable, and has a proof-sufficient ClawSweeper review at head 2226e28. (2226e281030a)
  • Superseding PR covers more of the same bug: The canonical PR adds model-scoped context metadata copy, provider-level budget handling, scoped/unscoped model-id matching, unmapped manual fallback, and stale session-route repair for the same OpenAI/Codex unification regression. (src/commands/doctor/shared/legacy-config-migrations.runtime.models.ts:1007, 2226e281030a)
  • This PR has a narrower migration shape: At PR head, the new helper raw-matches model ids and the no-canonical-provider path sanitizes legacy model rows down to id/name/context metadata, which leaves less compatibility coverage than the canonical PR. (src/commands/doctor/shared/legacy-config-migrations.runtime.models.ts:950, 214c00a496d4)

Likely related people:

  • Vincent Koc: Current checkout blame attributes the surrounding doctor migration and test files to the imported current-main commit in this shallow checkout. (role: recent adjacent contributor; confidence: medium; commits: 0176429ad787; files: src/commands/doctor/shared/legacy-config-migrations.runtime.models.ts, src/commands/doctor/shared/legacy-config-migrate.test.ts)
  • ooiuuii: Authored the viable superseding PR that now consolidates the same OpenAI/Codex context migration cleanup with broader provider-level and session-state coverage. (role: canonical fix author; confidence: high; commits: 2226e281030a; files: src/commands/doctor/shared/legacy-config-migrations.runtime.models.ts, src/commands/doctor/shared/codex-route-warnings.ts, src/commands/doctor/shared/legacy-config-migrate.test.ts)
  • Chunyue Wang: The durable review on the canonical PR identifies this person as author of the current safe merge path for legacy openai-codex models into canonical openai, which the migration work extends. (role: recent area contributor; confidence: medium; commits: e06f6ffc3e87; files: src/commands/doctor/shared/legacy-config-migrations.runtime.models.ts, src/commands/doctor/shared/legacy-config-migrate.test.ts)

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

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 5, 2026
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

Addressed the review finding in 0a27734b.

What changed:

  • Sanitized copied legacy openai-codex model rows so canonical openai.models[] receives only id, name, contextWindow, contextTokens, and maxTokens.
  • Excluded model-level transport/runtime fields such as baseUrl, api, headers, auth, params, compat, and request.
  • Added focused migration regression coverage for transport-field exclusion while preserving context metadata.

Verification:

git diff --check -- src/commands/doctor/shared/legacy-config-migrations.runtime.models.ts src/commands/doctor/shared/legacy-config-migrate.test.ts src/commands/doctor/shared/legacy-config-migrations.runtime.models.test.ts
# no output

node scripts/test-projects.mjs src/commands/doctor/shared/legacy-config-migrate.test.ts src/commands/doctor/shared/legacy-config-migrations.runtime.models.test.ts
[test] starting test/vitest/vitest.unit-fast.config.ts
Test Files  2 passed (2)
Tests  119 passed (119)
[test] passed 1 Vitest shard in 7.51s

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 5, 2026
Add braces to a guard clause and use const for a never-reassigned binding in the
runtime models migration, and switch the migration tests to optional chaining /
explicit casts so they pass both tsgo (no possibly-undefined access) and oxlint
(no unnecessary type assertions).
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Jun 8, 2026
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Pushed fixes for the failing gates: braced a guard clause + const for a never-reassigned binding (check-lint), and switched the migration tests to optional chaining / explicit casts so they pass both tsgo (check-test-types) and oxlint. The PR body now carries after-fix real-behavior proof: the real openai-codex → openai migration carries gpt-5.5 context metadata (contextWindow/contextTokens/maxTokens) into the canonical openai provider and removes the legacy one. Focused suites → 119 passed.

@clawsweeper

clawsweeper Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 8, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 8, 2026
@clawsweeper

clawsweeper Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

  • Action: closed this PR.
  • Close reason: duplicate or superseded.
  • Evidence: durable ClawSweeper review.
  • Coverage proof: PR B clearly carries PR A's core useful intent and is the broader, current canonical landing path for the same doctor OpenAI/Codex context migration work; PR A's remaining concerns are either fixed or reviewable on PR B rather than requiring a separate PR A review. Covering PR: fix(doctor): consolidate legacy Codex migration cleanup #90451.

@clawsweeper clawsweeper Bot closed this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex context override can fall back to 272k after 2026.6.1 OpenAI route unification

1 participant