Skip to content

fix(safe): each kernel build goes in a dir of its own, renamed into place whole - #1949

Merged
nicolas-abril merged 2 commits into
bendlang:mainfrom
nicolas-abril:fix/kernel-build-race
Oct 29, 2026
Merged

nicolas-abril merged 2 commits into
bendlang:mainfrom
nicolas-abril:fix/kernel-build-race

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1948.

kernel_bin built the BendTT kernel in ~/.bend/bendtt/<hash>/ itself. So --verdict runs that started together on an empty cache wrote over each other's bendtt.c, and one could fail to link. The cache also took bendtt's existence as "built", while leanc wrote it in place.

What

  • Each build runs in a fresh build-XXXXXX directory under the cache directory.
  • The finished bendtt is renamed into place. The rename is atomic, so bin, once there, is a finished kernel. When two builds finish, the later rename replaces an identical file, and a run already executing the earlier one keeps its inode.
  • The build directory is removed when the build ends, whether it succeeds or fails. A build stopped by a signal (Ctrl-C, SIGTERM or SIGKILL; the finally does not run then) leaves its build-XXXXXX directory behind, but no bendtt, so the next run builds normally. Leftover directories are not cleaned up: one could belong to a build still running.
  • run's tool parameter is exe, so it no longer shadows bin, the kernel path the rename writes.

Checks

The tests point HOME at an empty directory that links to the real ~/.elan, so each one starts from an empty cache.

  • Four --verdict runs at once on an empty cache:

    Branch Result
    main a failed run in 3 of 5 tries (leanc: … undefined symbol: main)
    this branch every run checks in 6 of 6 tries; only bendtt is left in the cache directory
  • A build stopped 5 s in, by SIGKILL, SIGINT or SIGTERM: the next run builds and checks; the stopped build's directory stays.

  • No Lean on the PATH: the same "the kernel did not build" error as before, and the build directory is gone.

  • bun gates/_run.ts: repo 54 / 54, test 1782 / 1782, perf 124 / 124, ping 80 / 81 (pass). The gates use a prebuilt kernel, so they do not reach this code.

  • safe.ts goes from 23900 to 23993 ttok, under its 24000 cap.

🤖 Generated with Claude Code

nicolas-abril and others added 2 commits October 29, 2026 19:45
…lace whole

--verdict built the kernel in ~/.bend/bendtt/<hash>/ itself, so runs that
started together on an empty cache wrote over each other's bendtt.c: four
at once failed a run in 3 of 5 tries (leanc: undefined symbol: main). And
the cache took bendtt's existence as built, while leanc wrote it in place.

kernel_bin now builds in a fresh build-XXXXXX dir under the cache dir and
renames the finished bendtt into place, which is atomic; the build dir goes
when the build ends, however it ends. Four at once: 20 of 20 runs check.

Fixes bendlang#1948

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the kernel it renames into place

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nicolas-abril
nicolas-abril merged commit 5c4d23e into bendlang:main Oct 29, 2026
1 check passed
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.

--verdict: runs that build the kernel at the same time can break each other's build

1 participant