Skip to content

fix(build-cache): look in the cache again once the lock is taken - #4159

Merged
devswha merged 1 commit into
mainfrom
fix/build-cache-together
Nov 18, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/build-cache-together

Conversation

@devswha

@devswha devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Summary

scripts/build-cache.test.ts "builds a commit once when its jobs start together" failed once in bun run check fast on a
loaded host (hosthatch) and passes elsewhere.

scripts/build-cache.ts has a check-then-lock race: a job looks in the cache, misses, and only then tries the lock. If
the job holding the lock stores its build and lets go in between, the late job takes the free lock and builds the same
commit a second time, which is what the test counts (exactly one build across four jobs).

Fix: once a job holds the lock it looks in the cache again; if the build is there it restores it, lets the lock go and
exits. No timing is involved, so a commit is built once however the jobs interleave.

Validation

  • bun test scripts/build-cache.test.ts: 52 pass, 0 fail.
  • bun run check fast: green.
  • The failure did not reproduce on demand: 148 runs of the test in the CI runner image on hosthatch passed (20 alone,
    48 as six parallel copies of the file, 80 as sixteen parallel copies with every core busy). The race above is the
    path through the code that produces two builds; the original failure's assertion would confirm it.

"builds a commit once when its jobs start together" failed once on a loaded
host's check fast. A job looks in the cache, misses, and only then tries the
lock. If the job that held the lock stores its build and lets go in between,
the late job takes the free lock and builds the same commit a second time
(the test counts two builds). Once a job holds the lock it now looks in the
cache again, and if the build is there it restores it, lets the lock go and
exits, so a commit is built once whatever the timing.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Improvements
    • Build jobs now check for an available cached result after acquiring the cache lock. If another job has populated the cache, the result is reused instead of running the build again. This can avoid redundant build work and help jobs complete more efficiently.

After acquiring the build-cache lock, the job retries the cache restore. If the restore succeeds, it releases the lock and exits successfully. Otherwise, it continues to the build.

Changes: Build cache flow

Layer / File(s) Summary
Locked cache recheck
scripts/build-cache.ts
After acquiring the lock, the job retries the cache restore. On success, it releases the lock and exits with status 0. If the restore fails, it continues to the build.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related PRs

  • devswha/ovis#2825: Introduced the cache and per-key lock used by this change.
  • devswha/ovis#3585: Changed the cache lookup and lock scope used by the added restore check.
Merge Risk: Minimal · up to 7ced6

The change prevents a redundant duplicate build after waiting on another job's lock. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: once a job takes the build-cache lock, it checks the cache again. It matches the raw summary and the PR objectives, and it follows the conventional commit style.
Description check Passed The description has a Summary section, but the repository template calls for Change and Validation sections. The Summary explains the check-then-lock race and the fix, and the Validation section lists…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description has a Summary section, but the repository template calls for Change and Validation sections. The Summary explains the check-then-lock race and the fix, and the Validation section lists the commands run and their results. The description does not follow the template headings. It also does not link an issue, which the template asks for on feature work. This is a fix, so the issue link is optional. The template also asks to list skipped checks, and the description does not say which checks were skipped.

Resolution

Consider renaming the Summary section to Change to match the template. Also state which checks were skipped, such as bun run check full, or confirm none were skipped. Reference the changelog entry in changelog.d/ if the repository requires one.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 288f732 and 7ced6a7.

Files selected for processing: 1

  • scripts/build-cache.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@devswha
devswha merged commit 6e64c0e into main Nov 18, 2026
15 checks passed
@devswha
devswha deleted the fix/build-cache-together branch November 18, 2026 17:32
@devswha

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 7ced6a766. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit reviewed this head.

Build-cache script fix (lead t10k asked for it): a job that took the lock looks in the cache again before building, closing a check-then-lock race that let a commit be built twice. Reviews: dori review CLEAR at 7ced6a7; CodeRabbit on this PR. Merged by the lane on the lead's word. Evidence: build-cache tests 52/52, check fast green; the flake did not reproduce in 148 runs (stated in the PR).

devswha added a commit that referenced this pull request Nov 24, 2026
…pe, worktree focus and agy temp links (#4550)

## What

Test bundle B5 of the test-suite plan: regression tests for four fixes
that went in without one (two of them regressed before). Tests only; no
production file changes.

| # | Fix | Test |
|---|---|---|
| A1 | #4159 `scripts/build-cache.ts` re-checks the cache after taking
the lock | `scripts/build-cache.test.ts`: two real `build-cache.ts` jobs
on one key, ordered by gate files (`fs.watch`, no sleep). Job 2 misses
the cache, meets job 1's lock, and is paused just before its retry; job
1 stores its build and releases. Both exit 0, one build in total, job
2's `dist/` restored from the cache. |
| A2 | #3028 Changes keeps its scope when Files moves to another pane/PC
| new `src/components/FilesDialog.test.tsx`: render `FilesDialog`, pick
Branch, compare with `main`, rerender with another `paneId`, then the
stale pane's answer arrives: Branch stays pressed and the stale file is
not shown. |
| A3 | #1222 the new worktree dialog focuses the Branch field |
`src/components/WorktreeDialog.test.tsx`: in create mode focus is on the
Branch input with its suggested value fully selected. |
| A4 | #2030 agy catalog under a symlinked temp dir (macOS `/var ->
/private/var`) | `server/agy.test.ts`: a new row of the WAL-catalog
table runs the reader with `TMPDIR`/`TEMP`/`TMP` pointing at a symlink.
|

## Evidence: each test goes red when its fix is reverted

Each mutation was written into the production file, the test run, and
the original bytes restored (sha256 checked; production diff is empty).

| # | Revert | Result |
|---|---|---|
| A1 | `if (owner && restored())` -> `if (false && ...)` (no look under
the lock) | red: builds `[1, 1]` instead of `[1, 0]` |
| A2 | put back `key={`${machineId}:${paneId}`}` on `<RepoChanges>` (the
key cbdcafa removed) | red: scope falls back to Working tree |
| A3 | move `ref={first}` from the Branch input to the Name input
(pre-#1222) | red: focus and selection on the Name input |
| A4 | remove `snapshot = realpathSync(snapshot)` in `server/agy.ts` |
red: only the symlinked row fails with `AgyUnavailable`; the other three
rows stay green. **This reproduces on Linux too**: SQLite's
`SQLITE_OPEN_NOFOLLOW` refuses a path with a symlinked directory
component, so Linux CI guards #2030. |

## Validation

- `bun test scripts/build-cache.test.ts
src/components/FilesDialog.test.tsx
src/components/WorktreeDialog.test.tsx server/agy.test.ts`: all new
tests pass.
- `bun scripts/typecheck.ts`: exit 0.
- `bun run check fast` (P620, 241 s): typecheck, build, generated files
ok; unit 24,890 pass, 160 skip, **1 fail**:
`scripts/conventions.test.ts` "waits marked fixed" on
`scripts/relay-new-pc-press-regression.ts:180`, which fails on
`origin/main` itself (1d71a71) and is fixed by #4547; this PR does not
touch that file. The branch takes main in once #4547 lands.
- Browser regressions that name FilesDialog or the worktree dialog
(`file-viewer-regression`, `files-panel-demo-regression`,
`repo-diff-browser-qa`, `ui-regression`,
`phone-worktree-sheet-regression`, ...): not run locally since no
component code changes; they run in this PR's Integration and browser
job (CI runner image).
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