Skip to content

fix(codex): keep workspace persona stable across incremental requests - #204136

Closed
NaturalMatchaKing wants to merge 3 commits into
openclaw:mainfrom
NaturalMatchaKing:fix/codex-incremental-workspace-persona
Closed

NaturalMatchaKing wants to merge 3 commits into
openclaw:mainfrom
NaturalMatchaKing:fix/codex-incremental-workspace-persona

Conversation

@NaturalMatchaKing

@NaturalMatchaKing NaturalMatchaKing commented Nov 23, 2026 •

Copy link
Copy Markdown

Related: #142501 (parent-only workspace profile delivery)

What Problem This Solves

Managed Codex sessions send workspace persona and per-turn guidance together in the top-level instructions. When the guidance changes, an incremental request cannot reuse the unchanged persona as part of its input prefix.

User Impact

Eligible managed Codex sessions keep unchanged persona text in a stable input prefix. Turn-specific guidance remains request-local. Removing a persona file or switching profiles rebuilds the prefix without carrying forward the previous selection.

Why This Change Was Made

The relay projects persona only when the native request shows incremental tool declarations in a Responses Lite window. Append-only edits add the new text; replacements, removals and compaction rebuild from the current selection. The relay does not persist persona in native history or project it into native child, warmup or compaction requests. WebSocket continuations require the preceding response on the same socket and admission. Legacy and unrecognized requests retain the existing instruction carrier.

Evidence

  • The pinned Codex app-server completed two turns over both HTTP and WebSocket through the relay to a synthetic upstream. The second request preserved the first input prefix while the top-level instructions changed. The same regression checks failed before the fix.

  • On the published head, 50 focused tests passed, including the two native transports and fork coverage. Extension type checking, scoped lint and formatting checks passed.

  • A credentialed A/B used the distributed OpenClaw private relay and native app-server 0.169.0 against ChatGPT's Codex backend, with two disposable threads, identical synthetic content, GPT-6.2 Sol (Standard, low), two distinct ordinary questions, a native manual compaction, then two new questions. Each arm returned all four expected facts. The harness submits directly to the relay/app-server; it is not an end-to-end test of managed Gateway turn preparation.

    Phase Legacy cached/input Projected cached/input
    First ordinary (entrance, unequal cache state) 9,856 / 11,860 0 / 11,864
    Second ordinary (both warm) 9,856 / 11,882 11,648 / 11,886
    Native summary 9,856 / 10,866 9,856 / 10,866
    First ordinary after compaction 9,856 / 11,948 10,880 / 11,950
    Following ordinary 9,856 / 11,967 11,904 / 11,969

    From the warm control through the following ordinary call, uncached input fell from 7,239 to 2,383 tokens. The summary used the same measured input (output 55 vs. 53), and the first ordinary after it used 2,092 vs. 1,070 uncached input. The complete five-response totals were 9,243 vs. 14,247 uncached input due to the unequal initial hit. This pair quantifies the warm-window savings, not cold-start savings, billing, or prevention of service cache misses.

  • The follow-up fixes the HTTP fork lifecycle: freshness is checked before a new upstream request, so an already-admitted request can settle after the parent changes persona, while new requests cannot sample the withdrawn selection. Actual fork cancellation still invalidates that request. Focused inference context and HTTP/native transport tests: 35 passed; the separate API-key-only native integration test was not run.

@clawsweeper

clawsweeper Bot commented Nov 23, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: L labels Nov 23, 2026

@THE-NAVVV THE-NAVVV left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

​

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR projects workspace persona into incremental Codex input while keeping turn-specific guidance in request-local instructions.

Example: SOUL.md says “Reply concisely,” while consecutive turns receive “First turn-only hint” and “Second turn-only hint.”

  • Before: Persona and changing guidance travel together in top-level instructions.
  • After: Eligible requests reuse the persona input prefix and send only the current guidance in top-level instructions.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful native wire regressions support the approach, but an introduced fork-lifecycle defect and absent real-behavior proof block merge.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Changing turn guidance prevents unchanged workspace persona from remaining in an append-only request input prefix.
Reason: The change supports the documented prefix-stability contract while retaining parent-only isolation and existing configuration.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR addresses a documented prefix-stability problem that remains on main, but its new persona invalidation check can fail an already-running side question.

Priority: P2
Reviewed head: d66f54bed37d507eceb207f566dec91c1ae25df2

Before merge

  • Add real behavior proof - The contributor reports two-turn native HTTP and WebSocket runs through the relay to a synthetic upstream, and the added tests support wire-layout coverage; no supplied logs, media, or artifact exercises the changed turn-preparation path through a shipped OpenClaw entry point to a real provider. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Let an admitted fork finish with its sampled persona (P2) - Start a background side question over HTTP, then register the parent's next turn after appending to or replacing SOUL.md while the fork awaits upstream response headers. Parent registration replaces the prefix object, so this newly installed assertCurrent callback throws even though the fork retains its own snapshot and execution authority. inference-proxy.ts invokes that callback after fetchWithSsrFGuard returns and before relaying the response, turning a successful upstream request into a 502 and possible replay. Parent prompt edits are not fork authority revocation. Keep any necessary freshness decision at request admission and let the running request finish with its sampled context; retain the existing genuine authority and cancellation checks.
  • Explain or restore the original intent of Retained side-question snapshot lifetime - 164bd67: Replay the sampled parent request for independent background questions while keeping model authority separate from retained prompt data.

Findings

  • [P2] Let an admitted fork finish with its sampled persona — extensions/codex/src/app-server/inference-context.ts:423-425

Provenance

  • Retained side-question snapshot lifetime changes intended behavior without addressing why it exists (164bd67: Replay the sampled parent request for independent background questions while keeping model authority separate from retained prompt data.)

Tests

  • Missing end-to-end proof: Provide redacted shipped-entry-point evidence of consecutive managed Codex turns with changing guidance and unchanged persona reaching a real provider, including persona replacement/removal behavior; remove IPs, API keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The Codex plugin registers host-prepared workspace instructions with a private inference relay, which transforms native HTTP and WebSocket requests before forwarding them upstream.

flowchart LR
  A[Workspace files] --> B[Turn preparation]
  B --> C[Inference context]
  D[Native Codex requests] --> E[Private relay]
  C --> E
  E --> F[Provider]
  C --> G[Side question snapshot]
Loading

Technical review

Best possible solution:

Keep projection in the existing inference-context owner and preserve an admitted fork's sampled persona without revoking its running request when parent text changes.

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

Current-main source shows persona sharing a changing top-level instruction carrier, and the PR reports red-before/green-after native wire tests; this review ran no target code and does not establish live cache behavior.

Is this the best way to solve the issue?

The transient relay projection preserves native-history isolation and uses the existing owner, but parent prompt freshness must not become a new lifetime condition for an already-running fork.

Full review comments:

  • [P2] Let an admitted fork finish with its sampled persona — extensions/codex/src/app-server/inference-context.ts:423-425
    Start a background side question over HTTP, then register the parent's next turn after appending to or replacing SOUL.md while the fork awaits upstream response headers. Parent registration replaces the prefix object, so this newly installed assertCurrent callback throws even though the fork retains its own snapshot and execution authority. inference-proxy.ts invokes that callback after fetchWithSsrFGuard returns and before relaying the response, turning a successful upstream request into a 502 and possible replay. Parent prompt edits are not fork authority revocation. Keep any necessary freshness decision at request admission and let the running request finish with its sampled context; retain the existing genuine authority and cancellation checks.
    Confidence: 0.96
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Parent-only persona carrier changes intended behavior with a stated reason (8169aac: Restore workspace profiles despite catalog guidance without adding persona to native history or automatically inherited child context.)
  • Terminal WebSocket event detection keeps the original intent (ddcd065: Avoid parsing ordinary streamed deltas while preserving terminal-event classification and release timing.)
  • Relay instruction diagnostics keeps the original intent (d13bd0f: Expose the registered relay instructions through existing diagnostics without creating another native instruction carrier.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test extensions/codex/src/app-server/inference-context.test.ts
  • pnpm test extensions/codex/src/app-server/inference-proxy.test.ts
  • pnpm test extensions/codex/src/app-server/inference-proxy.native.test.ts
  • pnpm test src/agents/agent-tools.prefix-stability.test.ts
  • git diff --check

What I checked:

PR surface

Source +335, Tests +367, Docs +8. Total +710 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 389 54 +335
Tests 3 372 5 +367
Docs 1 9 1 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 770 60 +710

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:

  • add P2: This is a bounded managed-Codex prefix improvement with an introduced background-fork failure, without evidence of an urgent widespread outage.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: This is a bounded managed-Codex prefix improvement with an introduced background-fork failure, without evidence of an urgent widespread outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 follows the weaker of proof and patch quality; ✨ 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 23, 2026, 11:45 AM ET / 16:45 UTC.

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]>
@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Thank you for this fix. The same root cause landed in #206554 (cf0c99c), which credits your work, so I'm closing this one as covered.

@obviyus obviyus closed this Nov 27, 2026
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 P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants