Skip to content

fix: keep session assessments and recaps working when Codex runs from a configured command - #208733

Open
brandon-julio-t wants to merge 1 commit into
openclaw:mainfrom
brandon-julio-t:fix/codex-subscription-advisory-utility-sampling
Open

brandon-julio-t wants to merge 1 commit into
openclaw:mainfrom
brandon-julio-t:fix/codex-subscription-advisory-utility-sampling

Conversation

@brandon-julio-t

Copy link
Copy Markdown
Contributor

Closes #204135

What Problem This Solves

When the utility model is a ChatGPT-subscription Codex model, such as openai/gpt-6-luna, and Codex runs from an explicitly configured appServer.command, every background utility task fails before inference. Affected tasks include session observer assessments, Activity recaps and generated chat titles. After 2 failures, Control UI shows "Session observer assessments stopped for this run after utility model … failed repeatedly" on run after run. Users read that as something they did wrong, although their chats are unaffected.

User Impact

Observer assessments, Activity recaps and conversation labels work again on subscription Codex routes without an owned inference relay. The warning stops appearing. On those routes, the internal answer budget is not applied. That matches what native Codex can do, because thread/start has no token or temperature fields.

Behavior that stays the same:

  • API-key routes still always use the relay and still apply the budget.
  • Limits a caller sets explicitly in streamParams are still honored or rejected before inference.
  • Subscription routes that do own a relay, such as the managed app-server, still apply the budget through it.

No configuration change is needed.

Why This Change Was Made

Internal callers already pass their own size cap as answerTokenBudget, which is documented as an internal budget, while an explicit caller limit goes in streamParams. Today the two are merged into one maxTokens before the harness sees them. Any maxTokens on a Codex subscription route then makes requireInferenceRoute true. An explicit command never registers relay ownership (commandSource: "config"), so the bounded turn throws Prepared Codex request requires an owned inference relay.

This change keeps that distinction through the harness boundary:

  • Core marks harness sampling as streamParamsMode: "preferred" when the limits come only from the internal answer budget. That includes a temperature the model filter already removed, as for Luna.
  • The Codex harness then asks for a preferred inference route on non-API-key routes. The bounded turn uses a relay when it owns one and otherwise runs without the advisory limits. required keeps today's error.

The field name and meaning follow #196344, which proposed the same advisory intent for ChatGPT token sharing. This PR does not touch that token-sharing branch, so the two compose. The ClawSweeper review on #204135 recommended this direction: keep explicit limits strict and API-key endpoint ownership intact.

Accepted edge case: a temperature-capable subscription model given an explicit internal temperature still needs a relay. No bundled subscription utility model currently accepts temperature.

Evidence

Real Gateway reproduction, before and after. This was an isolated Gateway built from this branch and its base ed76855c83d, with private state on loopback:

  • Setup: plugins.entries.codex.config.appServer.command pointed at the pinned Codex 0.172.0 linux-arm64 binary with homeScope: "user" on a real ChatGPT login. The main and utility model were both openai/gpt-6-luna.
  • Trigger: one openclaw agent turn that ran two shell commands. The reply itself succeeded on both builds.
  • Base: the Activity recap failed with the production error, and the session stored no recap.
    [gateway/activity-summary] Activity recap deferred {"agentId":"main","error":"Prepared Codex request requires an owned inference relay; no direct fallback was attempted.","retryScheduled":false}
    
  • This branch: no relay error, and the session entry stored a model-generated recap.
    "activitySummary":{"version":1,"formatRevision":3,"text":"Reported the UTC date and time as Mon Nov 30 02:13:52 UTC 2026 and the operating system as Linux. Done.", …}
    
  • The recap goes through the same isolated-completion boundary as the observer: an internal answerTokenBudget plus temperature: 0.2, then the Codex bounded turn.

Production observation (anonymized). A Gateway on 2026.11.11 with an explicit command and a subscription openai/gpt-6-luna utility model logged 107 session observer disabled after consecutive failures entries with this error over 4 days. Each one showed users the warning above. The first came 12 minutes after the explicit command was hot-reloaded.

Focused tests (pnpm test <files> --maxWorkers=1):

  • src/agents/isolated-completion.budget.test.ts: 7 tests, 49.9 s wall time. Most of that is transform; the tests themselves take 1%. A budget-only request is marked preferred on host and harness routes; an explicit temperature or maxTokens is not.
  • extensions/codex/src/app-server/isolated-completion.test.ts and bounded-turn.test.ts: 45 tests, 13.5 s. Subscription plus preferred asks for a preferred route, strict limits ask for required, and API-key stays required even when the budget is preferred. On a client without an owned relay, preferred runs the turn and required still throws before thread/start.
  • On the base, the new assertions fail: 4 in the core budget file, plus the Codex route expectations. With the fix, all pass.

Static checks: pnpm check:changed passes core and extension typechecks (including tests), changed-file lint and format, import-cycle and boundary guards. Its only failure is plugin boundaries. That failure comes from 2 SDK compatibility records that came due on 2026-11-29 and 2026-11-30 (plugin-sdk-session-agent-resolution-aliases, agent-harness-credential-prompt-string-argument), unrelated to this change. The dead-export scan's findings are all in files this PR doesn't touch. Net test lines: +50, under the 400-line allowance.

