Skip to content

fix(codex): restore workspace instructions for catalog-backed models - #142276

Merged
roboclaw-bot merged 3 commits into
mainfrom
openclaw/codex-persona-egress-workaround
Sep 8, 2026
Merged

roboclaw-bot merged 3 commits into
mainfrom
openclaw/codex-persona-egress-workaround

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #141270, #140422

Additional instructions

Maintainer edits are allowed.

What Problem This Solves

Fixes an issue where users of Codex-backed conversations lose their workspace persona, identity, user preferences, and loaded OpenClaw skills when the model catalog supplies its own collaboration instructions.

Moving those files into inherited thread instructions restores the parent but also gives them to native child histories. This change restores current parent instructions without adding that new context to native history.

Why This Change Was Made

For supported OpenClaw-managed bundled stdio inference, a private relay appends current parent context to the model request’s top-level instructions. Native base/catalog instructions and input history stay intact. Child requests, compaction, memory work, prewarm, and approval reviewers do not receive the parent-local addition. An admitted per-thread generation is checked against the live host owner before forwarding; metadata alone grants no authority.

The relay handles HTTP/Zstd and WebSocket frames, preserves native auth responses and backend paths, and honors Gateway proxy/TLS configuration. It requires no native Codex patch, dependency bump, credential store, or configuration flag. Roughly 1,000 net production lines implement the bounded transport and lifetime checks. It should be retired when native Codex provides a versioned parent-only instruction carrier covering refresh/removal, compaction retention, and child-history isolation.

Live testing also found that the existing generic-policy resume notice could withdraw independently supplied current persona. Its replacement scope now matches the generic policy it actually replaces. Private transport tokens are registered for redaction at creation through the existing secure-token producer; the SDK export budget is unchanged.

User Impact

  • Supported parents receive current SOUL.md, IDENTITY.md, USER.md, skills, and memory guidance, including edits and withdrawal.
  • Newly supplied parent context is not automatically inherited by native subagents. Shared runtime/project instructions and supported forks remain available.
  • Inference can stay on the Gateway while execution uses remote-exec.
  • The workaround covers standard native OpenAI endpoints. External/desktop/custom-command connections, custom upstreams, non-OpenAI providers, unsupported account modes, locked upstream settings, and native system-proxy profiles retain their legacy behavior with unverified-delivery reporting; they are not silently rerouted or newly blocked.
  • Existing history and explicit task handoffs are preserved. This is not retroactive history scrubbing or a secrecy guarantee for previously shared text.

Evidence

  • Original frozen source: 232 regression cases passed (head 6ee19378779c): 8 core and 224 Codex cases, including run-attempt, ownership/revocation, module-copy lifetime, unmodified internal RPC values, redaction, HTTP/Zstd, WebSocket deltas/auth/proxy routing, custom-profile preservation, and generic-policy scope.
  • Complete check:changed passed in AWS Crabbox, including all typecheck lanes, core/plugin/script lint, dead-export and boundary guards, prompt snapshot drift, and the 17 snapshot-owner cases. The terminal per-phase receipt records exit 0.
  • Original independent P0–P2 autoreview: scoped-clean, no accepted/actionable findings. The reviewer checked the exact 37-file source snapshot with pinned dependency evidence.
  • Four authenticated live cases passed through the actual agent --local entrypoint in AWS Crabbox: fresh persona, edited persona after a real native-process restart, withdrawal after restart, and a Gateway-proxy-routed parent. All verified the Codex runtime, no fallback, and no file/tool reads. The proxy case observed the upstream WebSocket through the CONNECT tunnel with end-to-end TLS and no target Authorization/Cookie headers outside it. These used the public API-key route and gpt-5.5.
  • Dependency-level probes against real Codex 0.153.4 with a synthetic upstream cover supported fresh/partial/full children, V1/V2, HTTP/WS, persistent/incognito contexts, edits/removal, process restart, and immediate post-compaction continuation. These establish the native request-only carrier contract; they are not authenticated live-child tests.

Primary dependency contracts personally inspected at Codex 3d2ee51ca2d5db578f328aa75e20aa22c0197c9a include codex-rs/core/src/context/world_state/collaboration_mode.rs:30–41, codex-rs/core/src/responses_metadata.rs:300–423, codex-rs/core/src/client.rs:1844–1870, and codex-rs/model-provider-info/src/lib.rs:293–319.

