Skip to content

refactor: move skill upload database work to the shared worker - #155283

Merged
steipete merged 4 commits into
mainfrom
codex/skill-upload-current-carry-0921
Sep 22, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/skill-upload-current-carry-0921

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Skill archive uploads still performed staging, expiry cleanup, and installation lease SQL on the Gateway thread, despite exposing asynchronous methods.

User Impact

Upload database work now runs in the shared SQLite worker. Upload and installation-lease expiry are evaluated after admission, so queue waits cannot admit expired uploads or revive an expired lease. Archive contents, offsets, idempotency, install permissions, TTL durations, and storage formats retain their contracts; no migration or operator action is required.

Why This Change Was Made

The upload owner now sends finite staging and lease operations to the existing shared worker while keeping archive materialization and installation callbacks on the host. Installation joins accepted renewals before consumption or release, and failed cleanup retains recovery custody. Release checks physical database identity and the exact lease owner, including when two paths refer to the same database. Requests carry durations and immutable input facts; the worker samples the clock inside the admitted transaction for begin, chunk, claim, renewal, consumption, and expiry deletion.

Evidence

The current source is dbf40a85ae0320a40b68c098c321565605b49cc3. It carries the previously qualified b6d2f51 upload feature onto main 6110505e6d475eff9e58029a2506177a07833728, including its shared lifecycle teardown fixes. Ten upload-owned source/test postimages remain byte-identical to b6d2f51. The shared worker contract retains both state-lease and upload cleanup operations; the retired-agent cleanup implementation and test match main exactly.

Before publication, a source audit against main 875aaaffcb7571385dbaca24fa56eef2f195896f found no overlap with the 15 changed paths and a conflict-free merge preserving every candidate postimage. Main has since added worker-generation retention, so local proof remains bound to the pinned candidate. Normal fresh-head CI run 35727378585 subsequently completed successfully on this head with all 158 jobs settled, including all five Windows jobs.

A controlled real-worker FIFO proof on the preceding 3e2f3e7 source reproduced late chunk acceptance, late installer entry, expired-lease renewal, and expired-lease consumption. The unchanged admission owner held an earlier real operation across the persisted deadline; no fake clock, substituted worker result, or production test seam was used. All four controls pass on the carried candidate with Node 24.21.0 and Bun 1.4.2.

Current focused validation passes 102 tests across seven files, with two Windows-only cases skipped on macOS: 15 upload kernel cases, 24 store/lifecycle cases, 14 registered Gateway cases, 47 tooling cases, one retired-agent cleanup case, and one native source-import case. An initial attempt using external-volume scratch was rejected by the unchanged filesystem permission guard and stopped; the affected store/lifecycle cases passed using macOS's normal private temporary directory. No permission, assertion, or deadline was weakened. The complete selected changed-check gate and fresh independent P2 review passed. The gate includes core types, all 25 core-test type shards, root-test types, typed lint, formatting, export scans, and the selected consistency guards.

The requested current isolated test costs were measured once per file, serially, on this exact clean head with Node 24.21.0 and pnpm 12.4.0 using pnpm test <file> --maxWorkers=1. External monotonic wall time includes the complete command, preparation, execution, and cleanup; existing compiler caches were reused. Both file hashes and the source tree were unchanged before and after each command. These are local command costs, not isolated CI seconds.

Current file Cases External wall Vitest duration
src/skills/lifecycle/upload-store-commit.test.ts 15 26.877 s 22.96 s
src/skills/lifecycle/upload-store.test.ts 20 30.202 s 22.37 s

Both commands exited zero, below the roughly 120-second per-job budget. The kernel cases exercise admitted transaction deadlines and actual archive/metadata separation; the store cases use real workers to verify chunk ordering, installation authority, renewal, expiry, and materialization cleanup. SQL mocks cannot establish that these operations cross the worker boundary or preserve physical database and lease ownership. The 30.202-second store wall time includes preparation and final worker-generation verification; its entire Vitest run was 22.37 seconds. No favorable timing rerun was selected. The completed hosted CI run is linked above; its shared shard durations are not presented as isolated per-file measurements.

The earlier Windows CI run 35679715678 failed the tooling fixture's historical numeric-PID liveness assertion. A bounded native Windows diagnostic preserved that assertion and passed 47 tooling cases with one skip. Its four fake CLI processes were absent at observation, and its inner command Job recorded empty membership, leader exit, and closed output. This is non-reproduction, not proof of PID reuse or a production fix. The diagnostic guest was Windows Server 2022 with 2 CPUs; the original CI used Windows 2025 with 16 CPUs. Replaying the original ordered file group stopped on an earlier watcher test's unchanged 120-second timeout before reaching the PID case. Both leases were stopped and independently verified released.

This candidate retains only a failure diagnostic in the existing Windows test: it records the fake CLI's native creation time and includes the currently observed creation time in the unchanged PID assertion message. Production process-management code is unchanged. All five Windows jobs in the fresh-head CI run passed; this does not establish PID reuse as the cause of the historical failure. The older four-file instrumented Windows source and receipts remain separate evidence.

Earlier 3e2f3e7 CI passed after a test-only cleanup-union discriminator correction. Main now types that mock to its actual agent-cleanup owner, so this carry uses main's exact implementation and test instead of retaining the superseded correction.

The following source/build/runtime results are retained historical evidence for f392014d023cc645e34540a550bfe03a7e70dfc5, before the six-file expiry correction:

  • The registered upload-handler regression detected caller-thread upload SQL before the change and passes after the cutover. All 47 focused cases passed on Node 24.21.0 and macOS Bun 1.4.2, including installation failure, renewal settlement, successor ownership, cleanup retries, and database aliases.
  • A normal build and full compiled Gateway/CLI flows passed on both runtimes: begin, chunks, commit retry, installation, exact artifact contents, consumption, and malformed-archive rejection. Both flows ended with zero upload rows and upload-install leases and joined Gateway shutdown.
  • Eight native SQLite counters were calibrated across constructor import paths. Upload-table data SQL and upload-bound lease executions were zero on the Gateway thread. Unrelated bootstrap, schema, background, and shared-lease SQL remains counted separately; this is not a global-zero claim.
  • That source's mechanical carry preserved all twelve upload-owned postimages and passed core types, targeted typed lint, formatting, diff checks, and integration review. The current expiry correction changes four production owners and two tests, so the older complete-build, Gateway/CLI flows, and native-counter measurements are not attributed to the current head. No new full compiled Gateway campaign is claimed. A current-main audit preserves the other worker commands and registrations.
Historical f392014 isolated test costs

Measured once per file, serially, with pnpm test <file> --maxWorkers=1 on macOS, Node 24.21.0 and pnpm 12.4.0. External monotonic wall time includes the complete maintained command, preparation, test execution and cleanup. No retries, source edits, build command, gate suite or review repeat was used.

Source before and after every command: f392014d023cc645e34540a550bfe03a7e70dfc5, clean tree 4a8ea4f672e3ef338617f6e687f394e759bceff2. The receipt includes all four file hashes before and after each command. These measurements are historical. The current expiry correction changes the commit-kernel and store test files; their new tests are covered by the separate current-source cohort above.

File Cases External wall Vitest duration
src/gateway/server-methods/skills-upload.test.ts 14 92.493 s 80.75 s
src/skills/lifecycle/upload-store-commit.test.ts 7 44.316 s 39.97 s
src/skills/lifecycle/upload-store-lifecycle.test.ts 4 20.072 s 16.42 s
src/skills/lifecycle/upload-store.test.ts 22 29.195 s 23.83 s

All four commands exited zero. Each is below the roughly 120-second job budget. These are local command durations, not CI seconds.

The Gateway file needs the explanation required above 30 seconds of test time. Its reported case durations total 56.378 seconds: the added registered staging check is 12.006 seconds, and the thirteen pre-existing cases total 44.372 seconds in this candidate run. The pre-existing commit/replay case alone took 26.397 seconds and retains the existing full skills-handler import; the new staging case imports the narrower upload handler. The file verifies actual registered RPC dispatch, worker placement, installation, terminal invalid-upload cleanup, and replacement recovery. Mocked SQL or isolated kernels cannot prove that the registered handlers invoke the worker or that installation preserves the previous skill. This is attribution of existing suite work on the candidate, not an independently measured old-revision speed comparison.

The kernel file retains six pre-existing cases and receives the existing metadata/blob test moved from the store file. The moved first case, which includes cold database initialization, took 16.313 seconds; the other six reported case durations total 0.616 seconds. The new lifecycle file's four reported case durations total 4.765 seconds and exercise accepted renewal settlement, release/close failure recovery, and physical-path aliases with real workers. The store file retains its twenty-two remaining behavior cases after the metadata case moves; their reported durations total 12.611 seconds. No cases or assertions were weakened.

Cached worker-output preparation was included in wall time: 10.457, 7.959, 5.974, and 7.691 seconds respectively. Reporter component timings are descriptive and should not be added to external wall time. No favorable timing rerun was selected, and no test-cost change is inferred from these historical measurements.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 23:52
@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 Sep 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 9:09 AM ET / 13:09 UTC (Revision 5).

ClawSweeper review

What this changes

Moves skill-upload staging, expiry cleanup, and installation-lease database operations into the shared SQLite worker while retaining archive installation on the Gateway host.

Merge readiness

✅ Ready for maintainer review

The PR remains useful and has no blocking findings. The earlier expiry defect is fixed, and the updated evidence resolves the outstanding test-cost request; current main still lacks this cutover.

Priority: P2
Reviewed head: dbf40a85ae0320a40b68c098c321565605b49cc3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent worker cutover with resolved prior feedback, focused lifecycle coverage, and successful CI for the reviewed head.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this member-authored PR. The body records current real-worker FIFO expiry results and separately identifies historical compiled Gateway evidence; source review found no unresolved authority expansion or stored-data contract change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this member-authored PR. The body records current real-worker FIFO expiry results and separately identifies historical compiled Gateway evidence; source review found no unresolved authority expansion or stored-data contract change.
Evidence reviewed 9 items Pinned change ownership: Reviewed the introduced delta from the pinned base to the original PR head. The supplied test merge is stale and was not used to infer removal of current-main behavior.
Current main still needs the cutover: Current main still directly executes staging, cleanup, claim, renewal, and release SQL from the host upload store; only archive commit already uses the worker.
Latest release retains host SQL: The upload-store source at the supplied latest-release commit also performs these operations directly; the requested cutover is not already shipped in v2026.9.5.
Findings None None.
Security None None.

How this fits together

The Gateway accepts skill archives through upload requests and stores their chunks until installation. The upload store coordinates SQLite staging and installation leases, then supplies an archive to the existing installer.

flowchart TD
  A[Upload requests] --> B[Gateway validation]
  B --> C[Upload store]
  C --> D[Shared SQLite worker]
  D --> E[Expiry and lease checks]
  E --> F[Stored archive and chunks]
  F --> G[Host archive installer]
  G --> D
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +298, Tests +514, Docs +9. Total +821 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 7 655 357 +298
Tests 7 770 256 +514
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 1434 613 +821

Review metrics

Metric Value Why it matters
Production versus test growth Production net +298 lines; tests and test support net +513 lines Production growth has a concrete purpose: typed worker dispatch and retained cleanup custody around the existing upload store.
Previously outstanding test costs Commit kernel 26.877 s; upload store 30.202 s Current individual wall-time measurements resolve the previous review's evidence request.

Technical review

Best possible solution:

Complete the existing worker migration while preserving upload formats, installation policy, admitted deadlines, and exact-owner cleanup.

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

Yes, source inspection traces registered upload requests to synchronous SQLite staging and lease operations on current main; this review did not execute a runtime reproduction.

Is this the best way to solve the issue?

Yes, extending the existing shared worker is the narrow ownership-preserving approach, and the patch keeps archive installation and persistent contracts with their existing owners.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway responsiveness and upload-lifecycle improvement with no demonstrated urgent user-facing outage.
  • 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 external-contributor proof gate does not apply to this member-authored PR. The body records current real-worker FIFO expiry results and separately identifies historical compiled Gateway evidence; source review found no unresolved authority expansion or stored-data contract change.

Evidence

What I checked:

  • Pinned change ownership: Reviewed the introduced delta from the pinned base to the original PR head. The supplied test merge is stale and was not used to infer removal of current-main behavior. (dbf40a85ae03)
  • Current main still needs the cutover: Current main still directly executes staging, cleanup, claim, renewal, and release SQL from the host upload store; only archive commit already uses the worker. (src/skills/lifecycle/upload-store.ts:331, 8c001ebde933)
  • Latest release retains host SQL: The upload-store source at the supplied latest-release commit also performs these operations directly; the requested cutover is not already shipped in v2026.9.5. (src/skills/lifecycle/upload-store.ts:400, ec9c1a13db89)
  • Prior expiry finding resolved: Begin, chunk, claim, renewal, consumption, and expiry deletion now sample time inside their admitted transactions. The upload-owned source and Gateway test are unchanged from the previously reviewed expiry correction. (src/skills/lifecycle/upload-store.kernel.ts:207, dbf40a85ae03)
  • Lease cleanup and authority: Cleanup joins the producer, retains failed cleanup for retry, and rejects physical database replacement. The worker release transaction matches physical identity, upload ID, and exact owner; consumption and renewal reject expired or replaced leases. Existing installation feature gates and archive-policy checks remain unchanged. (src/skills/lifecycle/upload-store-install-owner.ts:35, dbf40a85ae03)
  • Review continuity and scoped runtime evidence: The captured PR body now reports exact-head individual wall times of 26.877 seconds for the commit-kernel tests and 30.202 seconds for the store tests, resolving the previous rank-up request. It records four real-worker FIFO expiry controls passing on Node 24.21.0 and Bun 1.4.2. Complete compiled Gateway flows and native SQL counters are explicitly attributed only to historical f392014, not this head. (dbf40a85ae03)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-22T00:04:33.641Z sha 3fdc183 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T00:47:43.230Z sha 3e2f3e7 :: needs changes before merge. :: [P2] [P2] Recheck expiry after the worker queue wait
  • reviewed 2026-09-22T02:39:55.224Z sha b6d2f51 :: needs changes before merge. :: none
  • reviewed 2026-09-22T12:35:36.280Z sha dbf40a8 :: needs changes before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Sep 22, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 22, 2026
Preserve the reviewed upload expiry checks while retaining shared lifecycle cleanup fixes from main. Keep agent lease cleanup scoped to its owner and add creation-identity evidence to the unchanged Windows PID assertion on failure.
@steipete
steipete merged commit 79e76bb into main Sep 22, 2026
231 of 232 checks passed
@steipete
steipete deleted the codex/skill-upload-current-carry-0921 branch September 22, 2026 13:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
…law#155283)

* fix(skills): move upload staging and install leases into workers

* test(state): discriminate retired lease cleanup commands

* fix(skills): check upload expiry after worker admission
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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