Codex contract: Codex rust-v0.172.0 ThreadStartParams (codex-rs/app-server-protocol/src/protocol/v2/thread.rs) has no max_output_tokens or temperature. Only the OpenClaw relay can apply these limits to a native turn.

Not exercised: the Control UI observer notice itself in a browser, and the OpenClaw-stored OAuth profile variant with homeScope: "agent", which needs an interactive device-code sign-in. Both reach the same runCodexIsolatedCompletion → runBoundedCodexAppServerTurn path verified above.

AI-assisted: investigated, implemented and tested with Claude Opus 5.5 via Claude Code.

…mand

Session observer assessments, Activity recaps and conversation labels pass an
internal answerTokenBudget. On a ChatGPT-subscription Codex route, that budget
made the isolated completion require an owned inference relay, and a configured
appServer.command never registers one, so every utility call failed before
thread/start and Control UI repeatedly showed that assessments had stopped.

Mark harness sampling as streamParamsMode "preferred" when it holds only the
internal budget. The Codex harness then prefers the relay on non-API-key routes
and runs without the advisory limits when none is owned. Explicit caller limits
and API-key routes keep requiring the relay.

Verified with focused tests (red on base, green here) and an isolated Gateway
using a real ChatGPT login and an explicit Codex 0.172.0 command: the base
deferred the Activity recap with the relay error; this build stored a recap.
@clawsweeper

clawsweeper Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Pull request received.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: c55b3b3556441138b576d839132697199578413d

These sensitive security changes were made:

  • src/agents/isolated-completion-model-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 30, 2026
@clawsweeper

clawsweeper Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

The PR lets Codex omit internal answer budgets when a subscription route lacks an owned relay, while keeping explicit limits and API-key routes strict.

Example: An Activity recap uses openai/gpt-6-luna with a ChatGPT subscription and an explicitly configured appServer.command.

  • Before: The 240-token internal budget requires an unavailable relay, so the recap fails before inference.
  • After: The native completion runs without the advisory token cap and stores a generated recap.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused implementation and real Gateway evidence support the repair, with overall readiness capped by the unresolved public-contract decision.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): Supplied isolated-Gateway logs exercise the changed core-to-Codex path using a real subscription login and configured executable, showing the base relay failure and a persisted recap after the fix; browser notice rendering and agent-home OAuth were expressly unclaimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Configured-command Codex subscription users repeatedly lose observer assessments, recaps, and generated labels despite working ordinary chats.
Reason: Restoring utility output has clear value, but permitting internal budgets to be omitted changes the shared public sampling contract and requires an owner decision.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR addresses a current utility-completion failure with no definite correctness findings; the advisory sampling contract still needs an owner decision.

Reviewed head: c55b3b3556441138b576d839132697199578413d
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should internal answer budgets become advisory across the harness contract so native subscription utilities can run without an owned relay?
  • Recommendation: Approve the advisory contract: Accept omission of internal budgets on unsupported native subscription routes while retaining strict explicit limits and API-key relay ownership.
  • Why: The existing contract preserves sampling settings, while this PR adds a public optional mode permitting omission; neither this PR nor the linked issue records maintainer approval.

Before merge

  • Await maintainer action - A maintainer must complete the enforced security-sensitive approval for revision c55b3b3.

Findings

None.

Agent review details

How this fits together

Background utility callers send prompts and answer budgets through core isolated completion; the Codex harness selects the prepared authentication route and returns text from a bounded native turn.

flowchart TD
  A[Observer and recap callers] --> B[Core isolated completion]
  B --> C[Sampling intent]
  C --> D[Codex harness]
  D --> E[Owned relay when available]
  D --> F[Native subscription without advisory limits]
  E --> G[Bounded completion result]
  F --> G
Loading

Technical review

Best possible solution:

Use the existing completion and relay owners to distinguish advisory internal budgets from mandatory caller limits, with one agreed harness contract.

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

Current-main source establishes the configured-command failure path, and the contributor supplies a matching real Gateway reproduction; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch repairs intent loss at the shared sampling owner and reuses existing relay routing, preserving explicit limits, endpoint selection, and authentication boundaries.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6442e281211b.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 8fe5701 adds src/agents/isolated-completion-model-authority.ts:39 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8fe570151aed; files: src/agents/isolated-completion-model-authority.ts)
  • Peter Steinberger: Raw commit 75499a8 adds src/agents/isolated-completion-model-authority.ts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 75499a8cad84; files: src/agents/isolated-completion-model-authority.ts)

PR surface

Source +29, Tests +53, Docs +3. Total +85 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 36 7 +29
Tests 3 57 4 +53
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 96 11 +85

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • merge-risk: 🚨 compatibility: The public harness parameter gains streamParamsMode and a new sampling-omission contract, although the field is optional and omitted-mode behavior stays strict.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 29, 2026, 9:55 PM ET / November 30, 2026, 02:55 UTC.

This branch has not been deployed

No deployments
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 impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-review-required security-sensitive-changed size: S status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex subscription utility sampling requires a relay, stopping observer assessments

1 participant