Review and CI follow-up

  • Fixed the WebSocket proxy-only DNS regression identified in review. The environment proxy is selected before destination lookup; fixed-host policy remains enforced and direct routes retain pinned DNS. All 13 proxy cases passed, including unavailable/private direct DNS and rejected internal/literal-private upstreams.

  • Reproduced the initial CI cleanup/startup/settlement failures: the old native test fixtures did not answer the newly required read-only config/read and account/read requests. The scoped fixture repair preserves all cleanup assertions and production timeouts. All 65 affected cases passed, plus production/test types and focused lint.

  • Full build and a fifth authenticated live case passed in AWS Crabbox run run_1a4fcb8fad8e (lease cbx_8916b0d5f8cd). The actual agent --local process was given failing local DNS for api.openai.com; the SDK resolver confirmed ENOTFOUND in the same process that sent the successful parent response.create WebSocket frame through the CONNECT proxy. Persona markers appeared in top-level instructions, not input history. Codex runtime, no fallback, no tools, and unchanged end-to-end TLS were verified.

  • Fresh P0–P2 autoreview of the follow-up: scoped-clean, no actionable findings. The source delta is bound by full-index patch hash f226051d84f57a033cab4532b24698dcd13460fbe038e3245087eba60e645365 on parent 6ee19378779c1edf58341eccd220c5b9ba04fda6.

  • Complete follow-up check:changed passed in AWS Crabbox run run_5612fa47738f: all selected type, lint, doctor-contract, dead-export, boundary, database-first, and import-cycle checks. The full-index patch and all eight file hashes match committed head 24ee4101d9b16f79afd2e12d2aeaf2c3385751d8; the live test was not rerun against a different source tree.

Compatibility and remaining proof

No OpenClaw schema, on-disk format, retention rule, or migration is changed. Parent instruction registration is in memory; native history bytes and explicit historical handoffs remain intact. Existing native restart/edit/removal coverage is retained, rather than claiming retroactive isolation.

The secure-token overload and bundled Codex plugin must ship with the matching OpenClaw host. Official co-release synchronization updates compat.pluginApi and build metadata, and plugin packaging derives its host peer floor from that API range. This PR does not authorize independent publication of the plugin with the old manifest, or any release/version bump.

September 8 refreshed-head verification

  • Head f479595c25f83644018c031b1837c7d751ed95ad includes repaired main 81d8b17414b900f47cbaba0af3c259f8bd1cf436. The unrelated UI catalog blocker was resolved upstream by fix(ui): restore default-model picker discovery after the catalog store rewrite #142346 and subsequent owner fixes. All 14 catalog-discovery cases and 13 proxy cases pass on the refreshed head.
  • All PR-owned production and test files are byte-identical to the reviewed follow-up; only upstream token-use documentation changed. The PR remains the same 43-file repair.
  • Required hosted CI is green: run 34286544828, attempt 1, exact head f479595c25f83644018c031b1837c7d751ed95ad; openclaw/ci-gate reports success.
  • Fresh clean build and authenticated live smoke pass: AWS Crabbox run run_879498c42d9a, exact clean tree 6f97c94885d0e8f133af21b687babb2cf1937186. The real Codex parent still receives SOUL/IDENTITY/USER only in top-level request instructions while local destination DNS is unavailable and CONNECT owns resolution. No fallback or tools; end-to-end TLS preserved. Lease cbx_d81db1eb5a36 has been released.
  • ClawSweeper revision 3 reviewed this head and found no actionable introduced defects. No store/schema migration is introduced by this PR. Independent plugin publication remains excluded; the publish workflow requires explicit dispatch and release approval.

Release scope: This is a coordinated host/plugin change, not a standalone package release or deployment. Authenticated subscription refresh and native-child behavior are not claimed as additional live cases; their stated source/native-contract coverage remains unchanged.

Worked on by:

Co-authored-by: steipete [email protected]
Co-authored-by: vincentkoc [email protected]

Keep current parent persona, skills, and memory guidance in managed model-request
instructions rather than inherited native history. Preserve unsupported native
profiles and Gateway proxy routing, scope resumed policy replacement correctly,
and fence private transport ownership across client lifetimes and module copies.

Worked on by:
- @steipete
- @vincentkoc

Co-authored-by: steipete <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: XL maintainer Maintainer-authored PR labels Sep 8, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 8, 2026 15:33
@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 8, 2026, 6:40 PM ET / 22:40 UTC (Revision 3).

ClawSweeper review

What this changes

Restores workspace persona, skills, and memory guidance on managed Codex conversations through a parent-only inference relay, with lifecycle checks, token redaction, tests, and documentation.

Merge readiness

⛔ Blocked before merge - 2 items remain

This repair remains useful: current main still uses the replaceable collaboration carrier. The earlier DNS finding is resolved, and no blocking introduced defect was found. The documented coordinated-release scope addresses the prior host-version concern.

Priority: P2
Reviewed head: f479595c25f83644018c031b1837c7d751ed95ad

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent repair with substantial real-path evidence, resolved prior feedback, and an explicitly scoped package compatibility requirement.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): Captured agent --local observations exercise the production relay with fresh, edited, withdrawn, and proxy-routed parent context; native probes cover child exclusion and compaction. The relay is unchanged from the proved follow-up. Portal access was unavailable here; authenticated subscription refresh and live-child coverage are not claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): Captured agent --local observations exercise the production relay with fresh, edited, withdrawn, and proxy-routed parent context; native probes cover child exclusion and compaction. The relay is unchanged from the proved follow-up. Portal access was unavailable here; authenticated subscription refresh and live-child coverage are not claimed.
Evidence reviewed 10 items Pinned PR remains open: The REST endpoint confirms the reviewed head is f479595, targets base 81d8b17, and is unmerged. The protected maintainer label independently prevents cleanup closure.
Current main still has the affected carrier: Current main joins workspace, memory, and skills instructions into collaboration-mode developer instructions. It does not contain the new inference-context implementation; no merged fixing PR was established.
Native dependency contract inspected: Personally inspected the pinned dependency: CollaborationModeState selects catalog instructions before caller instructions. Responses metadata carries native thread/child identity and flattens application metadata; WebSocket requests retain top-level instructions. Ownership was verified through the dependency cache's origin URL, https://github.com/openai/codex.git. The PR's protocol addition and inference rewrite directly depend on this contract.
Findings None None.
Security None None.

How this fits together

The Codex plugin translates OpenClaw agent turns into native Codex requests. The new relay adds current workspace instructions immediately before model inference while leaving native conversation history and child requests unchanged.

flowchart TD
  A[Workspace persona and skills] --> B[Active parent registration]
  C[Native Codex request] --> D[Private inference relay]
  B --> D
  D --> E{Current admitted parent?}
  E -->|Yes| F[Append request instructions]
  E -->|Child or internal request| G[Preserve native instructions]
  F --> H[OpenAI inference]
  G --> H
Loading

Before merge

  • Resolve merge risk (P1) - The updated plugin depends on the new secure-token overload; publishing it independently with the old host floor would break older hosts. The PR explicitly limits shipment to coordinated host/plugin release preparation.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +1014, Tests +890, Docs +36. Total +1940 across 43 files.

View PR surface stats
Area Files Added Removed Net
Source 19 1038 24 +1014
Tests 19 1067 177 +890
Docs 5 54 18 +36
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 43 2159 219 +1940

Review metrics

Metric Value Why it matters
Production versus validation growth Production +1008 net lines; tests, support, and fixtures +896 The PR explicitly justifies the production growth as a temporary bounded relay with transport and lifetime enforcement.
Public API expansion 1 additive SDK overload; 0 new user configuration options Existing numeric token calls remain supported, while the new object form creates the documented host/plugin release dependency.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/codex/src/app-server/inference-proxy.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Retain the documented coordinated release (recommended)
    Use existing release preparation to advance the plugin's host API floor together with the secure-token implementation.

Technical review

Best possible solution:

Keep parent context at the inference boundary and ship the plugin with its matching host API through the existing coordinated release process.

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

Yes, from source: main puts workspace context in collaboration instructions, and pinned Codex selects catalog guidance instead when both exist. This review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes for the documented managed-runtime scope: request-time injection preserves native catalog policy and avoids adding persona to inherited history. Custom-executable and external connections remain outside this repair.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Repairs lost workspace instructions on a bounded Codex runtime path without an established process outage.
  • merge-risk: 🚨 compatibility: The plugin consumes a new host SDK argument shape, making coordinated package compatibility metadata essential.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Captured agent --local observations exercise the production relay with fresh, edited, withdrawn, and proxy-routed parent context; native probes cover child exclusion and compaction. The relay is unchanged from the proved follow-up. Portal access was unavailable here; authenticated subscription refresh and live-child coverage are not claimed.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured agent --local observations exercise the production relay with fresh, edited, withdrawn, and proxy-routed parent context; native probes cover child exclusion and compaction. The relay is unchanged from the proved follow-up. Portal access was unavailable here; authenticated subscription refresh and live-child coverage are not claimed.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Srikalyan Swayampakula: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-08T15:40:59.273Z sha 6ee1937 :: blocked before merge. :: [P2] [P2] Select the trusted proxy before resolving destination DNS
  • reviewed 2026-09-08T16:42:15.700Z sha 24ee410 :: blocked before merge. :: none

