Skip to content

Replace busy-wait with Atomics#74

Open
tembo[bot] wants to merge 1 commit intomainfrom
tembo/shippost-scannerbot-fix-code-quality
Open

Replace busy-wait with Atomics#74
tembo[bot] wants to merge 1 commit intomainfrom
tembo/shippost-scannerbot-fix-code-quality

Conversation

@tembo
Copy link
Copy Markdown
Contributor

@tembo tembo bot commented Feb 21, 2026

Summary

Replaced CPU-intensive busy-wait loop with Atomics.wait() in lock acquisition retry logic. The previous implementation used a spin loop (while (Date.now() < until)) that burned CPU cycles during the 50ms retry delay. Now uses Atomics.wait() with a SharedArrayBuffer to properly yield the thread during sleep.

Changes:

  • Added sleepBuffer using SharedArrayBuffer and Int32Array for Atomics.wait()
  • Implemented sleepSync() helper function that uses Atomics.wait() for efficient sleeping
  • Replaced busy-wait loop in acquireLock() with sleepSync(LOCK_RETRY_MS) call

Additional findings documented in .beads/issues.jsonl:

  • Race condition in lock file handling (t2p-scan01)
  • Infinite recursion risk in review.ts (t2p-scan02)
  • Unsafe process.env.HOME access (t2p-scan03)
  • Content analyzer validation bug (t2p-scan04)
  • Template substitution using replace() instead of replaceAll() (t2p-scan05)

Want tembo to make any changes? Add a review or comment with @tembo and i'll get back to work!

View on Tembo View Agent Settings

@tembo tembo bot added the tembo Pull request created by Tembo label Feb 21, 2026
@tembo tembo bot requested a review from ryw February 21, 2026 08:05
@tembo
Copy link
Copy Markdown
Contributor Author

tembo bot commented Feb 21, 2026

Requesting review from @ryw who has experience with the following files modified in this PR:

  • package-lock.json
  • .beads/issues.jsonl
  • src/services/file-system.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tembo Pull request created by Tembo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants