Skip to content

perf(skills): project the skill library once per catalog instead of four reads per entry - #165106

Merged
steipete merged 3 commits into
mainfrom
steipete/sqlite-skill-library-projection
Oct 4, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/sqlite-skill-library-projection

Conversation

@steipete

@steipete steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large skill libraries repeat actor, owner, and revision reads for every entry; new-session seeding also projects disabled skills before discarding them.

Related: #164165

User Impact

Library lists and new-session defaults avoid repeated SQLite calls and avatar copying. Disabled skills remain visible and explicitly attachable, but are excluded from default-seed SQL selection. Ownership, role ceilings, selected revisions, and the 64-skill selection limit are preserved. No schema, retention, configuration, or update migration changes.

Why This Change Was Made

Resolve the actor once inside the existing worker snapshot, join revision descriptions, and prepare owner metadata in bounded 500-ID cohorts using the existing profile owner. Catalog and exact reads share one prepared projection. Scoped display and session attachable entries reuse one catalog, with host authority rechecked after awaits.

This also restores the enabled-only seed selection lost in #164165. The older wide-profile fallback predates that PR. The supplied profile-metadata prerequisite is included here; legacy optional-column and malformed-value behavior remains intact. One consolidation pass folded the shared list projection into the existing store owner and removed the extra file.

Evidence

Production LOC: +202/-161 (net +41), accepted by the coordinator as a LOC-positive exception

Tests: +301/-5 (net +296). Counts use the branch merge base; unrelated changes from concurrently advancing origin/main are excluded.

The 2026-10-04 read-only measurements of team.openclaw.ai, label user_profiles, show 5.9 MiB for 75 rows, approximately 80 KiB per row. Production skill cardinality and list frequency were not supplied, and no specific slow-hold label was recorded for this path.

Component probe Before After
100 same-owner entries, fresh admitted read-only handle 404 native calls 5 native calls
Avatar BLOB bytes returned by that list 8,273,920 0
Disabled-only seed rows projected (100 rows before; 501 after) 100 0
Avatar BLOB bytes returned by disabled-only seed 8,273,920 0

The final 501-owner catalog, including merged aliases, missing profiles, and missing merge targets, takes 7 native calls. Its disabled-only seed takes 3 calls and returns zero pins, while general listing still returns all 501 entries. Counts include one freshness probe. Work scales with owner/alias cohorts; these component counts and transient bytes copied are not end-to-end timing or retained-leak claims. The supplied earlier 64-entry probe independently recorded 260 calls and 5,324,800 avatar bytes.

The regression failed on the original path, then passed after the change. The final counter case takes 1.218 seconds of test time. Existing worker-boundary cases retain no-host-SQL and live-authority revocation proof. The Gateway case verifies one catalog read for scoped display and attachable entries; the large-catalog fixture verifies that narrowing to “mine” clears an inapplicable limit notice.

All commands below used an isolated TMPDIR and --maxWorkers=1:

Command Result Wall seconds
pnpm test src/skills/library/service.test.ts --maxWorkers=1 26 passed 87.70
pnpm test src/skills/library/selection-authority.test.ts --maxWorkers=1 14 passed 28.85
pnpm test src/skills/library/service-roles.test.ts --maxWorkers=1 1 passed 21.23
pnpm test src/skills/library/mutations-worker.test.ts --maxWorkers=1 5 passed 25.22
pnpm test src/skills/library/persistence.test.ts --maxWorkers=1 3 passed 46.91
pnpm test src/state/user-profiles.test.ts --maxWorkers=1 27 passed 40.20
pnpm test src/gateway/server-methods/skills-library.test.ts --maxWorkers=1 6 passed 35.63

The service and persistence suites exercise real worker publication, retained files, and process lifetimes; their duration includes that boundary proof and test-worker setup. Unchanged role, mutation, persistence, and profile proof was reused after the pure list-projection consolidation. CI seconds are not yet available; this PR's first run will provide them.

Formatting, scoped oxlint, git diff --check, pnpm check:assertion-safety, pnpm check:max-lines-ratchet, pnpm check:line-cap-ratchet, and pnpm check:database-worker-ratchet passed. The worker inventory follows the renamed selector; SQL remains in its existing worker. Codex autoreview: scoped-clean at P2, first round, no accepted/actionable findings.

