Skip to content

fix(codex): stop background exec completions from replaying full history into a fresh thread - #184206

Merged
roboclaw-bot merged 8 commits into
openclaw:mainfrom
Marvinthebored:fix/codex-exec-event-thread
Nov 16, 2026
Merged

roboclaw-bot merged 8 commits into
openclaw:mainfrom
Marvinthebored:fix/codex-exec-event-thread

Conversation

@Marvinthebored

@Marvinthebored Marvinthebored commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #183286, #179363, #172026, #178982

What Problem This Solves

When a background exec finishes in a Codex-backed WebChat session, the completion wake does not continue the session's bound native thread. It starts a fresh transient thread, replays the full session history into it uncached, and does it again for the follow-up turn. On a long session every completion wake costs a full uncached history read. In one observed session, four completion wakes each sent about 190k uncached input tokens.

This finishes, for event wakes, what #183286 started: tool declarations belong to the session, not to the turn. #183286 kept seven native Codex thread, plugin, and supervision declarations stable across owner and completion turns. A completion wake still differed from the user turn in three other ways, and each one alone forces a new thread:

  1. Tool-policy scope. The default session-event source policy caps every follow-up at the producer's tool list. A wake with a cap runs as a turn-scoped restricted turn, which the Codex harness serves on a transient thread with native code mode off (48 eager dynamic tools instead of 10).
  2. skill_workshop schema. The personal-library schema is published only on human turns that carry an authoring grant. A wake publishes a narrower schema, the dynamic tool catalog fingerprint changes, and the bound thread rotates. The Claude CLI runner already fixed this in fix(claude-cli): stop cache-prefix churn after child completion #172026 (resolveStableCliSkillAuthoring); the embedded/harness path never used it.
  3. Conversation context. An internal (WebChat) session stores no delivery route, so buildSessionEventContext never matched the wake's own WebChat route and dropped the session chat type. The wake's developer instructions then lacked the "You are in a WebChat direct conversation" line, the live thread config fingerprint changed, and Codex had to cold-resume the thread.

Why This Change Was Made

Each layer is fixed where the difference starts, without widening authority:

  • Scope (A). A cap from a conversation-scoped producer turn is the session's own policy, and the follow-up re-derives that policy itself. createCodingToolsGatewayCaller marks the caller identity session-scoped when the policy scope is conversation and no caller-supplied source policy exists, and session-event-target skips it only when the follow-up's destination is the same session. The mark is not set when group, per-DM, or sender policy narrowed the producer (groupPolicy/senderPolicy). Those come from the inbound request, the wake cannot rebuild them, and the cap keeps carrying them. The caller-inheritance merge keeps the mark only for an inherited owner of the same agent and session that has no narrower cap of its own. Cross-session follow-ups, sender-narrowed producers, and turn-scoped producers keep the cap exactly as before.
  • Policy lifetime stays host-owned. No public SDK option is added. The host already computes the attempt's policy lifetime for Codex (pluginHarnessToolPolicyScope, resolvePluginHarnessToolPolicies). Host policy preparation now records that value in the attempt's host capability, and the host's tool construction (createToolSurfaceAsync, which is how Codex builds every dynamic tool) passes it to the internal tool options. A plugin cannot set it through tool options: a plugin-supplied toolPolicyScope is overwritten by the host value, and when the host has none the cap stays in place (fail-closed).
  • skill_workshop (B). The fix(claude-cli): stop cache-prefix churn after child completion #172026 helper moves from cli-runner/ to src/agents/stable-skill-authoring.ts as a per-runtime factory and is also applied at the embedded attempt dispatch. Internal turns publish the session's last human shape with an expired grant: the declaration matches, personal-library calls fail with AUTHORITY_EXPIRED, and workspace calls keep the ordinary no-grant rule (unsandboxed runs only). Grants that are already expired (transcript follow-ups, stranded-reply recovery) carry expired: true, publish the remembered human shape without replacing it, and continue refusing personal and workspace authoring.
  • Context (C). For a session that stores no delivery route, an event on that session's own WebChat route (channel: "webchat", to: <sessionKey>, the shape chat.send and subagent announce already use) keeps the session chat type. Events routed to any other session still get none.

Out of scope, noted for follow-up: when a thread's config does change (for example a model switch), Codex can take longer than OpenClaw's 2-second unload budget to close a code-mode thread after thread/unsubscribe (measured 0.7 s, 2.9 s, and 10.6 s in this harness). The cold resume then fails with "Codex did not confirm unloading its previous configuration". With this change, completion wakes no longer take that path.

AI-assisted: written with Claude Code. Every claim below was checked by running it.

User Impact

  • Background exec completion wakes in Codex-backed sessions continue the bound thread with native code mode on. The wake reads the session prefix from cache instead of replaying the full history uncached, and the next user turn stays on the same thread.
  • No tool, personal-library, or workspace access is widened. Sessions narrowed by group, per-DM, or sender policy keep today's behavior, including the fresh-thread wake.
  • On internal turns with a remembered personal default target, skill_workshop calls that rely on that default now return AUTHORITY_EXPIRED instead of running against the workspace. Explicit target=workspace calls keep the no-grant rule.

Evidence

The explicit-expired-grant regression fails before the repair (1 failed, 3 passed) and passes afterward (4 passed). It checks the remembered workspace schema, rejected personal invocation, rejected workspace execution, and the unchanged remembered shape.

Regression tests, each shown failing without its fix and passing with it:

Test Without fix With fix
host-capability.tool-policy-scope.test.ts (new): host-prepared scope reaches tool construction; a plugin-supplied toolPolicyScope: "conversation" does not 2 failed, 1 passed (host value not injected) 3 passed
session-event-permissions.test.ts "bounds a same-session background completion's final effects: same-session" fails: writeOffered: false, expected true (the producer cap is kept) passes
agent-tools.session-event-cap.test.ts "a sender narrowed by toolsBySender" (real createOpenClawCodingTools, real caller identity, no mock) fails: expected true to be undefined when the sender check is removed 3 passed
stable-skill-authoring.test.ts "keeps the human shape when a follow-up passes an expired grant" 1 failed, 3 passed 4 passed
session-event-context.test.ts "keeps the session chat type only for $route" 1 failed, 2 passed 3 passed
agent-tools.prefix-stability.test.ts "offers the human turn's skill_workshop definition on an internal turn" asserts the surfaces differ without the helper equal with it

Authority controls around the same-session exemption

session-event-permissions.test.ts "bounds a same-session background completion's final effects" runs the production path: a real captureSessionEventTargetForHost under a caller identity, the real enqueueSessionEventForHost admission, the real harness host capabilities and managed tool surface, and a real file write. Each row captures a producer whose ceiling lists only read:

Row Producer identity Follow-up tool surface File after the follow-up
same-session same session, marked session-scoped write offered written
restricted-sender same session, not marked (the caller leaves the mark off when senderPolicy or groupPolicy narrowed the turn; see the caller test above) no write unchanged
cross-session other session, marked no write unchanged
revoked-before-write same session, marked; the session permission mode is set to read-only after the tool surface is built write offered, call refused (authority/permission error) unchanged

Result: 4 passed. With session-event-target.ts restored to its base version, the same-session row fails (writeOffered: false).

Expired personal-library calls: agent-tools.prefix-stability.test.ts builds the real coding tools for an internal turn and shows skill_library with target: "personal" rejected with "fresh message" (AUTHORITY_EXPIRED). stable-skill-authoring.test.ts shows an expired grant refuses personal-library calls and never replaces the remembered human shape; the sandboxed-run refusal for workspace calls is unchanged code from #172026 and is not re-tested here.

What this does not show: the embedded dispatch wiring (resolveStableEmbeddedSkillAuthoring at run-attempt-dispatch.ts) is a single call covered by the two tests above through the same factory, not by a dispatch-level test.

Touched suites: the files above plus gateway-caller-context.test.ts and agent-tools.delegated-authority.test.ts pass. The new production-boundary rows pass 4 of 4. tsgo core and the src test shards: clean. oxfmt on the repository: clean. check:test-mock-exports and check:max-lines-ratchet against the base commit: OK (the PR adds no mock factory and no line to agent-tools.ts or cli-runner/prepare.ts).

Live run against a real Codex app-server (codex 0.162.1), an isolated gateway, and chat.send. Script: user turn, a turn that starts exec with background=true, the completion wake, then a user turn. Wire capture of the app-server JSON-RPC, base 4fa442e3327:

