Skip to content

fix(codex): stop post-tool summaries switching accounts and models - #136758

Merged
steipete merged 1 commit into
mainfrom
steipete/epic-montalcini-bbad60
Sep 3, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/epic-montalcini-bbad60

Conversation

@steipete

@steipete steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Closes #136724

What Problem This Solves

Fixes an issue where Codex users completed tool work but the post-tool summary switched to an outer account/model, or failed because those unrelated host settings were unavailable. A supervised native connection owns its authentication; a fresh private Codex home cannot inherit that account.

Why This Change Was Made

The settled-turn owner now records the ready thread's model/provider and resolved host profile selector alongside the existing bounded, verified transcript projection. Ordinary finalization reuses the canonical prepared-auth handoff, including the exact prepared API key or selected subscription profile, and retains its existing private-stdio isolation. The bounded turn inherits the model admitted by thread/start; final assistant attribution comes from that response while the bounded result's catalog-ID contract remains unchanged for other callers.

Genuine supervision instead publishes the existing frozen source: "unavailable" marker with an explicit diagnostic reason. Keeping the finalizer callback present preserves the core's established honest fallback. No host account is selected, no native credentials are copied, no follow-up native inference is attempted, and completed actions are not replayed. Stock Codex has no generic attested zero-tool summary operation on that native connection; this change does not invent one.

This is OpenClaw-only: no Codex changes or custom binary, dependency bump, configuration/environment surface, SQLite migration, sidebar changes, or terminal UI changes. The existing private-turn capability restrictions and bounded empty-answer retry remain unchanged.

User Impact

Ordinary host-authorized summaries continue to work, including preserve-native-model-only bindings and the documented ordinary homeScope: "user" private-host-auth sidecall. Supervised turns that already return a final answer are unchanged. When a supervised tool-only turn needs a reply, users receive:

The tool run finished, but no final summary was produced. I did not repeat any completed actions.

The completed outcome, tool receipts, transcript prefix, and native binding remain intact. The distinction is documented in Codex runtime behavior and auth/environment isolation.

Evidence

Reproduction and ownership proof

The composed fixture uses the stock managed Codex 0.152.1 binary, disposable homes, two synthetic accounts, a loopback Responses server, real native command execution, and real transcript persistence. Against pre-fix 65e5b2e19c9db6460494682bacc4bee10db755fd, three cases failed and the ordinary user-home contrast passed. All four cases pass with the repair:

Case Pre-fix observation Repaired observation
Supervised source; different usable host account/model Returned an outer-model summary through the host account No finalizer auth/client/RPC/model request; unavailable marker; original binding, receipts, and healthy sibling preserved
Prepared API key plus a different usable profile hint Summary used the profile's account instead of the prepared key Summary uses the exact prepared key
Preserve-native-model-only host binding Summary selected the outer model Summary uses the ready native model and the original host profile
Ordinary user-home session Private host-authorized summary succeeded Same supported behavior; native auth file remains unchanged

The source command marker remains exactly one line. The model contrast uses two stock models in the same native multi-agent generation, without overriding catalog/model metadata. The native command fixture is POSIX-only; the owner-boundary tests are platform-independent.

Core tests separately exercise the actual finalization backend and SQLite persistence for an unavailable harness, proving one fallback payload/row, unchanged original evidence, and no original-attempt replay. API-key/subscription selection, normalized-away provider metadata, cancellation/write fencing, empty output, catalog aliases, media, hosted search, and isolated completion are covered by focused sibling tests.

User-visible delivery proof

Both existing QA scenarios passed against the built candidate using an isolated real Gateway, mock provider, and synthetic QA channel:

{
  "providerMode": "mock-openai",
  "channelDriver": "qa-channel",
  "gateway": "isolated real child",
  "results": [
    {
      "scenario": "settled-write-finalizer-exhaustion-fallback",
      "status": "pass",
      "providerRequests": 4,
      "writes": 1,
      "finalizationRequests": 2,
      "outboundFallbackReplies": 1
    },
    {
      "scenario": "gateway-settled-finalizer-exhaustion-fallback",
      "status": "pass",
      "providerRequests": 4,
      "finalizationRequests": 2,
      "fallbackRowsInChatHistory": 1
    }
  ]
}

These QA scenarios cover the common fallback-delivery path after empty-finalizer exhaustion. The unavailable-native producer and thrown-unavailable core path are covered separately above. This is not live OAuth/OpenAI, native catalog admission, a full native-to-Gateway flow, or a real external-channel claim. No production account, Gateway, or state was used.

Dependency contract checked

Directly inspected openai/codex tag rust-v0.152.1, peeled commit 5adb68a49933ae446bf11935662c83dba55a0804: thread start parameters and returned selection, turn model override semantics, model metadata overriding code-mode flags, and exec/wait registration. Ordinary inference still uses tool_choice: "auto"; disabling environments is not a generic no-tools acknowledgement.

Validation and scope

Focused coverage spans 358 tests across 13 files, including four stock-native cases and 22 core finalization tests. The last broad run had three stale sibling assertions expecting the removed per-turn model override; those were corrected and both sibling files passed 23/23 on rerun. The final real-backend fallback fixture also passed after replacing an unbound-method assertion with an explicitly owned replay spy.

The build passed with OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build. All steps selected by check:changed were completed: its aggregate run reached core lint after the structural guards and all typechecks passed; the test-only lint issue was fixed, then the affected canonical type graph, core/plugin lint, and remaining storage/media/sidecar/import-cycle gates passed. There are 0 runtime import cycles. This records resumed validation, not a claim that one aggregate invocation exited green. Fresh independent Codex autoreview at P1 returned scoped-clean with no accepted/actionable findings.

Local proof commands
node scripts/run-vitest.mjs extensions/codex/src/app-server/settled-turn-finalizer.native.test.ts extensions/codex/src/app-server/settled-turn-finalizer.test.ts extensions/codex/src/app-server/settled-turn-context.test.ts extensions/codex/src/app-server/settled-turn-projection.test.ts extensions/codex/src/app-server/bounded-turn.test.ts extensions/codex/src/app-server/run-attempt.test.ts extensions/codex/src/app-server/session-history.test.ts extensions/codex/src/app-server/run-attempt-thread-cleanup.test.ts extensions/codex/media-understanding-provider.test.ts extensions/codex/src/web-search-provider.test.ts extensions/codex/src/app-server/isolated-completion.test.ts src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts src/agents/embedded-agent-runner/run/settled-turn-finalization.unavailable.test.ts
node scripts/run-vitest.mjs extensions/codex/media-understanding-provider.test.ts extensions/codex/src/web-search-provider.test.ts
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/settled-turn-finalization.unavailable.test.ts
node scripts/run-tsgo.mjs -b test/tsconfig/tsconfig.core.test.agents-other.json --builders 1
OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build
OPENCLAW_STATE_DIR="$(mktemp -d)" node scripts/check-changed.mjs
qa_state="$(mktemp -d)" && env -u CODEX_HOME -u CODEX_API_KEY -u OPENAI_API_KEY OPENCLAW_STATE_DIR="$qa_state" OPENCLAW_CONFIG_PATH="$qa_state/openclaw.json" OPENCLAW_ENABLE_PRIVATE_QA_CLI=1 OPENCLAW_DISABLE_BUNDLED_PLUGINS=0 node openclaw.mjs qa suite --repo-root "$PWD" --provider-mode mock-openai --channel-driver qa-channel --scenario settled-write-finalizer-exhaustion-fallback --scenario gateway-settled-finalizer-exhaustion-fallback --concurrency 1 --output-dir .artifacts/qa-e2e/settled-stock-fallback

LOC: production 89 added / 20 removed (+69); tests/support 1,598 added / 308 removed (+1,290); docs 29 added / 1 removed (+28). No generated, lockfile, or dependency changes.

Production delta is +69 lines across four existing plugin modules; no new production module. The growth carries source-owned selection, reuses prepared auth, records unsupported native ownership, and fences final writes rather than retaining a borrowed native client or adding a second execution path. Test/test-support and documentation deltas are reported separately.

The nearby thread-cleanup fixture now waits for actual turn/start readiness and aborts/joins its attempt on failure instead of imposing a five-second cold-start assumption. No runtime timeout was enlarged.

A cross-generation preserve-model fixture also exposed a separate pre-finalization rotation path. That finding was handed to the active native-ownership work; this PR does not change rotation or session-lock policy.

Capture source-ready model/profile facts and preserve prepared host auth for private summary turns. Attribute final answers to the admitted native selection. When supervision owns native auth, retain the existing honest no-summary reply instead of selecting an outer account or model. Preserve ordinary host-auth and user-home sidecalls without replaying completed actions.

