@memnexus-ai/mx-agent-cli 0.1.272 → 0.1.274

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.
Files changed (31) hide show
  1. package/dist/__tests__/codex-write-race.test.js +422 -1
  2. package/dist/__tests__/codex-write-race.test.js.map +1 -1
  3. package/dist/__tests__/coordination-401-production-wiring.test.d.ts +19 -0
  4. package/dist/__tests__/coordination-401-production-wiring.test.d.ts.map +1 -0
  5. package/dist/__tests__/coordination-401-production-wiring.test.js +97 -0
  6. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -0
  7. package/dist/__tests__/coordination-401-recovery.test.d.ts +22 -0
  8. package/dist/__tests__/coordination-401-recovery.test.d.ts.map +1 -0
  9. package/dist/__tests__/coordination-401-recovery.test.js +577 -0
  10. package/dist/__tests__/coordination-401-recovery.test.js.map +1 -0
  11. package/dist/__tests__/coordination-brief-pin.test.js +10 -2
  12. package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
  13. package/dist/__tests__/coordination-brief.test.js +9 -1
  14. package/dist/__tests__/coordination-brief.test.js.map +1 -1
  15. package/dist/__tests__/coordination-provision.test.js +17 -2
  16. package/dist/__tests__/coordination-provision.test.js.map +1 -1
  17. package/dist/__tests__/coordination-token.test.js +24 -0
  18. package/dist/__tests__/coordination-token.test.js.map +1 -1
  19. package/dist/agent-config/hooks/coordination-brief.sh +61 -9
  20. package/dist/commands/coordination.d.ts +40 -6
  21. package/dist/commands/coordination.d.ts.map +1 -1
  22. package/dist/commands/coordination.js +222 -10
  23. package/dist/commands/coordination.js.map +1 -1
  24. package/dist/lib/coordination-token.d.ts +104 -2
  25. package/dist/lib/coordination-token.d.ts.map +1 -1
  26. package/dist/lib/coordination-token.js +223 -42
  27. package/dist/lib/coordination-token.js.map +1 -1
  28. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  29. package/dist/lib/runtime/codex-config.js +113 -27
  30. package/dist/lib/runtime/codex-config.js.map +1 -1
  31. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"coordination-token.d.ts","sourceRoot":"","sources":["../../src/lib/coordination-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAUH;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,0GASf,CAAC;AAMX,eAAO,MAAM,aAAa,0BAA0B,CAAC;AAErD,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAM1D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAElE;AAYD,MAAM,MAAM,kBAAkB;AAC5B,sFAAsF;AACpF,oBAAoB;AACtB,iFAAiF;GAC/E,UAAU;AACZ,8EAA8E;GAC5E,eAAe;AACjB;;;;;;GAMG;GACD,eAAe;AACjB,+EAA+E;GAC7E,eAAe,CAAC;AAEpB,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;IACjD,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACxE,oFAAoF;IACpF,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG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M,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAC9B,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,yEAAyE;IACzE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACxC;AAaD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB,GAAG,kBAAkB,CAgG/G"}
@@ -27,6 +27,12 @@
27
27
  * report "unprovisioned" so the caller degrades, never crash.
28
28
  * - Fail-CLOSED only on a roster mismatch.
29
29
  *
30
+ * ROTATION RECOVERY (#4970): resolveCoordinationToken serves the per-worktree
31
+ * cache unconditionally, so a rotated secret would be presented forever. The
32
+ * companion refreshCoordinationToken() deletes that cache and refetches from the
33
+ * vault; it runs the SAME identity gates (slug validity, marker, roster) so a
34
+ * rejected token can never be turned into a fetch the first resolve would refuse.
35
+ *
30
36
  * ZERO-ORPHAN KV shim (Phase 1): the secret name is the parse-safe double-hyphen
31
37
  * `coordination-token--<project>--<team>` (ND-1). For the DEFAULT project
32
38
  * (memnexus) the live Key Vault still holds the PRE-migration single-hyphen
@@ -36,7 +42,7 @@
36
42
  * vault; Phase 2 renames the secrets and the fallback is removed.
37
43
  */
38
44
  import { execFileSync } from 'node:child_process';
39
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
45
+ import { existsSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
40
46
  import { join } from 'node:path';
41
47
  import { getConfigValue } from './config.js';
42
48
  import { CONFIG_KEY_TOKEN } from './coordination-client.js';
@@ -110,15 +116,37 @@ function defaultFetchSecret(vault, secretName) {
110
116
  return undefined;
111
117
  }
112
118
  }
113
- /** SF-3 born-0600 cache write. A write failure is tolerated (fail-open). */
119
+ /**
120
+ * SF-3 born-0600 cache write. A write failure is tolerated (fail-open) but is
121
+ * REPORTED: `true` only when the bytes actually landed. Callers use that to decide
122
+ * whether they may tell the operator a cached copy was replaced — see writeCache
123
+ * in TokenResolveDeps.
124
+ */
114
125
  function defaultWriteCache(path, value) {
115
126
  try {
116
127
  writeFileSync(path, value, { mode: 0o600 });
128
+ return true;
117
129
  }
118
130
  catch {
119
131
  /* A cache-write failure must not break provisioning — the token is still returned. */
132
+ return false;
120
133
  }
121
134
  }
135
+ /**
136
+ * A fetched secret is usable only if it has non-whitespace content.
137
+ *
138
+ * SF-4 of the #4970 delta security review. The guard below is what keeps a
139
+ * useless vault answer from deleting the ONLY local copy of the token, and it
140
+ * must reject every falsy AND blank value, not just `undefined`: the default
141
+ * fetcher happens to normalise `''` away (`trimmed || undefined`), but that is one
142
+ * line of a DIFFERENT function, and a fetcher that does not — a test double, or a
143
+ * future non-`az` backend — would otherwise delete the cache and write a blank
144
+ * file, restoring the exact defect this round closed. Whitespace-only is rejected
145
+ * here rather than trusted to the fetcher for the same reason.
146
+ */
147
+ function isUsableSecret(value) {
148
+ return typeof value === 'string' && value.trim() !== '';
149
+ }
122
150
  /** Extract the first line and strip all whitespace (marker/cache are single-value). */
123
151
  function firstLineNoSpace(raw) {
124
152
  const firstLine = raw.split(/\r?\n/, 1)[0] ?? '';
@@ -154,6 +182,52 @@ export function resolveRoster(project, env, readFileText) {
154
182
  }
155
183
  return BUILTIN_ROSTERS[project] ?? [];
156
184
  }
185
+ function resolveIdentity(env, readFileText, projectOverride) {
186
+ // Resolve the PROJECT (config-derived, default memnexus). Never throws.
187
+ const project = projectOverride ?? resolveProductSlug();
188
+ // Validate the resolved project slug BEFORE any roster lookup or az/KV call
189
+ // (KI-COORDMT-CLIENT-SLUG-VALIDATION). The default 'memnexus' is known-valid so
190
+ // this never trips the unset path; an explicitly-set invalid slug fails CLOSED
191
+ // as a typed result — it is NOT coerced to memnexus (that would bleed the
192
+ // misconfigured project's traffic into the memnexus tenant). No KV-name is
193
+ // built for an invalid slug.
194
+ if (!isValidProjectSlug(project)) {
195
+ return { ok: false, fail: { status: 'misconfigured', project, detail: invalidProjectSlugMessage(project) } };
196
+ }
197
+ // MF-2: read the authoritative team marker. No worktree/marker → fail-OPEN.
198
+ const worktree = env.CLAUDE_WORKTREE_PATH;
199
+ if (!worktree) {
200
+ return { ok: false, fail: { status: 'unprovisioned', project, detail: 'CLAUDE_WORKTREE_PATH is unset — cannot locate the coordination marker' } };
201
+ }
202
+ const markerRaw = readFileText(join(worktree, MARKER_FILE));
203
+ if (markerRaw === undefined) {
204
+ return { ok: false, fail: { status: 'unprovisioned', project, detail: 'no coordination marker (.mx-coordination-team) in this worktree' } };
205
+ }
206
+ const slug = firstLineNoSpace(markerRaw);
207
+ if (!slug) {
208
+ return { ok: false, fail: { status: 'unprovisioned', project, detail: 'coordination marker is empty' } };
209
+ }
210
+ // SF-2: roster-membership gate for THIS project BEFORE any az call. The roster
211
+ // comes from the OFFLINE file (single source), builtin fallback.
212
+ const roster = resolveRoster(project, env, readFileText);
213
+ if (!roster.includes(slug)) {
214
+ return { ok: false, fail: { status: 'not-on-roster', project, slug } };
215
+ }
216
+ // MF-1: (project, team)-bound per-worktree cache.
217
+ return { ok: true, id: { project, slug, cachePath: join(worktree, cacheFileName(project, slug)) } };
218
+ }
219
+ /**
220
+ * Fetch this identity's token from Key Vault. Primary: parse-safe double-hyphen
221
+ * name (ND-1). Fallback (memnexus only): legacy single-hyphen name — the
222
+ * zero-orphan dual-read against the un-migrated live vault (Phase 2 removes it).
223
+ */
224
+ function fetchFromKeyVault(id, fetchSecret) {
225
+ let fetched = fetchSecret(KEYVAULT_NAME, kvSecretName(id.project, id.slug));
226
+ if (!isUsableSecret(fetched) && id.project === DEFAULT_PRODUCT_SLUG) {
227
+ fetched = fetchSecret(KEYVAULT_NAME, legacyKvSecretName(id.slug));
228
+ }
229
+ return fetched;
230
+ }
157
231
  /**
158
232
  * Resolve the coordination token, self-provisioning from Key Vault when none is
159
233
  * configured. Never throws — every failure is a typed result the caller acts on.
@@ -176,54 +250,25 @@ export function resolveCoordinationToken(deps = {}) {
176
250
  }
177
251
  if (configToken)
178
252
  return { status: 'already-configured', token: configToken, source: 'config' };
179
- // 2. Resolve the PROJECT (config-derived, default memnexus). Never throws.
180
- const project = deps.project ?? resolveProductSlug();
181
- // 2a. Validate the resolved project slug BEFORE any roster lookup or az/KV
182
- // call (KI-COORDMT-CLIENT-SLUG-VALIDATION). The default 'memnexus' is
183
- // known-valid so this never trips the unset path; an explicitly-set
184
- // invalid slug fails CLOSED as a typed result — it is NOT coerced to
185
- // memnexus (that would bleed the misconfigured project's traffic into the
186
- // memnexus tenant). No KV-name is built for an invalid slug.
187
- if (!isValidProjectSlug(project)) {
188
- return { status: 'misconfigured', project, detail: invalidProjectSlugMessage(project) };
189
- }
190
- // 3. MF-2: read the authoritative team marker. No worktree/marker → fail-OPEN.
191
- const worktree = env.CLAUDE_WORKTREE_PATH;
192
- if (!worktree) {
193
- return { status: 'unprovisioned', project, detail: 'CLAUDE_WORKTREE_PATH is unset — cannot locate the coordination marker' };
194
- }
195
- const markerRaw = readFileText(join(worktree, MARKER_FILE));
196
- if (markerRaw === undefined) {
197
- return { status: 'unprovisioned', project, detail: 'no coordination marker (.mx-coordination-team) in this worktree' };
198
- }
199
- const slug = firstLineNoSpace(markerRaw);
200
- if (!slug) {
201
- return { status: 'unprovisioned', project, detail: 'coordination marker is empty' };
202
- }
203
- // 4. SF-2: roster-membership gate for THIS project BEFORE any az call. The
204
- // roster comes from the OFFLINE file (single source), builtin fallback.
205
- const roster = resolveRoster(project, env, readFileText);
206
- if (!roster.includes(slug)) {
207
- return { status: 'not-on-roster', project, slug };
208
- }
253
+ // 2-4. Resolve + gate the (project, team) identity: project slug validity,
254
+ // authoritative marker, roster membership. Shared with the 401 refresh
255
+ // path so both obey the same gates.
256
+ const identity = resolveIdentity(env, readFileText, deps.project);
257
+ if (!identity.ok)
258
+ return identity.fail;
259
+ const { project, slug, cachePath } = identity.id;
209
260
  // 5. MF-1: (project, team)-bound per-worktree cache.
210
- const cachePath = join(worktree, cacheFileName(project, slug));
211
261
  const cachedRaw = readFileText(cachePath);
212
262
  if (cachedRaw) {
213
263
  const cached = firstLineNoSpace(cachedRaw);
214
264
  if (cached)
215
265
  return { status: 'resolved', token: cached, project, slug, source: 'cache' };
216
266
  }
217
- // 6. Fetch from Key Vault. Primary: parse-safe double-hyphen name (ND-1).
218
- // Fallback (memnexus only): legacy single-hyphen name — the zero-orphan
219
- // dual-read against the un-migrated live vault (Phase 2 removes it).
267
+ // 6. Fetch from Key Vault (ND-1 primary name, memnexus legacy fallback).
220
268
  const fetchSecret = deps.fetchSecret ?? defaultFetchSecret;
221
- let fetched = fetchSecret(KEYVAULT_NAME, kvSecretName(project, slug));
222
- let source = 'keyvault';
223
- if (!fetched && project === DEFAULT_PRODUCT_SLUG) {
224
- fetched = fetchSecret(KEYVAULT_NAME, legacyKvSecretName(slug));
225
- }
226
- if (!fetched) {
269
+ const fetched = fetchFromKeyVault(identity.id, fetchSecret);
270
+ const source = 'keyvault';
271
+ if (!isUsableSecret(fetched)) {
227
272
  return {
228
273
  status: 'unprovisioned',
229
274
  project,
@@ -236,4 +281,140 @@ export function resolveCoordinationToken(deps = {}) {
236
281
  writeCache(cachePath, fetched);
237
282
  return { status: 'resolved', token: fetched, project, slug, source };
238
283
  }
284
+ /** Default cache deletion. A failure is reported, never thrown (fail-open). */
285
+ function defaultRemoveFile(path) {
286
+ try {
287
+ if (!existsSync(path))
288
+ return false;
289
+ rmSync(path, { force: true });
290
+ return true;
291
+ }
292
+ catch {
293
+ return false;
294
+ }
295
+ }
296
+ /**
297
+ * Invalidate the per-worktree token cache and refetch the team's token from its
298
+ * source, for retry after the coordination service REJECTED the current token
299
+ * (HTTP 401 — #4970).
300
+ *
301
+ * Why this exists: resolveCoordinationToken returns the per-worktree cache
302
+ * unconditionally when it is non-empty, and nothing anywhere deleted that cache
303
+ * on an HTTP error. After a token rotation every session-start brief would
304
+ * present the dead cached token forever, with no self-heal.
305
+ *
306
+ * Order of preference:
307
+ * 1. The cache already holds a DIFFERENT token — another process (or the
308
+ * hook) refreshed it since this client was built. Use it; do NOT delete a
309
+ * cache entry we never proved bad, and do NOT spend an `az` call.
310
+ * 2. Otherwise refetch from Key Vault and, ONLY if that yields a token,
311
+ * replace the cache with it (deleted, then re-written born 0600) so nothing
312
+ * — this process, the session-start hook, or a later run — can serve the
313
+ * rejected token again. If the fetch yields nothing the cache is LEFT
314
+ * ALONE: see the comment at the fetch below; deleting it converts a loud
315
+ * repeating failure into permanent silence. That "stays loud" guarantee
316
+ * holds only where a cache actually exists, so the returned detail is
317
+ * derived from the cache that was read — the no-cache case is reported as
318
+ * the one that will go silent and needs a human (SF-1).
319
+ *
320
+ * The SAME identity gates as the first resolve apply (valid project slug,
321
+ * authoritative marker, roster membership), so a 401 can never be turned into a
322
+ * fetch of a secret the initial resolve would have refused. Never throws, never
323
+ * logs the token, and never writes to the global config.
324
+ *
325
+ * `rejectedToken` is compared but never logged; pass '' when it is unknown.
326
+ */
327
+ export function refreshCoordinationToken(rejectedToken, deps = {}) {
328
+ const env = deps.env ?? process.env;
329
+ const readFileText = deps.readFileText ?? defaultReadFileText;
330
+ const identity = resolveIdentity(env, readFileText, deps.project);
331
+ if (!identity.ok)
332
+ return identity.fail;
333
+ const { project, slug, cachePath } = identity.id;
334
+ const cachedRaw = readFileText(cachePath);
335
+ const cached = cachedRaw ? firstLineNoSpace(cachedRaw) : '';
336
+ if (cached && cached !== rejectedToken) {
337
+ return { status: 'refreshed', token: cached, project, slug, source: 'cache', cacheInvalidated: false };
338
+ }
339
+ // FETCH FIRST, DELETE ONLY ON SUCCESS. Do NOT reorder this — the obvious
340
+ // "invalidate then refetch" order is a silent-outage bug (security review of
341
+ // #4970), and the reasoning is load-bearing:
342
+ //
343
+ // The az fetch is documented FAIL-OPEN, and "az not logged in" is an EXPECTED
344
+ // state in an agent worktree. Deleting first and then failing to fetch leaves
345
+ // the worktree with NO token at all. The session-start hook then finds no
346
+ // cache, its own az fetch fails too, and it takes its fail-open branch:
347
+ // exit 0 with NO OUTPUT. The brief is never invoked again, so neither the
348
+ // CLI's loud TOKEN REJECTED block nor the hook's 401 block can ever fire —
349
+ // session N is loud, every session after it is SILENT, on the channel that
350
+ // carries P0 escalations, until a human happens to run `az login`.
351
+ //
352
+ // Keeping the rejected token on disk is strictly better: it is refused again
353
+ // next session, which keeps the 401 — and therefore the loud block — firing
354
+ // every single session until someone fixes it. A credential the service
355
+ // already refuses grants nothing; losing the ONLY local copy costs the alarm.
356
+ //
357
+ // So: nothing is deleted unless we hold a replacement in hand.
358
+ const fetchSecret = deps.fetchSecret ?? defaultFetchSecret;
359
+ const fetched = fetchFromKeyVault(identity.id, fetchSecret);
360
+ if (!isUsableSecret(fetched)) {
361
+ // SF-1 of the delta security review: which of the TWO states we are in decides
362
+ // whether the loudness guarantee above actually holds, so the message is
363
+ // derived from the cache we just read, never asserted unconditionally.
364
+ //
365
+ // (a) The cache still holds the rejected token. The reasoning above applies
366
+ // verbatim: it is presented again next session, refused again, and the
367
+ // loud block fires again. Nothing to do beyond fixing the vault.
368
+ // (b) There is NO cached token — no cache file, an empty/whitespace-only
369
+ // one, or a write that failed earlier (the hook's cache write ends in
370
+ // `|| true`, and a token supplied via MX_COORD_SERVICE_TOKEN or the
371
+ // global config never writes a cache at all). Then the guarantee does
372
+ // NOT hold: next session resolveCoordinationToken finds no cache, its own
373
+ // az fetch fails, the session-start hook takes its fail-open exit 0 with
374
+ // no output, and the channel that carries P0 escalations goes silent with
375
+ // nothing on screen. This state needs a human before the next session,
376
+ // and the message has to say so — it is the only warning that gets shown.
377
+ const rejectedStillCached = cached !== '' && cached === rejectedToken;
378
+ return {
379
+ status: 'unprovisioned',
380
+ project,
381
+ slug,
382
+ cacheInvalidated: false,
383
+ detail: rejectedStillCached
384
+ ? 'Key Vault returned no token (az not logged in, KV unreachable, or secret missing); ' +
385
+ 'the rejected token was LEFT in the per-worktree cache on purpose, so this failure stays loud every session'
386
+ : 'Key Vault returned no token (az not logged in, KV unreachable, or secret missing), and this worktree ' +
387
+ 'holds NO cached token to fail loudly with. NEEDS MANUAL ATTENTION BEFORE THE NEXT SESSION: the next ' +
388
+ 'session-start brief will find no cache, fail the same fetch, and exit silently with no output, so ' +
389
+ 'queued cross-team escalations will read as an empty inbox. Run `az login` in this worktree, or ask the ' +
390
+ 'platform team to re-issue this team\'s token (P1).',
391
+ };
392
+ }
393
+ // Delete-then-write, in that order, is deliberate: writeFileSync applies `mode`
394
+ // only when it CREATES the file, so writing over a surviving entry would inherit
395
+ // whatever mode it already had and lose the SF-3 born-0600 property. Writing
396
+ // first and deleting after cannot fix SF-2 either — both operations target the
397
+ // same path. So the order stays and the CLAIM is what changes: cacheInvalidated
398
+ // is the result of the WRITE, not of the delete.
399
+ const removeFile = deps.removeFile ?? defaultRemoveFile;
400
+ const removed = removeFile(cachePath);
401
+ const writeCache = deps.writeCache ?? defaultWriteCache;
402
+ // A stub that reports nothing leaves the outcome UNKNOWN, and neither claim is
403
+ // made from an unknown: `true` is required to say a copy was replaced, `false`
404
+ // is required to say the write was lost.
405
+ const writeResult = writeCache(cachePath, fetched);
406
+ return {
407
+ status: 'refreshed',
408
+ token: fetched,
409
+ project,
410
+ slug,
411
+ source: 'keyvault',
412
+ // Replaced = the old entry is gone AND the new one landed. `removed === false`
413
+ // with a successful write is a first-time cache fill, not a replacement.
414
+ cacheInvalidated: removed && writeResult === true,
415
+ cacheWriteFailed: writeResult === false,
416
+ cacheRemoved: removed,
417
+ unchanged: fetched === rejectedToken,
418
+ };
419
+ }
239
420
  //# sourceMappingURL=coordination-token.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"coordination-token.js","sourceRoot":"","sources":["../../src/lib/coordination-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU;IACV,WAAW;IACX,KAAK;IACL,UAAU;IACV,WAAW;IACX,iBAAiB;IACjB,MAAM;IACN,SAAS;CACD,CAAC;AAEX,MAAM,eAAe,GAAsC;IACzD,CAAC,oBAAoB,CAAC,EAAE,YAAY;CACrC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAErD,qFAAqF;AACrF,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAC1D,oFAAoF;AACpF,MAAM,eAAe,GAAG,IAAI,CAAC,iBAAiB,EAAE,cAAc,EAAE,qCAAqC,CAAC,CAAC;AAEvG,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAE5C;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,IAAY;IACxD,OAAO,uBAAuB,OAAO,KAAK,IAAI,EAAE,CAAC;AACnD,CAAC;AAED,oFAAoF;AACpF,SAAS,kBAAkB,CAAC,I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gB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -1880,8 +1880,45 @@ function writeFileEnsuringDir(absPath, content, worktreeRoot) {
1880
1880
  const parentId = directoryIdentity(parentDir);
1881
1881
  let installed = false;
1882
1882
  let created = false;
1883
+ // Set false as the LAST statement of the `try`, so it is true for every path that leaves
1884
+ // the block by throwing and false only for a write that was accepted. The `finally` needs
1885
+ // to know which, because a `close` failure means opposite things on the two paths — see
1886
+ // the `finally` at the bottom of this function.
1887
+ let failing = true;
1888
+ // ── THE DESCRIPTOR IS HELD OPEN ACROSS THE INSTALL CHECK (#4908) ─────────────
1889
+ // `fd` is closed in the `finally` at the BOTTOM of this function, after the install has
1890
+ // been verified — not immediately after the content is written, which is where it used
1891
+ // to be closed.
1892
+ //
1893
+ // The install check below asks whether the entry now at `absPath` carries the `{dev,
1894
+ // ino}` of the inode this call renamed there. An inode NUMBER is not an identity: once
1895
+ // nothing holds the object, the number is FREE and the next object created on that
1896
+ // filesystem can take it. With the descriptor closed at the write, an attacker who
1897
+ // unlinks the just-installed artifact inside the `rename` → `lstat` window gets that
1898
+ // number handed straight back and writes attacker-controlled content that the primary
1899
+ // install check certifies. Measured: reuse on attempt 0, `ok=true`, the artifact listed
1900
+ // as WRITTEN, and `# ATTACKER CONTENT` on disk at `AGENTS.override.md` — which Codex
1901
+ // reads as a REPLACEMENT for `AGENTS.md`. 322 of 400 trials in a tighter variant.
1902
+ //
1903
+ // An OPEN DESCRIPTOR PINS THE INODE. The number cannot be recycled while this deploy
1904
+ // holds it, so an attacker who unlinks the artifact and creates a replacement gets a
1905
+ // DIFFERENT number, the `{dev, ino}` comparison fails, and the deploy reports a failed
1906
+ // write instead of a false success. Measured over the same harness:
1907
+ //
1908
+ // inode reuse WITHOUT holding an fd open: 200/200
1909
+ // inode reuse WHILE holding an fd open: 0/200
1910
+ //
1911
+ // Rejected alternative, tested: `birthtimeNs`/`ctimeNs` do NOT distinguish the reused
1912
+ // inode — both are byte-identical across the two creations, because the timestamps are
1913
+ // coarser than the race window. This is a LIFETIME, not another check; adding a fourth
1914
+ // field to a comparison that is defeated at its root would have been the fifth round of
1915
+ // the same mistake.
1916
+ //
1917
+ // The cost is one descriptor held for the duration of a rename and an lstat, per
1918
+ // artifact, written sequentially.
1919
+ let fd = -1;
1883
1920
  try {
1884
- const fd = openSync(tmpPath, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_NOFOLLOW,
1921
+ fd = openSync(tmpPath, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_NOFOLLOW,
1885
1922
  // 0o600 until the content is written — the final mode is set with `fchmod` below,
1886
1923
  // so the bytes are never briefly readable more widely than they end up.
1887
1924
  0o600);
@@ -1889,33 +1926,27 @@ function writeFileEnsuringDir(absPath, content, worktreeRoot) {
1889
1926
  // nothing moved, and under this name in another directory if something did. The
1890
1927
  // difference is what `tempResidueNote` reports (SF-K).
1891
1928
  created = true;
1892
- let opened;
1893
- try {
1894
- // ── CHECK 1 OF 3: BEFORE A SINGLE BYTE IS WRITTEN (MUST FIX) ─────────────
1895
- // `openSync` resolved `.../.codex/<name>.mx-tmp-…` by NAME. If `.codex` became a
1896
- // symlink to the main repo's `.codex` between the containment walk and this open,
1897
- // the file that now exists is in the MAIN REPO. Refusing here is what makes the
1898
- // measured worst case a zero-byte temp instead of a 4983-byte fleet-wide write —
1899
- // the `finally` below unlinks it.
1900
- assertSameDirectory(parentDir, parentId, absPath, 'while the temporary file was being created');
1901
- // DEFENCE IN DEPTH. `O_EXCL` should already make this impossible, so a link count
1902
- // other than 1 on a file this call just created means an assumption above is wrong.
1903
- // Refuse rather than write — the destination of the extra name is unknown, and on
1904
- // this path an unknown destination has been the main repo three reviews running.
1905
- opened = fstatSync(fd, { bigint: true });
1906
- if (opened.nlink !== 1n) {
1907
- throw new ContainedWriteRefusal(`refusing to write ${absPath}: the temporary file this deploy just created ` +
1908
- `(${tmpPath}) already has ${opened.nlink} names, so the bytes would also land outside ` +
1909
- 'this worktree. This should be unreachable (the entry was created exclusively) — treat ' +
1910
- 'it as a filesystem or race condition and inspect the path by hand. Nothing was ' +
1911
- `written, and ${absPath} is untouched.`);
1912
- }
1913
- fchmodSync(fd, mode);
1914
- writeFileSync(fd, content);
1915
- }
1916
- finally {
1917
- closeSync(fd);
1929
+ // ── CHECK 1 OF 3: BEFORE A SINGLE BYTE IS WRITTEN (MUST FIX) ───────────────
1930
+ // `openSync` resolved `.../.codex/<name>.mx-tmp-…` by NAME. If `.codex` became a
1931
+ // symlink to the main repo's `.codex` between the containment walk and this open,
1932
+ // the file that now exists is in the MAIN REPO. Refusing here is what makes the
1933
+ // measured worst case a zero-byte temp instead of a 4983-byte fleet-wide write —
1934
+ // the `catch` below unlinks it.
1935
+ assertSameDirectory(parentDir, parentId, absPath, 'while the temporary file was being created');
1936
+ // DEFENCE IN DEPTH. `O_EXCL` should already make this impossible, so a link count
1937
+ // other than 1 on a file this call just created means an assumption above is wrong.
1938
+ // Refuse rather than write — the destination of the extra name is unknown, and on
1939
+ // this path an unknown destination has been the main repo three reviews running.
1940
+ const opened = fstatSync(fd, { bigint: true });
1941
+ if (opened.nlink !== 1n) {
1942
+ throw new ContainedWriteRefusal(`refusing to write ${absPath}: the temporary file this deploy just created ` +
1943
+ `(${tmpPath}) already has ${opened.nlink} names, so the bytes would also land outside ` +
1944
+ 'this worktree. This should be unreachable (the entry was created exclusively) — treat ' +
1945
+ 'it as a filesystem or race condition and inspect the path by hand. Nothing was ' +
1946
+ `written, and ${absPath} is untouched.`);
1918
1947
  }
1948
+ fchmodSync(fd, mode);
1949
+ writeFileSync(fd, content);
1919
1950
  // ── CHECK 2 OF 3: THE LAST THING BEFORE THE INSTALL (MUST FIX) ─────────────
1920
1951
  // `renameSync` resolves BOTH names afresh. Re-identifying the directory here leaves a
1921
1952
  // residual window exactly one rename call wide — narrower than the two-syscall window
@@ -1966,6 +1997,9 @@ function writeFileEnsuringDir(absPath, content, worktreeRoot) {
1966
1997
  'is NOT this deploy\'s output and the deploy must not report it as written. Remove the ' +
1967
1998
  'entry at that path by hand and redeploy.');
1968
1999
  }
2000
+ // The artifact is accepted. Everything above either returned normally or threw, so this
2001
+ // is the only statement that can clear the flag, and it is the last one in the block.
2002
+ failing = false;
1969
2003
  }
1970
2004
  catch (err) {
1971
2005
  // NO `.mx-tmp-*` LITTER, on any failure path — the refusal above, a write error, a
@@ -1996,6 +2030,58 @@ function writeFileEnsuringDir(absPath, content, worktreeRoot) {
1996
2030
  }
1997
2031
  throw err;
1998
2032
  }
2033
+ finally {
2034
+ // The close that #4908 moved here. It runs after the acceptance on the success path
2035
+ // and after the cleanup on every failure path, so the inode this deploy installed is
2036
+ // pinned for the whole of the window an attacker would need to recycle its number.
2037
+ //
2038
+ // ── A `close` FAILURE IS SUPPRESSED ON THE FAILURE PATH ONLY (#4908 round 2) ─
2039
+ // The first version of this `finally` swallowed EVERY `close` error, and that was a
2040
+ // fail-closed → fail-open REGRESSION against the commit before it. Until #4908 moved
2041
+ // the `close` here it sat in an INNER `finally` with no `catch`, so a `close` failure
2042
+ // PROPAGATED and the artifact was reported as a FAILED write. Suppressing it turned
2043
+ // that same filesystem into a deploy reporting ok=true with the artifact listed as
2044
+ // WRITTEN — which is precisely the false green #4896/#4897 exist to remove.
2045
+ //
2046
+ // `close` is not a formality. It is where DEFERRED WRITE-BACK errors surface: ENOSPC
2047
+ // and EDQUOT when an allocation the write only reserved cannot be satisfied, EIO on a
2048
+ // media error, ESTALE on NFS, and on Linux any error the kernel recorded against this
2049
+ // file since the descriptor was opened (`errseq_t`). Every one of them means the bytes
2050
+ // this deploy generated may never have reached the disk — and because
2051
+ // `AGENTS.override.md` REPLACES `AGENTS.md`, a suppressed failure here is a worktree
2052
+ // launching on a truncated or empty instruction file that the deploy certified green.
2053
+ //
2054
+ // So the suppression is kept for exactly the case that motivated it, and no wider:
2055
+ //
2056
+ // FAILURE PATH (`failing`): an error is already propagating, and an exception thrown
2057
+ // from a `finally` REPLACES it. Rethrowing here would discard the refusal text
2058
+ // naming what is really on disk — a worse report than the one it replaces, about
2059
+ // the same failed write. Suppressed.
2060
+ //
2061
+ // SUCCESS PATH (`!failing`): nothing is propagating, and the only report that would
2062
+ // otherwise be produced is "written". There is no error to discard, and every
2063
+ // `close` errno above is a reason to doubt the bytes, so the write is reported
2064
+ // FAILED. (`EBADF` should be unreachable — `fd` is this call's own descriptor,
2065
+ // closed exactly once — and is deliberately not special-cased: an unexplained
2066
+ // errno on this path is more reason to refuse, not less.)
2067
+ if (fd >= 0) {
2068
+ try {
2069
+ closeSync(fd);
2070
+ }
2071
+ catch (closeErr) {
2072
+ if (!failing) {
2073
+ throw new Error(`${absPath} was installed, but the descriptor this deploy wrote it through could ` +
2074
+ `not be closed (${closeErr instanceof Error ? closeErr.message : String(closeErr)}). ` +
2075
+ '`close` is where a deferred write-back failure surfaces — ENOSPC, EDQUOT, EIO, ' +
2076
+ 'ESTALE — so this deploy CANNOT confirm that the bytes it generated reached the ' +
2077
+ 'disk, and the entry at that path may be truncated, empty, or the artifact a ' +
2078
+ 'previous deploy left. Treating the write as FAILED. Inspect that path by hand ' +
2079
+ 'and redeploy.');
2080
+ }
2081
+ /* failure path — see above, deliberately not surfaced */
2082
+ }
2083
+ }
2084
+ }
1999
2085
  }
2000
2086
  /**
2001
2087
  * Deploy every Codex config artifact into the worktree. Idempotent — each file is