@integrity-labs/agt-cli 0.28.1306 → 0.28.1307
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/dist/{api-client-W53BBB2B.js → api-client-HAN3QU6H.js} +2 -2
- package/dist/bin/agt.js +5 -5
- package/dist/{chunk-PT3QK5ZP.js → chunk-CQQYZUC5.js} +8 -1
- package/dist/chunk-CQQYZUC5.js.map +1 -0
- package/dist/{chunk-7V53KRPM.js → chunk-IA3IT3JM.js} +3 -3
- package/dist/{chunk-K5SXTDKK.js → chunk-VOYD7FPP.js} +2 -2
- package/dist/{claude-pair-runtime-MC3K2BXU.js → claude-pair-runtime-AAGIQSUI.js} +2 -2
- package/dist/lib/manager-worker.js +541 -213
- package/dist/lib/manager-worker.js.map +1 -1
- package/dist/{persistent-session-ZC4XAUTS.js → persistent-session-FJ4Y7XIB.js} +4 -2
- package/dist/{responsiveness-probe-TA47HG3A.js → responsiveness-probe-2MCC7NOE.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-PT3QK5ZP.js.map +0 -1
- /package/dist/{api-client-W53BBB2B.js.map → api-client-HAN3QU6H.js.map} +0 -0
- /package/dist/{chunk-7V53KRPM.js.map → chunk-IA3IT3JM.js.map} +0 -0
- /package/dist/{chunk-K5SXTDKK.js.map → chunk-VOYD7FPP.js.map} +0 -0
- /package/dist/{claude-pair-runtime-MC3K2BXU.js.map → claude-pair-runtime-AAGIQSUI.js.map} +0 -0
- /package/dist/{persistent-session-ZC4XAUTS.js.map → persistent-session-FJ4Y7XIB.js.map} +0 -0
- /package/dist/{responsiveness-probe-TA47HG3A.js.map → responsiveness-probe-2MCC7NOE.js.map} +0 -0
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
tripClass,
|
|
71
71
|
writeEtcEnvironment,
|
|
72
72
|
writeProfileDScript
|
|
73
|
-
} from "../chunk-
|
|
73
|
+
} from "../chunk-IA3IT3JM.js";
|
|
74
74
|
import {
|
|
75
75
|
ApiError,
|
|
76
76
|
adoptHostKeyInProcess,
|
|
@@ -88,7 +88,7 @@ import {
|
|
|
88
88
|
probeHostKey,
|
|
89
89
|
requireHost,
|
|
90
90
|
setConfigHash
|
|
91
|
-
} from "../chunk-
|
|
91
|
+
} from "../chunk-VOYD7FPP.js";
|
|
92
92
|
import {
|
|
93
93
|
BLOCKED_ON_PROMPT_DECISION,
|
|
94
94
|
CHANNEL_SECRET_ENV_KEYS,
|
|
@@ -164,6 +164,7 @@ import {
|
|
|
164
164
|
seedContainerMemory,
|
|
165
165
|
sessionBlockedOnPrompt,
|
|
166
166
|
sessionHealthyAndUnblocked,
|
|
167
|
+
setHostPathMigrationDeferral,
|
|
167
168
|
sha256,
|
|
168
169
|
sharedBusyBuckets,
|
|
169
170
|
shouldLogBlockedPrompt,
|
|
@@ -183,7 +184,7 @@ import {
|
|
|
183
184
|
webFetchBaselineValue,
|
|
184
185
|
webFetchRestartNeeded,
|
|
185
186
|
writeEgressAllowlist
|
|
186
|
-
} from "../chunk-
|
|
187
|
+
} from "../chunk-CQQYZUC5.js";
|
|
187
188
|
import {
|
|
188
189
|
isAgentIdle,
|
|
189
190
|
isStaleForToday,
|
|
@@ -1692,7 +1693,7 @@ function clearEpisode(codeName) {
|
|
|
1692
1693
|
|
|
1693
1694
|
// src/lib/manager-worker.ts
|
|
1694
1695
|
import { join as join48, dirname as dirname11, delimiter as pathDelimiter } from "path";
|
|
1695
|
-
import { homedir as homedir17, hostname, platform as platform3 } from "os";
|
|
1696
|
+
import { homedir as homedir17, hostname as hostname2, platform as platform3 } from "os";
|
|
1696
1697
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1697
1698
|
|
|
1698
1699
|
// ../../packages/core/dist/provisioning/channel-policy-env.js
|
|
@@ -5369,6 +5370,411 @@ function notAuthenticatedSkipOutcome() {
|
|
|
5369
5370
|
}
|
|
5370
5371
|
var NOT_AUTHENTICATED_CAUSE = "Claude Code is logged out on this host (subscription mode); log in again as the host user, a manager restart will not fix it";
|
|
5371
5372
|
|
|
5373
|
+
// src/lib/manager/auth-refresh-held-outcome.ts
|
|
5374
|
+
function authRefreshHeldOutcome(sessionHealthy) {
|
|
5375
|
+
return {
|
|
5376
|
+
decision: "held-auth-refresh",
|
|
5377
|
+
spawnAttempted: false,
|
|
5378
|
+
sessionHealthyAfter: sessionHealthy,
|
|
5379
|
+
detail: AUTH_REFRESH_HELD_CAUSE
|
|
5380
|
+
};
|
|
5381
|
+
}
|
|
5382
|
+
var AUTH_REFRESH_HELD_CAUSE = "held: the host's Claude login is inside its refresh window; no spawn or restart until it refreshes (usually about a minute, at most about 30), a manager restart will not help";
|
|
5383
|
+
|
|
5384
|
+
// src/lib/claude-auth-detect.ts
|
|
5385
|
+
import { readFile, readdir } from "fs/promises";
|
|
5386
|
+
import { homedir as homedir4, platform } from "os";
|
|
5387
|
+
import { join as join14 } from "path";
|
|
5388
|
+
import { execFile } from "child_process";
|
|
5389
|
+
import { promisify } from "util";
|
|
5390
|
+
var execFileAsync = promisify(execFile);
|
|
5391
|
+
var EXPIRING_SOON_MS = 48 * 60 * 60 * 1e3;
|
|
5392
|
+
async function detectClaudeAuth() {
|
|
5393
|
+
if (process.env["ANTHROPIC_API_KEY"] || process.env["ANTHROPIC_AUTH_TOKEN"]) {
|
|
5394
|
+
return { mode: "api_key", status: "valid", expires_at: null };
|
|
5395
|
+
}
|
|
5396
|
+
const creds = await readOauthCredentials();
|
|
5397
|
+
if (!creds) return null;
|
|
5398
|
+
return computeSubscriptionStatus(creds);
|
|
5399
|
+
}
|
|
5400
|
+
async function detectClaudeSubscriptionAuth() {
|
|
5401
|
+
const creds = await readOauthCredentials();
|
|
5402
|
+
if (!creds) return null;
|
|
5403
|
+
return computeSubscriptionStatus(creds);
|
|
5404
|
+
}
|
|
5405
|
+
async function findClaudeCredentialsPaths() {
|
|
5406
|
+
return (await discoverCredentialCandidates()).paths;
|
|
5407
|
+
}
|
|
5408
|
+
async function readOauthCredentials() {
|
|
5409
|
+
if (platform() === "darwin") {
|
|
5410
|
+
const fromKeychain = await readMacKeychain();
|
|
5411
|
+
if (fromKeychain) return fromKeychain;
|
|
5412
|
+
}
|
|
5413
|
+
const candidates = await findClaudeCredentialsPaths();
|
|
5414
|
+
for (const path of candidates) {
|
|
5415
|
+
const parsed = await readJsonSilently(path);
|
|
5416
|
+
if (parsed) {
|
|
5417
|
+
return parsed.claudeAiOauth ?? parsed.oauth ?? parsed;
|
|
5418
|
+
}
|
|
5419
|
+
}
|
|
5420
|
+
return null;
|
|
5421
|
+
}
|
|
5422
|
+
async function readMacKeychain() {
|
|
5423
|
+
try {
|
|
5424
|
+
const { stdout } = await execFileAsync(
|
|
5425
|
+
"security",
|
|
5426
|
+
["find-generic-password", "-s", "Claude Code-credentials", "-w"],
|
|
5427
|
+
{ timeout: 3e3 }
|
|
5428
|
+
);
|
|
5429
|
+
const parsed = JSON.parse(stdout.trim());
|
|
5430
|
+
return parsed.claudeAiOauth ?? parsed;
|
|
5431
|
+
} catch {
|
|
5432
|
+
return null;
|
|
5433
|
+
}
|
|
5434
|
+
}
|
|
5435
|
+
async function readJsonSilently(path) {
|
|
5436
|
+
try {
|
|
5437
|
+
const raw = await readFile(path, "utf-8");
|
|
5438
|
+
return JSON.parse(raw);
|
|
5439
|
+
} catch {
|
|
5440
|
+
return null;
|
|
5441
|
+
}
|
|
5442
|
+
}
|
|
5443
|
+
function credentialPresenceFrom(outcomes) {
|
|
5444
|
+
if (outcomes.includes("parsed")) return "present";
|
|
5445
|
+
if (outcomes.includes("unreadable")) return "unreadable";
|
|
5446
|
+
return "absent";
|
|
5447
|
+
}
|
|
5448
|
+
async function discoverCredentialCandidates(deps = {}) {
|
|
5449
|
+
const home = deps.home ?? homedir4();
|
|
5450
|
+
const paths = [join14(home, ".claude", ".credentials.json"), join14(home, ".claude", "credentials.json")];
|
|
5451
|
+
const outcomes = [];
|
|
5452
|
+
const linuxRoot = deps.linuxRoot ?? (platform() === "linux" && typeof process.getuid === "function" && process.getuid() === 0);
|
|
5453
|
+
if (linuxRoot) {
|
|
5454
|
+
const list = deps.readdirImpl ?? ((path) => readdir(path, { withFileTypes: true }));
|
|
5455
|
+
try {
|
|
5456
|
+
const entries = await list("/home");
|
|
5457
|
+
for (const entry of entries.filter((e) => e.isDirectory()).sort((x, y) => x.name.localeCompare(y.name))) {
|
|
5458
|
+
paths.push(join14("/home", entry.name, ".claude", ".credentials.json"));
|
|
5459
|
+
paths.push(join14("/home", entry.name, ".claude", "credentials.json"));
|
|
5460
|
+
}
|
|
5461
|
+
} catch (err) {
|
|
5462
|
+
const code = err.code;
|
|
5463
|
+
outcomes.push(code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable");
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5466
|
+
return { paths, outcomes };
|
|
5467
|
+
}
|
|
5468
|
+
function keychainOutcomeFrom(result) {
|
|
5469
|
+
if ("error" in result) return "unreadable";
|
|
5470
|
+
try {
|
|
5471
|
+
JSON.parse(result.stdout.trim());
|
|
5472
|
+
return "parsed";
|
|
5473
|
+
} catch {
|
|
5474
|
+
return "unreadable";
|
|
5475
|
+
}
|
|
5476
|
+
}
|
|
5477
|
+
async function keychainOutcome() {
|
|
5478
|
+
try {
|
|
5479
|
+
const { stdout } = await execFileAsync("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 3e3 });
|
|
5480
|
+
return keychainOutcomeFrom({ stdout });
|
|
5481
|
+
} catch (error) {
|
|
5482
|
+
return keychainOutcomeFrom({ error });
|
|
5483
|
+
}
|
|
5484
|
+
}
|
|
5485
|
+
async function claudeCredentialPresence(deps = {}) {
|
|
5486
|
+
if (process.env["ANTHROPIC_API_KEY"] || process.env["ANTHROPIC_AUTH_TOKEN"]) return "present";
|
|
5487
|
+
const outcomes = [];
|
|
5488
|
+
const keychain = deps.keychain === void 0 ? platform() === "darwin" ? keychainOutcome : null : deps.keychain;
|
|
5489
|
+
if (keychain) outcomes.push(await keychain());
|
|
5490
|
+
let paths;
|
|
5491
|
+
if (deps.paths) {
|
|
5492
|
+
paths = deps.paths;
|
|
5493
|
+
} else {
|
|
5494
|
+
const discovered = await discoverCredentialCandidates();
|
|
5495
|
+
paths = discovered.paths;
|
|
5496
|
+
outcomes.push(...discovered.outcomes);
|
|
5497
|
+
}
|
|
5498
|
+
for (const path of paths) {
|
|
5499
|
+
let raw;
|
|
5500
|
+
try {
|
|
5501
|
+
raw = await readFile(path, "utf-8");
|
|
5502
|
+
} catch (err) {
|
|
5503
|
+
const code = err.code;
|
|
5504
|
+
outcomes.push(code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable");
|
|
5505
|
+
continue;
|
|
5506
|
+
}
|
|
5507
|
+
try {
|
|
5508
|
+
JSON.parse(raw);
|
|
5509
|
+
outcomes.push("parsed");
|
|
5510
|
+
} catch {
|
|
5511
|
+
outcomes.push("unreadable");
|
|
5512
|
+
}
|
|
5513
|
+
}
|
|
5514
|
+
return credentialPresenceFrom(outcomes);
|
|
5515
|
+
}
|
|
5516
|
+
function computeSubscriptionStatus(creds) {
|
|
5517
|
+
const expiresAtMs = parseExpiresAt(creds.expiresAt);
|
|
5518
|
+
const hasRefreshToken = typeof creds.refreshToken === "string" && creds.refreshToken.trim().length > 0;
|
|
5519
|
+
if (expiresAtMs === null) {
|
|
5520
|
+
return {
|
|
5521
|
+
mode: "subscription",
|
|
5522
|
+
status: "unknown",
|
|
5523
|
+
expires_at: null
|
|
5524
|
+
};
|
|
5525
|
+
}
|
|
5526
|
+
const msUntilExpiry = expiresAtMs - Date.now();
|
|
5527
|
+
let status;
|
|
5528
|
+
if (hasRefreshToken) {
|
|
5529
|
+
status = "valid";
|
|
5530
|
+
} else {
|
|
5531
|
+
status = msUntilExpiry <= 0 ? "expired" : msUntilExpiry <= EXPIRING_SOON_MS ? "expiring_soon" : "valid";
|
|
5532
|
+
}
|
|
5533
|
+
return {
|
|
5534
|
+
mode: "subscription",
|
|
5535
|
+
status,
|
|
5536
|
+
expires_at: new Date(expiresAtMs).toISOString()
|
|
5537
|
+
};
|
|
5538
|
+
}
|
|
5539
|
+
function parseExpiresAt(raw) {
|
|
5540
|
+
if (typeof raw === "number" && Number.isFinite(raw)) {
|
|
5541
|
+
return raw < 1e12 ? raw * 1e3 : raw;
|
|
5542
|
+
}
|
|
5543
|
+
if (typeof raw === "string") {
|
|
5544
|
+
const parsed = Date.parse(raw);
|
|
5545
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
5546
|
+
}
|
|
5547
|
+
return null;
|
|
5548
|
+
}
|
|
5549
|
+
|
|
5550
|
+
// src/lib/manager/auth-refresh-hold.ts
|
|
5551
|
+
import { hostname } from "os";
|
|
5552
|
+
var HOLD_LEAD_MS = 6 * 6e4;
|
|
5553
|
+
var HOLD_MAX_PAST_EXPIRY_MS = 5 * 6e4;
|
|
5554
|
+
function authRefreshHoldVerdict(expiresAtMs, nowMs) {
|
|
5555
|
+
if (expiresAtMs === null || !Number.isFinite(expiresAtMs)) return { held: false, reason: "no-expiry" };
|
|
5556
|
+
if (expiresAtMs <= 0) return { held: false, reason: "tombstone" };
|
|
5557
|
+
if (nowMs < expiresAtMs - HOLD_LEAD_MS) return { held: false, reason: "before-window" };
|
|
5558
|
+
if (nowMs <= expiresAtMs + HOLD_MAX_PAST_EXPIRY_MS) return { held: true, reason: "in-window" };
|
|
5559
|
+
return { held: false, reason: "past-cap" };
|
|
5560
|
+
}
|
|
5561
|
+
var SINGLE_START_MAX_MS = 3 * 6e4;
|
|
5562
|
+
var SELF_UPDATE_AUTH_REFRESH_LEAD_MS = 10 * 6e4;
|
|
5563
|
+
var MAX_SINGLE_START_GRANTS = 3;
|
|
5564
|
+
var HOLD_WORST_PAST_EXPIRY_MS = HOLD_MAX_PAST_EXPIRY_MS + 2 * MAX_SINGLE_START_GRANTS * SINGLE_START_MAX_MS;
|
|
5565
|
+
var AuthRefreshHoldTracker = class {
|
|
5566
|
+
constructor(log2, host = hostname()) {
|
|
5567
|
+
this.log = log2;
|
|
5568
|
+
this.host = host;
|
|
5569
|
+
}
|
|
5570
|
+
state = { phase: "idle" };
|
|
5571
|
+
/** The expiry whose single-start phase already ran, so a stale expiry cannot re-open it. */
|
|
5572
|
+
singleDoneFor = null;
|
|
5573
|
+
/**
|
|
5574
|
+
* The last expiry actually read (null when the read said there is none). An
|
|
5575
|
+
* expiry is known hours ahead, so the clock alone can say when its window
|
|
5576
|
+
* opens: `rejudge` uses it to open a hold without a new read (CodeRabbit on
|
|
5577
|
+
* PR #7796, a restart timer firing between polls).
|
|
5578
|
+
*/
|
|
5579
|
+
lastSeen = null;
|
|
5580
|
+
/**
|
|
5581
|
+
* Feed one observation; returns whether the caller is held. Logs only on a
|
|
5582
|
+
* transition.
|
|
5583
|
+
*
|
|
5584
|
+
* `'unreadable'` is a failed read (a credentials file caught mid-rename during
|
|
5585
|
+
* the very refresh being held for, a keychain timeout). It is NOT "no expiry":
|
|
5586
|
+
* it changes nothing. An active hold re-judges the expiry that opened it, so it
|
|
5587
|
+
* can run no longer than its bounds; a free host stays free.
|
|
5588
|
+
*/
|
|
5589
|
+
observe(observation, nowMs, opts = {}) {
|
|
5590
|
+
if (observation === "unreadable") {
|
|
5591
|
+
if (this.state.phase === "idle") return false;
|
|
5592
|
+
return this.observe(this.state.for, nowMs, opts);
|
|
5593
|
+
}
|
|
5594
|
+
const expiresAtMs = observation;
|
|
5595
|
+
this.lastSeen = expiresAtMs;
|
|
5596
|
+
const verdict = authRefreshHoldVerdict(expiresAtMs, nowMs);
|
|
5597
|
+
if (verdict.reason === "in-window") {
|
|
5598
|
+
if (this.state.phase === "idle" || this.state.for !== expiresAtMs) {
|
|
5599
|
+
if (this.state.phase === "idle") {
|
|
5600
|
+
this.log(
|
|
5601
|
+
`[auth-hold] host=${this.host} engaged expires_at=${new Date(expiresAtMs).toISOString()} (no spawn, restart, self-update or one-shot until the refresh lands; usually about a minute, at most ${HOLD_WORST_PAST_EXPIRY_MS / 6e4}m past expiry) [ENG-12287]`
|
|
5602
|
+
);
|
|
5603
|
+
}
|
|
5604
|
+
this.state = { phase: "engaged", for: expiresAtMs };
|
|
5605
|
+
}
|
|
5606
|
+
return true;
|
|
5607
|
+
}
|
|
5608
|
+
if (verdict.reason === "past-cap" && this.singleDoneFor !== expiresAtMs) {
|
|
5609
|
+
const e = expiresAtMs;
|
|
5610
|
+
if (this.state.phase !== "single" || this.state.for !== e) {
|
|
5611
|
+
this.state = { phase: "single", for: e, since: nowMs, grantedAt: null, grants: 0 };
|
|
5612
|
+
this.log(
|
|
5613
|
+
`[auth-hold] host=${this.host} past-cap expires_at=${new Date(e).toISOString()}: the token was not refreshed in the window; allowing ONE session start to refresh it, every other start held (at most ${SINGLE_START_MAX_MS / 6e4}m) [ENG-12287]`
|
|
5614
|
+
);
|
|
5615
|
+
}
|
|
5616
|
+
const single = this.state;
|
|
5617
|
+
if (nowMs > (single.grantedAt ?? single.since) + SINGLE_START_MAX_MS) {
|
|
5618
|
+
if (single.grantedAt !== null && single.grants < MAX_SINGLE_START_GRANTS) {
|
|
5619
|
+
single.grantedAt = null;
|
|
5620
|
+
single.since = nowMs;
|
|
5621
|
+
this.log(
|
|
5622
|
+
`[auth-hold] host=${this.host} single start ${single.grants} did not refresh; offering another (${single.grants}/${MAX_SINGLE_START_GRANTS}) [ENG-12287]`
|
|
5623
|
+
);
|
|
5624
|
+
} else {
|
|
5625
|
+
this.singleDoneFor = e;
|
|
5626
|
+
this.release("past-cap", expiresAtMs);
|
|
5627
|
+
return false;
|
|
5628
|
+
}
|
|
5629
|
+
}
|
|
5630
|
+
if (opts.claimStart && single.grantedAt === null) {
|
|
5631
|
+
single.grantedAt = nowMs;
|
|
5632
|
+
single.grants += 1;
|
|
5633
|
+
this.log(`[auth-hold] host=${this.host} single start granted (${single.grants}/${MAX_SINGLE_START_GRANTS}) [ENG-12287]`);
|
|
5634
|
+
return false;
|
|
5635
|
+
}
|
|
5636
|
+
return true;
|
|
5637
|
+
}
|
|
5638
|
+
if (this.state.phase !== "idle") {
|
|
5639
|
+
const from = this.state.for;
|
|
5640
|
+
const reason = verdict.reason === "tombstone" ? "tombstone" : verdict.reason === "no-expiry" ? "no-expiry" : expiresAtMs !== null && expiresAtMs > from ? "refreshed" : "past-cap";
|
|
5641
|
+
this.release(reason, expiresAtMs);
|
|
5642
|
+
}
|
|
5643
|
+
return false;
|
|
5644
|
+
}
|
|
5645
|
+
release(reason, expiresAtMs) {
|
|
5646
|
+
this.log(
|
|
5647
|
+
`[auth-hold] host=${this.host} released reason=${reason}` + (expiresAtMs !== null && expiresAtMs > 0 ? ` expires_at=${new Date(expiresAtMs).toISOString()}` : "") + " [ENG-12287]"
|
|
5648
|
+
);
|
|
5649
|
+
this.state = { phase: "idle" };
|
|
5650
|
+
}
|
|
5651
|
+
/**
|
|
5652
|
+
* Judge the hold against `nowMs` without a new read, from the last expiry
|
|
5653
|
+
* read. It opens exactly when the clock enters that expiry's window and can
|
|
5654
|
+
* never outlive the hold's bounds (the cap, the single-start limit). Its only
|
|
5655
|
+
* error is a refresh that has landed but not been read yet: that over-holds
|
|
5656
|
+
* until the next read, still within those bounds. Never claims the single start.
|
|
5657
|
+
*/
|
|
5658
|
+
rejudge(nowMs) {
|
|
5659
|
+
if (this.state.phase !== "idle") return this.observe("unreadable", nowMs);
|
|
5660
|
+
if (this.lastSeen === null) return false;
|
|
5661
|
+
return this.observe(this.lastSeen, nowMs);
|
|
5662
|
+
}
|
|
5663
|
+
/**
|
|
5664
|
+
* The granted caller is not starting after all (its previous process is not
|
|
5665
|
+
* positively dead, so it defers): hand the grant back unspent. Spending it at
|
|
5666
|
+
* claim would hold every other start for `SINGLE_START_MAX_MS` while nothing
|
|
5667
|
+
* refreshes (Obi Wan 72785e3c523a). The phase's own clock (`since`) is not
|
|
5668
|
+
* reset, so a caller that keeps claiming and returning cannot extend the hold:
|
|
5669
|
+
* with no grant outstanding it still releases `SINGLE_START_MAX_MS` after
|
|
5670
|
+
* `since`, and the worst case in the docblock is unchanged. No-op outside a
|
|
5671
|
+
* granted single phase.
|
|
5672
|
+
*/
|
|
5673
|
+
returnStart(nowMs) {
|
|
5674
|
+
if (this.state.phase !== "single" || this.state.grantedAt === null) return;
|
|
5675
|
+
this.state.grantedAt = null;
|
|
5676
|
+
this.state.grants -= 1;
|
|
5677
|
+
this.log(
|
|
5678
|
+
`[auth-hold] host=${this.host} single start returned unspent at ${new Date(nowMs).toISOString()} (the granted session's previous process is not confirmed dead); the next claimer may take it [ENG-12287]`
|
|
5679
|
+
);
|
|
5680
|
+
}
|
|
5681
|
+
/** Any phase but idle holds restarts, self-updates, one-shots and /restart flags. */
|
|
5682
|
+
get engaged() {
|
|
5683
|
+
return this.state.phase !== "idle";
|
|
5684
|
+
}
|
|
5685
|
+
/**
|
|
5686
|
+
* A refresher may be running: inside the window proper, or in the single-start
|
|
5687
|
+
* phase once the one start has been granted (that start is the refresher).
|
|
5688
|
+
* False in the single phase before the grant, so the grant stays claimable.
|
|
5689
|
+
*/
|
|
5690
|
+
get refresherMayRun() {
|
|
5691
|
+
return this.state.phase === "engaged" || this.state.phase === "single" && this.state.grantedAt !== null;
|
|
5692
|
+
}
|
|
5693
|
+
/**
|
|
5694
|
+
* Pure, no transition: will the last-read expiry's window be open (or still
|
|
5695
|
+
* open) `leadMs` from `nowMs`? For work that cannot be held once it starts.
|
|
5696
|
+
*/
|
|
5697
|
+
windowOpensWithin(nowMs, leadMs) {
|
|
5698
|
+
if (this.lastSeen === null) return false;
|
|
5699
|
+
return authRefreshHoldVerdict(this.lastSeen, nowMs + leadMs).reason === "in-window";
|
|
5700
|
+
}
|
|
5701
|
+
};
|
|
5702
|
+
var READ_CACHE_MS = 5e3;
|
|
5703
|
+
function createAuthRefreshHold(deps) {
|
|
5704
|
+
const tracker = new AuthRefreshHoldTracker(deps.log);
|
|
5705
|
+
const now = deps.now ?? Date.now;
|
|
5706
|
+
let cached = null;
|
|
5707
|
+
let inflight = null;
|
|
5708
|
+
const openRouterBacked = /* @__PURE__ */ new Set();
|
|
5709
|
+
return {
|
|
5710
|
+
async isHeld(opts = {}) {
|
|
5711
|
+
const t = now();
|
|
5712
|
+
if (!cached || t - cached.at >= READ_CACHE_MS) {
|
|
5713
|
+
if (!inflight) {
|
|
5714
|
+
inflight = deps.readExpiresAtMs().catch(() => "unreadable").finally(() => {
|
|
5715
|
+
inflight = null;
|
|
5716
|
+
});
|
|
5717
|
+
}
|
|
5718
|
+
cached = { at: t, expiresAtMs: await inflight };
|
|
5719
|
+
}
|
|
5720
|
+
return tracker.observe(cached.expiresAtMs, now(), opts);
|
|
5721
|
+
},
|
|
5722
|
+
wasHeld: () => tracker.rejudge(now()),
|
|
5723
|
+
wasInWindow: () => {
|
|
5724
|
+
tracker.rejudge(now());
|
|
5725
|
+
return tracker.refresherMayRun;
|
|
5726
|
+
},
|
|
5727
|
+
async heldOrOpensWithin(leadMs) {
|
|
5728
|
+
if (await this.isHeld()) return true;
|
|
5729
|
+
return tracker.windowOpensWithin(now(), leadMs);
|
|
5730
|
+
},
|
|
5731
|
+
returnStart: () => tracker.returnStart(now()),
|
|
5732
|
+
heldFor: (codeName) => !openRouterBacked.has(codeName) && tracker.rejudge(now()),
|
|
5733
|
+
noteSubscriptionBacked: (codeName, backed) => {
|
|
5734
|
+
if (backed) openRouterBacked.delete(codeName);
|
|
5735
|
+
else openRouterBacked.add(codeName);
|
|
5736
|
+
}
|
|
5737
|
+
};
|
|
5738
|
+
}
|
|
5739
|
+
function stragglerSignalDeps(holdActive, real) {
|
|
5740
|
+
if (!holdActive) return real;
|
|
5741
|
+
const tracker = real.signalledHostPids;
|
|
5742
|
+
return {
|
|
5743
|
+
killStraggler: () => false,
|
|
5744
|
+
killHostStragglers: () => [],
|
|
5745
|
+
// CodeRabbit on PR #7796: survivors signalled BEFORE the hold still block a
|
|
5746
|
+
// spawn (a fresh scan can miss a descendant whose root exited), so reads go
|
|
5747
|
+
// through; only NEW records are suppressed, because nothing is signalled now.
|
|
5748
|
+
signalledHostPids: tracker === void 0 ? void 0 : { survivors: (c) => tracker.survivors(c), verify: (t) => tracker.verify(t), remember: () => void 0 },
|
|
5749
|
+
// CodeRabbit on PR #7796: a held check advances no SIGTERM-to-SIGKILL count.
|
|
5750
|
+
// The count is frozen, not reset: a streak built BEFORE the hold is kept, so
|
|
5751
|
+
// the first check after release continues it (SIGKILL if it had already
|
|
5752
|
+
// passed the SIGTERM attempts), and one that started at zero starts at SIGTERM.
|
|
5753
|
+
deferStreak: void 0
|
|
5754
|
+
};
|
|
5755
|
+
}
|
|
5756
|
+
|
|
5757
|
+
// src/lib/manager/host-auth-refresh-hold.ts
|
|
5758
|
+
async function readHostExpiresAtMs() {
|
|
5759
|
+
const hostMode = getCachedClaudeAuthModeRaw();
|
|
5760
|
+
if (hostMode === "api_key" || hostMode === "openrouter" || hostMode === "xai") return null;
|
|
5761
|
+
const report = await detectClaudeSubscriptionAuth();
|
|
5762
|
+
if (report === null) {
|
|
5763
|
+
return await claudeCredentialPresence() === "absent" ? null : "unreadable";
|
|
5764
|
+
}
|
|
5765
|
+
if (report.mode !== "subscription") return null;
|
|
5766
|
+
if (report.expires_at === null) return "unreadable";
|
|
5767
|
+
const ms = Date.parse(report.expires_at);
|
|
5768
|
+
return Number.isNaN(ms) ? "unreadable" : ms;
|
|
5769
|
+
}
|
|
5770
|
+
var hostAuthRefreshHold = createAuthRefreshHold({ readExpiresAtMs: readHostExpiresAtMs, log });
|
|
5771
|
+
var AuthRefreshHeldError = class extends Error {
|
|
5772
|
+
constructor(label) {
|
|
5773
|
+
super(`[auth-hold] ${label} not started: the host's Claude login is refreshing (ENG-12287)`);
|
|
5774
|
+
this.name = "AuthRefreshHeldError";
|
|
5775
|
+
}
|
|
5776
|
+
};
|
|
5777
|
+
|
|
5372
5778
|
// src/lib/heartbeat-claude-auth-absent.ts
|
|
5373
5779
|
function fileAuthAfterHeartbeat(current, input) {
|
|
5374
5780
|
if (input.rawMode !== "subscription" || input.detectionFailed) return current;
|
|
@@ -5423,7 +5829,7 @@ function collectEnvGates(env) {
|
|
|
5423
5829
|
|
|
5424
5830
|
// ../../packages/core/dist/direct-chat/cursor-advance-telemetry.js
|
|
5425
5831
|
import { readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
5426
|
-
import { join as
|
|
5832
|
+
import { join as join15 } from "path";
|
|
5427
5833
|
var CURSOR_SHORTFALL_COUNTER_SUFFIX = "-cursor-advance-classifications.json";
|
|
5428
5834
|
function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
5429
5835
|
if (!agentDir)
|
|
@@ -5431,7 +5837,7 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
5431
5837
|
const key = cursorAdvanceCounterKey(route, verdict);
|
|
5432
5838
|
if (key === null)
|
|
5433
5839
|
return;
|
|
5434
|
-
const path =
|
|
5840
|
+
const path = join15(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
|
|
5435
5841
|
const counts = {};
|
|
5436
5842
|
try {
|
|
5437
5843
|
const parsed = JSON.parse(readFileSync13(path, "utf-8"));
|
|
@@ -5451,9 +5857,9 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
5451
5857
|
}
|
|
5452
5858
|
|
|
5453
5859
|
// src/lib/artifact-stream.ts
|
|
5454
|
-
import { join as
|
|
5455
|
-
import { homedir as
|
|
5456
|
-
import { readdir, stat, readFile } from "fs/promises";
|
|
5860
|
+
import { join as join16 } from "path";
|
|
5861
|
+
import { homedir as homedir5 } from "os";
|
|
5862
|
+
import { readdir as readdir2, stat, readFile as readFile2 } from "fs/promises";
|
|
5457
5863
|
var ARTEFACT_ENTRY_FILE = "index.html";
|
|
5458
5864
|
function errMessage(err) {
|
|
5459
5865
|
return err instanceof Error ? err.message : String(err);
|
|
@@ -5537,7 +5943,7 @@ var ArtifactStreamScanner = class {
|
|
|
5537
5943
|
return;
|
|
5538
5944
|
}
|
|
5539
5945
|
for (const name of names) {
|
|
5540
|
-
const file =
|
|
5946
|
+
const file = join16(this.artifactsDir, name, ARTEFACT_ENTRY_FILE);
|
|
5541
5947
|
const mtime = await this.fsDeps.mtimeMs(file).catch(() => null);
|
|
5542
5948
|
if (mtime === null) continue;
|
|
5543
5949
|
if (this.seenMtime.get(name) === mtime) continue;
|
|
@@ -5568,11 +5974,11 @@ var ArtifactStreamScanner = class {
|
|
|
5568
5974
|
}
|
|
5569
5975
|
};
|
|
5570
5976
|
function artifactsDirFor(codeName) {
|
|
5571
|
-
return
|
|
5977
|
+
return join16(homedir5(), ".augmented", codeName, "artifacts");
|
|
5572
5978
|
}
|
|
5573
5979
|
var nodeArtifactFs = {
|
|
5574
5980
|
async listArtefactNames(artifactsDir) {
|
|
5575
|
-
const entries = await
|
|
5981
|
+
const entries = await readdir2(artifactsDir, { withFileTypes: true });
|
|
5576
5982
|
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
5577
5983
|
},
|
|
5578
5984
|
async mtimeMs(filePath) {
|
|
@@ -5583,7 +5989,7 @@ var nodeArtifactFs = {
|
|
|
5583
5989
|
}
|
|
5584
5990
|
},
|
|
5585
5991
|
readFile(filePath) {
|
|
5586
|
-
return
|
|
5992
|
+
return readFile2(filePath, "utf8");
|
|
5587
5993
|
}
|
|
5588
5994
|
};
|
|
5589
5995
|
|
|
@@ -5845,169 +6251,6 @@ import { createHash as createHash7 } from "crypto";
|
|
|
5845
6251
|
import { readFile as readFile3, readdir as readdir3 } from "fs/promises";
|
|
5846
6252
|
import { homedir as homedir6, platform as platform2 } from "os";
|
|
5847
6253
|
import { dirname as dirname6, join as join17 } from "path";
|
|
5848
|
-
|
|
5849
|
-
// src/lib/claude-auth-detect.ts
|
|
5850
|
-
import { readFile as readFile2, readdir as readdir2 } from "fs/promises";
|
|
5851
|
-
import { homedir as homedir5, platform } from "os";
|
|
5852
|
-
import { join as join16 } from "path";
|
|
5853
|
-
import { execFile } from "child_process";
|
|
5854
|
-
import { promisify } from "util";
|
|
5855
|
-
var execFileAsync = promisify(execFile);
|
|
5856
|
-
var EXPIRING_SOON_MS = 48 * 60 * 60 * 1e3;
|
|
5857
|
-
async function detectClaudeAuth() {
|
|
5858
|
-
if (process.env["ANTHROPIC_API_KEY"] || process.env["ANTHROPIC_AUTH_TOKEN"]) {
|
|
5859
|
-
return { mode: "api_key", status: "valid", expires_at: null };
|
|
5860
|
-
}
|
|
5861
|
-
const creds = await readOauthCredentials();
|
|
5862
|
-
if (!creds) return null;
|
|
5863
|
-
return computeSubscriptionStatus(creds);
|
|
5864
|
-
}
|
|
5865
|
-
async function findClaudeCredentialsPaths() {
|
|
5866
|
-
return (await discoverCredentialCandidates()).paths;
|
|
5867
|
-
}
|
|
5868
|
-
async function readOauthCredentials() {
|
|
5869
|
-
if (platform() === "darwin") {
|
|
5870
|
-
const fromKeychain = await readMacKeychain();
|
|
5871
|
-
if (fromKeychain) return fromKeychain;
|
|
5872
|
-
}
|
|
5873
|
-
const candidates = await findClaudeCredentialsPaths();
|
|
5874
|
-
for (const path of candidates) {
|
|
5875
|
-
const parsed = await readJsonSilently(path);
|
|
5876
|
-
if (parsed) {
|
|
5877
|
-
return parsed.claudeAiOauth ?? parsed.oauth ?? parsed;
|
|
5878
|
-
}
|
|
5879
|
-
}
|
|
5880
|
-
return null;
|
|
5881
|
-
}
|
|
5882
|
-
async function readMacKeychain() {
|
|
5883
|
-
try {
|
|
5884
|
-
const { stdout } = await execFileAsync(
|
|
5885
|
-
"security",
|
|
5886
|
-
["find-generic-password", "-s", "Claude Code-credentials", "-w"],
|
|
5887
|
-
{ timeout: 3e3 }
|
|
5888
|
-
);
|
|
5889
|
-
const parsed = JSON.parse(stdout.trim());
|
|
5890
|
-
return parsed.claudeAiOauth ?? parsed;
|
|
5891
|
-
} catch {
|
|
5892
|
-
return null;
|
|
5893
|
-
}
|
|
5894
|
-
}
|
|
5895
|
-
async function readJsonSilently(path) {
|
|
5896
|
-
try {
|
|
5897
|
-
const raw = await readFile2(path, "utf-8");
|
|
5898
|
-
return JSON.parse(raw);
|
|
5899
|
-
} catch {
|
|
5900
|
-
return null;
|
|
5901
|
-
}
|
|
5902
|
-
}
|
|
5903
|
-
function credentialPresenceFrom(outcomes) {
|
|
5904
|
-
if (outcomes.includes("parsed")) return "present";
|
|
5905
|
-
if (outcomes.includes("unreadable")) return "unreadable";
|
|
5906
|
-
return "absent";
|
|
5907
|
-
}
|
|
5908
|
-
async function discoverCredentialCandidates(deps = {}) {
|
|
5909
|
-
const home = deps.home ?? homedir5();
|
|
5910
|
-
const paths = [join16(home, ".claude", ".credentials.json"), join16(home, ".claude", "credentials.json")];
|
|
5911
|
-
const outcomes = [];
|
|
5912
|
-
const linuxRoot = deps.linuxRoot ?? (platform() === "linux" && typeof process.getuid === "function" && process.getuid() === 0);
|
|
5913
|
-
if (linuxRoot) {
|
|
5914
|
-
const list = deps.readdirImpl ?? ((path) => readdir2(path, { withFileTypes: true }));
|
|
5915
|
-
try {
|
|
5916
|
-
const entries = await list("/home");
|
|
5917
|
-
for (const entry of entries.filter((e) => e.isDirectory()).sort((x, y) => x.name.localeCompare(y.name))) {
|
|
5918
|
-
paths.push(join16("/home", entry.name, ".claude", ".credentials.json"));
|
|
5919
|
-
paths.push(join16("/home", entry.name, ".claude", "credentials.json"));
|
|
5920
|
-
}
|
|
5921
|
-
} catch (err) {
|
|
5922
|
-
const code = err.code;
|
|
5923
|
-
outcomes.push(code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable");
|
|
5924
|
-
}
|
|
5925
|
-
}
|
|
5926
|
-
return { paths, outcomes };
|
|
5927
|
-
}
|
|
5928
|
-
function keychainOutcomeFrom(result) {
|
|
5929
|
-
if ("error" in result) return "unreadable";
|
|
5930
|
-
try {
|
|
5931
|
-
JSON.parse(result.stdout.trim());
|
|
5932
|
-
return "parsed";
|
|
5933
|
-
} catch {
|
|
5934
|
-
return "unreadable";
|
|
5935
|
-
}
|
|
5936
|
-
}
|
|
5937
|
-
async function keychainOutcome() {
|
|
5938
|
-
try {
|
|
5939
|
-
const { stdout } = await execFileAsync("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 3e3 });
|
|
5940
|
-
return keychainOutcomeFrom({ stdout });
|
|
5941
|
-
} catch (error) {
|
|
5942
|
-
return keychainOutcomeFrom({ error });
|
|
5943
|
-
}
|
|
5944
|
-
}
|
|
5945
|
-
async function claudeCredentialPresence(deps = {}) {
|
|
5946
|
-
if (process.env["ANTHROPIC_API_KEY"] || process.env["ANTHROPIC_AUTH_TOKEN"]) return "present";
|
|
5947
|
-
const outcomes = [];
|
|
5948
|
-
const keychain = deps.keychain === void 0 ? platform() === "darwin" ? keychainOutcome : null : deps.keychain;
|
|
5949
|
-
if (keychain) outcomes.push(await keychain());
|
|
5950
|
-
let paths;
|
|
5951
|
-
if (deps.paths) {
|
|
5952
|
-
paths = deps.paths;
|
|
5953
|
-
} else {
|
|
5954
|
-
const discovered = await discoverCredentialCandidates();
|
|
5955
|
-
paths = discovered.paths;
|
|
5956
|
-
outcomes.push(...discovered.outcomes);
|
|
5957
|
-
}
|
|
5958
|
-
for (const path of paths) {
|
|
5959
|
-
let raw;
|
|
5960
|
-
try {
|
|
5961
|
-
raw = await readFile2(path, "utf-8");
|
|
5962
|
-
} catch (err) {
|
|
5963
|
-
const code = err.code;
|
|
5964
|
-
outcomes.push(code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable");
|
|
5965
|
-
continue;
|
|
5966
|
-
}
|
|
5967
|
-
try {
|
|
5968
|
-
JSON.parse(raw);
|
|
5969
|
-
outcomes.push("parsed");
|
|
5970
|
-
} catch {
|
|
5971
|
-
outcomes.push("unreadable");
|
|
5972
|
-
}
|
|
5973
|
-
}
|
|
5974
|
-
return credentialPresenceFrom(outcomes);
|
|
5975
|
-
}
|
|
5976
|
-
function computeSubscriptionStatus(creds) {
|
|
5977
|
-
const expiresAtMs = parseExpiresAt(creds.expiresAt);
|
|
5978
|
-
const hasRefreshToken = typeof creds.refreshToken === "string" && creds.refreshToken.trim().length > 0;
|
|
5979
|
-
if (expiresAtMs === null) {
|
|
5980
|
-
return {
|
|
5981
|
-
mode: "subscription",
|
|
5982
|
-
status: "unknown",
|
|
5983
|
-
expires_at: null
|
|
5984
|
-
};
|
|
5985
|
-
}
|
|
5986
|
-
const msUntilExpiry = expiresAtMs - Date.now();
|
|
5987
|
-
let status;
|
|
5988
|
-
if (hasRefreshToken) {
|
|
5989
|
-
status = "valid";
|
|
5990
|
-
} else {
|
|
5991
|
-
status = msUntilExpiry <= 0 ? "expired" : msUntilExpiry <= EXPIRING_SOON_MS ? "expiring_soon" : "valid";
|
|
5992
|
-
}
|
|
5993
|
-
return {
|
|
5994
|
-
mode: "subscription",
|
|
5995
|
-
status,
|
|
5996
|
-
expires_at: new Date(expiresAtMs).toISOString()
|
|
5997
|
-
};
|
|
5998
|
-
}
|
|
5999
|
-
function parseExpiresAt(raw) {
|
|
6000
|
-
if (typeof raw === "number" && Number.isFinite(raw)) {
|
|
6001
|
-
return raw < 1e12 ? raw * 1e3 : raw;
|
|
6002
|
-
}
|
|
6003
|
-
if (typeof raw === "string") {
|
|
6004
|
-
const parsed = Date.parse(raw);
|
|
6005
|
-
return Number.isNaN(parsed) ? null : parsed;
|
|
6006
|
-
}
|
|
6007
|
-
return null;
|
|
6008
|
-
}
|
|
6009
|
-
|
|
6010
|
-
// src/lib/claude-account-fingerprint.ts
|
|
6011
6254
|
async function candidateHomes() {
|
|
6012
6255
|
const homes = [homedir6()];
|
|
6013
6256
|
const isLinuxRoot = platform2() === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
@@ -7185,8 +7428,8 @@ var DEFAULT_LOCAL_EVAL_MODEL = "gemma4:12b";
|
|
|
7185
7428
|
var EVAL_TIMEOUT_MS = 12e4;
|
|
7186
7429
|
async function runLocalEvalChat(prompt, opts) {
|
|
7187
7430
|
const endpoint = new URL(opts.url);
|
|
7188
|
-
const
|
|
7189
|
-
const isLoopback =
|
|
7431
|
+
const hostname3 = endpoint.hostname.toLowerCase();
|
|
7432
|
+
const isLoopback = hostname3 === "localhost" || hostname3 === "127.0.0.1" || hostname3 === "::1" || hostname3 === "[::1]";
|
|
7190
7433
|
if (!isLoopback) {
|
|
7191
7434
|
throw new Error(`local eval url must be loopback-only, got host '${endpoint.hostname}'`);
|
|
7192
7435
|
}
|
|
@@ -11088,6 +11331,7 @@ async function applyClaudeAuthToEnv(childEnv, label, options = {}) {
|
|
|
11088
11331
|
}
|
|
11089
11332
|
return { isolated: !!options.isolateApiKeyConfigDir };
|
|
11090
11333
|
}
|
|
11334
|
+
if (await hostAuthRefreshHold.isHeld()) throw new AuthRefreshHeldError(label);
|
|
11091
11335
|
delete childEnv.ANTHROPIC_API_KEY;
|
|
11092
11336
|
return { isolated: false };
|
|
11093
11337
|
}
|
|
@@ -15774,7 +16018,7 @@ function createFileMigrationReportIO(codeName, log2) {
|
|
|
15774
16018
|
};
|
|
15775
16019
|
}
|
|
15776
16020
|
var managerHostPost = async (path, body) => {
|
|
15777
|
-
const { api: api2, ApiError: ApiError3 } = await import("../api-client-
|
|
16021
|
+
const { api: api2, ApiError: ApiError3 } = await import("../api-client-HAN3QU6H.js");
|
|
15778
16022
|
try {
|
|
15779
16023
|
const json = await api2.post(path, body);
|
|
15780
16024
|
return { status: 200, json };
|
|
@@ -16085,8 +16329,9 @@ async function processRestartFlags(opts) {
|
|
|
16085
16329
|
const flags = readRestartFlags();
|
|
16086
16330
|
if (flags.length === 0) return;
|
|
16087
16331
|
for (const flag of flags) {
|
|
16332
|
+
let deferred = false;
|
|
16088
16333
|
try {
|
|
16089
|
-
await processOne(flag, opts);
|
|
16334
|
+
deferred = await processOne(flag, opts) === "deferred";
|
|
16090
16335
|
} catch (err) {
|
|
16091
16336
|
opts.log(`[restart-handler] Failed to process flag for '${flag.codeName}': ${err.message}`);
|
|
16092
16337
|
try {
|
|
@@ -16096,7 +16341,7 @@ async function processRestartFlags(opts) {
|
|
|
16096
16341
|
}
|
|
16097
16342
|
} finally {
|
|
16098
16343
|
try {
|
|
16099
|
-
deleteRestartFlag(flag.codeName);
|
|
16344
|
+
if (!deferred) deleteRestartFlag(flag.codeName);
|
|
16100
16345
|
} catch (err) {
|
|
16101
16346
|
opts.log(`[restart-handler] Failed to delete flag for '${flag.codeName}': ${err.message}`);
|
|
16102
16347
|
}
|
|
@@ -16117,7 +16362,10 @@ async function processOne(flag, opts) {
|
|
|
16117
16362
|
}
|
|
16118
16363
|
const reasonSuffix = flag.source === "agent" && flag.reason ? ` reason="${flag.reason}"` : "";
|
|
16119
16364
|
opts.log(`[restart-handler] Restarting tmux session for '${flag.codeName}' (source: ${flag.source})${reasonSuffix}`);
|
|
16120
|
-
opts.stopSession(flag.codeName, flag)
|
|
16365
|
+
if (opts.stopSession(flag.codeName, flag) === false) {
|
|
16366
|
+
opts.log(`[restart-handler] Restart for '${flag.codeName}' deferred (Claude login refresh hold); flag kept for the next poll [ENG-12287]`);
|
|
16367
|
+
return "deferred";
|
|
16368
|
+
}
|
|
16121
16369
|
if (opts.reportRestartEvent) {
|
|
16122
16370
|
void opts.reportRestartEvent(flag).catch((err) => {
|
|
16123
16371
|
opts.log(`[restart-handler] restart-event report failed for '${flag.codeName}': ${err.message}`);
|
|
@@ -17126,7 +17374,7 @@ async function runDangerousRmBackstop(agentId, codeName, pane) {
|
|
|
17126
17374
|
try {
|
|
17127
17375
|
action = dangerousRmBackstop.observe(codeName, pane, Date.now());
|
|
17128
17376
|
if (!action || pane === null) return;
|
|
17129
|
-
const host =
|
|
17377
|
+
const host = hostname2();
|
|
17130
17378
|
const scrub = (s) => {
|
|
17131
17379
|
const r = redactPaneFrame(s);
|
|
17132
17380
|
return r.length > 400 ? `${r.slice(0, 399)}\u2026` : r;
|
|
@@ -17863,7 +18111,7 @@ var pendingDayRolloverReset = /* @__PURE__ */ new Set();
|
|
|
17863
18111
|
var dayRolloverInboundHold = /* @__PURE__ */ new Map();
|
|
17864
18112
|
var INBOUND_HOLD_EPISODE_GAP_MS = 12e4;
|
|
17865
18113
|
async function channelInboundActivityAgeSecondsFor(codeName) {
|
|
17866
|
-
const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-
|
|
18114
|
+
const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-2MCC7NOE.js");
|
|
17867
18115
|
const newest = newestPendingInboundActivityMtimeMs(dirname11(paneLogPath(codeName)));
|
|
17868
18116
|
if (newest === null) return null;
|
|
17869
18117
|
return Math.max(0, Math.floor((Date.now() - newest) / 1e3));
|
|
@@ -17980,6 +18228,11 @@ async function selfUpdateDiskHold(force) {
|
|
|
17980
18228
|
const room = await ensureDiskForSelfUpdate({ ...deps, force, readStat: () => tightestDiskStat(installPaths) });
|
|
17981
18229
|
return room.ok ? room.release : "failed";
|
|
17982
18230
|
}
|
|
18231
|
+
async function selfUpdateAuthRefreshHold(force) {
|
|
18232
|
+
if (!await hostAuthRefreshHold.heldOrOpensWithin(SELF_UPDATE_AUTH_REFRESH_LEAD_MS)) return null;
|
|
18233
|
+
log(`[self-update] HELD${force ? ' (forced "Update CLI now")' : ""} - the host's Claude login is inside, or within ${SELF_UPDATE_AUTH_REFRESH_LEAD_MS / 6e4}m of, its refresh window; the install's manager restart would respawn every agent into it. Retrying after the refresh [ENG-12287]`);
|
|
18234
|
+
return "failed";
|
|
18235
|
+
}
|
|
17983
18236
|
async function selfUpdateDeviceStateHold(force) {
|
|
17984
18237
|
if (!await hostShouldHaveClaudeDeviceState()) return null;
|
|
17985
18238
|
const deviceState = deviceStateRotationGate.mayRotate(SELF_UPDATE_DEVICE_STATE_HOLD_KEY, Date.now());
|
|
@@ -18029,6 +18282,7 @@ function cachedAgentTimezoneFor(codeName) {
|
|
|
18029
18282
|
});
|
|
18030
18283
|
}
|
|
18031
18284
|
function performLazyDayRolloverReset(codeName, agentTimezone) {
|
|
18285
|
+
if (pendingDayRolloverReset.has(codeName) && hostAuthRefreshHold.heldFor(codeName)) return false;
|
|
18032
18286
|
const flagged = pendingDayRolloverReset.has(codeName);
|
|
18033
18287
|
const sessionHealthy = flagged && isSessionHealthy(codeName);
|
|
18034
18288
|
const staleForToday = flagged ? isStaleForToday(codeName, /* @__PURE__ */ new Date(), agentTimezone ?? void 0) : false;
|
|
@@ -18052,7 +18306,7 @@ function performLazyDayRolloverReset(codeName, agentTimezone) {
|
|
|
18052
18306
|
log(
|
|
18053
18307
|
`[persistent-session] Day rollover for '${codeName}' (yesterday=${current.date}) \u2014 first real trigger after an idle rollover; minting a fresh session now (deferred boot, paid alongside real work) [ENG-8461]`
|
|
18054
18308
|
);
|
|
18055
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover");
|
|
18309
|
+
if (!stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover")) return false;
|
|
18056
18310
|
agentState.persistentSessionAgents.delete(codeName);
|
|
18057
18311
|
rotatePaneLogForDayRollover(codeName, log, agentTimezone);
|
|
18058
18312
|
pendingDayRolloverReset.delete(codeName);
|
|
@@ -18079,7 +18333,9 @@ function transcriptAgeSecondsFor(codeName) {
|
|
|
18079
18333
|
return transcriptActivityAgeSeconds(getProjectDir2(codeName), sessionId, /* @__PURE__ */ new Date());
|
|
18080
18334
|
}
|
|
18081
18335
|
var restartGateDeferStreaks = /* @__PURE__ */ new Map();
|
|
18336
|
+
var dashboardRestartsHeldLogged = /* @__PURE__ */ new Set();
|
|
18082
18337
|
function restartGateFor(codeName, reason) {
|
|
18338
|
+
if (reason !== void 0 && hostAuthRefreshHold.heldFor(codeName)) return "defer-auth-refresh";
|
|
18083
18339
|
if (!isGateableRestartReason(reason)) return "bypass";
|
|
18084
18340
|
const tzInputs = agentRestartTimezoneInputs.get(codeName);
|
|
18085
18341
|
const perAgentWindow = cachedMaintenanceWindow ? {
|
|
@@ -18759,7 +19015,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
|
|
|
18759
19015
|
var lastVersionCheckAt = 0;
|
|
18760
19016
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
18761
19017
|
var lastResponsivenessProbeAt = 0;
|
|
18762
|
-
var agtCliVersion = true ? "0.28.
|
|
19018
|
+
var agtCliVersion = true ? "0.28.1307" : "dev";
|
|
18763
19019
|
function resolveBrewPath(execFileSync5) {
|
|
18764
19020
|
try {
|
|
18765
19021
|
const out = execFileSync5("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -19768,6 +20024,11 @@ async function checkAndUpdateCliViaBrew(force = false) {
|
|
|
19768
20024
|
log(`[self-update] agt CLI update available: ${installed} \u2192 ${latest}. Upgrading via brew${force ? " (forced \u2014 Update CLI now)" : ""}...`);
|
|
19769
20025
|
const brewDiskHold = await selfUpdateDiskHold(force);
|
|
19770
20026
|
if (typeof brewDiskHold === "string") return brewDiskHold;
|
|
20027
|
+
const brewAuthRefreshHold = await selfUpdateAuthRefreshHold(force);
|
|
20028
|
+
if (brewAuthRefreshHold) {
|
|
20029
|
+
brewDiskHold();
|
|
20030
|
+
return brewAuthRefreshHold;
|
|
20031
|
+
}
|
|
19771
20032
|
const brewInstallHold = await selfUpdateDeviceStateHold(force);
|
|
19772
20033
|
if (brewInstallHold) {
|
|
19773
20034
|
brewDiskHold();
|
|
@@ -19967,6 +20228,11 @@ async function installAgtCliViaNpm(version, reasonLabel, force = false) {
|
|
|
19967
20228
|
const args = isRoot ? installArgs : ["-n", "npm", ...installArgs];
|
|
19968
20229
|
const npmDiskHold = await selfUpdateDiskHold(force);
|
|
19969
20230
|
if (typeof npmDiskHold === "string") return npmDiskHold;
|
|
20231
|
+
const npmAuthRefreshHold = await selfUpdateAuthRefreshHold(force);
|
|
20232
|
+
if (npmAuthRefreshHold) {
|
|
20233
|
+
npmDiskHold();
|
|
20234
|
+
return npmAuthRefreshHold;
|
|
20235
|
+
}
|
|
19970
20236
|
const npmInstallHold = await selfUpdateDeviceStateHold(force);
|
|
19971
20237
|
if (npmInstallHold) {
|
|
19972
20238
|
npmDiskHold();
|
|
@@ -20885,7 +21151,7 @@ function flushRestartedAgentDiagnostics(hostId, codeNames) {
|
|
|
20885
21151
|
if (codeNames.length === 0) return;
|
|
20886
21152
|
void (async () => {
|
|
20887
21153
|
try {
|
|
20888
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
21154
|
+
const { collectDiagnostics } = await import("../persistent-session-FJ4Y7XIB.js");
|
|
20889
21155
|
await api.post("/host/heartbeat", {
|
|
20890
21156
|
host_id: hostId,
|
|
20891
21157
|
agent_diagnostics: collectDiagnostics(codeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -20931,16 +21197,18 @@ async function pollCycleInner() {
|
|
|
20931
21197
|
if (restartAfterUpgrade) return;
|
|
20932
21198
|
flushDeliveryBaselineIfDirty();
|
|
20933
21199
|
flushStuckStreaksIfChanged();
|
|
21200
|
+
await hostAuthRefreshHold.isHeld();
|
|
20934
21201
|
try {
|
|
20935
21202
|
await processRestartFlags({
|
|
20936
21203
|
log,
|
|
20937
21204
|
resolveFramework: (codeName) => agentFrameworkCache.get(codeName) ?? null,
|
|
20938
21205
|
stopSession: (codeName, flag) => {
|
|
20939
21206
|
const breakerReason = flag.source === "agent" ? "agent-requested" : "channel-restart-flag";
|
|
20940
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, breakerReason);
|
|
21207
|
+
if (!stopPersistentSessionAndForgetMcpBaseline(codeName, breakerReason)) return false;
|
|
20941
21208
|
agentState.persistentSessionAgents.delete(codeName);
|
|
20942
21209
|
claudeAuthTupleBySession.delete(codeName);
|
|
20943
21210
|
clearSessionPolicyBaseline(codeName);
|
|
21211
|
+
return true;
|
|
20944
21212
|
},
|
|
20945
21213
|
getTelegramTokens: (codeName) => {
|
|
20946
21214
|
const t = agentChannelTokens.get(codeName);
|
|
@@ -21028,7 +21296,7 @@ async function pollCycleInner() {
|
|
|
21028
21296
|
}
|
|
21029
21297
|
try {
|
|
21030
21298
|
const { detectHostSecurity } = await import("../host-security-KQYYZZVW.js");
|
|
21031
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
21299
|
+
const { collectDiagnostics } = await import("../persistent-session-FJ4Y7XIB.js");
|
|
21032
21300
|
const recordedSinceHeartbeat = new Set(spawnOutcomesSinceHeartbeat.drain());
|
|
21033
21301
|
const diagCodeNames = heartbeatDiagnosticsCodeNames(agentState.persistentSessionAgents, recordedSinceHeartbeat);
|
|
21034
21302
|
const heartbeatSpawnOutcomeFor = spawnOutcomeIfRecorded(spawnOutcomeForDiagnostics, recordedSinceHeartbeat);
|
|
@@ -21364,7 +21632,7 @@ async function pollCycleInner() {
|
|
|
21364
21632
|
collectPanelessActivityProbes,
|
|
21365
21633
|
getResponsivenessIntervalMs,
|
|
21366
21634
|
occupancyQualificationClassifications
|
|
21367
|
-
} = await import("../responsiveness-probe-
|
|
21635
|
+
} = await import("../responsiveness-probe-2MCC7NOE.js");
|
|
21368
21636
|
const probeIntervalMs = getResponsivenessIntervalMs();
|
|
21369
21637
|
if (now - lastResponsivenessProbeAt > probeIntervalMs) {
|
|
21370
21638
|
const probeCodeNames = [...agentState.persistentSessionAgents];
|
|
@@ -21481,7 +21749,7 @@ async function pollCycleInner() {
|
|
|
21481
21749
|
collectResponsivenessProbes,
|
|
21482
21750
|
livePendingInboundOldestAgeSeconds,
|
|
21483
21751
|
parkPendingInbound
|
|
21484
|
-
} = await import("../responsiveness-probe-
|
|
21752
|
+
} = await import("../responsiveness-probe-2MCC7NOE.js");
|
|
21485
21753
|
const { getProjectDir: wedgeProjectDir } = await import("../scheduler-engine-5PCBGRNY.js");
|
|
21486
21754
|
const wedgeNow = /* @__PURE__ */ new Date();
|
|
21487
21755
|
const liveAgents = agentState.persistentSessionAgents;
|
|
@@ -21553,10 +21821,11 @@ async function pollCycleInner() {
|
|
|
21553
21821
|
}
|
|
21554
21822
|
continue;
|
|
21555
21823
|
}
|
|
21824
|
+
const { execSync: es } = await import("child_process");
|
|
21825
|
+
if (hostAuthRefreshHold.heldFor(codeName)) continue;
|
|
21556
21826
|
try {
|
|
21557
21827
|
const newId = rotateSessionForWedge(codeName);
|
|
21558
21828
|
try {
|
|
21559
|
-
const { execSync: es } = await import("child_process");
|
|
21560
21829
|
es(`tmux kill-session -t ${tmuxSessionTarget(`agt-${codeName}`)} 2>/dev/null`, { stdio: "ignore" });
|
|
21561
21830
|
} catch {
|
|
21562
21831
|
}
|
|
@@ -21745,13 +22014,14 @@ async function pollCycleInner() {
|
|
|
21745
22014
|
}
|
|
21746
22015
|
continue;
|
|
21747
22016
|
}
|
|
22017
|
+
if (hostAuthRefreshHold.heldFor(codeName)) continue;
|
|
21748
22018
|
try {
|
|
21749
22019
|
const newId = rotateSessionForWedge(codeName);
|
|
21750
22020
|
try {
|
|
21751
22021
|
syncExecFile("tmux", ["kill-session", "-t", tmuxSessionTarget(`agt-${codeName}`)], { stdio: "ignore" });
|
|
21752
22022
|
} catch {
|
|
21753
22023
|
}
|
|
21754
|
-
stopPersistentSessionAndForgetMcpBaseline(
|
|
22024
|
+
const paneFatalTornDown = stopPersistentSessionAndForgetMcpBaseline(
|
|
21755
22025
|
codeName,
|
|
21756
22026
|
"pane-fatal-error",
|
|
21757
22027
|
void 0,
|
|
@@ -21767,7 +22037,8 @@ async function pollCycleInner() {
|
|
|
21767
22037
|
}
|
|
21768
22038
|
}
|
|
21769
22039
|
);
|
|
21770
|
-
|
|
22040
|
+
if (!paneFatalTornDown) continue;
|
|
22041
|
+
const { parkPendingInbound } = await import("../responsiveness-probe-2MCC7NOE.js");
|
|
21771
22042
|
const { parked, deadLettered } = parkPendingInbound(codeName, new Date(fatalNowMs));
|
|
21772
22043
|
paneFatalStreak.delete(codeName);
|
|
21773
22044
|
paneFatalRestarts.set(codeName, [...history, fatalNowMs]);
|
|
@@ -21798,7 +22069,7 @@ async function pollCycleInner() {
|
|
|
21798
22069
|
TRANSCRIPT_MOUNT_ESCALATION_REFRESH_MS,
|
|
21799
22070
|
bindSourceEscalations
|
|
21800
22071
|
} = await import("../transcript-mount-health-OHE6IVJV.js");
|
|
21801
|
-
const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-
|
|
22072
|
+
const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-FJ4Y7XIB.js");
|
|
21802
22073
|
const mountConfig = resolveTranscriptMountConfig();
|
|
21803
22074
|
const liveAgents = agentState.persistentSessionAgents;
|
|
21804
22075
|
for (const tracked of [
|
|
@@ -21928,7 +22199,7 @@ async function pollCycleInner() {
|
|
|
21928
22199
|
continue;
|
|
21929
22200
|
}
|
|
21930
22201
|
try {
|
|
21931
|
-
stopPersistentSessionAndForgetMcpBaseline(
|
|
22202
|
+
const mountTornDown = stopPersistentSessionAndForgetMcpBaseline(
|
|
21932
22203
|
codeName,
|
|
21933
22204
|
"transcript-mount-orphaned",
|
|
21934
22205
|
void 0,
|
|
@@ -21943,6 +22214,7 @@ async function pollCycleInner() {
|
|
|
21943
22214
|
}
|
|
21944
22215
|
}
|
|
21945
22216
|
);
|
|
22217
|
+
if (!mountTornDown) continue;
|
|
21946
22218
|
containerPidCache.delete(codeName);
|
|
21947
22219
|
transcriptMountStreak.delete(codeName);
|
|
21948
22220
|
transcriptMountRestarts.set(codeName, [...history, mountNowMs]);
|
|
@@ -22092,6 +22364,15 @@ async function pollCycleInner() {
|
|
|
22092
22364
|
}
|
|
22093
22365
|
}
|
|
22094
22366
|
if (!alreadyServiced) {
|
|
22367
|
+
if (hostAuthRefreshHold.heldFor(agent.code_name)) {
|
|
22368
|
+
const heldKey = `${agent.agent_id}@${requested}`;
|
|
22369
|
+
if (!dashboardRestartsHeldLogged.has(heldKey)) {
|
|
22370
|
+
dashboardRestartsHeldLogged.add(heldKey);
|
|
22371
|
+
log(`[auth-hold] dashboard restart for '${agent.code_name}' held until the Claude login refresh lands, not acked [ENG-12287]`);
|
|
22372
|
+
}
|
|
22373
|
+
continue;
|
|
22374
|
+
}
|
|
22375
|
+
dashboardRestartsHeldLogged.delete(`${agent.agent_id}@${requested}`);
|
|
22095
22376
|
const restartReason = agent.restart_reason ?? null;
|
|
22096
22377
|
log(
|
|
22097
22378
|
`[restart] Dashboard requested restart for '${agent.code_name}' at ${requested} (reason=${restartReason ?? "manual"})`
|
|
@@ -24590,6 +24871,10 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
24590
24871
|
probe: probeTmuxSession,
|
|
24591
24872
|
stopOpencode: (code) => stopOpencodeSession(code, log),
|
|
24592
24873
|
stopClaudeCode: (code) => {
|
|
24874
|
+
if (hostAuthRefreshHold.heldFor(code)) {
|
|
24875
|
+
log(`[auth-hold] config-change reload restart for '${code}' held until the Claude login refresh lands [ENG-12287]`);
|
|
24876
|
+
return;
|
|
24877
|
+
}
|
|
24593
24878
|
try {
|
|
24594
24879
|
syncExecFile("tmux", ["kill-session", "-t", tmuxSessionTarget(`agt-${code}`)], { stdio: "ignore" });
|
|
24595
24880
|
} catch {
|
|
@@ -25797,6 +26082,7 @@ Retried to the limit after repeated stalls \u2014 needs a look.`).catch(() => {
|
|
|
25797
26082
|
acpSessions: []
|
|
25798
26083
|
});
|
|
25799
26084
|
}
|
|
26085
|
+
setHostPathMigrationDeferral(() => hostAuthRefreshHold.wasHeld());
|
|
25800
26086
|
function respawnConfirmedSince(result, codeName, laneStartedAt) {
|
|
25801
26087
|
if (isConfirmedRespawn(result)) return true;
|
|
25802
26088
|
const state10 = getSessionState(codeName);
|
|
@@ -25966,6 +26252,9 @@ function refreshLiveEgressAllowlist(agent, refreshData, modelPolicy) {
|
|
|
25966
26252
|
}
|
|
25967
26253
|
}
|
|
25968
26254
|
}
|
|
26255
|
+
function openRouterForAgentFrom(raw) {
|
|
26256
|
+
return raw && raw.auth_token && raw.model ? { authToken: raw.auth_token, model: raw.model, smallFastModel: raw.small_fast_model ?? null, fingerprint: raw.fingerprint ?? null } : null;
|
|
26257
|
+
}
|
|
25969
26258
|
async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refreshData) {
|
|
25970
26259
|
const codeName = agent.code_name;
|
|
25971
26260
|
if ((agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK) === "claude-code" && !isSessionHealthy(codeName)) {
|
|
@@ -26007,15 +26296,28 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26007
26296
|
}
|
|
26008
26297
|
}
|
|
26009
26298
|
let stragglerGateRan = false;
|
|
26299
|
+
let grantedSingleStart = false;
|
|
26300
|
+
let subscriptionBacked = openRouterForAgentFrom(
|
|
26301
|
+
refreshData.openrouter ?? null
|
|
26302
|
+
) ? false : null;
|
|
26010
26303
|
const runStragglerGate = () => {
|
|
26011
26304
|
stragglerGateRan = true;
|
|
26305
|
+
if (!grantedSingleStart && subscriptionBacked !== false && hostAuthRefreshHold.wasInWindow()) {
|
|
26306
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26307
|
+
}
|
|
26308
|
+
const signalDeps = stragglerSignalDeps(hostAuthRefreshHold.wasHeld(), {
|
|
26309
|
+
killStraggler: killStragglerProcess,
|
|
26310
|
+
killHostStragglers,
|
|
26311
|
+
signalledHostPids,
|
|
26312
|
+
deferStreak: stragglerDeferStreak
|
|
26313
|
+
});
|
|
26012
26314
|
const gate = stragglerSpawnGate(codeName, {
|
|
26013
26315
|
probeProcess: probeSessionProcess,
|
|
26014
26316
|
probeTmux: (c) => probeTmuxSession(`agt-${c}`),
|
|
26015
26317
|
isDocker: (c) => effectiveIsolationMode(c) === "docker",
|
|
26016
|
-
killStraggler:
|
|
26318
|
+
killStraggler: signalDeps.killStraggler,
|
|
26017
26319
|
log,
|
|
26018
|
-
deferStreak:
|
|
26320
|
+
deferStreak: signalDeps.deferStreak,
|
|
26019
26321
|
// Obi Wan 417cd9e6ce9a: under 'reload-confirm', which /host/reaper-event
|
|
26020
26322
|
// accepts (REAPER_EVENT_ALLOWLIST); an unlisted reaper name is a 400 and
|
|
26021
26323
|
// the alert would never open.
|
|
@@ -26026,8 +26328,8 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26026
26328
|
// event (a signal SENT, not a confirmed exit: CodeRabbit on #7365), so
|
|
26027
26329
|
// prod can count them.
|
|
26028
26330
|
scanHostStragglers,
|
|
26029
|
-
killHostStragglers,
|
|
26030
|
-
signalledHostPids,
|
|
26331
|
+
killHostStragglers: signalDeps.killHostStragglers,
|
|
26332
|
+
signalledHostPids: signalDeps.signalledHostPids,
|
|
26031
26333
|
reportHostKill: (_code, root, signal, sent) => void reportReaperEvent(
|
|
26032
26334
|
agent.agent_id,
|
|
26033
26335
|
"reload-confirm",
|
|
@@ -26067,7 +26369,9 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26067
26369
|
})();
|
|
26068
26370
|
const frameworkId = agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
|
|
26069
26371
|
if (frameworkId === "opencode") {
|
|
26070
|
-
|
|
26372
|
+
const opencode = await ensureOpencodeRuntime(agent, refreshData, agentTimezone ?? null);
|
|
26373
|
+
if (opencode.spawnAttempted || opencode.sessionHealthyAfter) hostAuthRefreshHold.noteSubscriptionBacked(codeName, false);
|
|
26374
|
+
return opencode;
|
|
26071
26375
|
}
|
|
26072
26376
|
const channelConfigs = refreshData.channel_configs;
|
|
26073
26377
|
const { devChannels, pluginChannels } = resolveChannelLaunchFlags(
|
|
@@ -26077,12 +26381,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26077
26381
|
const channels = [...pluginChannels];
|
|
26078
26382
|
devChannels.push("server:direct-chat");
|
|
26079
26383
|
const openRouterRaw = refreshData.openrouter ?? null;
|
|
26080
|
-
const openRouterForAgent = openRouterRaw
|
|
26081
|
-
authToken: openRouterRaw.auth_token,
|
|
26082
|
-
model: openRouterRaw.model,
|
|
26083
|
-
smallFastModel: openRouterRaw.small_fast_model ?? null,
|
|
26084
|
-
fingerprint: openRouterRaw.fingerprint ?? null
|
|
26085
|
-
} : null;
|
|
26384
|
+
const openRouterForAgent = openRouterForAgentFrom(openRouterRaw);
|
|
26086
26385
|
const modelPolicy = parseModelPolicy(
|
|
26087
26386
|
refreshData.model_policy
|
|
26088
26387
|
);
|
|
@@ -26156,6 +26455,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26156
26455
|
detail: `${authFailure.reason} (${kind}): ${msg}`
|
|
26157
26456
|
};
|
|
26158
26457
|
}
|
|
26458
|
+
subscriptionBacked = claudeAuthMode === "subscription" && !openRouterForAgent;
|
|
26159
26459
|
if (claudeAuthMode === "openrouter" || openRouterForAgent) {
|
|
26160
26460
|
if (!openRouterForAgent) {
|
|
26161
26461
|
log(
|
|
@@ -26176,6 +26476,17 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26176
26476
|
return notAuthenticatedSkipOutcome();
|
|
26177
26477
|
}
|
|
26178
26478
|
}
|
|
26479
|
+
const healthyBeforeHold = isSessionHealthy(codeName);
|
|
26480
|
+
if (await hostAuthRefreshHold.isHeld({ claimStart: !healthyBeforeHold })) {
|
|
26481
|
+
if (isSessionHealthy(codeName)) refreshLiveEgressAllowlist(agent, refreshData, modelPolicy);
|
|
26482
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26483
|
+
}
|
|
26484
|
+
grantedSingleStart = !healthyBeforeHold && hostAuthRefreshHold.wasHeld();
|
|
26485
|
+
if (grantedSingleStart && probeSessionProcess(codeName) !== "dead") {
|
|
26486
|
+
hostAuthRefreshHold.returnStart();
|
|
26487
|
+
grantedSingleStart = false;
|
|
26488
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26489
|
+
}
|
|
26179
26490
|
} else if (!anthropicApiKey) {
|
|
26180
26491
|
log(`[persistent-session] Skipping '${codeName}' \u2014 api_key mode but no key returned from exchange`);
|
|
26181
26492
|
return {
|
|
@@ -26268,7 +26579,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26268
26579
|
);
|
|
26269
26580
|
} else {
|
|
26270
26581
|
restartNoticeDeliveredFor.delete(codeName);
|
|
26271
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, "auth-tuple-change", void 0, void 0, {
|
|
26582
|
+
const authTupleTornDown = stopPersistentSessionAndForgetMcpBaseline(codeName, "auth-tuple-change", void 0, void 0, {
|
|
26272
26583
|
reason: authTupleDiff.summary,
|
|
26273
26584
|
detail: {
|
|
26274
26585
|
auth_tuple: {
|
|
@@ -26278,6 +26589,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26278
26589
|
}
|
|
26279
26590
|
}
|
|
26280
26591
|
});
|
|
26592
|
+
if (!authTupleTornDown) return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26281
26593
|
agentState.persistentSessionAgents.delete(codeName);
|
|
26282
26594
|
restartTrigger = "auth-tuple";
|
|
26283
26595
|
}
|
|
@@ -26316,7 +26628,9 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26316
26628
|
log(
|
|
26317
26629
|
`[persistent-session] Day rollover FORCED for '${codeName}' (yesterday=${rolloverCurrent.date}) \u2014 agent busy-blocked ${overdueMin}m past the day boundary (grace ${DAY_ROLLOVER_FORCE_GRACE_MIN}m), restarting anyway to reset context`
|
|
26318
26630
|
);
|
|
26319
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover")
|
|
26631
|
+
if (!stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover")) {
|
|
26632
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26633
|
+
}
|
|
26320
26634
|
agentState.persistentSessionAgents.delete(codeName);
|
|
26321
26635
|
pendingDayRolloverReset.delete(codeName);
|
|
26322
26636
|
dayRolloverInboundHold.delete(codeName);
|
|
@@ -26585,6 +26899,10 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash21("sha256")
|
|
|
26585
26899
|
return deferred;
|
|
26586
26900
|
}
|
|
26587
26901
|
}
|
|
26902
|
+
if (!grantedSingleStart && subscriptionBacked === true && hostAuthRefreshHold.wasInWindow()) {
|
|
26903
|
+
closeSessionRunForCode(codeName, "cancelled", "held: the host Claude login refresh window opened before the spawn (ENG-12287)");
|
|
26904
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26905
|
+
}
|
|
26588
26906
|
let spawnCopyFailedNow = false;
|
|
26589
26907
|
const spawnMcpConfigPath = prepareSpawnMcpConfig({
|
|
26590
26908
|
codeName,
|
|
@@ -26690,6 +27008,7 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash21("sha256")
|
|
|
26690
27008
|
agentState.persistentSessionAgents.add(codeName);
|
|
26691
27009
|
claudeAuthTupleBySession.set(codeName, currentAuthTuple);
|
|
26692
27010
|
recordSessionPolicyBaseline(codeName, currentPolicyModel, currentPolicyId);
|
|
27011
|
+
hostAuthRefreshHold.noteSubscriptionBacked(agent.code_name, subscriptionBacked !== false);
|
|
26693
27012
|
denyWebFetchBySession.set(codeName, spawnDenyWebFetch);
|
|
26694
27013
|
persistDeliveryBaselineEntry("webFetch", agent.agent_id, webFetchBaselineValue(spawnDenyWebFetch));
|
|
26695
27014
|
seedSessionLaunchBaselines(codeName, projectDir, spawnMcpConfigPath);
|
|
@@ -27086,6 +27405,10 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27086
27405
|
}
|
|
27087
27406
|
return;
|
|
27088
27407
|
}
|
|
27408
|
+
if (await hostAuthRefreshHold.isHeld() && hostAuthRefreshHold.heldFor(codeName)) {
|
|
27409
|
+
log(`[restart-lane] restart for '${codeName}' held until the Claude login refresh lands; the poll services it after [ENG-12287]`);
|
|
27410
|
+
return;
|
|
27411
|
+
}
|
|
27089
27412
|
if (restartInFlight.has(agentId)) return;
|
|
27090
27413
|
restartInFlight.add(agentId);
|
|
27091
27414
|
let laneStartedAt = Date.now();
|
|
@@ -27095,7 +27418,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27095
27418
|
if (!refreshData) return;
|
|
27096
27419
|
const framework = refreshData.agent?.framework ?? agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
|
|
27097
27420
|
const hostId = await getHostId();
|
|
27098
|
-
const parkForRestart = await import("../responsiveness-probe-
|
|
27421
|
+
const parkForRestart = await import("../responsiveness-probe-2MCC7NOE.js").then(
|
|
27099
27422
|
(m) => m.parkPendingInbound,
|
|
27100
27423
|
(err) => err
|
|
27101
27424
|
);
|
|
@@ -27119,6 +27442,10 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27119
27442
|
return;
|
|
27120
27443
|
}
|
|
27121
27444
|
}
|
|
27445
|
+
if (hostAuthRefreshHold.heldFor(codeName)) {
|
|
27446
|
+
log(`[restart-lane] restart for '${codeName}' held until the Claude login refresh lands; the poll services it after [ENG-12287]`);
|
|
27447
|
+
return;
|
|
27448
|
+
}
|
|
27122
27449
|
log(`[restart-lane] Fast restart for '${codeName}' at ${requestedAt}`);
|
|
27123
27450
|
const displayName = refreshData.agent?.display_name ?? codeName;
|
|
27124
27451
|
const wedgeStreakAtRestart = consecutiveWedgeCycles.get(codeName) ?? 0;
|
|
@@ -27172,7 +27499,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27172
27499
|
void api.post("/host/restart-ack", { host_id: hostId, agent_id: agentId, restart_requested_at: requestedAt }).catch((err) => log(`[restart-lane] ack failed for '${codeName}': ${err.message}`));
|
|
27173
27500
|
void (async () => {
|
|
27174
27501
|
try {
|
|
27175
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
27502
|
+
const { collectDiagnostics } = await import("../persistent-session-FJ4Y7XIB.js");
|
|
27176
27503
|
await api.post("/host/heartbeat", {
|
|
27177
27504
|
host_id: hostId,
|
|
27178
27505
|
agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -27225,7 +27552,7 @@ async function respawnAgentAfterMcpStop(codeName, reason) {
|
|
|
27225
27552
|
}
|
|
27226
27553
|
try {
|
|
27227
27554
|
const hostId = await getHostId();
|
|
27228
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
27555
|
+
const { collectDiagnostics } = await import("../persistent-session-FJ4Y7XIB.js");
|
|
27229
27556
|
await api.post("/host/heartbeat", {
|
|
27230
27557
|
host_id: hostId,
|
|
27231
27558
|
agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -28104,7 +28431,7 @@ async function processClaudePairSessions(agents) {
|
|
|
28104
28431
|
snapshotPairConfig,
|
|
28105
28432
|
// ENG-11659: result -> report body + the manager.log line that records it.
|
|
28106
28433
|
planPairStartReport
|
|
28107
|
-
} = await import("../claude-pair-runtime-
|
|
28434
|
+
} = await import("../claude-pair-runtime-AAGIQSUI.js");
|
|
28108
28435
|
const { resetClaudeSignin, describeSigninResetForLog, describeSigninResetFailure } = await import("../claude-signin-reset-6IJMMVYG.js");
|
|
28109
28436
|
for (const pairId of pendingResp.cancelled_pair_ids ?? []) {
|
|
28110
28437
|
log(`[claude-pair] sweeping orphan tmux session for pair ${pairId.slice(0, 8)}`);
|
|
@@ -29600,6 +29927,7 @@ export {
|
|
|
29600
29927
|
maybeUpgradeClaudeCode,
|
|
29601
29928
|
memoryManifestPath,
|
|
29602
29929
|
memoryManifests,
|
|
29930
|
+
openRouterForAgentFrom,
|
|
29603
29931
|
pruneRealtimeRebindState,
|
|
29604
29932
|
readCrossSessionBlockStatus,
|
|
29605
29933
|
realtimeRebindBackoffMs,
|