Fixes #136724
@steipete steipete self-assigned this Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: codex size: XL maintainer Maintainer-authored PR labels Sep 3, 2026
@steipete
steipete marked this pull request as ready for review September 3, 2026 00:21
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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 Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 2, 2026, 8:31 PM ET / September 3, 2026, 00:31 UTC.

ClawSweeper review

What this changes

The PR captures the completed Codex thread’s model, provider, and host-auth selection for private post-tool summaries, while supervised native sessions use the existing honest fallback instead of borrowing host credentials.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open. This maintainer-authored PR has a source-grounded repair for the linked Codex account/model-switching bug, and the central change is not present on current main; no blocking correctness finding was identified.

Priority: P1
Reviewed head: 824c7ee2c0292a2d8e3d162a7195e573884013ee

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A solid owner-boundary bug fix with targeted native and core regression coverage; no actionable defect was found in the reviewed patch.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The source-visible native regression fixture nevertheless exercises the real managed Codex app-server with an isolated loopback provider and verifies the repaired account/model and fallback boundaries.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The source-visible native regression fixture nevertheless exercises the real managed Codex app-server with an isolated loopback provider and verifies the repaired account/model and fallback boundaries.
Evidence reviewed 7 items Current-main defect path: Current main builds the private finalizer from outer attempt model, a literal OpenAI provider, and the outer profile rather than the settled thread’s actual selection.
Introduced owner-boundary repair: The PR captures the ready thread model/provider and selected host profile at finalization capture, then resolves the prepared host-auth handoff before starting the bounded summary.
Supervised-session containment: For supervision connections the PR produces a frozen unavailable context before any host-auth finalizer can be created; the generic core path already converts unavailable/failed finalization into one non-replaying fallback.
Findings None None.
Security None None.

How this fits together

The Codex plugin executes native tool turns and, when a turn finishes without visible assistant text, can request a bounded private final summary. The plugin passes its result to the embedded agent runner, which either delivers the attributed summary or records and sends the existing fallback reply.

flowchart LR
A[Native Codex tool turn] --> B[Ready thread selection]
B --> C[Verified settled transcript]
C --> D{Authentication owner}
D -->|Host-authenticated| E[Private bounded summary]
D -->|Supervised native session| F[Honest fallback]
E --> G[Agent reply delivery]
F --> G
Loading

Before merge

  • Resolve merge risk (P2) - This deliberately changes supervised tool-only no-answer turns from a potentially cross-account summary to the documented fallback; it is the safer auth boundary, but remains an auth-provider compatibility surface until exact-head checks complete.
Agent review details

Security

None.

PR surface

Source +69, Tests +1290, Docs +28. Total +1387 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 4 89 20 +69
Tests 12 1598 308 +1290
Docs 2 29 1 +28
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 1716 329 +1387

Review metrics

Metric Value Why it matters
Production versus test delta production +69/-20; tests/support +1,598/-308; docs +29/-1 The production growth carries source-owned model/auth facts and cancellation fencing; the substantially larger test delta covers native and core fallback boundaries.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #136724
Summary: This PR directly implements the linked issue’s account/model-selection defect and remains the open candidate fix until it lands.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Retain the supervised fallback (recommended)
    Accept the documented fallback for supervised tool-only turns because a private host-auth summary cannot safely represent the native connection’s account.
  2. Wait for a native summary contract
    Pause this path if product requirements require supervised summaries rather than the honest fallback, pending a stock Codex operation that preserves and attests native authentication.

Technical review

Best possible solution:

Preserve the captured ready-thread selection and prepared host-auth route for ordinary finalization, while keeping supervised native-auth turns on the non-replaying fallback path.

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

Yes, from source: current main passes outer model/provider/profile fields into the private finalizer, while the reviewed fixture constructs divergent host and native selections around that exact path. This read-only review did not execute the fixture.

Is this the best way to solve the issue?

Yes. Capturing selection at the ready-thread owner and reusing the already prepared host-auth handoff removes the competing outer selection; retaining the core fallback is safer than inventing a supervised native credential transfer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b7fa0f52c6a9.

Labels

Label changes:

  • add P1: The fix addresses a real Codex agent workflow where a completed tool action can receive a summary through a different account or model.
  • add merge-risk: 🚨 auth-provider: The PR changes which prepared credential/profile and model selection a post-tool finalization uses, and deliberately fails closed for supervised native authentication.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The source-visible native regression fixture nevertheless exercises the real managed Codex app-server with an isolated loopback provider and verifies the repaired account/model and fallback boundaries.

Label justifications:

  • P1: The fix addresses a real Codex agent workflow where a completed tool action can receive a summary through a different account or model.
  • merge-risk: 🚨 auth-provider: The PR changes which prepared credential/profile and model selection a post-tool finalization uses, and deliberately fails closed for supervised native authentication.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies the author as a MEMBER, so the external-contributor proof gate does not apply. The source-visible native regression fixture nevertheless exercises the real managed Codex app-server with an isolated loopback provider and verifies the repaired account/model and fallback boundaries.

Evidence

What I checked:

  • Current-main defect path: Current main builds the private finalizer from outer attempt model, a literal OpenAI provider, and the outer profile rather than the settled thread’s actual selection. (extensions/codex/src/app-server/settled-turn-finalizer.ts:39, b7fa0f52c6a9)
  • Introduced owner-boundary repair: The PR captures the ready thread model/provider and selected host profile at finalization capture, then resolves the prepared host-auth handoff before starting the bounded summary. (extensions/codex/src/app-server/run-attempt-finalize.ts:317, 824c7ee2c029)
  • Supervised-session containment: For supervision connections the PR produces a frozen unavailable context before any host-auth finalizer can be created; the generic core path already converts unavailable/failed finalization into one non-replaying fallback. (extensions/codex/src/app-server/run-attempt-finalize.ts:318, 824c7ee2c029)
  • Direct Codex protocol inspection: The locally available Codex source at rust-v0.152.1 defines model/modelProvider on thread start and returns the resolved selection; turn-start model is an optional override. Omitting the second override therefore preserves the newly started thread selection. (codex-rs/app-server-protocol/src/protocol/v2/thread.rs:62, 5adb68a49933ae446bf11935662c83dba55a0804)
  • Focused regression coverage: The added native fixture exercises divergent host/native accounts and models, asserts no client/auth request for supervised finalization, and verifies private host-authorized summaries retain the actual native selection without replaying completed work. (extensions/codex/src/app-server/settled-turn-finalizer.native.test.ts:389, 824c7ee2c029)
  • Feature history: The settled-turn finalization surface was added by a raw-parent-verified commit that created the Codex context module and generic core finalization module; later shipped work refined the always-reply fallback path. (extensions/codex/src/app-server/settled-turn-context.ts, 6eea20ce181e)

Likely related people:

  • joshavant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready at 824c7ee.

Accepting the recommended supervised fallback from the ClawSweeper ownership review. This is the intentional stock-Codex/OpenClaw-only auth boundary: a supervised native connection does not authorize selecting a different host account to obtain a summary. Ordinary host-auth and ordinary user-home sidecalls remain supported. No completed action is replayed and no finalizer tool capability is widened.

Exact-head CI run 33699175608 is completed/success for that SHA, including the required openclaw/ci-gate. This completes the review's outstanding exact-head-check condition; no correctness or security finding remained.

Local proof includes four real stock-Codex ownership cases (three demonstrated pre-fix failures plus the preserved user-home contrast), owner/core/sibling coverage, the successful private-QA build, and two real isolated-Gateway QA scenarios. The observed delivery was one fallback after one write and one copy in chat history. Exact local commands, fixture corrections/reruns, resumed check-plan results, and the sanitized QA verdict are recorded in the PR's Evidence section. Fresh independent Codex autoreview at P1 was scoped-clean with no accepted/actionable findings.

The native fixture uses synthetic accounts/provider responses; no production account/state, live OAuth/OpenAI, native catalog admission, full native-to-Gateway flow, or external real-channel proof is claimed. Source delta is +69, tests/support +1290, docs +28; there are no new config, schema, dependency, or production-module surfaces.

@steipete
steipete merged commit db98474 into main Sep 3, 2026
251 checks passed
@steipete
steipete deleted the steipete/epic-montalcini-bbad60 branch September 3, 2026 00:42
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
…136758)

Capture source-ready model/profile facts and preserve prepared host auth for private summary turns. Attribute final answers to the admitted native selection. When supervision owns native auth, retain the existing honest no-summary reply instead of selecting an outer account or model. Preserve ordinary host-auth and user-home sidecalls without replaying completed actions.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex post-tool summaries can switch the selected account or model

1 participant