Skip to content

[WRONG BRANCH] fix(lab): retain grace period for stale ledger locks - #297

Closed
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-ledger-stale-lock-issue
Closed

[WRONG BRANCH] fix(lab): retain grace period for stale ledger locks#297
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-ledger-stale-lock-issue

Conversation

@luvs01

@luvs01 luvs01 commented Aug 16, 2026

Copy link
Copy Markdown
Owner

Motivation

  • A recent change made stale-lock recovery treat any lock whose recorded PID is dead as immediately recoverable, which exposed an ABA race allowing a waiter to unlink a newly created live lock and violate ledger serialization.
  • The intent is to avoid deleting a live replacement lock installed between liveness check and unlink, restoring the previous freshness guard that reduced the recovery window for short-lived writers.

Description

  • Change isLedgerLockStale in src/lab/ledger/store.ts to require that a well-formed lock is both owned by a dead PID and that its createdAt is older than LEDGER_LOCK_STALE_MS before it is considered stale.
  • Keep the existing recovery mutex / recoverStaleLedgerLock path intact so stale recovery remains ownership-safe while refusing to reclaim freshly-created locks.
  • Update the focused test in tests/lab-ledger-mutation-lock.test.ts to set the lock createdAt to older than LEDGER_LOCK_STALE_MS and rename the test to reflect the aged-lock expectation.
  • Commit message: fix(lab): retain grace period for stale ledger locks.

Testing

  • Ran bun run typecheck with no errors.
  • Ran the focused test file with bun run test -- tests/lab-ledger-mutation-lock.test.ts and observed all tests in that file pass (5 passed).
  • Verified git diff --check and committed the changes locally as described; a full repository test run in this environment was started but large unrelated suites produce long output and were truncated, so only the focused tests were used for verification.

Codex Task

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@luvs01, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Limit details: You’ve used all 3 included reviews currently available under your plan.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1702ad8f-5e01-4df7-b506-7508fa6f0f23

📥 Commits

Reviewing files that changed from the base of the PR and between d9de895 and 9a0fd13.

📒 Files selected for processing (2)
  • src/lab/ledger/store.ts
  • tests/lab-ledger-mutation-lock.test.ts

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 16, 2026
@github-actions github-actions Bot changed the title fix(lab): retain grace period for stale ledger locks [WRONG BRANCH] fix(lab): retain grace period for stale ledger locks Aug 16, 2026
@github-actions

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request is being kept as a draft automatically. Once every issue above is resolved, it will be marked ready for review again.

@github-actions
github-actions Bot marked this pull request as draft August 16, 2026 04:05

@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: 9a0fd13ec2

ℹ️ 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/lab/ledger/store.ts
Comment on lines +93 to +94
return Date.now() - meta.createdAt > LEDGER_LOCK_STALE_MS
&& !isLockHolderAlive(meta.pid);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recover recently orphaned locks without waiting a minute

When a ledger owner crashes or is killed less than 60 seconds after acquiring the lock, this new age condition treats its lock as live even though the PID check would prove the owner is gone. tryAcquireLedgerLock only waits 5 seconds (LEDGER_LOCK_WAIT_MS), so every Lab mutation during the remaining grace period synchronously blocks for five seconds and then fails with EEXIST, preventing experiment results and other ledger updates from being persisted after a normal crash/restart. Preserve the ABA protection by making recovery conditional on the identity of the lock that was inspected, rather than delaying recovery of every dead owner beyond the acquisition deadline.

Useful? React with 👍 / 👎.

@luvs01 luvs01 closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant