@phnx-labs/agents-cli 1.23.49 → 1.23.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.50
4
+
5
+ - **A launch killed in its first second no longer locks the harness for ten minutes (PHNX-4610).** `withFileLockAsync` took its lock through proper-lockfile's async `lock()`, which registers the exit cleanup only after `mkdir` and two more fs callbacks, and its async `unlock()` drops that registration before the `rmdir`. A SIGTERM or SIGHUP landing in either gap left `<target>.lock` behind, and every later caller read it as held until it went stale. For the installation lock that is ten minutes, longer than the three minutes `agents __launch-lease` waits, so the next launch of that harness failed with `Could not acquire lock … Lock file is already being held` and `could not safely coordinate this launch with a possibly in-progress update`. Rush Cloud hit it when Stop landed during the shim's launch: the follow-up waited six minutes and failed. The async variant now takes and releases the lock through the same sync API `withFileLock` uses, so registration and removal never straddle an event-loop turn; the retry wait between attempts stays asynchronous. Measured with 12 children cycling the lock and killed mid-cycle: 8 of 12 left the lock before, 0 of 12 after. A SIGKILL still leaves it, as before. Source: `cli/src/lib/fs-atomic.ts`, `cli/src/lib/fs-atomic.test.ts`.
6
+
3
7
  ## 1.23.49
4
8
 
5
9
  - **You hear the seat count before the names.** The daemon now notifies you once when the seat count differs from your active accounts at low confidence ("claude: about 5 of 8 accounts cover your usage"), saying when it will name which ones. Before, it stayed silent until every account had 3 weeks of readings. Source: `cli/src/lib/accounting/advise.ts`.
@@ -53,6 +53,24 @@ export async function atomicWriteFile(filePath, content, options = 'utf-8') {
53
53
  throw err;
54
54
  }
55
55
  }
56
+ function lockOnce(filePath, staleMs, realpath, onCompromised) {
57
+ try {
58
+ return lockfile.lockSync(filePath, { stale: staleMs, realpath, onCompromised });
59
+ }
60
+ catch (err) {
61
+ if (err instanceof Error && err.code === 'ENOTDIR') {
62
+ try {
63
+ const base = realpath ? fs.realpathSync(filePath) : filePath;
64
+ const lockPath = `${base}.lock`;
65
+ const st = fs.statSync(lockPath);
66
+ if (st.isFile())
67
+ fs.unlinkSync(lockPath);
68
+ }
69
+ catch { }
70
+ }
71
+ throw err;
72
+ }
73
+ }
56
74
  export function withFileLock(filePath, fn, opts = {}) {
57
75
  let release = null;
58
76
  let lastError;
@@ -62,25 +80,11 @@ export function withFileLock(filePath, fn, opts = {}) {
62
80
  const deadline = Date.now() + acquireTimeoutMs;
63
81
  for (let attempt = 0;; attempt++) {
64
82
  try {
65
- release = lockfile.lockSync(filePath, {
66
- stale: staleMs,
67
- realpath: opts.realpath ?? true,
68
- onCompromised: (err) => { compromised = err; },
69
- });
83
+ release = lockOnce(filePath, staleMs, opts.realpath ?? true, (err) => { compromised = err; });
70
84
  break;
71
85
  }
72
86
  catch (err) {
73
87
  lastError = err;
74
- if (err instanceof Error && err.code === 'ENOTDIR') {
75
- try {
76
- const base = (opts.realpath ?? true) ? fs.realpathSync(filePath) : filePath;
77
- const lockPath = `${base}.lock`;
78
- const st = fs.statSync(lockPath);
79
- if (st.isFile())
80
- fs.unlinkSync(lockPath);
81
- }
82
- catch { }
83
- }
84
88
  if (Date.now() >= deadline)
85
89
  break;
86
90
  const backoff = Math.min(LOCK_RETRY_MIN_MS * (attempt + 1), LOCK_RETRY_MAX_MS);
@@ -123,25 +127,11 @@ export async function withFileLockAsync(filePath, fn, opts = {}) {
123
127
  const deadline = Date.now() + acquireTimeoutMs;
124
128
  for (let attempt = 0;; attempt++) {
125
129
  try {
126
- release = await lockfile.lock(filePath, {
127
- stale: staleMs,
128
- realpath: opts.realpath ?? true,
129
- onCompromised: (err) => { compromised = err; },
130
- });
130
+ release = lockOnce(filePath, staleMs, opts.realpath ?? true, (err) => { compromised = err; });
131
131
  break;
132
132
  }
133
133
  catch (err) {
134
134
  lastError = err;
135
- if (err instanceof Error && err.code === 'ENOTDIR') {
136
- try {
137
- const base = (opts.realpath ?? true) ? fs.realpathSync(filePath) : filePath;
138
- const lockPath = `${base}.lock`;
139
- const st = fs.statSync(lockPath);
140
- if (st.isFile())
141
- fs.unlinkSync(lockPath);
142
- }
143
- catch { }
144
- }
145
135
  if (Date.now() >= deadline)
146
136
  break;
147
137
  const backoff = Math.min(LOCK_RETRY_MIN_MS * (attempt + 1), LOCK_RETRY_MAX_MS);
@@ -170,7 +160,7 @@ export async function withFileLockAsync(filePath, fn, opts = {}) {
170
160
  }
171
161
  finally {
172
162
  try {
173
- await release();
163
+ release();
174
164
  }
175
165
  catch { }
176
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.49",
3
+ "version": "1.23.50",
4
4
  "description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",