mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
`FileAuthStorageBackend` locked `auth.json` with proper-lockfile and `realpath: false`, so the lock directory was `<path as given>.lock`. Reads and writes follow symlinks to the same real file, but each path alias got its own lock. For example, an agent dir whose `auth.json` is a symlink to a shared file used a different lock than the real file. Two pi processes could then enter the credential-modification section at the same time and refresh the same OAuth token concurrently. This change drops `realpath: false` from the sync and async lock calls, so proper-lockfile resolves the path and every alias of the file uses one lock. Resolving the path needs the file to exist, which is already the case: `ensureFileExists()` runs before either lock is taken. The same `realpath: false` pattern is also in `settings-manager.ts`, `trust-manager.ts`, and `package-manager-cli.ts`. This change leaves those alone. ## Testing - I added a test to `test/auth-storage.test.ts`. It holds the lock on the real `auth.json`, then checks that a backend opened through a symlink alias waits in `withLockAsync` until aborted, and gets `ELOCKED` from `withLock`. Neither path runs the mutation. Without the fix the test fails because the async call enters the lock; with the fix it passes. - `node ../../node_modules/vitest/dist/cli.js --run test/auth-storage test/settings`: 151 tests pass. - `npm run check` passes. - With the reproduction script from the issue, current main prints `symlink alias: ENTERED`; with this change it prints `symlink alias: BLOCKED`. The same-path control prints `BLOCKED` in both cases. Fixes #11655 Requested by @badlogic Co-authored-by: triagent <triagent@localhost> Co-authored-by: Mario Zechner <contact@badlogicgames.com> |
||
|---|---|---|
| .. | ||
| agent | ||
| ai | ||
| chord | ||
| codemode | ||
| coding-agent | ||
| durable | ||
| env | ||
| evals | ||
| mcp | ||
| schema | ||
| telemetry | ||
| tui | ||