Repository navigation
fix(skills): record skill usage again and retire dead curator tables - #129769
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
dca0b91 to
d98924d
Compare
|
Codex review: needs changes before merge. Reviewed August 26, 2026, 2:31 AM ET / 06:31 UTC. ClawSweeper reviewWhat this changesThe PR restores trusted skill-use accounting, retires obsolete curator tables through a schema-11 migration, and makes retired curator actions return explicit errors. Merge readinessKeep open: the skills repair remains useful, but the current head retains a P2 assertion-ratchet bypass that can misclassify string content as a SAFETY comment. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherSkill Workshop records and reviews workspace skills; trusted gateway diagnostic events feed usage facts into the shared state database, which drives curator status and collection-review prompts. flowchart LR
A[Agent reads a skill] --> B[Trusted skill-use event]
B --> C[Gateway maintenance]
C --> D[Shared state database]
D --> E[Curator status]
D --> F[Collection review]
G[Legacy curator tables] --> H[Schema migration]
H --> D
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +28, Tests +316, Docs +73, Config 0, Generated -20, Other 0. Total +397 across 50 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep the producer reconnection and table retirement, but restore parser-recognized SAFETY-comment detection with a same-line string-literal regression before merge. Do we have a high-confidence way to reproduce the issue? Yes, from source: an unsafe assertion followed on the same line by a string containing Is this the best way to solve the issue? No: the skill-state repair follows the producer and migration owners, but the concurrent ratchet rewrite weakens its enforcement contract and must be corrected. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2c9bcf33b513. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
Maintainer decision: archived-skill reactivation acceptedRecording the explicit acceptance ClawSweeper asks for on the schema-11 upgrade contract. This change was proposed to the maintainer before any code was written, and the reactivation behavior was stated as part of the proposal: hand archived rows to the new canonical owner — unarchive them and let the weekly collection review judge them by content, which may drop them, because that is its job. The maintainer accepted that design and directed the implementation. The alternative ClawSweeper lists (preserve archived state or expose a separate recovery path) was considered and rejected: keeping a lifecycle table alive purely to remember "archived" would preserve the exact producer gap this PR exists to close, since nothing has written that state since #121653 and no shipped code can create it. Accepted contract: state schema 11 drops Why this is safe in practice: the only thing archived state did was hide a skill from snapshots, and Rank-up moves
CI statusTwo jobs are red on this head and neither is attributable to this change:
Both are queued for rerun. Everything else is green (171 checks), and this will not be merged onto a red gate. |
13f5e2c to
e913b92
Compare
Correction: the earlier
|
e913b92 to
a33fc5b
Compare
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.
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.
a33fc5b to
7b2affc
Compare
|
Merged via squash.
|
The raw skipTrivia=false scanner in collectSafetyCommentLines never re-scanned the `}` ending a template substitution, so it lexed a phantom NoSubstitutionTemplateLiteral that swallowed every later comment in the file. #129769 already fixed this with per-line text matching, but shipped without a regression test, leaving the fix unpinned against reintroduction.
The raw skipTrivia=false scanner in collectSafetyCommentLines never re-scanned the `}` ending a template substitution, so it lexed a phantom NoSubstitutionTemplateLiteral that swallowed every later comment in the file. #129769 already fixed this with per-line text matching, but shipped without a regression test, leaving the fix unpinned against reintroduction.
) The raw skipTrivia=false scanner in collectSafetyCommentLines never re-scanned the `}` ending a template substitution, so it lexed a phantom NoSubstitutionTemplateLiteral that swallowed every later comment in the file. #129769 already fixed this with per-line text matching, but shipped without a regression test, leaving the fix unpinned against reintroduction.
…penclaw#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 (openclaw#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.
…claw#130191) The raw skipTrivia=false scanner in collectSafetyCommentLines never re-scanned the `}` ending a template substitution, so it lexed a phantom NoSubstitutionTemplateLiteral that swallowed every later comment in the file. openclaw#129769 already fixed this with per-line text matching, but shipped without a regression test, leaving the fix unpinned against reintroduction.
What Problem This Solves
Three shared-state tables in the skills workshop have producer gaps: code reads them, nothing writes them.
skill_usageandskill_lifecyclegot real producers in #101214 (shipped in stable v2026.7.1): a trustedskill.usedconsumer wrote usage, and a daily sweep aged skillsactive -> stale (30d) -> archived (90d). #121653 replaced age-based curation with the weekly collection review and deleted both producers, but left every reader in place. Since then:skills.curator.statusreportslastUsedAtMs: nullanduseCount: 0forever — theskill.usedevents are still emitted atsrc/agents/agent-tools.before-tool-call.diagnostics.ts:438, they just land nowhere.skills.curator.pin/unpin/restoreoperate on rows shipped code cannot create. On a fresh install they always throw "not found"; on a v2026.7.1-upgraded install pin silently succeeds and gates nothing, because the only consumer ofpinnedwas the deleted sweep. That is the silent-non-outcome class this repo treats as the worst bug.restoreonly works if a row exists).skill_workshop_proposal_origin_runsis different: it was born write-only in #114535. I checked the introducing commit and every revision since — there has never been aselectFromon it. Authoritative provenance isrecord_json(record.originRunIds, read atsrc/skills/workshop/service-query.ts:95).Separately,
SkillsCuratorStatusResultSchemaomittedcollectionReview/experienceRevieweven though the runtime returns them and the docs describe them.Why This Change Was Made
Restore the producer that has a real owner; retire what has none.
Usage is a fact worth recording: the weekly review currently judges skills on content alone and has no signal for "is this actually used". The events already exist, so the fix is to reconnect them at the owner boundary rather than delete a shipped protocol field.
Lifecycle curation has no owner left. Per the Architecture rules, legacy shapes normalize in doctor/migration code, not in steady-state runtime — so the table goes, and the archived rows are handed to the new canonical owner (the weekly review) rather than stranded.
The pin/unpin/restore methods stay registered on the wire because existing clients enumerate them (
apps/android/.../GatewayProtocol.kt:528-531), but they now fail loudly with an explanation instead of lying.User Impact
openclaw skills curator statusreports real usage again (useCount,lastUsedAtMs) plus collection/experience review outcomes.curator pin|unpin|restoreexit non-zero with: "Skill lifecycle curation is retired. The weekly collection review manages the skill collection; pin, unpin, and restore no longer exist." Previously pin appeared to work and did nothing.skill_lifecycleandskill_workshop_proposal_origin_runs. Previously archived Workshop skills return to the active collection, where the weekly review judges them by content. The migration logs how many. This is the one operator-visible state change; it is documented, including a manual 11 -> 10 downgrade recipe.useCount/lastUsedDaysAgoper skill, with prompt text stating usage supports keeping a procedure and never alone justifies a drop.Evidence
Live proof on an isolated rig (own
OPENCLAW_STATE_DIR, port 19178; the operator's Gateway was never touched):[state/db] 1 previously archived workshop skills return to the active collection; the weekly collection review will judge them. Result:user_version 11,schema_meta 11, both tables and bothidx_skill_lifecycle_*indexes gone,skill_usage/skill_curator_state/record_jsonprovenance intact,PRAGMA quick_check: ok.skill_usagegained its row (use_count: 1,skill_source: workspace,last_agent_id: main). A second turn:use_count: 2,first_used_at_msheld,last_used_at_msadvanced — the upsert semantics are correct.skills curator statusthen reporteduseCount: 2with a reallastUsedAtMs(previously permanently0/null).skills curator pinagainst the live Gateway: WS logres ✗ skills.curator.pin errorCode=INVALID_REQUEST ...retired..., CLI exit code 1 on stderr.Regression coverage: the usage-producer test fails on pre-fix code (no producer exists). Added tests for the v11 migration through both runtime-open and doctor-repair paths, status derivation from applied create proposals, reconcile clearing usage only for dropped skills, prompt usage evidence, and the retired gateway methods. Tests for removed behavior were deleted rather than updated.
Gates: full
check-changed(all lanes, including Swift lint and the native schema guard at v11), plus the state, migration, workshop, CLI, gateway, and protocol suites. Autoreview (Codexgpt-5.6-sol) reported no P0 findings.Notes for reviewers
Scope beyond the reported gap (Pathfinder / same-invariant work, called out deliberately):
scripts/check-assertion-safety-ratchet.mts(separate commit). Its rawts.createScannerloop read the}closing a template-literal substitution as a block close, desyncing the scanner so every// SAFETY:comment after a file's first${...}was invisible. Replaced the 52-line token scanner with a 17-line line scan, which removes the desync bug class entirely and produces a byte-identical baseline across all 4,256 tracked files. The fix reveals already-annotated assertions in eight unrelated files, so the baseline shrinks (shrink-only ratchet maintenance).openclaw-state-db-schema-repair.tscrossed the 700-linemax-linescap, so retirement code moved toopenclaw-state-db-table-retirements.ts. That module now owns both retirements and exposes onerunRetiredStateTableMigrations, replacing duplicated call sequences at two sites inopenclaw-state-db.ts— the ordering and the operator-visible labels can no longer drift apart. Nomax-linessuppression was added.assertOpenClawStateDatabaseV<N>ForMigrationguard; v10 had none, so the v11 migration would have run without the ownership/table-presence check its siblings enforce. Added.satisfies neverswitches (src/infra/state-migrations.doctor.tsandextensions/voice-call/doctor-contract-api.ts) — the guards working as designed.toBe(10)); they now assertOPENCLAW_STATE_SCHEMA_VERSIONso the next bump does not break them.Sequencing: this was authored as schema v10 and rebased to v11 after the six-dead-table retirement landed first. Both retirements now share one owner module, and the pinned pre-v10 audit reader undoes both in schema order.
Production LOC: net -1 against the merge base, with tests +346 and docs +73. Getting there meant deleting three kinds of waste rather than trimming behavior: the retirements ledger was reformatted wholesale by a generator (six unrelated entries churned) and is now an append of two records; the relocated commitments schema carried two 43-line SQL constants differing only by
) STRICT;and two indexes, now composed from shared column and index fragments (verified byte-identical before rewriting, and the v6→v7 fingerprint tests still pass); and the assertion ratchet's 52-line token scanner became a 17-line line scan that produces a byte-identical baseline across all 4,256 tracked files.skill_usagealso gained a single reader shared by curator status and the review prompt, replacing the same query written twice.