Select profile metadata from admitted schema facts so separate read-only
handles use the narrow cached query instead of copying avatar BLOBs.
Share the existing fact-keyed role detector with display and avatar reads.

Keep historical role-absent tables, one-hop merges, live role revocation,
and malformed non-BLOB conversion behavior. Unadmitted display handles
still need the column probe; authorizer-controlled ensured writers need
the existing ensure fallback to avoid probes and unrelated denied columns.
Preserving those contracts requires +21/-11 production LOC, net +10.

The admitted-reader regression returns zero avatar bytes instead of
655360 across two three-entry lists, with 26 profile statements unchanged.
Both focused suites pass: 27 profile tests and 13 library authority tests.
Resolve actor authority once per catalog, join revision descriptions, and
prepare bounded owner metadata through the existing profile owner. Reuse
one catalog for scoped display and session attachment while preserving
worker snapshots and host authority readback.

Restore enabled-only SQL selection for new-session seeds (Related: #164165).
The 100-entry probe drops from 404 to 5 native calls and from 8,273,920
avatar bytes to zero. Disabled-only seeds no longer project disabled rows.

The combined +41 production-line delta, including the profile-metadata
prerequisite, is accepted by the coordinator as a LOC-positive exception.
@clawsweeper

clawsweeper Bot commented Oct 4, 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 gateway Gateway runtime scripts Repository scripts size: L labels Oct 4, 2026
@steipete
steipete marked this pull request as ready for review October 4, 2026 20:51
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 4:56 PM ET / 20:56 UTC.

ClawSweeper review

What this changes

The PR batches skill-library ownership and revision reads, avoids copying profile avatars, reuses one catalog for session browsing, and excludes disabled skills from default-seed queries.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still performs per-entry projection reads. No actionable correctness or security defect was found in the introduced changes.

Priority: P2
Reviewed head: c18dfa67b5ce0eb38ee43f4694294b7f0c89b941

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful regression coverage and no supported blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-state context identifies a member-authored PR, so the external-contributor proof gate does not apply. Inspected SQLite counter and worker-boundary tests support the changed projection path; reported measurements are component evidence, and this reviewer ran no target code. No stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-state context identifies a member-authored PR, so the external-contributor proof gate does not apply. Inspected SQLite counter and worker-boundary tests support the changed projection path; reported measurements are component evidence, and this reviewer ran no target code. No stored-data contract changes require migration proof.
Evidence reviewed 10 items Introduced patch: Reviewed the pinned merge-base-to-head changes, including the profile-metadata prerequisite; endpoint drift was not attributed to this PR.
Current-main necessity: Current main's list implementation still projects each entry separately through projectSkillLibraryEntry; the submitted batching remains distinct useful work.
Catalog ownership and filtering: The shared selector joins the requested revision, batches owner displays in 500-ID cohorts, records original and canonical profile dependencies, and preserves private-entry visibility and edit checks.
Findings None None.
Security None None.

How this fits together

The skill library stores personal and shared skills with immutable revisions. Gateway requests and new-session admission read this library through SQLite workers to produce visible catalogs and session selections.

flowchart TD
  A[Gateway request or new session] --> B[Captured operator authority]
  B --> C[SQLite worker snapshot]
  C --> D[Skills and revision metadata]
  C --> E[Batched profile metadata]
  D --> F[Authorized catalog or enabled seeds]
  E --> F
  F --> G[Host authority revalidation]
  G --> H[Library response or session selections]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +41, Tests +296, Other 0. Total +337 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 201 160 +41
Tests 3 301 5 +296
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 9 503 166 +337

Review metrics

Metric Value Why it matters
Projection efficiency Reported 100-entry probe: 404 → 5 native calls; 8,273,920 → 0 avatar bytes The component measurements support reduced SQLite traffic and transient copying without claiming end-to-end latency gains.

Technical review

Best possible solution:

Keep catalog preparation within the existing worker and profile owners, preserving session revision pins and live authority checks.

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

Yes, source inspection establishes repeated per-entry reads on current main, and the PR supplies focused SQLite counter regressions. This reviewer did not execute the probes.

Is this the best way to solve the issue?

Yes, batching through the existing store and profile owners is a focused solution that preserves revision selection, alias semantics, and host revalidation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded performance improvement for large skill libraries with preserved user-facing contracts.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state context identifies a member-authored PR, so the external-contributor proof gate does not apply. Inspected SQLite counter and worker-boundary tests support the changed projection path; reported measurements are component evidence, and this reviewer ran no target code. No stored-data contract changes require migration proof.

Label justifications:

  • P2: This is a bounded performance improvement for large skill libraries with preserved user-facing contracts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state context identifies a member-authored PR, so the external-contributor proof gate does not apply. Inspected SQLite counter and worker-boundary tests support the changed projection path; reported measurements are component evidence, and this reviewer ran no target code. No stored-data contract changes require migration proof.

Evidence

What I checked:

  • Introduced patch: Reviewed the pinned merge-base-to-head changes, including the profile-metadata prerequisite; endpoint drift was not attributed to this PR. (c18dfa67b5ce)
  • Current-main necessity: Current main's list implementation still projects each entry separately through projectSkillLibraryEntry; the submitted batching remains distinct useful work. (src/skills/library/service.kernel.ts:64, 97a770b1a7ef)
  • Catalog ownership and filtering: The shared selector joins the requested revision, batches owner displays in 500-ID cohorts, records original and canonical profile dependencies, and preserves private-entry visibility and edit checks. (src/skills/library/store.ts:298, c18dfa67b5ce)
  • Authority lifecycle: Actor reuse is confined to a synchronous worker snapshot. The existing access owner binds returned profile dependencies and rechecks library, profile, configuration, and request authority after awaits; session browsing retains selected-session revalidation. (src/skills/library/store-access.ts:74, c18dfa67b5ce)
  • Existing user contract: Documentation defines disabled skills as excluded from new-session defaults but explicitly attachable, preserves immutable session revisions, and specifies the 64-skill limit with personal-first stable ordering. Public docs: docs/tools/skills.md. (docs/tools/skills.md:188, c18dfa67b5ce)
  • Focused regression evidence: Inspected real-SQLite counter cases covering 100 entries, 501 owners, merged aliases, missing owners, zero avatar payload bytes, and zero disabled seed rows. Existing worker cases cover role/alias revocation and prepared-pin binding. The captured PR body reports passing focused suites; this read-only review did not execute them. (src/skills/library/selection-authority.test.ts:50, c18dfa67b5ce)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete enabled auto-merge (squash) October 4, 2026 21:01
@steipete
steipete merged commit e50a9d9 into main Oct 4, 2026
205 of 206 checks passed
@steipete
steipete deleted the steipete/sqlite-skill-library-projection branch October 4, 2026 21:02
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…our reads per entry (openclaw#165106)

* perf(state): read user profile metadata without copying avatar bytes

Select profile metadata from admitted schema facts so separate read-only
handles use the narrow cached query instead of copying avatar BLOBs.
Share the existing fact-keyed role detector with display and avatar reads.

Keep historical role-absent tables, one-hop merges, live role revocation,
and malformed non-BLOB conversion behavior. Unadmitted display handles
still need the column probe; authorizer-controlled ensured writers need
the existing ensure fallback to avoid probes and unrelated denied columns.
Preserving those contracts requires +21/-11 production LOC, net +10.

The admitted-reader regression returns zero avatar bytes instead of
655360 across two three-entry lists, with 26 profile statements unchanged.
Both focused suites pass: 27 profile tests and 13 library authority tests.

* perf(skills): batch library catalog projections

Resolve actor authority once per catalog, join revision descriptions, and
prepare bounded owner metadata through the existing profile owner. Reuse
one catalog for scoped display and session attachment while preserving
worker snapshots and host authority readback.

Restore enabled-only SQL selection for new-session seeds (Related: openclaw#164165).
The 100-entry probe drops from 404 to 5 native calls and from 8,273,920
avatar bytes to zero. Disabled-only seeds no longer project disabled rows.

The combined +41 production-line delta, including the profile-metadata
prerequisite, is accepted by the coordinator as a LOC-positive exception.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant