Skip to content

fix(gateway): parent prompt cache misses when a subagent settles - #195378

Open
AmoghAtreya wants to merge 16 commits into
openclaw:mainfrom
AmoghAtreya:fix/skill-library-settle-prompt-cache
Open

AmoghAtreya wants to merge 16 commits into
openclaw:mainfrom
AmoghAtreya:fix/skill-library-settle-prompt-cache

Conversation

@AmoghAtreya

@AmoghAtreya AmoghAtreya commented Nov 8, 2026 •

Copy link
Copy Markdown

Closes #195328

What Problem This Solves

A subagent completion must retain the parent conversation’s skill-library presentation while losing the human requester’s execution authority. Reconstructing that presentation only from a live grant or process memory leaves the Gateway without a durable record after restart.

User Impact

Conversations retain their skill-library tool shape across human and completion turns, including a listing recorded by the first chat. Personal-library calls still require a current human requester. Ordinary unsandboxed Workshop access remains available; sandbox and expired-authority restrictions remain enforced.

This changes security-sensitive authority handling. Fresh maintainer security approval is required on the final head before merge.

Why This Change Was Made

The existing session entry owns two bounded presentation facts (multipleProfiles and defaultTarget). The Gateway reads them through the session worker and commits them through the canonical session writer. First-chat creation records them atomically with the new session row; an earlier patch-only write had no row to update.

The conflict port uses current main’s shared src/agents/stable-skill-authoring.ts for CLI and embedded runs. It preserves main’s expired: true semantics, transcript-followup expiry, and abort/cron/native-app lifecycle behavior. It does not restore the removed CLI-only helper. Current main’s turn-local deferred directory remains separate from the cached system directory.

Original contributor work and ancestry by @AmoghAtreya are preserved. The maintainer updates port that work to the current owners and cover first-chat persistence. Release-note context: keep skill-library presentation stable without granting background personal-library access. There is no new config/default or SQLite schema version; the optional field uses the existing session entry_json store.

Evidence

Reviewed and tested head: a4d57cb71504a4d19b0070e29c398763b9e24017.
Frozen main baseline: cf9a9839e03ba76b526d9f61fe453e3ccc8a93a9.
All execution used sanitized AWS machines with no instance profile, Tailscale, credential hydration, or forwarded secrets. Contributor code was not executed locally.

  • 54 focused tests passed: Gateway first-chat persistence and storage reopen, human→settle→human presentation, requester/profile/scope/role revocation, shared CLI/embedded expired-grant behavior, plugin-tool selection, Workshop sandbox denial and ordinary unsandboxed access, and prefix siblings.
  • Formatting, targeted lint, core typecheck, full build, and whitespace checks passed on that head.
  • Real Gateway + fixture provider behavior assertions passed: seven parent provider requests retained the same prefix and cache identity through first human chat, actual spawned-child completion, and Gateway restart. The completion’s personal-library call was refused; the subsequent human call returned the library listing.
  • Published stable upgrade passed: [email protected] created a real session; candidate doctor --fix --non-interactive exited 0; the stored entry remained byte-identical and retained its session ID and label; the candidate Gateway listed it after restart. The new optional field was absent in the stable row. This proof covers that session row, not an old transcript fixture.
  • Fresh scoped autoreview found no P0–P2 source issue.

Retained failure and follow-up

The Gateway behavior assertions passed, but its suite failed during teardown with shutdown step failed (gateway close): Plugin openai is retiring. A separate fresh machine at frozen main reproduced the same failure and stack (src/plugins/plugin-instance.ts:793 → src/gateway/server-shutdown.ts:210). No checkout, HOME, or compiler cache was shared between the two heads. This is a named follow-up for Gateway/OpenAI plugin retirement after restart; it is not reported as a green suite or used to waive security/review gates.

Main also refused the internal call using its existing expired-grant message. The baseline’s different refusal text is not evidence of a cache regression. The port preserves that existing boundary while adding durable Gateway presentation.

Exact proof receipts and review scope
{"head":"a4d57cb71504a4d19b0070e29c398763b9e24017","gateway":{"parentRequests":7,"stablePrefixAssertions":"passed","firstHumanListing":true,"internalPersonalRefused":true,"restartHumanPersonalAllowed":true,"suiteTeardown":"failed; matching isolated-main signature"},"stableUpgrade":{"baseline":"2026.11.2","doctorExit":0,"sessionIdPreserved":true,"entryBytesPreserved":true,"candidateGatewayListsSession":true,"entrySha256":"107d5cb655e5cce9fd2bb1428338b99ddcfccd6c00842193a7ce96e542bc6829"}}

The first upgrade attempt stopped before session creation because the disposable fixture used a noncanonical device-identity path. It was corrected to the existing client/credentials.sqlite contract; only the upgrade proof was rerun on the unchanged candidate and its already completed build.

Scope reviewed: Gateway dispatch/session creation → prepared authoring → worker-owned session facts → tool construction/invocation; shared CLI/embedded helper; transcript followup; plugin-tool and Workshop siblings; session parser/reserved slots; relevant history and current main. Direct Codex dependency inspection covered codex-rs/protocol/src/dynamic_tools.rs:13, codex-rs/app-server/src/dynamic_tools.rs:16, codex-rs/app-server/src/request_processors/thread_processor.rs:1100, and codex-rs/app-server/src/bespoke_event_handling.rs:810 in the sibling source checkout. This is source-contract evidence, not a Codex runtime test claim.

Production: +229/-20 (net +209). Tests: +383/-7 (net +376). The production growth provides durable presentation ownership, guarded persistence, and first-chat atomic creation; it does not add another runtime store or restore the obsolete helper.

Terminal hosted CI and native preparation

Fresh human maintainer security approval on a4d57cb71504a4d19b0070e29c398763b9e24017 remains mandatory. The inherited-CI evidence does not supply that approval. No merge has been requested.

Announce, settle, and steer turns dropped the personal skill library from the deferred tool directory, so the parent prompt cache missed. Record the session listing and refuse those turns at execution instead.

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

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

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

Current SHA: 433d3d5a674e5ed9f26620f26c19f6f1edd6bfde

These sensitive security changes were made:

  • src/agents/stable-skill-authoring.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/server-methods/agent.caller-authority.test-utils.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/skill-library-authoring.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

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

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Persist skill-library presentation in session entries and restore it for background turns while refusing personal-library execution without an admitted grant.

Example: A parent conversation receives a spawned child's completion after the Gateway restarts.

  • Before: Without a human authoring grant or remembered presentation, skill_library disappears from the available tool surface.
  • After: The recorded skill_library definition remains available, but a personal-library call is refused until an authorized human turn.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The source change is coherent and retains distinct boundary coverage, but earlier behavior receipts do not validate the current persistence and admission path.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A conversation can lose its personal-library tool presentation on background turns after restart even though listing the tool need not authorize its execution.
Reason: Durable presentation extends the existing prompt-stability contract while preserving personal-library refusal and ordinary Workshop behavior.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR provides durable skill-library presentation that current main lacks; no actionable source defect was found.

Reviewed head: 433d3d5a674e5ed9f26620f26c19f6f1edd6bfde

Before merge

  • Add real behavior proof - Retained Gateway receipts at a4d57cb cover seven provider requests, completion refusal and post-restart human access, with teardown failure disclosed separately; later TurnGrant and transcript-lease changes materially affect that path, and the recorded upgrade starts at 2026.11.2 rather than latest stable v2026.11.10. The previous proof requests therefore remain applicable; redact credentials, IPs, phone numbers and non-public endpoints from replacement evidence. 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.
  • Await maintainer action - A human maintainer must review and approve the security-sensitive changes on head 433d3d5 through the enforced approval mechanism.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide Gateway evidence covering first chat, actual child completion, refusal and restart through the current TurnGrant/transcript-lease path, plus a v2026.11.10 upgrade preserving session settings and data; base-red/head-green regression execution is also not established.
Agent review details

How this fits together

Gateway turn preparation combines session-owned presentation facts with the current execution grant, then supplies tool definitions and guarded invocations to agent runtimes.

flowchart TD
  A[Human or completion turn] --> B[Gateway turn preparation]
  C[Session entry owner] --> B
  D[Admitted turn grant] --> B
  B --> E[Stable tool definition]
  E --> F[Execution gate]
  F --> G[Personal skill library]
Loading

Technical review

Best possible solution:

Keep bounded presentation facts under the existing session owner and retain admitted grants as the sole authority for personal-library execution.

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

Current-main source shows that Gateway authoring preparation returns no capability without a grant and stores no durable presentation; the original cached-directory mechanism was separately addressed by #197835, so the remaining reproducible boundary is presentation across completion and restart.

Is this the best way to solve the issue?

Using the existing session field store and execution gate fits the documented presentation-versus-authority contract without introducing another persistent owner or restoring the retired CLI helper.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +263, Tests +400, Docs +7, Other +1. Total +671 across 21 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 14 277 14 +263
Tests 5 409 9 +400
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 21 694 23 +671

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.

Review metrics

Metric Value Why it matters
Production versus test changes Production +277/-14; tests and test support +409/-9. Growth supports durable session presentation, first-chat persistence, and distinct storage, runtime, and authority boundaries.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #195328
Summary: The linked issue owns the original missing-tool report; another open candidate addresses in-process presentation, while merged work covers cached-directory and native-runtime portions.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record current-path Gateway completion and restart behavior.
  • Demonstrate upgrade from v2026.11.10 with existing session settings and data preserved.

Rating scale

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

Workflow

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

History

Review history (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-11-08T21:55:37.471Z sha 05ef13f :: blocked before merge. :: [P2] Preserve unsandboxed Workshop access for embedded internal turns
  • reviewed 2026-11-12T10:09:38.059Z sha a10c9a8 :: blocked before merge. :: none
  • reviewed 2026-11-12T11:19:07.574Z sha 00fc9d2 :: blocked before merge. :: none
  • reviewed 2026-11-19T07:31:41.961Z sha a4d57cb :: blocked before merge. :: none
  • reviewed 2026-11-27T02:01:50.995Z sha a302ef4 :: blocked before merge. :: none
  • reviewed 2026-11-27T02:22:34.739Z sha ccbda59 :: needs real behavior proof before merge. :: [P2] Add the allocation required by the test-line budget
  • reviewed 2026-11-27T02:34:37.176Z sha ae8d953 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-27T02:48:18.404Z sha 136003f :: needs real behavior proof before merge. :: none

Reviewed November 26, 2026, 10:09 PM ET / November 27, 2026, 03:09 UTC (Revision 12).

…essions

Admitted session entries are frozen, so writing the prompt listing onto them failed the turn. Keep the listing in the process map and the session patch, and ship the new module in the PR wrapper inventory.

Co-authored-by: Cursor <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 8, 2026
The fixture only had a session id, which shares no field with the listing parameter, so the gateway test typecheck rejected it.

Co-authored-by: Cursor <[email protected]>
AmoghAtreya and others added 2 commits November 8, 2026 12:19
Human turns were writing the new listing onto the caller's session entry, including frozen cache rows. Persist it through the session owner and read the committed row instead.

Co-authored-by: Cursor <[email protected]>
A sessionKey-only cache could erase or revive a listing after the store changed. Settle turns now follow the row that store published.

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

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 8, 2026
@vincentkoc vincentkoc self-assigned this Nov 19, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. label Nov 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Nov 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@AmoghAtreya

Copy link
Copy Markdown
Author

Thanks for porting this onto the latest TurnGrant and transcript-lease changes, @vincentkoc!

I’m holding off on pushing any new commits so we don’t reset the 433d3d5 security/CI state. Would you like me to run the updated Gateway completion/restart proof and v2026.11.10 upgrade check on 433d3d5 and update the PR description, or is there anything else you need from my side before security/workflow approval?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts security-review-required security-sensitive-changed 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.

Subagent announce/settle runs drop skill_library from the deferred tool directory, breaking the parent's prompt cache

2 participants