# stock (4fa442e3327)
in thread/start None dynTools=10
-> thread thread-A
# user turn
in turn/start thread-A
usage thread-A in= 20064 cached= 0
out turn/completed thread-A completed
# user turn that starts the background exec
in turn/start thread-A
usage thread-A in= 20204 cached= 20061
usage thread-A in= 21343 cached= 20201
usage thread-A in= 21589 cached= 21340
out turn/completed thread-A completed
in thread/start None dynTools=48
-> thread thread-B
# completion wake (turn 1 of 2)
in turn/start thread-B
usage thread-B in= 29269 cached= 0
out turn/completed thread-B completed
in thread/start None dynTools=48
-> thread thread-C
# completion wake (turn 2 of 2)
in turn/start thread-C
usage thread-C in= 29183 cached= 0
out turn/completed thread-C completed
# this branch
in thread/start None dynTools=10
-> thread thread-A
# user turn
in turn/start thread-A
usage thread-A in= 20064 cached= 0
out turn/completed thread-A completed
# user turn that starts the background exec
in turn/start thread-A
usage thread-A in= 20204 cached= 20061
usage thread-A in= 21336 cached= 20201
usage thread-A in= 21632 cached= 21333
out turn/completed thread-A completed
# completion wake (turn 1 of 2)
in turn/start thread-A
usage thread-A in= 21761 cached= 21629
out turn/completed thread-A completed
# completion wake (turn 2 of 2)
in turn/start thread-A
usage thread-A in= 21830 cached= 21758
out turn/completed thread-A completed
# next user turn
in turn/start thread-A
usage thread-A in= 22124 cached= 21827
out turn/completed thread-A completed

The live trace was captured with commit 591bd2b60aa on base 4fa442e3327.

Stock: each wake turn starts a fresh thread with 48 dynamic tools and 0 cached tokens. Patched: one thread with 10 dynamic tools for the whole session. The wake turns are plain turn/start calls on the bound thread, reading 99% of their input from cache, with no thread/resume or thread/unsubscribe in the wire log. The next user turn stays on the same thread. (The stock run's next user turn did not reach the app-server before the harness stopped, so it is not shown.)

What this evidence does not show: the harness covers a WebChat direct session with no group, per-DM, or sender policy. Sessions with those policies are covered by the unit tests above, not by a live run.

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Oct 26, 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.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Maintainer security changes approved

A maintainer approved this revision with an explicit security approval comment.

A later push requires a fresh approval comment for an external contributor's PR.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR stabilizes session tool policy, skill declarations, and WebChat context so background command completions reuse the bound Codex thread.

Example: A WebChat user starts a background exec command and receives its completion.

  • Before: The supplied trace starts separate completion threads with 48 dynamic tools and zero cached input tokens.
  • After: Both completion turns reuse thread-A with 10 dynamic tools; the first reports 21,629 cached tokens out of 21,761 input tokens.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with shipped-entry-point evidence, distinct authority controls, and no identified code defects; the enforced security approval is a workflow gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied isolated Gateway chat.send trace exercises a real Codex app-server through human turn, background exec, completion wakes, and another human turn, showing bound-thread reuse and cached input; production-path authority regressions additionally record allowed writes and rejection for restricted senders, cross-session targets, and permission revocation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Finishing a background command repeatedly cold-loads the conversation into new Codex threads, wasting cached history and adding latency.
Reason: Stable declarations are an established repository contract, and the supplied live trace demonstrates the concrete benefit without adding configuration or a public API.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR addresses a current-main completion-thread bug with useful live evidence and no identified correctness findings; current-head maintainer security approval remains required.

Priority: P2
Reviewed head: 447a0205b43a861415c66cc73a2657fa58535a67

Before merge

  • Await maintainer action - A maintainer must review head 447a020 and provide /allow-security-sensitive-change before merge.

Findings

None.

Agent review details

How this fits together

Background exec completions enter ordinary session admission, which prepares current tool authority and conversation context before dispatching the turn to the Codex harness.

flowchart TD
  A[Background exec completion] --> B[Captured session target]
  B --> C[Ordinary session admission]
  C --> D[Host tool policy and skill declarations]
  D --> E[Codex thread compatibility]
  E --> F[Bound native thread]
  D --> G[Current authority checks before effects]
Loading

Technical review

Best possible solution:

Retain the focused session-stability repair with host-owned policy lifetime and current authority checks at execution.

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

Current-main source retains all three destabilizing paths, and the contributor supplies a discriminating stock-versus-patched Gateway/app-server trace; no target code was executed during this review.

Is this the best way to solve the issue?

The repair uses the existing caller, event-target, host-policy, and skill-authoring owners, removes the superseded CLI helper, and preserves genuinely restricted turns rather than weakening Codex isolation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Session-event producer ceilings and caller inheritance changes intended behavior with a stated reason (753a7a5: Ordinary-session notification admission retained the producer's permission ceiling and destination; the later CLI repair preserved complete source policy rather than a partial factory catalog.)
  • Stable skill-authoring declarations keeps the original intent (77d9f42: Human and completion CLI turns needed identical declarations while personal-library execution remained expired on internal turns.)
  • Expired transcript-followup authoring keeps the original intent (fix(auto-reply): Control UI forgotten-send retry fails with an authoring error #182219: Replacement turns must not rebind the source grant or fall back to broader workspace authoring; the explicit expired marker preserves that restriction while retaining declaration shape.)
  • WebChat event context keeps the original intent (753a7a5: Immediate notifications preserve conversation identity and routing; the new own-session WebChat match handles sessions without a stored delivery route.)
  • Host tool construction keeps the original intent (ddcae51: The existing host construction boundary carries prepared policy and live authority into dynamic tools; the new lifetime value stays inside that boundary.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head hunks, including host-only policy scope, caller inheritance, same-session cap exemption, shared skill-shape handling, WebChat context, and their regressions; base-only changes were excluded. (447a0205b43a)
  • Current main still contains the responsible paths: Current main unconditionally retains a caller tool ceiling for session events, preserves chat type only for an exact stored route, and applies stable skill authoring only in the CLI runner. (src/auto-reply/reply/session-event-target.ts:189, 1ebc46e1a52f)
  • Supplied live behavior evidence: Read the complete PR body, including the previously omitted evidence. Its isolated Gateway chat.send trace with a real Codex app-server shows user, background-exec, completion, and subsequent user turns sharing one native thread after the fix. The trace is attributed to historical commit 591bd2b60aa, rather than presented as a new current-head run. (447a0205b43a)
  • Final-effect authority controls: The supplied passing regression table uses real event capture, admission, managed tool construction, and filesystem writes. Same-session work writes successfully; restricted-sender and cross-session work leave the file unchanged; a permission downgrade after construction refuses the write. (src/auto-reply/reply/session-event-permissions.test.ts:916, 447a0205b43a)
  • Host owns the exemption: Host construction overwrites plugin-supplied toolPolicyScope with its prepared value; caller marking excludes explicit source policy and narrowed group or sender policy, and target capture requires the same session. (src/agents/harness/host-capability.ts:421, 447a0205b43a)
  • Current security approval gate: The security guard requests /allow-security-sensitive-change for head 447a020; no approving review was returned. GitHub reports the head mergeable with mergeable_state blocked, consistent with the recorded approval statuses rather than a conflict. (447a0205b43a)

PR surface

Source +92, Tests +289, Other +3. Total +384 across 25 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 15 184 92 +92
Tests 9 328 39 +289
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 3 0 +3
Total 25 515 131 +384

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 rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Repeated background completions can unnecessarily replay substantial uncached history, increasing cost and latency in otherwise working Codex sessions.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 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.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-26T04:55:44.855Z sha d8641bc45ec7ddfbd2b217e23048c3a5b161d9e9 :: needs real behavior proof before merge. :: [P2] Keep the new logic within the enforced production module budgets | [P3] Preserve the real caller module in the new mock
  • reviewed 2026-10-26T08:23:58.561Z sha 80b8c1192d9d788727071e6a14504b197239ee42 :: blocked before merge. :: none
  • reviewed 2026-10-26T09:39:17.618Z sha ff45957647a4235a9ed0e52728ed994b52c8e980 :: blocked before merge. :: none
  • reviewed 2026-10-26T09:55:02.486Z sha 7c0114c04a09b09524288c41de35938ac1240b3f :: blocked before merge. :: none
  • reviewed 2026-11-01T03:38:15.247Z sha 7976461d8a0984495f3b1b6cccbba8f5090f35cd :: blocked before merge. :: none
  • reviewed 2026-11-08T09:42:28.842Z sha e780ca27f5d147f7f148b0893f2c261958c53278 :: blocked before merge. :: none

Reviewed November 9, 2026, 9:59 PM ET / November 10, 2026, 02:59 UTC (Revision 7).

@openclaw-barnacle openclaw-barnacle Bot added size: L r: too-many-prs Auto-close: author has more than twenty active PRs. and removed size: M labels Oct 26, 2026
@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 26, 2026
@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 26, 2026
@Marvinthebored Marvinthebored removed the r: too-many-prs Auto-close: author has more than twenty active PRs. label Oct 26, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Oct 28, 2026
Peetiegonzalez and others added 5 commits November 10, 2026 10:23
…vers

The same-session, restricted-sender, and cross-session decisions are asserted
through admission and an actual write in the final-effect table, so the extra
target-field assertions only restated them. Document the toolPolicyScope
option's contract where it is declared.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
toolPolicyScope is no longer a public tool-factory option. Host policy preparation records the attempt's scope, and the host's tool construction supplies it, so a plugin cannot claim conversation lifetime through options.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Retain expired invocation authority and explicitly reject workspace execution while restoring the remembered schema. Move unchanged inherited tool policy composition to its existing owner and infer the host capability return type to meet module line limits.
@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Nov 10, 2026
@sallyom sallyom self-assigned this Nov 16, 2026
@roboclaw-bot

roboclaw-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Review update: the merge conflict is resolved in 663ead5b0269, and GitHub confirms this head is mergeable.

The follow-up moves the unchanged WebChat route regression table into session-event-context.webchat-route.test.ts, leaving main’s independently added recovery/authority coverage intact. No production code or contributor history was changed by the follow-up.

Validation on the exact candidate tree in secretless AWS: 36 tests passed across the context, WebChat-route, and session-event-permissions suites; formatting and targeted lint passed. Independent review found no additional code blockers.

New-head CI, CodeQL, CodeQL Critical Quality, and OpenGrep passed. The remaining observed gate is current-head maintainer security approval; the aggregate openclaw/ci-gate is reporting that missing approval, not a test failure. Thanks for the detailed reproduction and before/after cache trace.

Keep both regression groups mergeable without replaying unrelated main history. The WebChat route table is unchanged; no production behavior changes.

Co-authored-by: sallyom <[email protected]>
@sallyom

sallyom commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

/allow-security-sensitive-change

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Rationale for the security approval on 663ead5b0269: this removes an extra inherited producer-tool allowlist only for host-identified, conversation-scoped completions returning to the same session. Those ordinary completions rely on the session’s normal admission and tool-authorization checks instead of being treated as special restricted turns, which was breaking Codex thread reuse and prompt caching.

Sender/group-restricted and turn-scoped producers do not receive this exemption. Cross-session completions and explicit source ceilings retain their restrictions.

@roboclaw-bot
roboclaw-bot merged commit 163519e into openclaw:main Nov 16, 2026
125 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…ory into a fresh thread (openclaw#184206)

* fix(codex): keep background exec completion wakes on the bound thread

A background exec completion wake started a fresh native thread with the
full session history instead of continuing the bound Codex thread. Three
differences between the wake and the user turn each forced that:

- The default session-event source policy capped every follow-up at the
  producer's tool list, so the wake ran as a turn-scoped restricted turn.
  A cap from a conversation-scoped producer that no group, per-DM or
  sender policy narrowed is now session-scoped and is skipped for
  follow-ups into the same session. Request-derived policy keeps the cap.
- skill_workshop exposed its personal-library schema only on human turns.
  The embedded/harness path now reuses the stable skill authoring helper
  the CLI runner already had (openclaw#172026): internal turns publish the
  session's last human shape with an expired grant. Expired follow-up
  grants no longer replace the remembered shape.
- An internal session stores no delivery route, so a wake on its own
  WebChat route dropped the session chat type and the conversation line
  in the developer instructions changed.

* fix(codex): keep the session-scoped cap decision with the caller owner and prove its final effects

Decide the session-scoped marking inside createCodingToolsGatewayCaller so
agent-tools.ts and the session-event contract return to their base size, share
the CLI stable skill-authoring instance from its module so prepare.ts keeps its
line count, and replace the mocked caller test with one that observes the real
caller identity. Add a production-boundary test showing that a same-session
follow-up is uncapped only when the caller marked it, while a restricted
sender, a cross-session destination, and authority revoked before the write
all stay denied.

* test(codex): drop the target-field cap test the final-effect table covers

The same-session, restricted-sender, and cross-session decisions are asserted
through admission and an actual write in the final-effect table, so the extra
target-field assertions only restated them. Document the toolPolicyScope
option's contract where it is declared.

* fix(codex): keep tool-policy lifetime behind host tool construction

toolPolicyScope is no longer a public tool-factory option. Host policy preparation records the attempt's scope, and the host's tool construction supplies it, so a plugin cannot claim conversation lifetime through options.

* test(codex): allocate completion authority regression coverage

* test: track Skill Workshop's move to its bundled plugin and the exact test-line allocation

* fix(codex): preserve the human tool shape on expired follow-ups

Retain expired invocation authority and explicitly reject workspace execution while restoring the remembered schema. Move unchanged inherited tool policy composition to its existing owner and infer the host capability return type to meet module line limits.

* test: separate WebChat route regressions from recovery coverage

Keep both regression groups mergeable without replaying unrelated main history. The WebChat route table is unchanged; no production behavior changes.

Co-authored-by: sallyom <[email protected]>

---------

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

Labels

agents Agent runtime and tooling clawtributors PR from a clawtributor P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: L 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.

4 participants