Skip to content

Commit b0c27e2

Browse files
authored
fix(skills): fork the foreground session for lean experience review (#129282)
## What Problem This Solves Skill Workshop experience review ran as an isolated agent with a re-rendered 60k-character transcript, its own bootstrap, and a trimmed tool surface. Every review was a cold request: no prompt-cache reuse, a large re-serialized trajectory, and a reasoning/tool profile that differed from the foreground turn. Autonomous updates could target any workspace skill, size limits allowed 40 KB skills to grow unchecked (one deployed workspace hit a 21 KB `SKILL.md`), the collection reviewer had to re-list every skill in its plan and read them under a fixed 24k-character budget (a 16-skill workspace failed every pass with "Read every current skill before reconciling"), collection review only recorded successes so a failing pass retried on every Gateway restart, and `openclaw skills curator status` showed nothing about what the last reviews did. ## Why This Change Was Made - **Warm fork.** Experience review now continues the finished turn from the same in-memory session prefix (same session identity, bootstrap, skills prompt, tool schemas, `promptCacheKey`), appends one short review message, and runs with `sessionPersistence: "detached"` so nothing it writes reaches the foreground transcript or session record. Only `skill_workshop` executes; every other tool keeps its schema for cache parity and fails with a next-step message. The gate wraps the core tool list before Code Mode / Tool Search compaction, so catalog-hidden tools stay gated while `tool_call`/`exec` remain callable. `src/agents/embedded-agent-runner/run/attempt.skills-policy.test.ts` asserts identical system-prompt and tool digests between a foreground turn and its review, and that `tool_call` reaches `skill_workshop` but not `read` during review. Code Mode swarm globals (`phase`, `log`, `agents.run`) are the `sessions_spawn` capability and gate on the same allowlist, so a review cannot emit foreground lifecycle events or launch collectors. The review shares the foreground session, so it no longer retires that session's MCP runtime on run end; it reuses the warm runtime like any turn. Accepted tradeoff: the review inherits foreground tool construction (it creates the session MCP runtime only when the session has none, and spawns per-attempt LSP servers only when configured), because splitting tool construction from the foreground turn would break the cache-parity invariant this PR exists for. - **One apply owner, rechecked at the write boundary.** `src/skills/workshop/autonomous-apply.ts` decides apply-vs-pending for both the post-review loop and foreground repair: creates and updates to Workshop-authored skills apply; updates to user-authored skills stay pending with a recorded reason. `applySkillProposalTransition` rechecks path-based ownership under the commit lock for non-operator actors (agent, or no actor), so a claim released after the pre-check cannot let an agent write a user-authored skill; gateway and CLI operators still approve any pending proposal. The user-authored pending write runs under the same commit lock and rereads the row, so an operator apply that lands first is kept. The old `auto-apply.ts` path and name-based `listWorkshopAuthoredSkillNames` are deleted. - **Sparse collection plan and model-relative reads.** The collection reviewer returns only `write` and `drop` entries; unlisted skills stay untouched, so a 16-skill workspace no longer has to restate 16 keeps. The skill read budget is derived from the model's context window (35%) instead of a fixed 24k characters, with the 10,000-character skill cap still enforced per skill. No windowed read parameters: a skill is read whole or not at all. - **Weekly cadence.** Collection review runs once every 7 days instead of daily (`REVIEW_INTERVAL_MS`), matching how slowly a skill library actually changes; the attempt is recorded before the model starts, so a failed pass does not retry on every restart. - **Lean cap.** `AUTONOMOUS_SKILL_MAX_CHARS = 10,000` in `src/skills/workshop/collection-contracts.ts` is enforced by the tool and by collection reconcile; an oversized skill may only shrink. Tool description, experience prompt, and collection prompt were rewritten around procedures-not-records, one trigger per branch, and "NOTHING_TO_LEARN is the correct answer for most turns". - **Detached runs end quietly.** A detached run writes no transcript or session record and runs under the foreground session key, so `attempt-finalize` now skips agent_end side effects for it: plugins do not observe the review as a foreground turn, and a deep review cannot schedule a successor review of itself. - **Recorded outcomes.** Experience review records `applied | proposed | nothing | failed` with usage; one attempt per turn, drop on error. `openclaw skills curator status` prints the last collection and experience review outcome. ## User Impact - Default `auto` mode: experience review reuses the foreground prompt cache and skips message/other tool execution, so review cost is one bounded continuation instead of a cold re-render. - Autonomous edits touch only Workshop-authored skills; handwritten skills surface as pending proposals for operator approval. - Autonomous `SKILL.md` results stay ≤ 10,000 characters. - Collection review runs weekly and succeeds on larger skill libraries. A workspace with no recorded attempt reviews at the first daily check after Gateway start; an upgraded install keeps its recorded last attempt and reviews once it is older than 7 days. The 10,000-character cap applies to the next autonomous write; existing oversized skills are only ever shrunk. - `openclaw skills curator status` shows the last collection and experience review outcome, time, and tokens. - Docs: https://docs.openclaw.ai/tools/self-learning, https://docs.openclaw.ai/tools/skill-workshop Related: #123866, #128871 both patch skills above the reviewer read budget; this PR caps autonomous skill size and restricts oversized skills to shrink-only rewrites. ## Evidence - Live gateway (Linux, Telegram, `xai` provider) at `133ffe3`: manual experience review on a real foreground turn → `nothing` (usage: 0 uncached input, 13,902 cached, 36 output — the forked review hit the foreground prompt cache); manual collection review over the workspace → `succeeded`; the three oversized skills were rewritten under the cap (21,002 → 9,449; 11,882 → 7,735; 10,300 → 7,413 bytes, originals in `skill-workshop/collection-backups/`), the rest untouched, and the pre-PR "Read every current skill before reconciling" failure is gone. The next foreground turn's automatic experience review recorded `nothing` and `openclaw skills curator status` shows both outcomes. The apply recheck, MCP-runtime change (`26e821f`), and detached agent_end skip (`7e4a506`) landed after that run and are covered by the regression tests below. - `pnpm test src/skills/workshop src/agents/tools/skill-workshop-tool src/gateway/server-methods/skills` plus `src/agents/embedded-agent-runner/run/attempt.skills-policy.test.ts`, `src/agents/embedded-agent-runner/run/attempt.tool-search-catalog-abort.test.ts`, `src/cli/skills-cli.curator.test.ts`, `src/agents/harness/tool-surface-bridge.test.ts` — green. New regression tests (`service.test.ts` agent-vs-operator apply on a user-authored skill and operator apply kept over a stale pending snapshot; `experience-review.apply.test.ts` no `cleanupBundleMcpOnRunEnd`; `attempt-phase-lifecycle.test.ts` no agent_end for a detached run; `code-mode-swarm.test.ts` swarm globals refused under the review allowlist) fail on the pre-fix code. - Dependent sweep: 46 test files importing the touched modules — green. - `oxfmt`, `scripts/run-oxlint.mjs` on changed files, `git diff --check` — clean. - `pnpm tsgo && pnpm check:test-types` on Blacksmith Testbox — clean. - Local ClawSweeper review (`gpt-5.6-terra`, high): `133ffe3` raised two findings (ownership recheck removed from the apply boundary; review retiring the shared session's MCP runtime), fixed in `26e821f`; `26e821f` raised one (detached review re-entering agent-end scheduling), fixed in `7e4a506`; `7e4a506` raised three: pending write racing an operator apply and Code Mode swarm globals bypassing the execution gate, both fixed in `e4b4322`; "prove detached review does not start configured MCP or LSP runtimes" is skipped as the cache-parity tradeoff stated above (LSP tool schemas come from the LSP runtime; the MCP runtime is session-owned and already warm). Maintainer decision on `e4b4322`: accepted — a detached review reuses the session MCP runtime and re-spawns configured per-attempt LSP servers exactly like a foreground turn; it still cannot execute them. - Unrelated CI on `26e821f`/`7e4a506`: `check-lint-core-2` (`max-lines` in `src/gateway/server-methods/models-list-result.ts`, unused param in `models.test.ts`, both from #129332) and `checks-node-compact-small-8` (`doctor-auth.profile-health.test.ts`, Claude CLI auth from #129052) fail identically on `main` run 32857954734; `checks-node-compact-small-31` pins plugin SDK export counts (`4340` vs `4342`) that #129052 moved — this PR touches no `src/plugin-sdk` file. On `e4b4322` the failing set is the same twelve `checks-node-compact` shards that fail on `main` run 32857954734 (`large-5/12/13/14/15/18/22`, `small-8/14/20/21/26`) plus `small-31`; `check-lint-core-2` passes here. None are fixed here; #129357 carries the `main` fix. - LOC (raw numstat): production +712 / −664 (net +48; the four review-fix commits after the live run add +76 / −26); tests + docs +1269 / −1238 (net +31).
1 parent ebf79b4 commit b0c27e2

66 files changed

Lines changed: 1982 additions & 1903 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3788,7 +3788,7 @@ src/skills/runtime/refresh.ts 3
37883788
src/skills/runtime/remote-probe-utils.ts 2
37893789
src/skills/runtime/remote-skills.ts 1
37903790
src/skills/security/clawhub-verdicts.ts 2
3791-
src/skills/workshop/experience-review.ts 2
3791+
src/skills/workshop/experience-review.ts 1
37923792
src/skills/workshop/history-scan.ts 2
37933793
src/skills/workshop/policy.ts 1
37943794
src/skills/workshop/store-record.ts 3

‎docs/cli/skills.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Notes:
142142
| `curator --json` | Accepted before or after a Curator leaf command, for example `curator --json status` or `curator status --json`. |
143143
| `list` | Default action when no subcommand is provided. |
144144
| `list`/`info`/`check` output | Rendered output goes to stdout. With `--json`, the machine-readable payload stays on stdout for pipes and scripts. |
145-
| `curator status --json` | Returns legacy age-based lifecycle state written by older releases. Daily collection review does not use this state. |
145+
| `curator status --json` | Returns legacy age-based lifecycle state written by older releases. Weekly collection review does not use this state. |
146146

147147
Community ClawHub skill installs and updates check trust before downloading.
148148
Versioned community archive releases use exact-release trust metadata.

‎docs/tools/self-learning.md‎

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ is no template or pattern-matching path: content that reaches a proposal was
4141
written by the reviewer against the Workshop authoring standards, never copied
4242
from conversation text.
4343

44-
After substantial work, OpenClaw can run one isolated background review to find
44+
After substantial work, OpenClaw can run one detached background review to find
4545
a reusable recovery technique or a stable procedure that would remove at least
4646
two future model or tool round trips. Deep turns the user interrupted qualify
4747
too: the wrong path and its correction are exactly the evidence worth keeping.
@@ -54,9 +54,7 @@ Experience review starts only when all of these conditions hold:
5454

5555
- the foreground turn completed or was interrupted, but did not end in a
5656
provider or prompt error;
57-
- the current turn used at least 10 model iterations, or same-sender shallow
58-
turns in the session accumulated that much unreviewed work (the accumulated
59-
review covers the bounded message window of those turns);
57+
- the current turn used at least 10 model iterations;
6058
- the run was an eligible foreground conversation, not cron, heartbeat, memory,
6159
overflow, hook, subagent, or review work;
6260
- the runtime reported the resolved provider, model, and actual availability of
@@ -67,22 +65,26 @@ Experience review starts only when all of these conditions hold:
6765
A later foreground completion in the same session restarts the quiet period.
6866
Only one experience review runs at a time. The foreground answer is never delayed.
6967

70-
The reviewer is isolated and biased toward small, well-evidenced captures. It
68+
The reviewer continues the finished turn from the same transcript prefix. This
69+
lets the provider reuse the foreground prompt cache. Its appended review message
70+
and tool results never enter the foreground transcript or session record.
71+
72+
The reviewer is detached and biased toward small, well-evidenced captures. It
7173
receives an authoritative receipt of the skills the foreground run actually
7274
read or command-invoked, plus a bounded workspace skill list. It prefers a used
7375
writable skill when that skill governs the learning, then another existing
7476
skill, and creates a new skill only when nothing covers the class.
7577

76-
Before changing an existing skill, the reviewer must read its complete current
77-
body. Both targeted patches and full-body rewrites bind the proposal to that
78-
read's content hash. Skills beyond the bounded read budget cannot be updated
79-
autonomously. A patch quotes the exact live text to change, while a rewrite must
80-
preserve everything still useful. In `auto` mode, either form goes through the
81-
same scanner-gated apply path without operator review. The one-mutation budget
82-
is shared across retries. The reviewer cannot apply, reject, quarantine,
83-
message, or use general agent tools itself; the orchestrating pipeline applies
84-
the finished capture only after the isolated review ends. The reviewed
85-
trajectory is evidence, not instructions.
78+
Before changing an existing skill, the reviewer reads its current body. Both
79+
update forms bind the proposal to that content hash. An oversized skill can be
80+
rewritten only when the result is shorter. Autonomous `SKILL.md` results stay at
81+
or below 10,000 characters. Longer reference and examples move into bundled
82+
files. The reviewer sees the foreground tool schemas, but only `skill_workshop`
83+
can execute. The reviewed transcript is evidence, not instructions.
84+
85+
Workshop-authored skills can apply automatically. Updates to user-authored skills
86+
stay pending with a reason for operator review. Each review gets one attempt.
87+
A failure is logged and dropped instead of retrying the turn.
8688

8789
Good candidates include:
8890

@@ -105,11 +107,11 @@ The reviewer should abstain for:
105107

106108
## Mode policy
107109

108-
| Mode | Capture behavior |
109-
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
110-
| `off` | Does not create experience-review captures. |
111-
| `propose` | Creates or revises pending proposals. Nothing applies automatically. |
112-
| `auto` | Creates or revises proposals, then applies every autonomous capture through the normal scanner-gated Workshop path. No operator review is required. This is the default. |
110+
| Mode | Capture behavior |
111+
| --------- | ----------------------------------------------------------------------------------------------------------------------------- |
112+
| `off` | Does not create experience-review captures. |
113+
| `propose` | Creates or revises pending proposals. Nothing applies automatically. |
114+
| `auto` | Applies autonomous creates and Workshop-authored updates. User-authored updates stay pending for review. This is the default. |
113115

114116
Set the mode with the CLI:
115117

@@ -147,18 +149,17 @@ Every learned skill receives these controls:
147149

148150
- **Security scan at apply:** Workshop reruns the scanner immediately before the
149151
live write. A critical finding quarantines the proposal instead of applying it.
150-
- **Workshop-owned writes:** creates target the selected workspace. Updates can
151-
target only skill directories owned by an applied Workshop `create` proposal.
152-
Handwritten workspace skills, plus bundled, plugin, managed, personal-agent,
153-
system, and extra-root skills, remain read-only.
152+
- **Workshop-owned writes:** creates target the selected workspace. Only updates
153+
to skills created by Workshop apply automatically. User-authored updates stay
154+
pending. Bundled, plugin, managed, system, and extra-root skills remain read-only.
154155
- **Hash binding:** update proposals bind to the current live skill and go stale
155156
if that target changes before apply.
156-
- **Read before update:** the reviewer must read the complete current skill
157-
before either a targeted patch or a full-body rewrite.
157+
- **Lean cap:** autonomous results stay at or below 10,000 characters. A skill
158+
already above the cap can only become shorter.
158159
- **Rollback metadata:** apply records the prior skill and support-file contents
159160
before the live write.
160-
- **Collection review:** once a day in `auto` mode, an isolated model session
161-
reads the workspace skills. Externally owned skills must be kept; only
161+
- **Collection review:** once a week in `auto` mode, an isolated model session
162+
reads the skills it intends to change. Externally owned skills stay untouched; only
162163
Workshop-owned paths can be rewritten or dropped. Collection-created skills
163164
receive automatically applied `create` proposal records.
164165
- **Collection backup:** review validates and scans every rewrite before changing
@@ -177,7 +178,7 @@ openclaw skills workshop reject <proposal-id> --reason "Not reusable"
177178
```
178179

179180
Applied captures remain visible in `openclaw skills workshop list` and retain
180-
their rollback metadata. The daily collection review can later improve, merge,
181+
their rollback metadata. The weekly collection review can later improve, merge,
181182
or remove them. This makes
182183
approval-free learning reversible and observable rather than silent.
183184

@@ -200,28 +201,24 @@ Experience review adds one bounded model run on the configured provider only
200201
after a substantial turn, not after every message. The review can make more
201202
than one provider request while it inspects or drafts its single proposal.
202203

203-
A deep-turn review receives only the current turn beginning with its most
204-
recent user message. A review triggered by accumulated shallow turns instead
205-
receives the bounded message window of those same-sender turns (at most 40
206-
messages); accumulation restarts whenever the sender, provider, model, or auth
207-
profile changes, so no turn is disclosed to a provider identity other than its
208-
own. Either way the rendered trajectory is limited to 60,000 characters; when
209-
the bundle is too large, OpenClaw keeps the first message and newest evidence
210-
and marks the omitted middle.
204+
The review forks the foreground transcript in memory and appends one small user
205+
message. It uses the same provider, model, auth profile, session identity,
206+
bootstrap context, skills prompt, and tool schemas. The provider can reuse the
207+
finished turn's cached request prefix. Review writes remain detached.
211208

212209
The reviewer reuses the foreground provider, model, and available auth identity,
213210
with model fallbacks disabled. Provider pricing and data-handling terms apply to
214211
the additional run.
215212

216-
Daily collection review also uses the configured agent model. It receives the
213+
Weekly collection review also uses the configured agent model. It receives the
217214
names, descriptions, and ownership state of eligible workspace skills, then reads each
218-
complete skill before making one atomic collection change. Disabled and
215+
skill it intends to change before one atomic call listing only changes. Disabled and
219216
agent-filtered skills stay untouched. Shared workspaces use the union of each
220217
agent's allowed skills only when provider, model, and resolved auth identity
221218
match. Reconciliation must leave every sharing agent at least one visible skill.
222219
It has no message tool or general agent tools. Skill bodies are treated as
223-
untrusted evidence, not as instructions. A persisted per-workspace success time
224-
prevents Gateway restarts from repeating the review within 24 hours. The
220+
untrusted evidence, not as instructions. A persisted per-workspace attempt time
221+
prevents Gateway restarts from repeating a failed or successful review within 7 days. The
225222
foreground agent can restore the one retained collection backup when asked to
226223
undo the cleanup, unless an affected skill changed afterward.
227224

@@ -274,7 +271,7 @@ result pending regardless of autonomous mode.
274271

275272
| Setting | Default | Effect |
276273
| ------------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------ |
277-
| `skills.workshop.autonomous.mode` | `"auto"` | Chooses capture behavior; `auto` also enables daily collection review. |
274+
| `skills.workshop.autonomous.mode` | `"auto"` | Chooses capture behavior; `auto` also enables weekly collection review. |
278275
| `skills.workshop.approvalPolicy` | `"auto"` | Controls prompts for normal agent-initiated lifecycle calls. It never expands the isolated reviewer tool surface. |
279276
| `skills.workshop.maxPending` | `50` | Caps pending and quarantined proposals per workspace. |
280277
| `skills.workshop.maxSkillBytes` | `40000` | Caps proposal body size in bytes. |
@@ -301,6 +298,8 @@ Check the following:
301298

302299
An eligible experience review can still abstain. No proposal is the expected
303300
result when the evidence does not clear the reusable-procedure bar.
301+
Use `openclaw skills curator status` to inspect the last collection and
302+
experience review outcomes.
304303

305304
### Doctor reports that Workshop is hidden
306305

@@ -316,7 +315,7 @@ Automatic apply runs once. Inspect the proposal and its scanner state:
316315
openclaw skills workshop inspect <proposal-id>
317316
```
318317

319-
A normal write or target failure leaves it pending for manual review. A critical
318+
A user-authored target or normal write failure leaves it pending for manual review. A critical
320319
scanner result moves it to quarantine. Fix the cause and apply manually; do not
321320
build a retry loop around automatic capture.
322321

0 commit comments

Comments
 (0)