Select the trusted WebSocket proxy before destination resolution, retaining
fixed-host checks and direct-route DNS pinning. Model the native read-only
config and account replies in attempt fixtures without weakening cleanup
assertions or changing production timeouts.

Worked on by:
- @steipete
- @vincentkoc

Co-authored-by: steipete <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
@roboclaw-bot

roboclaw-bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

The proxy-only DNS finding is addressed in 24ee4101d9b16f79afd2e12d2aeaf2c3385751d8. Proxy selection now precedes destination resolution; immutable-host policy and direct-route DNS pinning remain intact. The regression failed before the repair, and all 13 proxy tests now pass.

A fifth authenticated live case exercised the actual Codex agent --local path with local api.openai.com DNS unavailable. The same egress process proved SDK ENOTFOUND and sent the successful parent WebSocket request through CONNECT, retaining end-to-end TLS. Persona appeared only in top-level parent instructions, not input history. Full build, the complete follow-up changed-file gate, and fresh P0–P2 autoreview passed. The PR body links both Crabbox runs and binds their exact source to this commit; the VM has been released.

The initial cleanup/startup/settlement CI failures were missing read-only config/account responses in old test fixtures. Those fixtures now model the native contract without changing timeouts or weakening cleanup assertions; 65 affected cases passed. Those separate compiler failures were traced to the main-branch catalog migration, fixed upstream, and resolved by the current-main refresh.

Compatibility notes: there is no new OpenClaw schema, persistent format, retention rule, or history scrub. Instruction registration is in memory; restart/edit/removal coverage remains recorded. The token overload and Codex plugin must ship with the matching host API; official co-release metadata supplies that floor. Independent plugin publication with the old manifest is not part of this PR.

Final: merged through native guarded prepare/merge at 8169aac from exact tested head f479595. Required CI run 34286544828 passed; fresh build/live run_879498c42d9a passed and its VM was released. Independent readback verified source head, both requested contributor credits, main-branch containment, and the landed tree against the actual squash parent. The task checkout is clean on current main.

Named tooling follow-up (outside this repair): the native mainline-drift report emitted non-fatal comm sorting diagnostics. No merge check was disabled. Its reported protocol overlap was an unrelated typed experimentalFeature/list addition; the final composed tree was independently verified. The sorting diagnostic deserves a separate maintainer investigation rather than changes to this already-validated repair.

@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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 8, 2026
Include the completed model-catalog caller migration so the existing Codex
persona repair can obtain current-base CI without restoring the retired UI cache.

Worked on by:
- @steipete
- @vincentkoc

Co-authored-by: steipete <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
@roboclaw-bot
roboclaw-bot merged commit 8169aac into main Sep 8, 2026
182 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/codex-persona-egress-workaround branch September 8, 2026 22:54
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…penclaw#142276)

Restore workspace persona, skills, and memory guidance on managed Codex parent
requests without adding that new context to native history or lean subagent
prompts. Preserve native catalog instructions, authentication, supported forks,
and unsupported-profile behavior.

Keep proxy-owned DNS working, retain direct-route network safeguards, and
revalidate parent instruction ownership at the inference boundary.

The Codex plugin and host SDK change are a coordinated-release unit; this
merge does not publish a standalone plugin or deploy a running Gateway.

Worked on by:
- @steipete
- @vincentkoc

Co-authored-by: steipete <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Colton-Harris added a commit to Colton-Harris/openclaw that referenced this pull request Sep 14, 2026
The parent-local inference relay caller still passed
`skillsCollaborationInstructions` into `buildCodexParentLocalInstructions`,
a field this branch removed when the eligible skill catalog moved onto the
thread developer carrier. It survived the rebase because the relay caller
landed upstream in openclaw#142276 after the rename, so nothing reconciled the two.

That left a missing-property read and an excess property on the options
object, failing type validation with TS2339 and TS2561.

The catalog rides the thread carrier, so the relay must not receive it.
Drop the option, matching how `run-attempt-prompt.ts` already builds its
parent-local context.
obviyus added a commit that referenced this pull request Nov 27, 2026
Root cause: extensions/codex/src/app-server/thread-lifecycle-run.ts:154 dropped the native thread developer carrier whenever the managed inference relay existed, and extensions/codex/src/app-server/run-attempt-turn-request.ts:293 put skills, shared persona, memory and session project guidance into the relay text that inference-context.ts:271 adds to every request's top-level `instructions`. GPT-6.2 Sol and Astra never cache `instructions`, so every warm request in a turn re-paid that whole block.

Fixes #206421

Thanks @brandon-julio-t for the precise report (managed vs `appServer.command` A/B with per-request usage), and @NaturalMatchaKing for the A/B evidence in #204136.

## What changed

- Skills, shared persona (`SOUL.md`, `IDENTITY.md`, workspace-root `USER.md`), memory guidance and session project guidance now always ride the existing refreshable thread developer section, on managed connections too. Codex sends that as a `developer` input item, so it sits in the cached prefix, and later requests in a turn only append.
- The relay keeps only parent-only text: the selected personal `users/<id>/USER.md` overlay, cron policy, plugin `before_prompt_build` system context, and per-turn conversation instructions. Per-turn plugin context stays off the thread on relay connections (`turnRefreshableInstructions` split; still thread-carried when there is no relay, as before).
- `workspace-context.ts` renders the personal-only persona with the same renderer; the codex context plumbs `personalPersonaInstructions` instead of the full persona.
- Edits to that section no longer refuse a thread kept alive by background work. Before this, a skill, persona or memory edit made the next message cold-resume the thread, and a thread kept alive by a running background command refused with "still has background work… stop its running work and retry". `appServer.command` and other non-relay connections already failed this way on main; managed connections would have started to with the carrier move. Now the refreshable section is left out of the thread configuration fingerprint, and persistent live threads keep the same in-memory record incognito threads already had of the section the thread was natively given (`nativeRefreshableInstructions`) and the one last delivered. On reuse (`thread-lifecycle-warm.ts`):
  - Idle thread, section changed: cold resume, as on main, so native configuration carries the current section and compaction rebuilds from it. On managed connections this costs one uncached turn per edit.
  - Protected thread (running background command or child), section changed: the existing appended developer handoff instead of the refusal; the existing post-compaction restore re-delivers it.
  - Self-heal: the first later turn where the thread is no longer protected and its native section still differs from the current one cold-resumes.
  - Managed relay fallback: while a thread's native section differs from the current one (an edited incognito thread, or a protected persistent thread waiting for its cold resume), the relay also sends the current section in request `instructions`, as main did for every request, so a post-compaction continuation sees it. It stops when the native copy matches again (after the self-heal cold resume); unedited threads never pay for it. The section never holds the selected personal overlay, so that is still sent once (`renderCodexRelayRefreshableFallback`, thread-policy.ts).

  No new field, flag or persisted state: the comparison uses the in-memory record, and ephemeral lifetime is keyed off the generic policy that only ephemeral records carry.
- Remaining narrow gap, only on connections without a relay (`appServer.command`): an edit made while background work keeps the thread protected, followed by a native compaction before that work ends, can let one continuation request see the previous section. On main those threads refuse the next turn outright. Codex samples the continuation right after compaction, before injected developer messages are drained (`codex-rs/core/src/session/turn.rs` pending-input drain is deferred after auto-compaction; `session/inject.rs` queues injections into the active turn), and the host restore lands on the request after it. It heals on the first unprotected turn. Not taken: (B) carrying the section in turn-level `collaborationMode.settings.developer_instructions`, because a model catalog's default-mode override wins over caller text, it replaces the built-in Default-mode text and collides with OpenClaw's cron collaboration instructions, and native children do not inherit it; (D) asking Codex to drain injected developer messages before the post-compaction continuation, or to accept developer instructions in thread settings, needs a Codex dependency bump.
- Report estimate counts the stable section on the thread in both modes.
- No model-facing wording changed. Layout change: a user with a personal overlay gets two `## OpenClaw Agent Soul` blocks (shared in the thread, personal in the relay).
- `inference-dispatch.ts` untouched (#206475 size recovery kept).

## What remains: 97.2% vs 99.5%

Live gpt-6.2-sol against main `712db11dfc9e`, the reporter's five-tool-call turn. Two runs per arm on `2ca1ebe03be6` plus one per arm on `a286631217b9` (the stale-section cold resume does not touch an unedited turn; earlier heads had three runs per arm with the same results). Warm-request cache hit and per-request `input/cached` come from the Codex rollout:

| arm | warm hit | uncached input per warm request | previous request's input not cached | uncached input per turn |
|---|---|---|---|---|
| main, managed relay | 70.6–70.7% | ~6,150–6,200 tokens | 6,054–6,100 tokens | 51.5–51.8k |
| this PR, managed relay | 97.2–97.3% | ~570 tokens | 421 tokens | 23.9–24.0k |
| `appServer.command` (no relay) | 99.5% | ~100 tokens | 3 tokens | 20.5–20.6k |

The remaining ~420 tokens per warm request are the relay's per-turn conversation instructions and tool bindings, which still go in top-level `instructions` and are never cached on these models. They are per-turn facts, so moving them is a separate change (for example to turn `additionalContext`); this PR does not move them.

## Earlier attempt

#141270 (@mbelinky) aimed at the same carrier: workspace persona and memory on the thread developer instructions. This PR is a smaller change at the relay/lifecycle owners and does not build on it.

## Deliberate decision reversed

This reverses #142276's parent-only delivery for shared text: native Codex subagents now inherit shared persona, skills and memory guidance through `developer_instructions` (`codex-rs/core/src/agent/child_config.rs` `inherited_developer_instructions`). Reasoning: that is already the behavior of every connection without a relay (#162156 called it intentional); native delegation is off wherever session tools are denied; the original #142276 problem (catalog collaboration text replacing caller instructions) is solved by thread developer instructions; and keeping the split costs every managed user about 2.2x the uncached input on a five-tool-call turn (51.8k vs 24.0k tokens; about 11x per warm request). The personal overlay stays parent-only (#162156 privacy boundary kept). A child created after an in-place edit inherits the thread's creation-time section, the same limitation incognito threads already document.

## Evidence

Proof comments: #206554 (comment) (cache and request bodies), #206554 (comment) (background-work P1), #206554 (comment) (`2ca1ebe03be6`: scripted lane, live cache, live managed P1), #206554 (comment) (`a286631217b9`: stale-section cold resume, compaction and self-heal regressions, live P1 on both routes, cache), #206554 (comment) (`76341cb30f58`: managed relay fallback regression, live managed P1). Child-inheritance decision: #206554 (comment)

- Scripted lane (real managed bundled codex 0.172.0 app-server, real relay, synthetic Responses upstream recording bodies): `run-attempt.skills.native.test.ts` "keeps managed skills in the cached native prefix across a multi-request turn" is red on main (skills in `instructions` on every frame) and green here (marker once in a `developer` input item, each frame's input extends the previous one byte-for-byte).
- Background-work regression: `run-attempt.native-background-outcome.test.ts` "refreshes edited skills on a protected thread, then cold-resumes once it ends" (managed relay and `appServer.command`): the protected edit arrives as one handoff with no refusal, and after the listener ends the next turn unsubscribes and cold-resumes with the edited catalog. Red on `8fd3970192d6` (refusal) and on `2ca1ebe03be6` (no self-heal); green here.
- Compaction regression: `run-attempt.skills.native.test.ts` "keeps a withdrawn catalog withdrawn after native compaction rebuilds the persistent thread" (real Codex binary, pre-sampling auto-compaction): the continuation request after compaction no longer carries the withdrawn creation catalog. Red on `2ca1ebe03be6`, green here; the incognito case keeps its documented one-request reversion.
- Real Gateway + `openclaw agent`, gpt-6.2-sol, a native-shell `sleep` listener started on turn 1, a skill installed with `openclaw skills install`, then turn 2: previous head refuses on both routes; this PR answers with the new skill on both, through a warm refresh handoff, with turn 2's first request cached up to the previous input. After a Gateway restart, the cold resume carries the current section.

## Merge danger

Two-way door: no stored state, schema or config changes; a revert restores the previous layout. On first turn after upgrade each managed thread gets one cold resume (Gateway restart) that installs the section, as before. Restricted threads on connections without a relay rotate once after upgrade because their stored fingerprint included the section; afterwards edits cold-resume them instead of rotating them. Blast radius: Codex harness thread lifecycle and relay instructions.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…#206554)

Root cause: extensions/codex/src/app-server/thread-lifecycle-run.ts:154 dropped the native thread developer carrier whenever the managed inference relay existed, and extensions/codex/src/app-server/run-attempt-turn-request.ts:293 put skills, shared persona, memory and session project guidance into the relay text that inference-context.ts:271 adds to every request's top-level `instructions`. GPT-6.2 Sol and Astra never cache `instructions`, so every warm request in a turn re-paid that whole block.

Fixes openclaw#206421

Thanks @brandon-julio-t for the precise report (managed vs `appServer.command` A/B with per-request usage), and @NaturalMatchaKing for the A/B evidence in openclaw#204136.

## What changed

- Skills, shared persona (`SOUL.md`, `IDENTITY.md`, workspace-root `USER.md`), memory guidance and session project guidance now always ride the existing refreshable thread developer section, on managed connections too. Codex sends that as a `developer` input item, so it sits in the cached prefix, and later requests in a turn only append.
- The relay keeps only parent-only text: the selected personal `users/<id>/USER.md` overlay, cron policy, plugin `before_prompt_build` system context, and per-turn conversation instructions. Per-turn plugin context stays off the thread on relay connections (`turnRefreshableInstructions` split; still thread-carried when there is no relay, as before).
- `workspace-context.ts` renders the personal-only persona with the same renderer; the codex context plumbs `personalPersonaInstructions` instead of the full persona.
- Edits to that section no longer refuse a thread kept alive by background work. Before this, a skill, persona or memory edit made the next message cold-resume the thread, and a thread kept alive by a running background command refused with "still has background work… stop its running work and retry". `appServer.command` and other non-relay connections already failed this way on main; managed connections would have started to with the carrier move. Now the refreshable section is left out of the thread configuration fingerprint, and persistent live threads keep the same in-memory record incognito threads already had of the section the thread was natively given (`nativeRefreshableInstructions`) and the one last delivered. On reuse (`thread-lifecycle-warm.ts`):
  - Idle thread, section changed: cold resume, as on main, so native configuration carries the current section and compaction rebuilds from it. On managed connections this costs one uncached turn per edit.
  - Protected thread (running background command or child), section changed: the existing appended developer handoff instead of the refusal; the existing post-compaction restore re-delivers it.
  - Self-heal: the first later turn where the thread is no longer protected and its native section still differs from the current one cold-resumes.
  - Managed relay fallback: while a thread's native section differs from the current one (an edited incognito thread, or a protected persistent thread waiting for its cold resume), the relay also sends the current section in request `instructions`, as main did for every request, so a post-compaction continuation sees it. It stops when the native copy matches again (after the self-heal cold resume); unedited threads never pay for it. The section never holds the selected personal overlay, so that is still sent once (`renderCodexRelayRefreshableFallback`, thread-policy.ts).

  No new field, flag or persisted state: the comparison uses the in-memory record, and ephemeral lifetime is keyed off the generic policy that only ephemeral records carry.
- Remaining narrow gap, only on connections without a relay (`appServer.command`): an edit made while background work keeps the thread protected, followed by a native compaction before that work ends, can let one continuation request see the previous section. On main those threads refuse the next turn outright. Codex samples the continuation right after compaction, before injected developer messages are drained (`codex-rs/core/src/session/turn.rs` pending-input drain is deferred after auto-compaction; `session/inject.rs` queues injections into the active turn), and the host restore lands on the request after it. It heals on the first unprotected turn. Not taken: (B) carrying the section in turn-level `collaborationMode.settings.developer_instructions`, because a model catalog's default-mode override wins over caller text, it replaces the built-in Default-mode text and collides with OpenClaw's cron collaboration instructions, and native children do not inherit it; (D) asking Codex to drain injected developer messages before the post-compaction continuation, or to accept developer instructions in thread settings, needs a Codex dependency bump.
- Report estimate counts the stable section on the thread in both modes.
- No model-facing wording changed. Layout change: a user with a personal overlay gets two `## OpenClaw Agent Soul` blocks (shared in the thread, personal in the relay).
- `inference-dispatch.ts` untouched (openclaw#206475 size recovery kept).

## What remains: 97.2% vs 99.5%

Live gpt-6.2-sol against main `2553b7e25179`, the reporter's five-tool-call turn. Two runs per arm on `2ca1ebe03be6` plus one per arm on `a286631217b9` (the stale-section cold resume does not touch an unedited turn; earlier heads had three runs per arm with the same results). Warm-request cache hit and per-request `input/cached` come from the Codex rollout:

| arm | warm hit | uncached input per warm request | previous request's input not cached | uncached input per turn |
|---|---|---|---|---|
| main, managed relay | 70.6–70.7% | ~6,150–6,200 tokens | 6,054–6,100 tokens | 51.5–51.8k |
| this PR, managed relay | 97.2–97.3% | ~570 tokens | 421 tokens | 23.9–24.0k |
| `appServer.command` (no relay) | 99.5% | ~100 tokens | 3 tokens | 20.5–20.6k |

The remaining ~420 tokens per warm request are the relay's per-turn conversation instructions and tool bindings, which still go in top-level `instructions` and are never cached on these models. They are per-turn facts, so moving them is a separate change (for example to turn `additionalContext`); this PR does not move them.

## Earlier attempt

openclaw#141270 (@mbelinky) aimed at the same carrier: workspace persona and memory on the thread developer instructions. This PR is a smaller change at the relay/lifecycle owners and does not build on it.

## Deliberate decision reversed

This reverses openclaw#142276's parent-only delivery for shared text: native Codex subagents now inherit shared persona, skills and memory guidance through `developer_instructions` (`codex-rs/core/src/agent/child_config.rs` `inherited_developer_instructions`). Reasoning: that is already the behavior of every connection without a relay (openclaw#162156 called it intentional); native delegation is off wherever session tools are denied; the original openclaw#142276 problem (catalog collaboration text replacing caller instructions) is solved by thread developer instructions; and keeping the split costs every managed user about 2.2x the uncached input on a five-tool-call turn (51.8k vs 24.0k tokens; about 11x per warm request). The personal overlay stays parent-only (openclaw#162156 privacy boundary kept). A child created after an in-place edit inherits the thread's creation-time section, the same limitation incognito threads already document.

## Evidence

Proof comments: openclaw#206554 (comment) (cache and request bodies), openclaw#206554 (comment) (background-work P1), openclaw#206554 (comment) (`2ca1ebe03be6`: scripted lane, live cache, live managed P1), openclaw#206554 (comment) (`a286631217b9`: stale-section cold resume, compaction and self-heal regressions, live P1 on both routes, cache), openclaw#206554 (comment) (`76341cb30f58`: managed relay fallback regression, live managed P1). Child-inheritance decision: openclaw#206554 (comment)

- Scripted lane (real managed bundled codex 0.172.0 app-server, real relay, synthetic Responses upstream recording bodies): `run-attempt.skills.native.test.ts` "keeps managed skills in the cached native prefix across a multi-request turn" is red on main (skills in `instructions` on every frame) and green here (marker once in a `developer` input item, each frame's input extends the previous one byte-for-byte).
- Background-work regression: `run-attempt.native-background-outcome.test.ts` "refreshes edited skills on a protected thread, then cold-resumes once it ends" (managed relay and `appServer.command`): the protected edit arrives as one handoff with no refusal, and after the listener ends the next turn unsubscribes and cold-resumes with the edited catalog. Red on `8fd3970192d6` (refusal) and on `2ca1ebe03be6` (no self-heal); green here.
- Compaction regression: `run-attempt.skills.native.test.ts` "keeps a withdrawn catalog withdrawn after native compaction rebuilds the persistent thread" (real Codex binary, pre-sampling auto-compaction): the continuation request after compaction no longer carries the withdrawn creation catalog. Red on `2ca1ebe03be6`, green here; the incognito case keeps its documented one-request reversion.
- Real Gateway + `openclaw agent`, gpt-6.2-sol, a native-shell `sleep` listener started on turn 1, a skill installed with `openclaw skills install`, then turn 2: previous head refuses on both routes; this PR answers with the new skill on both, through a warm refresh handoff, with turn 2's first request cached up to the previous input. After a Gateway restart, the cold resume carries the current section.

## Merge danger

Two-way door: no stored state, schema or config changes; a revert restores the previous layout. On first turn after upgrade each managed thread gets one cold resume (Gateway restart) that installs the section, as before. Restricted threads on connections without a relay rotate once after upgrade because their stored fingerprint included the section; afterwards edits cold-resume them instead of rotating them. Blast radius: Codex harness thread lifecycle and relay instructions.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR 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: 🐚 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.

1 participant