Skip to content

fix(cli): make account store updates transactional - #747

Open
grandizzy wants to merge 6 commits into
mainfrom
fix/accounts-store-lock
Open

fix(cli): make account store updates transactional#747
grandizzy wants to merge 6 commits into
mainfrom
fix/accounts-store-lock

Conversation

@grandizzy

@grandizzy grandizzy commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevent concurrent Accounts store writers from overwriting fresh store.json state or restoring retired access-key credentials.

This complements tempoxyz/tempo#6965 by making the Accounts CLI filesystem adapter participate in the same store.json.lock advisory-lock protocol.

Koffi provides access to BSD flock, which Node does not expose natively, while supporting the Linux/macOS x64/arm64 targets required by wallet-cli.

Changes

  • Acquire an exclusive BSD flock on store.json.lock for every filesystem mutation.
  • Reread store.json only after acquiring the lock.
  • Apply the local state transition to that fresh snapshot before atomically replacing the canonical file.
  • Preserve concurrent access-key retirements by merging field-level mutation intent rather than writing a stale Zustand snapshot.
  • Prevent stale hydration from restoring privateKey, handle, or keyPair.
  • Handle stores created by another process after an initial empty hydration.
  • Add deterministic process-contention and stale-credential regression tests.
  • Add a patch changeset.

Testing

  • vp test src/core/Store.test.ts src/cli/storage.test.ts --run
  • tsc -b --noEmit
  • pnpm build
  • Manual interoperability check against Rust std::fs::File::lock()

Follow-up

wallet-cli’s standalone esbuild/@yao-pkg/pkg pipeline will need to stage and smoke-test the target-specific Koffi native addon for Linux and macOS x64/arm64 when it adopts this Accounts revision.

Co-Authored-By: grandizzy 38490174+grandizzy@users.noreply.github.com

Prompted by: grandizzy

Co-Authored-By: grandizzy <38490174+grandizzy@users.noreply.github.com>
@grandizzy grandizzy self-assigned this Jul 31, 2026
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
accounts-site Ready Ready Preview Aug 3, 2026 9:05am

Request Review

@socket-security

socket-security Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedkoffi@​3.1.2911008496100

View full report

@pkg-pr-new

pkg-pr-new Bot commented Jul 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/tempoxyz/accounts@747

commit: 1d58599

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
Worker Preview
Wagmi https://b243b6f4-accounts-wagmi.porto.workers.dev

Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fb66c-1cab-748e-95c4-a70fdf739f43
Co-authored-by: Amp <amp@ampcode.com>
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
Worker Preview
Playground https://d4a1da75-accounts-playground.porto.workers.dev

Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fb66c-1cab-748e-95c4-a70fdf739f43
Co-authored-by: Amp <amp@ampcode.com>
@grandizzy
grandizzy force-pushed the fix/accounts-store-lock branch from 5497702 to bc3b328 Compare July 31, 2026 13:17
@jxom
jxom marked this pull request as ready for review August 3, 2026 05:49

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

Copy link
Copy Markdown

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: bc3b328c52

ℹ️ 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/cli/storage.test.ts Outdated
Comment thread src/core/Store.ts Outdated
Comment thread src/core/Store.ts Outdated
Comment thread src/core/Store.ts Outdated
Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fb66c-1cab-748e-95c4-a70fdf739f43
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fb66c-1cab-748e-95c4-a70fdf739f43
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fb66c-1cab-748e-95c4-a70fdf739f43
Co-authored-by: Amp <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant