Skip to content

refactor(state): move skill upload staging to SQLite - #108346

Merged
steipete merged 5 commits into
mainfrom
codex/sqlite-skill-upload-staging
Jul 15, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/sqlite-skill-upload-staging

Conversation

@steipete

@steipete steipete commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #108318

What Problem This Solves

Resolves a problem where remote skill uploads stored transient metadata, idempotency pointers, and archive bytes as JSON and ZIP files under the OpenClaw state directory. That split steady-state ownership required directory scans and process-local file coordination instead of the database-first state contract.

Why This Change Was Made

Skill-upload metadata and ordered archive chunks now live in the shared SQLite state database. Begin, chunk, commit, expiry, idempotency, capacity, and removal use short Kysely-backed transactions with authoritative row revalidation; commit assembles and hashes outside the write transaction, then stores one canonical archive BLOB and removes chunk rows atomically.

Installation claims a renewable SQLite lease, materializes a private temporary archive only for the existing installer callback, and removes it afterward. Upload consumption requires the exact live lease owner. Lease expiry advances from each successful claim or heartbeat, expired owners cannot renew or delete state, and begin-time checksum metadata stays immutable for idempotent retries.

openclaw doctor --fix discards the legacy transient staging tree. Runtime fallback, dual-write, lazy import, and unscoped removal paths are intentionally absent.

User Impact

The Gateway upload protocol and configured limits are unchanged. Remote skill uploads gain cross-process transactional idempotency, capacity, expiry, commit, crash recovery, and install ownership without leaving JSON metadata, idempotency sidecars, or ZIP staging trees in the state directory. Unfinished pre-upgrade transient uploads must be retried.

Evidence

  • Focused Vitest proof: 589 passed, 1 skipped across upload-store, shared state DB, Gateway upload methods, Doctor cleanup, database-first guard, and task-boundary tests.
  • Regression coverage includes concurrent chunks and commits, omitted-checksum idempotent retries, maximum-size chunks, SHA and size validation, expiry races, renewable install leases, abandoned-lease recovery, stale-owner fencing, temporary archive permissions and cleanup, legacy symlink-safe cleanup, and retryable Gateway publish failures.
  • Exact-head hosted CI: https://github.com/openclaw/openclaw/actions/runs/29428534468 passed at dec4b23fef20a9f0f300d9a07072f93d019c417a.
  • Blacksmith Testbox tbx_01kxk23abwb8kzw1x0n5y591qq: pnpm check:changed passed all selected guards, core/core-test/root-test typechecks, and lint lanes; pnpm build passed bundled assets, runtime, SDK declarations, and Control UI production build.
  • Generated Kysely declarations verify cleanly; database-first legacy-store guard, max-lines ratchet, targeted formatting, lint, and git diff --check pass.
  • Fresh structured autoreview converged with no accepted or actionable findings. All GitHub review threads were addressed and resolved.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts commands Command implementations size: XL maintainer Maintainer-authored PR labels Jul 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d907b86e6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/skills/lifecycle/upload-store.ts Resolved
@steipete
steipete force-pushed the codex/sqlite-skill-upload-staging branch from d907b86 to e76ff70 Compare July 15, 2026 14:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e76ff701b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/skills/lifecycle/upload-store.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c85dde0cfe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dec4b23fef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const heartbeat = setInterval(() => {
const heartbeatAt = now();
try {
renewSkillUploadInstallLease({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop using an upload after its lease is lost

When a host sleep or event-loop stall delays this heartbeat past installLeaseMs, renewSkillUploadInstallLease now returns false for the expired lease, but that result is ignored and the installer keeps using the materialized archive. If the install then succeeds, installUploadedSkillArchive catches the later upload.remove() ownership failure (src/skills/lifecycle/upload-install.ts:125), so the caller can see a successful install while the upload remains retryable, and another gateway may install the same archive after claiming the expired lease. Treat a false renewal as lost ownership and fail/abort the callback instead of reporting success.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit f41c143 into main Jul 15, 2026
121 checks passed
@steipete
steipete deleted the codex/sqlite-skill-upload-staging branch July 15, 2026 15:40
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 16, 2026
* refactor(state): move skill upload staging to sqlite

* test(skills): make archive mode assertion portable

* fix(skills): fence upload finalization by lease owner

* fix(skills): handle nullable lease expiry

* fix(skills): bound upload install leases
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
* refactor(state): move skill upload staging to sqlite

* test(skills): make archive mode assertion portable

* fix(skills): fence upload finalization by lease owner

* fix(skills): handle nullable lease expiry

* fix(skills): bound upload install leases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(state): move skill upload staging to SQLite

1 participant