ECC/scripts
Jamkris 116e61d8cb fix(lib): retry rename on Windows EPERM/EACCES/EBUSY in writeBridgeAtomic
PR #1983 round 1 introduced unique-suffix tmp paths so two concurrent
writers no longer share a single `.tmp` file. That fix is correct
under POSIX semantics — `rename(2)` is atomic between source and
destination, so each writer renames onto the same target without
conflict.

Windows `MoveFileExW` is not the same. It fails with
EPERM / EACCES / EBUSY when the target is currently being renamed
by *another* process — a short race window that fires reliably under
this hook's PostToolUse + statusline concurrency. Round 1's CI run
made this visible:

  Test (windows-latest, Node 18.x, npm) — FAILURE
  Error: EPERM: operation not permitted, rename
    'C:\…\ecc-metrics-test-bridge-race-….json.9504.4aef575a.tmp' ->
    'C:\…\ecc-metrics-test-bridge-race-….json'
      at writeBridgeAtomic (scripts/lib/session-bridge.js:79:8)

All nine Windows matrix cells (Node 18 / 20 / 22 × npm / pnpm / yarn)
hit the same path. POSIX matrices (Linux + macOS) passed unchanged.

Fix: extract a `renameWithRetry(tmp, target)` helper that retries
`fs.renameSync` up to 5 times on EPERM / EACCES / EBUSY with
exponential backoff (20 ms → 320 ms total). Other error codes
(ENOENT, ENOSPC, EROFS, …) re-throw on the first attempt — they are
not transient. POSIX runs hit the first try and exit immediately.

The backoff uses `Atomics.wait` on a throwaway `SharedArrayBuffer`
so the retry path does not busy-spin the CPU; verified on Node ≥ 17
that this works on the main thread. There is a `try/catch` fallback
to a brief busy-wait for older runtimes where `Atomics.wait` is
restricted to workers.

`writeBridgeAtomic` calls the helper instead of `fs.renameSync` and
keeps its existing best-effort tmp cleanup on terminal failure.

`renameWithRetry` is added to `module.exports` so the companion
`writeWarnState` in `scripts/hooks/ecc-context-monitor.js` can
adopt the same retry policy without duplicating the helper. That
adoption lands in the next commit.

Local: `node tests/lib/session-bridge.test.js` 14/14, `yarn test`
green, `yarn lint` clean. The round-1 test (two concurrent child
writers, 200 iterations each) now passes on macOS without retrying
at all (POSIX path) and is expected to pass on Windows via the new
retry loop.
2026-05-19 04:57:10 -04:00
..
ci fix(ci): cover other widely-cited invisible code points in check-unicode-safety 2026-05-18 21:20:36 -04:00
codemaps feat: add scripts/codemaps/generate.ts codemap generator Fixes #247 - The generate.ts script referenced in agents/doc-updater.md was missing from the repository. This adds the actual implementation. The script: - Recursively walks the src directory (skipping node_modules, dist, etc.) - Classifies files into 5 areas: frontend, backend, database, integrations, workers - Generates docs/CODEMAPS/INDEX.md + one .md per area - Uses the codemap format defined in doc-updater.md - Supports optional srcDir argument: npx tsx scripts/codemaps/generate.ts [srcDir] 2026-02-22 16:19:16 +05:30
codex feat: support disabling bundled mcp servers 2026-04-05 14:37:28 -07:00
codex-git-hooks fix: skip pre-push checks on branch deletion 2026-03-29 23:09:26 +09:00
hooks fix(hooks): use unique tmp suffix in writeWarnState (ecc-context-monitor) 2026-05-19 04:57:10 -04:00
lib fix(lib): retry rename on Windows EPERM/EACCES/EBUSY in writeBridgeAtomic 2026-05-19 04:57:10 -04:00
auto-update.js feat: add auto-update command 2026-04-29 21:01:27 -04:00
build-opencode.js fix: restore ci baseline for opencode packaging 2026-04-05 14:47:26 -07:00
catalog.js feat: add install catalog and project config autodetection 2026-03-27 05:56:39 -04:00
claw.js fix(scripts): resolve claude.cmd on Windows by enabling shell for spawn (#1471) 2026-04-21 18:02:13 -04:00
consult.js fix: tune machine learning workflow routing 2026-05-11 18:11:05 -04:00
discussion-audit.js Add discussion audit gate 2026-05-15 16:26:57 -04:00
doctor.js fix(scripts): add os.homedir() fallback for Windows compatibility 2026-03-28 11:28:12 +08:00
ecc.js feat: add platform and supply-chain audit commands (#1926) 2026-05-15 08:06:26 -04:00
gan-harness.sh fix: harden install planning and sync tracked catalogs 2026-03-31 22:57:48 -07:00
gemini-adapt-agents.js feat: add gemini agent adapter 2026-04-08 15:38:49 -07:00
harness-adapter-compliance.js docs: add data-backed harness adapter scorecard (#1785) 2026-05-12 02:59:52 -04:00
harness-audit.js fix: salvage stale PR plugin install fixes 2026-05-11 18:48:23 -04:00
install-apply.js feat(installer): add --locale flag for translated docs installation 2026-05-17 20:32:52 -04:00
install-plan.js fix: restore short Claude plugin slug and skill installs (#1712) 2026-05-11 02:10:36 -04:00
list-installed.js fix(scripts): add os.homedir() fallback for Windows compatibility 2026-03-28 11:28:12 +08:00
loop-status.js fix: handle dotted reserved snapshot names 2026-04-30 12:25:14 -04:00
observability-readiness.js security: add supply-chain IOC scanner (#1904) 2026-05-14 21:15:35 -04:00
operator-readiness-dashboard.js docs: narrow ecc tools billing blocker 2026-05-18 16:45:31 -04:00
orchestrate-codex-worker.sh fix: resolve all CI test failures (19 fixes across 6 files) (#519) 2026-03-16 01:59:53 -07:00
orchestrate-worktrees.js fix: preserve orchestration launcher compatibility 2026-03-12 15:40:25 -07:00
orchestration-status.js feat: orchestration harness, selective install, observer improvements 2026-03-14 12:55:25 -07:00
platform-audit.js test: point platform audit at May 18 evidence 2026-05-17 22:22:02 -04:00
preview-pack-smoke.js docs: refresh publication readiness gate 2026-05-18 10:49:49 -04:00
release.sh feat: add GitHub Copilot prompt support 2026-05-12 23:00:00 -04:00
repair.js fix(scripts): add os.homedir() fallback for Windows compatibility 2026-03-28 11:28:12 +08:00
session-inspect.js feat: self-improving skills loop — observe, inspect, amend, evaluate 2026-03-14 23:21:18 -07:00
sessions-cli.js fix(scripts): add os.homedir() fallback for Windows compatibility 2026-03-28 11:28:12 +08:00
setup-package-manager.js fix: reject flags passed as package manager names in setup-package-manager CLI 2026-02-13 03:37:46 -08:00
skill-create-output.js fix: narrow unicode cleanup scope 2026-03-29 21:21:18 -04:00
skills-health.js feat(design): skill health dashboard mockup (#518) 2026-03-16 14:01:41 -07:00
status.js feat: add status exit code gate 2026-05-11 12:38:59 -04:00
sync-ecc-to-codex.sh feat: sync the codex baseline and agent roles 2026-04-01 16:08:03 -07:00
uninstall.js fix(scripts): add os.homedir() fallback for Windows compatibility 2026-03-28 11:28:12 +08:00
work-items.js feat: sync GitHub queue into work items 2026-05-11 13:07:29 -04:00