Skip to content

Commit 4bd8859

Browse files
authored
fix(skills): record skill usage again and retire dead curator tables (#129769)
* fix(scripts): see SAFETY comments after template substitutions The assertion ratchet scanned each file with a raw ts.createScanner, which reads the `}` closing a template-literal substitution as a block close. The scanner desynced there, so every `// SAFETY:` comment after a file's first `${...}` was invisible and its annotated assertions were counted as bare. Track substitution brace depth and rescan the closing brace the way the parser does. The fix uncovers already-annotated assertions in eight files, so the baseline shrinks accordingly. * fix(skills): record skill usage again and retire dead curator tables Skill lifecycle curation shipped in 2026.7.1 with two producers: a trusted `skill.used` consumer writing `skill_usage`, and a daily sweep aging skills into `skill_lifecycle`. The weekly collection review (#121653) replaced that policy and deleted both producers, but left every reader in place. Since then `skill_usage` has had no writer, so curator status reported `lastUsedAtMs: null` and `useCount: 0` forever, and `skill_lifecycle` had no writer either, so pin/unpin/restore either threw "not found" on fresh installs or, worse, "succeeded" on upgraded ones while gating nothing at all. `skill_workshop_proposal_origin_runs` was never read in any revision; proposal provenance is authoritative in `record_json`. Restore the usage producer at its owner and retire what has no owner: - `skill.used` events populate `skill_usage` again, registered with the collection-review maintenance it belongs beside. Curator status derives curated skills from applied Workshop create proposals and reports real usage. - Weekly review receives bounded `useCount` / `lastUsedDaysAgo` evidence, with prompt text stating usage supports keeping a procedure and never alone justifies a drop. - State schema 10 drops `skill_lifecycle` and `skill_workshop_proposal_origin_runs`. Previously archived skills return to the active collection, where review judges them by content; the migration logs how many. Reconcile now clears usage only for skills it actually drops. - `skills.curator.pin`/`unpin`/`restore` stay registered for existing clients but fail with an explicit retirement message instead of silently doing nothing. Retirement code moves to openclaw-state-db-table-retirements.ts to keep the schema-repair module under max-lines; that split is a pure relocation. Production delta is +23 raw: about -46 for the change itself, +44 for the file split, +25 for the ratchet fix in the previous commit.
1 parent c2f98e3 commit 4bd8859

50 files changed

Lines changed: 1299 additions & 902 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.

‎apps/macos/Tests/OpenClawIPCTests/PortGuardianRecordStoreTests.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ struct PortGuardianRecordStoreTests {
568568
let fixture = try Self.fixture()
569569
defer { fixture.cleanup() }
570570

571-
for version in [4, 5, 6, 7, 8, 9, 10] {
571+
for version in [4, 5, 6, 7, 8, 9, 10, 11] {
572572
let databaseURL = fixture.root.appendingPathComponent("supported-v\(version).sqlite")
573573
try Self.seedVersionedPortGuardianDatabase(databaseURL, schemaVersion: version)
574574
let store = try PortGuardianRecordStore(databaseURL: databaseURL)
@@ -580,7 +580,7 @@ struct PortGuardianRecordStoreTests {
580580
#expect(try store.records() == [record])
581581
}
582582

583-
for version in [11, 99] {
583+
for version in [12, 99] {
584584
let databaseURL = fixture.root.appendingPathComponent("newer-v\(version).sqlite")
585585
try Self.seedVersionedPortGuardianDatabase(databaseURL, schemaVersion: version)
586586
#expect(throws: PortGuardianStoreError.self) {

‎apps/shared/OpenClawKit/Sources/OpenClawNativeState/OpenClawNativeStateSQLite.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public enum OpenClawNativeStateSQLiteValueType: Equatable, Sendable {
3737
/// One recursive connection lock serializes transactions and statement access.
3838
public final class OpenClawNativeStateSQLite: @unchecked Sendable {
3939
// Keep aligned with OPENCLAW_STATE_SCHEMA_VERSION. Native clients never upgrade this database.
40-
private static let maximumSupportedSchemaVersion: Int64 = 10
40+
private static let maximumSupportedSchemaVersion: Int64 = 11
4141
private static let defaultBusyTimeoutMilliseconds: Int32 = 5000
4242

4343
private struct SchemaObject: Hashable {

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15549,6 +15549,8 @@ public struct SkillsCuratorStatusResult: Codable, Sendable {
1554915549
public let lastattemptatms: AnyCodable
1555015550
public let lastsuccessatms: AnyCodable
1555115551
public let lasterror: AnyCodable
15552+
public let collectionreview: [String: AnyCodable]?
15553+
public let experiencereview: [String: AnyCodable]?
1555215554
public let counts: [String: AnyCodable]
1555315555
public let skills: [SkillsCuratorActionResult]
1555415556
public let overlaps: [[String: AnyCodable]]
@@ -15557,13 +15559,17 @@ public struct SkillsCuratorStatusResult: Codable, Sendable {
1555715559
lastattemptatms: AnyCodable,
1555815560
lastsuccessatms: AnyCodable,
1555915561
lasterror: AnyCodable,
15562+
collectionreview: [String: AnyCodable]? = nil,
15563+
experiencereview: [String: AnyCodable]? = nil,
1556015564
counts: [String: AnyCodable],
1556115565
skills: [SkillsCuratorActionResult],
1556215566
overlaps: [[String: AnyCodable]])
1556315567
{
1556415568
self.lastattemptatms = lastattemptatms
1556515569
self.lastsuccessatms = lastsuccessatms
1556615570
self.lasterror = lasterror
15571+
self.collectionreview = collectionreview
15572+
self.experiencereview = experiencereview
1556715573
self.counts = counts
1556815574
self.skills = skills
1556915575
self.overlaps = overlaps
@@ -15573,6 +15579,8 @@ public struct SkillsCuratorStatusResult: Codable, Sendable {
1557315579
case lastattemptatms = "lastAttemptAtMs"
1557415580
case lastsuccessatms = "lastSuccessAtMs"
1557515581
case lasterror = "lastError"
15582+
case collectionreview = "collectionReview"
15583+
case experiencereview = "experienceReview"
1557615584
case counts
1557715585
case skills
1557815586
case overlaps

‎config/assertion-safety-baseline.txt‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ extensions/discord/src/monitor/provider.deploy.ts 4
410410
extensions/discord/src/monitor/provider.lifecycle.ts 2
411411
extensions/discord/src/monitor/provider.startup-log.ts 1
412412
extensions/discord/src/monitor/provider.startup.ts 2
413-
extensions/discord/src/monitor/provider.ts 1
414413
extensions/discord/src/monitor/reply-context.ts 1
415414
extensions/discord/src/monitor/reply-safety.ts 1
416415
extensions/discord/src/monitor/rest-fetch.ts 3
@@ -469,7 +468,7 @@ extensions/feishu/src/card-action.ts 1
469468
extensions/feishu/src/card-interaction.ts 1
470469
extensions/feishu/src/channel.ts 9
471470
extensions/feishu/src/chat.ts 2
472-
extensions/feishu/src/client.ts 5
471+
extensions/feishu/src/client.ts 4
473472
extensions/feishu/src/comment-handler.ts 2
474473
extensions/feishu/src/comment-reaction.ts 2
475474
extensions/feishu/src/comment-shared.ts 1
@@ -590,7 +589,7 @@ extensions/imessage/src/monitor/catchup-bridge.ts 1
590589
extensions/imessage/src/monitor/catchup.ts 2
591590
extensions/imessage/src/monitor/conversation-repair.ts 1
592591
extensions/imessage/src/monitor/inbound-processing.ts 2
593-
extensions/imessage/src/monitor/monitor-provider.ts 3
592+
extensions/imessage/src/monitor/monitor-provider.ts 2
594593
extensions/imessage/src/probe.ts 1
595594
extensions/imessage/src/remote-host.ts 1
596595
extensions/imessage/src/send.ts 5
@@ -922,7 +921,7 @@ extensions/ollama/src/provider-models.ts 1
922921
extensions/ollama/src/setup-pull.ts 1
923922
extensions/ollama/src/setup.runtime.ts 1
924923
extensions/ollama/src/stream-compat.ts 1
925-
extensions/ollama/src/stream.runtime.ts 7
924+
extensions/ollama/src/stream.runtime.ts 6
926925
extensions/onepassword/index.ts 2
927926
extensions/onepassword/src/op-client.ts 2
928927
extensions/onepassword/src/tool.ts 1
@@ -1290,7 +1289,7 @@ extensions/telegram/src/message-cache.ts 10
12901289
extensions/telegram/src/miniapp/command.ts 1
12911290
extensions/telegram/src/miniapp/init-data.ts 1
12921291
extensions/telegram/src/miniapp/routes.ts 1
1293-
extensions/telegram/src/monitor.ts 3
1292+
extensions/telegram/src/monitor.ts 2
12941293
extensions/telegram/src/network-config.ts 1
12951294
extensions/telegram/src/network-errors.ts 8
12961295
extensions/telegram/src/outbound-adapter.ts 5
@@ -1394,7 +1393,7 @@ extensions/whatsapp/src/approval-handler.runtime.ts 1
13941393
extensions/whatsapp/src/approval-native.ts 1
13951394
extensions/whatsapp/src/approval-reactions.ts 1
13961395
extensions/whatsapp/src/auth-store.ts 3
1397-
extensions/whatsapp/src/auto-reply/monitor.ts 3
1396+
extensions/whatsapp/src/auto-reply/monitor.ts 2
13981397
extensions/whatsapp/src/auto-reply/monitor/inbound-dispatch.ts 4
13991398
extensions/whatsapp/src/auto-reply/monitor/process-message.ts 2
14001399
extensions/whatsapp/src/channel-outbound.ts 1
@@ -2539,7 +2538,7 @@ src/commands/doctor-session-incognito-key-repair.ts 4
25392538
src/commands/doctor-session-snapshots.ts 5
25402539
src/commands/doctor-session-sqlite-compact.ts 1
25412540
src/commands/doctor-session-sqlite-migration-run.ts 8
2542-
src/commands/doctor-session-sqlite-readers.ts 11
2541+
src/commands/doctor-session-sqlite-readers.ts 9
25432542
src/commands/doctor-session-sqlite-recover-report.ts 3
25442543
src/commands/doctor-session-sqlite.ts 3
25452544
src/commands/doctor-session-state-providers.ts 3
@@ -3814,7 +3813,7 @@ src/state/openclaw-state-db-readonly.ts 1
38143813
src/state/openclaw-state-db-schema-additive.ts 1
38153814
src/state/openclaw-state-db-schema-helpers.ts 4
38163815
src/state/openclaw-state-db-schema-migration-required.ts 2
3817-
src/state/openclaw-state-db-schema-repair.ts 7
3816+
src/state/openclaw-state-db-schema-repair.ts 2
38183817
src/state/openclaw-state-ownership.ts 1
38193818
src/state/openclaw-state-snapshot-sanitizer.ts 1
38203819
src/state/user-profiles-tailscale-avatar.ts 2

‎docs/cli/skills.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ Notes:
151151
| `curator --json` | Accepted before or after a Curator leaf command, for example `curator --json status` or `curator status --json`. |
152152
| `list` | Default action when no subcommand is provided. |
153153
| `list`/`info`/`check` output | Rendered output goes to stdout. With `--json`, the machine-readable payload stays on stdout for pipes and scripts. |
154-
| `curator status --json` | Returns legacy age-based lifecycle state written by older releases. Weekly collection review does not use this state. |
154+
| `curator status --json` | Reports live Workshop skill usage recorded from trusted `skill.used` events and the latest collection and experience review outcomes per workspace. |
155+
| `curator pin`/`unpin`/`restore` | Retired commands remain registered but return an error explaining that weekly collection review manages the skill collection. |
155156

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

‎docs/reference/database-schemas.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ Version 3 was an unshipped development step folded into version 4.
127127
| 8 | Cloud-worker placement execution modes and mode-aware turn claims | Unreleased |
128128
| 9 | In-root agent database registry paths stored relative to the state directory | Unreleased |
129129
| 10 | Six dead tables retired (agent_model_catalogs, android_notification_recent_packages, command_log_entries, diagnostic_stability_bundles, media_blobs, model_capability_cache) | Unreleased |
130+
| 11 | Legacy skill curator lifecycle table and never-read proposal origin-run projection retired | Unreleased |
131+
132+
### State schema 11
133+
134+
Schema 11 removes the `skill_lifecycle` and `skill_workshop_proposal_origin_runs` tables. Archived-skill lifecycle state is discarded during the upgrade: previously archived Workshop skills return to the active collection, where weekly collection review judges them by content. The origin-run rows were a never-read projection; canonical proposal provenance stays in `skill_workshop_proposals.record_json`. Recorded skill usage and collection-review state are preserved.
130135

131136
### State schema 9
132137

@@ -183,6 +188,60 @@ The general procedure is:
183188
3. Set `PRAGMA user_version` and `schema_meta.schema_version` to the target version.
184189
4. Run the target release's full database verification before starting the Gateway.
185190

191+
### Example: state schema 11 to 10
192+
193+
Schema 11 removed the retired skill lifecycle table and the never-read proposal
194+
origin-run projection. A schema 10 build still requires both canonical tables, so
195+
a manual downgrade must recreate their exact empty schemas and lifecycle indexes
196+
before lowering the version.
197+
198+
Run equivalent SQL against the global state database after inspecting the exact
199+
schema that wrote it:
200+
201+
```sql
202+
BEGIN IMMEDIATE;
203+
204+
CREATE TABLE skill_lifecycle (
205+
skill_file TEXT NOT NULL PRIMARY KEY,
206+
skill_key TEXT NOT NULL,
207+
skill_name TEXT NOT NULL,
208+
state TEXT NOT NULL CHECK (state IN ('active', 'stale', 'archived')),
209+
pinned INTEGER NOT NULL DEFAULT 0,
210+
state_changed_at_ms INTEGER NOT NULL,
211+
created_at_ms INTEGER NOT NULL,
212+
archived_reason TEXT
213+
) STRICT;
214+
215+
CREATE INDEX idx_skill_lifecycle_key
216+
ON skill_lifecycle(skill_key, skill_file);
217+
218+
CREATE INDEX idx_skill_lifecycle_state
219+
ON skill_lifecycle(state, skill_file);
220+
221+
CREATE TABLE skill_workshop_proposal_origin_runs (
222+
proposal_id TEXT NOT NULL,
223+
run_id TEXT NOT NULL,
224+
position INTEGER NOT NULL,
225+
mutation_count INTEGER NOT NULL CHECK (mutation_count > 0),
226+
PRIMARY KEY (proposal_id, run_id),
227+
FOREIGN KEY (proposal_id) REFERENCES skill_workshop_proposals(proposal_id) ON DELETE CASCADE
228+
) STRICT;
229+
230+
PRAGMA user_version = 10;
231+
UPDATE schema_meta
232+
SET schema_version = 10,
233+
updated_at = unixepoch('now') * 1000
234+
WHERE meta_key = 'primary';
235+
236+
COMMIT;
237+
```
238+
239+
Both recreated tables start empty. The upgrade discarded archived-skill
240+
lifecycle state, so those skills returned to the active collection and a manual
241+
downgrade cannot recover their previous archived state. Proposal origin-run
242+
rows were never read; authoritative provenance remains in each proposal's
243+
`record_json`. A botched downgrade means restore from the verified backup.
244+
186245
### Example: state schema 10 to 9
187246

188247
Schema 10 removed six dead shared-state tables. A schema 9 build still requires those canonical tables and indexes, so a manual downgrade must recreate their exact empty schemas before lowering the version.

‎docs/tools/self-learning.md‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,15 @@ with model fallbacks disabled. Provider pricing and data-handling terms apply to
211211
the additional run.
212212

213213
Weekly collection review also uses the configured agent model. It receives the
214-
names, descriptions, and ownership state of eligible workspace skills, then reads each
215-
skill it intends to change before one atomic call listing only changes. Disabled and
216-
agent-filtered skills stay untouched. Shared workspaces use the union of each
217-
agent's allowed skills only when provider, model, and resolved auth identity
218-
match. Reconciliation must leave every sharing agent at least one visible skill.
219-
It has no message tool or general agent tools. Skill bodies are treated as
214+
names, descriptions, ownership state, and available usage counts and last-used
215+
recency of eligible workspace skills, then reads each skill it intends to change
216+
before one atomic call listing only changes. Usage is supporting evidence: heavy
217+
use favors preserving a skill's procedure, while no recorded use alone never
218+
justifies dropping it. Disabled and agent-filtered skills stay untouched. Shared
219+
workspaces use the union of each agent's allowed skills only when provider,
220+
model, and resolved auth identity match. Reconciliation must leave every
221+
sharing agent at least one visible skill. It has no message tool or general
222+
agent tools. Skill bodies are treated as
220223
untrusted evidence, not as instructions. A persisted per-workspace attempt time
221224
prevents Gateway restarts from repeating a failed or successful review within 7 days. The
222225
foreground agent can restore the one retained collection backup when asked to
@@ -299,7 +302,9 @@ Check the following:
299302
An eligible experience review can still abstain. No proposal is the expected
300303
result when the evidence does not clear the reusable-procedure bar.
301304
Use `openclaw skills curator status` to inspect the last collection and
302-
experience review outcomes.
305+
experience review outcomes alongside live skill usage. Age-based curation is
306+
retired; the `curator pin`, `unpin`, and `restore` commands return an error
307+
explaining that weekly collection review manages the skill collection.
303308

304309
### Doctor reports that Workshop is hidden
305310

‎docs/tools/skill-workshop.md‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ skill created during collection review is recorded as an automatically applied
7272
`create` proposal, which makes that directory Workshop-owned. Disabled and
7373
agent-filtered skills stay untouched.
7474

75+
Recorded usage counts and last-used recency are supporting evidence, not an
76+
age-based lifecycle: heavy use favors preserving a skill's procedure, while no
77+
recorded use alone never justifies removing it.
78+
7579
Skills that predate ownership tracking, including skills that earlier reconcile
7680
runs created directly, have no applied `create` proposal. Skill Workshop
7781
intentionally classifies them as user-authored and read-only. It manages only
@@ -420,9 +424,12 @@ Proposal descriptions are always capped at 160 bytes, independent of
420424
| `skills.curator.unpin` | `operator.admin` |
421425
| `skills.curator.restore` | `operator.admin` |
422426

423-
`skills.curator.status` also reports the latest collection and experience review
424-
outcome per workspace. The other curator methods manage lifecycle state written
425-
by older releases. Weekly review does not use age, pin, or overlap state.
427+
`skills.curator.status` reports live skill usage recorded from trusted
428+
`skill.used` events, plus the latest collection and experience review outcomes
429+
per workspace. Age-based skill lifecycle curation is retired.
430+
`skills.curator.pin`, `skills.curator.unpin`, and `skills.curator.restore` remain
431+
registered for existing clients, but always return an error explaining that the
432+
weekly collection review now manages the skill collection.
426433

427434
`requestRevision` is Gateway-only (no CLI or agent-tool equivalent): it
428435
forwards free-text revision instructions to the owning agent's chat session
@@ -450,8 +457,9 @@ proposals.
450457

451458
Default state directory: `~/.openclaw`.
452459

453-
- `state/openclaw.sqlite`: canonical proposal records, the active generation
454-
reference, lifecycle status, origin attribution, and apply rollback metadata.
460+
- `state/openclaw.sqlite`: canonical proposal records and provenance, the active
461+
generation reference, proposal status, recorded skill usage, collection and
462+
experience review outcomes, and apply rollback metadata.
455463
- Each generation contains one `PROPOSAL.md` and all of that revision's support
456464
files. Revision publication never overwrites the active generation in place.
457465
- Generation files are flushed before publication. After the complete bundle is

‎extensions/voice-call/doctor-contract-api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ function describeVoiceCallSchemaMigration(migration: OpenClawStateDatabaseSchema
146146
return "retired commitments storage -> removed table and indexes";
147147
case "state-table-retirement-v10":
148148
return "retired shared-state tables -> removed tables and indexes";
149+
case "state-table-retirement-v11":
150+
return "retired skill curator tables -> removed tables and indexes";
149151
case "worker-placement-execution-mode-v8":
150152
return "cloud worker placements -> execution-mode claims";
151153
case "operator-approvals-system-agent":

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "2026.8.1",
44
"openclaw": {
55
"schemaVersions": {
6-
"state": 10,
6+
"state": 11,
77
"agent": 17
88
}
99
},

0 commit comments

Comments
 (0)