lukasa1993/tanstack-skills-extracted/tanstack-ai-core-locks
Claude Code and agent skill by lukasa1993/tanstack-skills-extracted
- community
Checking that the SKILL.md file is still in the repository.
LockStore, InMemoryLockStore, LocksCapability and withLocks for multi-instance coordination in TanStack AI. Ships in @tanstack/ai — NOT in @tanstack/ai-persistence. Separate from AIPersistence state stores — not a stores key, not composable. InMemoryLockStore vs a distributed (e.g. Cloudflare Durable Object) lock, lease recovery, AbortSignal in critical sections. Use when sandbox or other middleware needs cross-worker mutual exclusion — NOT for storing messages/runs (use withPersistence).
Install
npx vskill@latest install lukasa1993/tanstack-skills-extracted/tanstack-ai-core-locksSKILL.md
Locks (coordination — not persistence)
Dependency note: This skill builds on ai-core and ai-core/middleware.withLocksis a ChatMiddleware that provides a capability. Locks are notpart ofAIPersistence.storesand are not composed withcomposePersistence— they ship in@tanstack/ai, independent of@tanstack/ai-persistence.
Why separate?
State stores answer "what is durable chat data?" Locks answer "who may run this critical section right now?"
withPersistence does not automatically lock a whole turn. Take a per-thread (or other) lock yourself when multi-writer races matter.
Wire locks
Alongside persistence — optional, locks do not require it:
withLocks provides LocksCapability for downstream middleware (e.g. sandbox). Order: usually state first, locks alongside or after depending on who consumes the capability.
The contract
InMemoryLockStore ships in `@tanstack/ai/locks`: a per-key promise chain, correct within a single process only. Multi-instance deployments need a distributed implementation — you write it. The Cloudflare Durable Object recipe is in ai-persistence/build-cloudflare-adapter (@tanstack/ai-persistence).
Type your own store with defineLock (autocomplete, no : LockStore annotation), then hand it to withLocks. Acquire the key, run fn, release when fn settles:
Lease semantics
A good LockStore:
- Serializes owners per key,
- Uses leases (or equivalent) so a crashed owner cannot block forever,
- Passes an
AbortSignalinto the critical section viawithLock; when the
lease is lost, abort so work stops starting external mutations.
Callbacks must honor the signal and pass it to cancellable dependencies. InMemoryLockStore never aborts its signal — within one process, ownership cannot be lost.
Capability identity
The 'locks' capability token lives in @tanstack/ai/locks. Capability identity is by object reference, so one shared token means a withLocks in the chain reaches withSandbox automatically.
Common mistakes
HIGH: Importing locks from @tanstack/ai-persistence
They are not exported there. Use @tanstack/ai.
HIGH: Putting locks on AIPersistence.stores
Not supported. stores accepts only messages, runs, interrupts, metadata — never locks. Use withLocks.
HIGH: Passing locks to composePersistence overrides
Same rejection, at the override layer. Locks are not state.
HIGH: Passing 'locks' to the conformance testkit's skip
skip accepts only chat state store keys. The suite does not cover locks at all — test lease expiry and abort separately.
HIGH: InMemoryLockStore across multiple processes
No mutual exclusion between machines — use a distributed lock store.
MEDIUM: Ignoring lease abort
Continuing work after losing the lease races other owners.
Cross-references
- See also: ../tanstack-ai-core-middleware/SKILL.md -- the middleware chain and capability plumbing
- See also: `@tanstack/ai-persistence` skills (
../tanstack-ai-persistence/SKILL.mdin that package) --ai-persistence/server(state middleware) andai-persistence/build-cloudflare-adapter(Durable Object lock recipe)
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/tanstack-ai-core-locks/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/lukasa1993/tanstack-skills-extracted/tanstack-ai-core-locks)