@integrity-labs/agt-cli 0.28.1306 → 0.28.1308
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-QHGAABOL.js} +3 -3
- package/dist/bin/agt.js +7 -7
- package/dist/{chunk-K5SXTDKK.js → chunk-GZT7DHPV.js} +3 -3
- package/dist/{chunk-7V53KRPM.js → chunk-HMH4EOV5.js} +5 -5
- package/dist/{chunk-I6HGFJNX.js → chunk-JZOA4A3J.js} +2 -2
- package/dist/{chunk-GLX5CD6S.js → chunk-NXTNYNNV.js} +2 -2
- package/dist/{chunk-PT3QK5ZP.js → chunk-VSJUMNQ5.js} +115 -13
- package/dist/chunk-VSJUMNQ5.js.map +1 -0
- package/dist/{chunk-4KSUIAI4.js → chunk-WW2CTOEO.js} +9 -73
- package/dist/chunk-WW2CTOEO.js.map +1 -0
- package/dist/{claude-code-updater-KA4VMUWK.js → claude-code-updater-OU4AEM5Y.js} +3 -3
- package/dist/{claude-pair-runtime-MC3K2BXU.js → claude-pair-runtime-H7A7ZOEW.js} +3 -3
- package/dist/lib/manager-worker.js +674 -223
- package/dist/lib/manager-worker.js.map +1 -1
- package/dist/mcp/direct-chat-channel.js +8 -72
- package/dist/mcp/index.js +18 -73
- package/dist/mcp/origami.js +8 -72
- package/dist/mcp/slack-channel.js +111 -180
- package/dist/mcp/telegram-channel.js +8 -72
- package/dist/{persistent-session-ZC4XAUTS.js → persistent-session-OUCTECWP.js} +20 -4
- package/dist/{responsiveness-probe-TA47HG3A.js → responsiveness-probe-SC72APRB.js} +4 -4
- package/dist/{session-auth-dead-MDZWPSED.js → session-auth-dead-MQR2SLW5.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-4KSUIAI4.js.map +0 -1
- package/dist/chunk-PT3QK5ZP.js.map +0 -1
- /package/dist/{api-client-W53BBB2B.js.map → api-client-QHGAABOL.js.map} +0 -0
- /package/dist/{chunk-K5SXTDKK.js.map → chunk-GZT7DHPV.js.map} +0 -0
- /package/dist/{chunk-7V53KRPM.js.map → chunk-HMH4EOV5.js.map} +0 -0
- /package/dist/{chunk-I6HGFJNX.js.map → chunk-JZOA4A3J.js.map} +0 -0
- /package/dist/{chunk-GLX5CD6S.js.map → chunk-NXTNYNNV.js.map} +0 -0
- /package/dist/{claude-code-updater-KA4VMUWK.js.map → claude-code-updater-OU4AEM5Y.js.map} +0 -0
- /package/dist/{claude-pair-runtime-MC3K2BXU.js.map → claude-pair-runtime-H7A7ZOEW.js.map} +0 -0
- /package/dist/{persistent-session-ZC4XAUTS.js.map → persistent-session-OUCTECWP.js.map} +0 -0
- /package/dist/{responsiveness-probe-TA47HG3A.js.map → responsiveness-probe-SC72APRB.js.map} +0 -0
- /package/dist/{session-auth-dead-MDZWPSED.js.map → session-auth-dead-MQR2SLW5.js.map} +0 -0
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
tripClass,
|
|
71
71
|
writeEtcEnvironment,
|
|
72
72
|
writeProfileDScript
|
|
73
|
-
} from "../chunk-
|
|
73
|
+
} from "../chunk-HMH4EOV5.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-GZT7DHPV.js";
|
|
92
92
|
import {
|
|
93
93
|
BLOCKED_ON_PROMPT_DECISION,
|
|
94
94
|
CHANNEL_SECRET_ENV_KEYS,
|
|
@@ -105,6 +105,7 @@ import {
|
|
|
105
105
|
creditWatchdogGiveUpCount,
|
|
106
106
|
creditWatchdogUnclaimedDialogCount,
|
|
107
107
|
denyWebFetchForToolsContent,
|
|
108
|
+
dockerStartReadinessAsync,
|
|
108
109
|
effectiveIsolationMode,
|
|
109
110
|
egressMode,
|
|
110
111
|
execFilePromiseLong,
|
|
@@ -164,6 +165,7 @@ import {
|
|
|
164
165
|
seedContainerMemory,
|
|
165
166
|
sessionBlockedOnPrompt,
|
|
166
167
|
sessionHealthyAndUnblocked,
|
|
168
|
+
setHostPathMigrationDeferral,
|
|
167
169
|
sha256,
|
|
168
170
|
sharedBusyBuckets,
|
|
169
171
|
shouldLogBlockedPrompt,
|
|
@@ -183,7 +185,7 @@ import {
|
|
|
183
185
|
webFetchBaselineValue,
|
|
184
186
|
webFetchRestartNeeded,
|
|
185
187
|
writeEgressAllowlist
|
|
186
|
-
} from "../chunk-
|
|
188
|
+
} from "../chunk-VSJUMNQ5.js";
|
|
187
189
|
import {
|
|
188
190
|
isAgentIdle,
|
|
189
191
|
isStaleForToday,
|
|
@@ -195,7 +197,7 @@ import {
|
|
|
195
197
|
subagentActivityAgeSeconds,
|
|
196
198
|
subagentTranscriptDir,
|
|
197
199
|
transcriptActivityAgeSeconds
|
|
198
|
-
} from "../chunk-
|
|
200
|
+
} from "../chunk-NXTNYNNV.js";
|
|
199
201
|
import {
|
|
200
202
|
classifyUnanswerablePane,
|
|
201
203
|
focusedConfirmDialogBlock,
|
|
@@ -221,7 +223,7 @@ import {
|
|
|
221
223
|
runSafeCleanup,
|
|
222
224
|
tightestDiskStat,
|
|
223
225
|
withPackageCacheLock
|
|
224
|
-
} from "../chunk-
|
|
226
|
+
} from "../chunk-JZOA4A3J.js";
|
|
225
227
|
import {
|
|
226
228
|
parsePsRows,
|
|
227
229
|
reapOrphanChannelMcps
|
|
@@ -350,7 +352,7 @@ import {
|
|
|
350
352
|
stabiliseResetInstant,
|
|
351
353
|
sumTranscriptUsageInWindow,
|
|
352
354
|
summarizeTranscriptActivity
|
|
353
|
-
} from "../chunk-
|
|
355
|
+
} from "../chunk-WW2CTOEO.js";
|
|
354
356
|
import {
|
|
355
357
|
CLAUDE_CONFIG_DIR_ENV,
|
|
356
358
|
claudeConfigDirFor,
|
|
@@ -1692,7 +1694,7 @@ function clearEpisode(codeName) {
|
|
|
1692
1694
|
|
|
1693
1695
|
// src/lib/manager-worker.ts
|
|
1694
1696
|
import { join as join48, dirname as dirname11, delimiter as pathDelimiter } from "path";
|
|
1695
|
-
import { homedir as homedir17, hostname, platform as platform3 } from "os";
|
|
1697
|
+
import { homedir as homedir17, hostname as hostname2, platform as platform3 } from "os";
|
|
1696
1698
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1697
1699
|
|
|
1698
1700
|
// ../../packages/core/dist/provisioning/channel-policy-env.js
|
|
@@ -5369,6 +5371,411 @@ function notAuthenticatedSkipOutcome() {
|
|
|
5369
5371
|
}
|
|
5370
5372
|
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
5373
|
|
|
5374
|
+
// src/lib/manager/auth-refresh-held-outcome.ts
|
|
5375
|
+
function authRefreshHeldOutcome(sessionHealthy) {
|
|
5376
|
+
return {
|
|
5377
|
+
decision: "held-auth-refresh",
|
|
5378
|
+
spawnAttempted: false,
|
|
5379
|
+
sessionHealthyAfter: sessionHealthy,
|
|
5380
|
+
detail: AUTH_REFRESH_HELD_CAUSE
|
|
5381
|
+
};
|
|
5382
|
+
}
|
|
5383
|
+
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";
|
|
5384
|
+
|
|
5385
|
+
// src/lib/claude-auth-detect.ts
|
|
5386
|
+
import { readFile, readdir } from "fs/promises";
|
|
5387
|
+
import { homedir as homedir4, platform } from "os";
|
|
5388
|
+
import { join as join14 } from "path";
|
|
5389
|
+
import { execFile } from "child_process";
|
|
5390
|
+
import { promisify } from "util";
|
|
5391
|
+
var execFileAsync = promisify(execFile);
|
|
5392
|
+
var EXPIRING_SOON_MS = 48 * 60 * 60 * 1e3;
|
|
5393
|
+
async function detectClaudeAuth() {
|
|
5394
|
+
if (process.env["ANTHROPIC_API_KEY"] || process.env["ANTHROPIC_AUTH_TOKEN"]) {
|
|
5395
|
+
return { mode: "api_key", status: "valid", expires_at: null };
|
|
5396
|
+
}
|
|
5397
|
+
const creds = await readOauthCredentials();
|
|
5398
|
+
if (!creds) return null;
|
|
5399
|
+
return computeSubscriptionStatus(creds);
|
|
5400
|
+
}
|
|
5401
|
+
async function detectClaudeSubscriptionAuth() {
|
|
5402
|
+
const creds = await readOauthCredentials();
|
|
5403
|
+
if (!creds) return null;
|
|
5404
|
+
return computeSubscriptionStatus(creds);
|
|
5405
|
+
}
|
|
5406
|
+
async function findClaudeCredentialsPaths() {
|
|
5407
|
+
return (await discoverCredentialCandidates()).paths;
|
|
5408
|
+
}
|
|
5409
|
+
async function readOauthCredentials() {
|
|
5410
|
+
if (platform() === "darwin") {
|
|
5411
|
+
const fromKeychain = await readMacKeychain();
|
|
5412
|
+
if (fromKeychain) return fromKeychain;
|
|
5413
|
+
}
|
|
5414
|
+
const candidates = await findClaudeCredentialsPaths();
|
|
5415
|
+
for (const path of candidates) {
|
|
5416
|
+
const parsed = await readJsonSilently(path);
|
|
5417
|
+
if (parsed) {
|
|
5418
|
+
return parsed.claudeAiOauth ?? parsed.oauth ?? parsed;
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
return null;
|
|
5422
|
+
}
|
|
5423
|
+
async function readMacKeychain() {
|
|
5424
|
+
try {
|
|
5425
|
+
const { stdout } = await execFileAsync(
|
|
5426
|
+
"security",
|
|
5427
|
+
["find-generic-password", "-s", "Claude Code-credentials", "-w"],
|
|
5428
|
+
{ timeout: 3e3 }
|
|
5429
|
+
);
|
|
5430
|
+
const parsed = JSON.parse(stdout.trim());
|
|
5431
|
+
return parsed.claudeAiOauth ?? parsed;
|
|
5432
|
+
} catch {
|
|
5433
|
+
return null;
|
|
5434
|
+
}
|
|
5435
|
+
}
|
|
5436
|
+
async function readJsonSilently(path) {
|
|
5437
|
+
try {
|
|
5438
|
+
const raw = await readFile(path, "utf-8");
|
|
5439
|
+
return JSON.parse(raw);
|
|
5440
|
+
} catch {
|
|
5441
|
+
return null;
|
|
5442
|
+
}
|
|
5443
|
+
}
|
|
5444
|
+
function credentialPresenceFrom(outcomes) {
|
|
5445
|
+
if (outcomes.includes("parsed")) return "present";
|
|
5446
|
+
if (outcomes.includes("unreadable")) return "unreadable";
|
|
5447
|
+
return "absent";
|
|
5448
|
+
}
|
|
5449
|
+
async function discoverCredentialCandidates(deps = {}) {
|
|
5450
|
+
const home = deps.home ?? homedir4();
|
|
5451
|
+
const paths = [join14(home, ".claude", ".credentials.json"), join14(home, ".claude", "credentials.json")];
|
|
5452
|
+
const outcomes = [];
|
|
5453
|
+
const linuxRoot = deps.linuxRoot ?? (platform() === "linux" && typeof process.getuid === "function" && process.getuid() === 0);
|
|
5454
|
+
if (linuxRoot) {
|
|
5455
|
+
const list = deps.readdirImpl ?? ((path) => readdir(path, { withFileTypes: true }));
|
|
5456
|
+
try {
|
|
5457
|
+
const entries = await list("/home");
|
|
5458
|
+
for (const entry of entries.filter((e) => e.isDirectory()).sort((x, y) => x.name.localeCompare(y.name))) {
|
|
5459
|
+
paths.push(join14("/home", entry.name, ".claude", ".credentials.json"));
|
|
5460
|
+
paths.push(join14("/home", entry.name, ".claude", "credentials.json"));
|
|
5461
|
+
}
|
|
5462
|
+
} catch (err) {
|
|
5463
|
+
const code = err.code;
|
|
5464
|
+
outcomes.push(code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable");
|
|
5465
|
+
}
|
|
5466
|
+
}
|
|
5467
|
+
return { paths, outcomes };
|
|
5468
|
+
}
|
|
5469
|
+
function keychainOutcomeFrom(result) {
|
|
5470
|
+
if ("error" in result) return "unreadable";
|
|
5471
|
+
try {
|
|
5472
|
+
JSON.parse(result.stdout.trim());
|
|
5473
|
+
return "parsed";
|
|
5474
|
+
} catch {
|
|
5475
|
+
return "unreadable";
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5478
|
+
async function keychainOutcome() {
|
|
5479
|
+
try {
|
|
5480
|
+
const { stdout } = await execFileAsync("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 3e3 });
|
|
5481
|
+
return keychainOutcomeFrom({ stdout });
|
|
5482
|
+
} catch (error) {
|
|
5483
|
+
return keychainOutcomeFrom({ error });
|
|
5484
|
+
}
|
|
5485
|
+
}
|
|
5486
|
+
async function claudeCredentialPresence(deps = {}) {
|
|
5487
|
+
if (process.env["ANTHROPIC_API_KEY"] || process.env["ANTHROPIC_AUTH_TOKEN"]) return "present";
|
|
5488
|
+
const outcomes = [];
|
|
5489
|
+
const keychain = deps.keychain === void 0 ? platform() === "darwin" ? keychainOutcome : null : deps.keychain;
|
|
5490
|
+
if (keychain) outcomes.push(await keychain());
|
|
5491
|
+
let paths;
|
|
5492
|
+
if (deps.paths) {
|
|
5493
|
+
paths = deps.paths;
|
|
5494
|
+
} else {
|
|
5495
|
+
const discovered = await discoverCredentialCandidates();
|
|
5496
|
+
paths = discovered.paths;
|
|
5497
|
+
outcomes.push(...discovered.outcomes);
|
|
5498
|
+
}
|
|
5499
|
+
for (const path of paths) {
|
|
5500
|
+
let raw;
|
|
5501
|
+
try {
|
|
5502
|
+
raw = await readFile(path, "utf-8");
|
|
5503
|
+
} catch (err) {
|
|
5504
|
+
const code = err.code;
|
|
5505
|
+
outcomes.push(code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable");
|
|
5506
|
+
continue;
|
|
5507
|
+
}
|
|
5508
|
+
try {
|
|
5509
|
+
JSON.parse(raw);
|
|
5510
|
+
outcomes.push("parsed");
|
|
5511
|
+
} catch {
|
|
5512
|
+
outcomes.push("unreadable");
|
|
5513
|
+
}
|
|
5514
|
+
}
|
|
5515
|
+
return credentialPresenceFrom(outcomes);
|
|
5516
|
+
}
|
|
5517
|
+
function computeSubscriptionStatus(creds) {
|
|
5518
|
+
const expiresAtMs = parseExpiresAt(creds.expiresAt);
|
|
5519
|
+
const hasRefreshToken = typeof creds.refreshToken === "string" && creds.refreshToken.trim().length > 0;
|
|
5520
|
+
if (expiresAtMs === null) {
|
|
5521
|
+
return {
|
|
5522
|
+
mode: "subscription",
|
|
5523
|
+
status: "unknown",
|
|
5524
|
+
expires_at: null
|
|
5525
|
+
};
|
|
5526
|
+
}
|
|
5527
|
+
const msUntilExpiry = expiresAtMs - Date.now();
|
|
5528
|
+
let status;
|
|
5529
|
+
if (hasRefreshToken) {
|
|
5530
|
+
status = "valid";
|
|
5531
|
+
} else {
|
|
5532
|
+
status = msUntilExpiry <= 0 ? "expired" : msUntilExpiry <= EXPIRING_SOON_MS ? "expiring_soon" : "valid";
|
|
5533
|
+
}
|
|
5534
|
+
return {
|
|
5535
|
+
mode: "subscription",
|
|
5536
|
+
status,
|
|
5537
|
+
expires_at: new Date(expiresAtMs).toISOString()
|
|
5538
|
+
};
|
|
5539
|
+
}
|
|
5540
|
+
function parseExpiresAt(raw) {
|
|
5541
|
+
if (typeof raw === "number" && Number.isFinite(raw)) {
|
|
5542
|
+
return raw < 1e12 ? raw * 1e3 : raw;
|
|
5543
|
+
}
|
|
5544
|
+
if (typeof raw === "string") {
|
|
5545
|
+
const parsed = Date.parse(raw);
|
|
5546
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
5547
|
+
}
|
|
5548
|
+
return null;
|
|
5549
|
+
}
|
|
5550
|
+
|
|
5551
|
+
// src/lib/manager/auth-refresh-hold.ts
|
|
5552
|
+
import { hostname } from "os";
|
|
5553
|
+
var HOLD_LEAD_MS = 6 * 6e4;
|
|
5554
|
+
var HOLD_MAX_PAST_EXPIRY_MS = 5 * 6e4;
|
|
5555
|
+
function authRefreshHoldVerdict(expiresAtMs, nowMs) {
|
|
5556
|
+
if (expiresAtMs === null || !Number.isFinite(expiresAtMs)) return { held: false, reason: "no-expiry" };
|
|
5557
|
+
if (expiresAtMs <= 0) return { held: false, reason: "tombstone" };
|
|
5558
|
+
if (nowMs < expiresAtMs - HOLD_LEAD_MS) return { held: false, reason: "before-window" };
|
|
5559
|
+
if (nowMs <= expiresAtMs + HOLD_MAX_PAST_EXPIRY_MS) return { held: true, reason: "in-window" };
|
|
5560
|
+
return { held: false, reason: "past-cap" };
|
|
5561
|
+
}
|
|
5562
|
+
var SINGLE_START_MAX_MS = 3 * 6e4;
|
|
5563
|
+
var SELF_UPDATE_AUTH_REFRESH_LEAD_MS = 10 * 6e4;
|
|
5564
|
+
var MAX_SINGLE_START_GRANTS = 3;
|
|
5565
|
+
var HOLD_WORST_PAST_EXPIRY_MS = HOLD_MAX_PAST_EXPIRY_MS + 2 * MAX_SINGLE_START_GRANTS * SINGLE_START_MAX_MS;
|
|
5566
|
+
var AuthRefreshHoldTracker = class {
|
|
5567
|
+
constructor(log2, host = hostname()) {
|
|
5568
|
+
this.log = log2;
|
|
5569
|
+
this.host = host;
|
|
5570
|
+
}
|
|
5571
|
+
state = { phase: "idle" };
|
|
5572
|
+
/** The expiry whose single-start phase already ran, so a stale expiry cannot re-open it. */
|
|
5573
|
+
singleDoneFor = null;
|
|
5574
|
+
/**
|
|
5575
|
+
* The last expiry actually read (null when the read said there is none). An
|
|
5576
|
+
* expiry is known hours ahead, so the clock alone can say when its window
|
|
5577
|
+
* opens: `rejudge` uses it to open a hold without a new read (CodeRabbit on
|
|
5578
|
+
* PR #7796, a restart timer firing between polls).
|
|
5579
|
+
*/
|
|
5580
|
+
lastSeen = null;
|
|
5581
|
+
/**
|
|
5582
|
+
* Feed one observation; returns whether the caller is held. Logs only on a
|
|
5583
|
+
* transition.
|
|
5584
|
+
*
|
|
5585
|
+
* `'unreadable'` is a failed read (a credentials file caught mid-rename during
|
|
5586
|
+
* the very refresh being held for, a keychain timeout). It is NOT "no expiry":
|
|
5587
|
+
* it changes nothing. An active hold re-judges the expiry that opened it, so it
|
|
5588
|
+
* can run no longer than its bounds; a free host stays free.
|
|
5589
|
+
*/
|
|
5590
|
+
observe(observation, nowMs, opts = {}) {
|
|
5591
|
+
if (observation === "unreadable") {
|
|
5592
|
+
if (this.state.phase === "idle") return false;
|
|
5593
|
+
return this.observe(this.state.for, nowMs, opts);
|
|
5594
|
+
}
|
|
5595
|
+
const expiresAtMs = observation;
|
|
5596
|
+
this.lastSeen = expiresAtMs;
|
|
5597
|
+
const verdict = authRefreshHoldVerdict(expiresAtMs, nowMs);
|
|
5598
|
+
if (verdict.reason === "in-window") {
|
|
5599
|
+
if (this.state.phase === "idle" || this.state.for !== expiresAtMs) {
|
|
5600
|
+
if (this.state.phase === "idle") {
|
|
5601
|
+
this.log(
|
|
5602
|
+
`[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]`
|
|
5603
|
+
);
|
|
5604
|
+
}
|
|
5605
|
+
this.state = { phase: "engaged", for: expiresAtMs };
|
|
5606
|
+
}
|
|
5607
|
+
return true;
|
|
5608
|
+
}
|
|
5609
|
+
if (verdict.reason === "past-cap" && this.singleDoneFor !== expiresAtMs) {
|
|
5610
|
+
const e = expiresAtMs;
|
|
5611
|
+
if (this.state.phase !== "single" || this.state.for !== e) {
|
|
5612
|
+
this.state = { phase: "single", for: e, since: nowMs, grantedAt: null, grants: 0 };
|
|
5613
|
+
this.log(
|
|
5614
|
+
`[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]`
|
|
5615
|
+
);
|
|
5616
|
+
}
|
|
5617
|
+
const single = this.state;
|
|
5618
|
+
if (nowMs > (single.grantedAt ?? single.since) + SINGLE_START_MAX_MS) {
|
|
5619
|
+
if (single.grantedAt !== null && single.grants < MAX_SINGLE_START_GRANTS) {
|
|
5620
|
+
single.grantedAt = null;
|
|
5621
|
+
single.since = nowMs;
|
|
5622
|
+
this.log(
|
|
5623
|
+
`[auth-hold] host=${this.host} single start ${single.grants} did not refresh; offering another (${single.grants}/${MAX_SINGLE_START_GRANTS}) [ENG-12287]`
|
|
5624
|
+
);
|
|
5625
|
+
} else {
|
|
5626
|
+
this.singleDoneFor = e;
|
|
5627
|
+
this.release("past-cap", expiresAtMs);
|
|
5628
|
+
return false;
|
|
5629
|
+
}
|
|
5630
|
+
}
|
|
5631
|
+
if (opts.claimStart && single.grantedAt === null) {
|
|
5632
|
+
single.grantedAt = nowMs;
|
|
5633
|
+
single.grants += 1;
|
|
5634
|
+
this.log(`[auth-hold] host=${this.host} single start granted (${single.grants}/${MAX_SINGLE_START_GRANTS}) [ENG-12287]`);
|
|
5635
|
+
return false;
|
|
5636
|
+
}
|
|
5637
|
+
return true;
|
|
5638
|
+
}
|
|
5639
|
+
if (this.state.phase !== "idle") {
|
|
5640
|
+
const from = this.state.for;
|
|
5641
|
+
const reason = verdict.reason === "tombstone" ? "tombstone" : verdict.reason === "no-expiry" ? "no-expiry" : expiresAtMs !== null && expiresAtMs > from ? "refreshed" : "past-cap";
|
|
5642
|
+
this.release(reason, expiresAtMs);
|
|
5643
|
+
}
|
|
5644
|
+
return false;
|
|
5645
|
+
}
|
|
5646
|
+
release(reason, expiresAtMs) {
|
|
5647
|
+
this.log(
|
|
5648
|
+
`[auth-hold] host=${this.host} released reason=${reason}` + (expiresAtMs !== null && expiresAtMs > 0 ? ` expires_at=${new Date(expiresAtMs).toISOString()}` : "") + " [ENG-12287]"
|
|
5649
|
+
);
|
|
5650
|
+
this.state = { phase: "idle" };
|
|
5651
|
+
}
|
|
5652
|
+
/**
|
|
5653
|
+
* Judge the hold against `nowMs` without a new read, from the last expiry
|
|
5654
|
+
* read. It opens exactly when the clock enters that expiry's window and can
|
|
5655
|
+
* never outlive the hold's bounds (the cap, the single-start limit). Its only
|
|
5656
|
+
* error is a refresh that has landed but not been read yet: that over-holds
|
|
5657
|
+
* until the next read, still within those bounds. Never claims the single start.
|
|
5658
|
+
*/
|
|
5659
|
+
rejudge(nowMs) {
|
|
5660
|
+
if (this.state.phase !== "idle") return this.observe("unreadable", nowMs);
|
|
5661
|
+
if (this.lastSeen === null) return false;
|
|
5662
|
+
return this.observe(this.lastSeen, nowMs);
|
|
5663
|
+
}
|
|
5664
|
+
/**
|
|
5665
|
+
* The granted caller is not starting after all (its previous process is not
|
|
5666
|
+
* positively dead, so it defers): hand the grant back unspent. Spending it at
|
|
5667
|
+
* claim would hold every other start for `SINGLE_START_MAX_MS` while nothing
|
|
5668
|
+
* refreshes (Obi Wan 72785e3c523a). The phase's own clock (`since`) is not
|
|
5669
|
+
* reset, so a caller that keeps claiming and returning cannot extend the hold:
|
|
5670
|
+
* with no grant outstanding it still releases `SINGLE_START_MAX_MS` after
|
|
5671
|
+
* `since`, and the worst case in the docblock is unchanged. No-op outside a
|
|
5672
|
+
* granted single phase.
|
|
5673
|
+
*/
|
|
5674
|
+
returnStart(nowMs) {
|
|
5675
|
+
if (this.state.phase !== "single" || this.state.grantedAt === null) return;
|
|
5676
|
+
this.state.grantedAt = null;
|
|
5677
|
+
this.state.grants -= 1;
|
|
5678
|
+
this.log(
|
|
5679
|
+
`[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]`
|
|
5680
|
+
);
|
|
5681
|
+
}
|
|
5682
|
+
/** Any phase but idle holds restarts, self-updates, one-shots and /restart flags. */
|
|
5683
|
+
get engaged() {
|
|
5684
|
+
return this.state.phase !== "idle";
|
|
5685
|
+
}
|
|
5686
|
+
/**
|
|
5687
|
+
* A refresher may be running: inside the window proper, or in the single-start
|
|
5688
|
+
* phase once the one start has been granted (that start is the refresher).
|
|
5689
|
+
* False in the single phase before the grant, so the grant stays claimable.
|
|
5690
|
+
*/
|
|
5691
|
+
get refresherMayRun() {
|
|
5692
|
+
return this.state.phase === "engaged" || this.state.phase === "single" && this.state.grantedAt !== null;
|
|
5693
|
+
}
|
|
5694
|
+
/**
|
|
5695
|
+
* Pure, no transition: will the last-read expiry's window be open (or still
|
|
5696
|
+
* open) `leadMs` from `nowMs`? For work that cannot be held once it starts.
|
|
5697
|
+
*/
|
|
5698
|
+
windowOpensWithin(nowMs, leadMs) {
|
|
5699
|
+
if (this.lastSeen === null) return false;
|
|
5700
|
+
return authRefreshHoldVerdict(this.lastSeen, nowMs + leadMs).reason === "in-window";
|
|
5701
|
+
}
|
|
5702
|
+
};
|
|
5703
|
+
var READ_CACHE_MS = 5e3;
|
|
5704
|
+
function createAuthRefreshHold(deps) {
|
|
5705
|
+
const tracker = new AuthRefreshHoldTracker(deps.log);
|
|
5706
|
+
const now = deps.now ?? Date.now;
|
|
5707
|
+
let cached = null;
|
|
5708
|
+
let inflight = null;
|
|
5709
|
+
const openRouterBacked = /* @__PURE__ */ new Set();
|
|
5710
|
+
return {
|
|
5711
|
+
async isHeld(opts = {}) {
|
|
5712
|
+
const t = now();
|
|
5713
|
+
if (!cached || t - cached.at >= READ_CACHE_MS) {
|
|
5714
|
+
if (!inflight) {
|
|
5715
|
+
inflight = deps.readExpiresAtMs().catch(() => "unreadable").finally(() => {
|
|
5716
|
+
inflight = null;
|
|
5717
|
+
});
|
|
5718
|
+
}
|
|
5719
|
+
cached = { at: t, expiresAtMs: await inflight };
|
|
5720
|
+
}
|
|
5721
|
+
return tracker.observe(cached.expiresAtMs, now(), opts);
|
|
5722
|
+
},
|
|
5723
|
+
wasHeld: () => tracker.rejudge(now()),
|
|
5724
|
+
wasInWindow: () => {
|
|
5725
|
+
tracker.rejudge(now());
|
|
5726
|
+
return tracker.refresherMayRun;
|
|
5727
|
+
},
|
|
5728
|
+
async heldOrOpensWithin(leadMs) {
|
|
5729
|
+
if (await this.isHeld()) return true;
|
|
5730
|
+
return tracker.windowOpensWithin(now(), leadMs);
|
|
5731
|
+
},
|
|
5732
|
+
returnStart: () => tracker.returnStart(now()),
|
|
5733
|
+
heldFor: (codeName) => !openRouterBacked.has(codeName) && tracker.rejudge(now()),
|
|
5734
|
+
noteSubscriptionBacked: (codeName, backed) => {
|
|
5735
|
+
if (backed) openRouterBacked.delete(codeName);
|
|
5736
|
+
else openRouterBacked.add(codeName);
|
|
5737
|
+
}
|
|
5738
|
+
};
|
|
5739
|
+
}
|
|
5740
|
+
function stragglerSignalDeps(holdActive, real) {
|
|
5741
|
+
if (!holdActive) return real;
|
|
5742
|
+
const tracker = real.signalledHostPids;
|
|
5743
|
+
return {
|
|
5744
|
+
killStraggler: () => false,
|
|
5745
|
+
killHostStragglers: () => [],
|
|
5746
|
+
// CodeRabbit on PR #7796: survivors signalled BEFORE the hold still block a
|
|
5747
|
+
// spawn (a fresh scan can miss a descendant whose root exited), so reads go
|
|
5748
|
+
// through; only NEW records are suppressed, because nothing is signalled now.
|
|
5749
|
+
signalledHostPids: tracker === void 0 ? void 0 : { survivors: (c) => tracker.survivors(c), verify: (t) => tracker.verify(t), remember: () => void 0 },
|
|
5750
|
+
// CodeRabbit on PR #7796: a held check advances no SIGTERM-to-SIGKILL count.
|
|
5751
|
+
// The count is frozen, not reset: a streak built BEFORE the hold is kept, so
|
|
5752
|
+
// the first check after release continues it (SIGKILL if it had already
|
|
5753
|
+
// passed the SIGTERM attempts), and one that started at zero starts at SIGTERM.
|
|
5754
|
+
deferStreak: void 0
|
|
5755
|
+
};
|
|
5756
|
+
}
|
|
5757
|
+
|
|
5758
|
+
// src/lib/manager/host-auth-refresh-hold.ts
|
|
5759
|
+
async function readHostExpiresAtMs() {
|
|
5760
|
+
const hostMode = getCachedClaudeAuthModeRaw();
|
|
5761
|
+
if (hostMode === "api_key" || hostMode === "openrouter" || hostMode === "xai") return null;
|
|
5762
|
+
const report = await detectClaudeSubscriptionAuth();
|
|
5763
|
+
if (report === null) {
|
|
5764
|
+
return await claudeCredentialPresence() === "absent" ? null : "unreadable";
|
|
5765
|
+
}
|
|
5766
|
+
if (report.mode !== "subscription") return null;
|
|
5767
|
+
if (report.expires_at === null) return "unreadable";
|
|
5768
|
+
const ms = Date.parse(report.expires_at);
|
|
5769
|
+
return Number.isNaN(ms) ? "unreadable" : ms;
|
|
5770
|
+
}
|
|
5771
|
+
var hostAuthRefreshHold = createAuthRefreshHold({ readExpiresAtMs: readHostExpiresAtMs, log });
|
|
5772
|
+
var AuthRefreshHeldError = class extends Error {
|
|
5773
|
+
constructor(label) {
|
|
5774
|
+
super(`[auth-hold] ${label} not started: the host's Claude login is refreshing (ENG-12287)`);
|
|
5775
|
+
this.name = "AuthRefreshHeldError";
|
|
5776
|
+
}
|
|
5777
|
+
};
|
|
5778
|
+
|
|
5372
5779
|
// src/lib/heartbeat-claude-auth-absent.ts
|
|
5373
5780
|
function fileAuthAfterHeartbeat(current, input) {
|
|
5374
5781
|
if (input.rawMode !== "subscription" || input.detectionFailed) return current;
|
|
@@ -5423,7 +5830,7 @@ function collectEnvGates(env) {
|
|
|
5423
5830
|
|
|
5424
5831
|
// ../../packages/core/dist/direct-chat/cursor-advance-telemetry.js
|
|
5425
5832
|
import { readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
5426
|
-
import { join as
|
|
5833
|
+
import { join as join15 } from "path";
|
|
5427
5834
|
var CURSOR_SHORTFALL_COUNTER_SUFFIX = "-cursor-advance-classifications.json";
|
|
5428
5835
|
function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
5429
5836
|
if (!agentDir)
|
|
@@ -5431,7 +5838,7 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
5431
5838
|
const key = cursorAdvanceCounterKey(route, verdict);
|
|
5432
5839
|
if (key === null)
|
|
5433
5840
|
return;
|
|
5434
|
-
const path =
|
|
5841
|
+
const path = join15(agentDir, `${source}${CURSOR_SHORTFALL_COUNTER_SUFFIX}`);
|
|
5435
5842
|
const counts = {};
|
|
5436
5843
|
try {
|
|
5437
5844
|
const parsed = JSON.parse(readFileSync13(path, "utf-8"));
|
|
@@ -5451,9 +5858,9 @@ function recordCursorAdvanceOutcome(agentDir, source, route, verdict) {
|
|
|
5451
5858
|
}
|
|
5452
5859
|
|
|
5453
5860
|
// src/lib/artifact-stream.ts
|
|
5454
|
-
import { join as
|
|
5455
|
-
import { homedir as
|
|
5456
|
-
import { readdir, stat, readFile } from "fs/promises";
|
|
5861
|
+
import { join as join16 } from "path";
|
|
5862
|
+
import { homedir as homedir5 } from "os";
|
|
5863
|
+
import { readdir as readdir2, stat, readFile as readFile2 } from "fs/promises";
|
|
5457
5864
|
var ARTEFACT_ENTRY_FILE = "index.html";
|
|
5458
5865
|
function errMessage(err) {
|
|
5459
5866
|
return err instanceof Error ? err.message : String(err);
|
|
@@ -5537,7 +5944,7 @@ var ArtifactStreamScanner = class {
|
|
|
5537
5944
|
return;
|
|
5538
5945
|
}
|
|
5539
5946
|
for (const name of names) {
|
|
5540
|
-
const file =
|
|
5947
|
+
const file = join16(this.artifactsDir, name, ARTEFACT_ENTRY_FILE);
|
|
5541
5948
|
const mtime = await this.fsDeps.mtimeMs(file).catch(() => null);
|
|
5542
5949
|
if (mtime === null) continue;
|
|
5543
5950
|
if (this.seenMtime.get(name) === mtime) continue;
|
|
@@ -5568,11 +5975,11 @@ var ArtifactStreamScanner = class {
|
|
|
5568
5975
|
}
|
|
5569
5976
|
};
|
|
5570
5977
|
function artifactsDirFor(codeName) {
|
|
5571
|
-
return
|
|
5978
|
+
return join16(homedir5(), ".augmented", codeName, "artifacts");
|
|
5572
5979
|
}
|
|
5573
5980
|
var nodeArtifactFs = {
|
|
5574
5981
|
async listArtefactNames(artifactsDir) {
|
|
5575
|
-
const entries = await
|
|
5982
|
+
const entries = await readdir2(artifactsDir, { withFileTypes: true });
|
|
5576
5983
|
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
5577
5984
|
},
|
|
5578
5985
|
async mtimeMs(filePath) {
|
|
@@ -5583,7 +5990,7 @@ var nodeArtifactFs = {
|
|
|
5583
5990
|
}
|
|
5584
5991
|
},
|
|
5585
5992
|
readFile(filePath) {
|
|
5586
|
-
return
|
|
5993
|
+
return readFile2(filePath, "utf8");
|
|
5587
5994
|
}
|
|
5588
5995
|
};
|
|
5589
5996
|
|
|
@@ -5845,169 +6252,6 @@ import { createHash as createHash7 } from "crypto";
|
|
|
5845
6252
|
import { readFile as readFile3, readdir as readdir3 } from "fs/promises";
|
|
5846
6253
|
import { homedir as homedir6, platform as platform2 } from "os";
|
|
5847
6254
|
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
6255
|
async function candidateHomes() {
|
|
6012
6256
|
const homes = [homedir6()];
|
|
6013
6257
|
const isLinuxRoot = platform2() === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
@@ -7185,8 +7429,8 @@ var DEFAULT_LOCAL_EVAL_MODEL = "gemma4:12b";
|
|
|
7185
7429
|
var EVAL_TIMEOUT_MS = 12e4;
|
|
7186
7430
|
async function runLocalEvalChat(prompt, opts) {
|
|
7187
7431
|
const endpoint = new URL(opts.url);
|
|
7188
|
-
const
|
|
7189
|
-
const isLoopback =
|
|
7432
|
+
const hostname3 = endpoint.hostname.toLowerCase();
|
|
7433
|
+
const isLoopback = hostname3 === "localhost" || hostname3 === "127.0.0.1" || hostname3 === "::1" || hostname3 === "[::1]";
|
|
7190
7434
|
if (!isLoopback) {
|
|
7191
7435
|
throw new Error(`local eval url must be loopback-only, got host '${endpoint.hostname}'`);
|
|
7192
7436
|
}
|
|
@@ -11088,6 +11332,7 @@ async function applyClaudeAuthToEnv(childEnv, label, options = {}) {
|
|
|
11088
11332
|
}
|
|
11089
11333
|
return { isolated: !!options.isolateApiKeyConfigDir };
|
|
11090
11334
|
}
|
|
11335
|
+
if (await hostAuthRefreshHold.isHeld()) throw new AuthRefreshHeldError(label);
|
|
11091
11336
|
delete childEnv.ANTHROPIC_API_KEY;
|
|
11092
11337
|
return { isolated: false };
|
|
11093
11338
|
}
|
|
@@ -15774,7 +16019,7 @@ function createFileMigrationReportIO(codeName, log2) {
|
|
|
15774
16019
|
};
|
|
15775
16020
|
}
|
|
15776
16021
|
var managerHostPost = async (path, body) => {
|
|
15777
|
-
const { api: api2, ApiError: ApiError3 } = await import("../api-client-
|
|
16022
|
+
const { api: api2, ApiError: ApiError3 } = await import("../api-client-QHGAABOL.js");
|
|
15778
16023
|
try {
|
|
15779
16024
|
const json = await api2.post(path, body);
|
|
15780
16025
|
return { status: 200, json };
|
|
@@ -16085,8 +16330,9 @@ async function processRestartFlags(opts) {
|
|
|
16085
16330
|
const flags = readRestartFlags();
|
|
16086
16331
|
if (flags.length === 0) return;
|
|
16087
16332
|
for (const flag of flags) {
|
|
16333
|
+
let deferred = false;
|
|
16088
16334
|
try {
|
|
16089
|
-
await processOne(flag, opts);
|
|
16335
|
+
deferred = await processOne(flag, opts) === "deferred";
|
|
16090
16336
|
} catch (err) {
|
|
16091
16337
|
opts.log(`[restart-handler] Failed to process flag for '${flag.codeName}': ${err.message}`);
|
|
16092
16338
|
try {
|
|
@@ -16096,7 +16342,7 @@ async function processRestartFlags(opts) {
|
|
|
16096
16342
|
}
|
|
16097
16343
|
} finally {
|
|
16098
16344
|
try {
|
|
16099
|
-
deleteRestartFlag(flag.codeName);
|
|
16345
|
+
if (!deferred) deleteRestartFlag(flag.codeName);
|
|
16100
16346
|
} catch (err) {
|
|
16101
16347
|
opts.log(`[restart-handler] Failed to delete flag for '${flag.codeName}': ${err.message}`);
|
|
16102
16348
|
}
|
|
@@ -16117,7 +16363,10 @@ async function processOne(flag, opts) {
|
|
|
16117
16363
|
}
|
|
16118
16364
|
const reasonSuffix = flag.source === "agent" && flag.reason ? ` reason="${flag.reason}"` : "";
|
|
16119
16365
|
opts.log(`[restart-handler] Restarting tmux session for '${flag.codeName}' (source: ${flag.source})${reasonSuffix}`);
|
|
16120
|
-
opts.stopSession(flag.codeName, flag)
|
|
16366
|
+
if (opts.stopSession(flag.codeName, flag) === false) {
|
|
16367
|
+
opts.log(`[restart-handler] Restart for '${flag.codeName}' deferred (Claude login refresh hold); flag kept for the next poll [ENG-12287]`);
|
|
16368
|
+
return "deferred";
|
|
16369
|
+
}
|
|
16121
16370
|
if (opts.reportRestartEvent) {
|
|
16122
16371
|
void opts.reportRestartEvent(flag).catch((err) => {
|
|
16123
16372
|
opts.log(`[restart-handler] restart-event report failed for '${flag.codeName}': ${err.message}`);
|
|
@@ -16412,6 +16661,81 @@ var PersistentSessionStuckTracker = class {
|
|
|
16412
16661
|
}
|
|
16413
16662
|
};
|
|
16414
16663
|
|
|
16664
|
+
// src/lib/isolation-fail-closed.ts
|
|
16665
|
+
function isolationSpawnRefusal(mode, readiness) {
|
|
16666
|
+
if (mode !== "docker") return null;
|
|
16667
|
+
const r = readiness();
|
|
16668
|
+
return r.ok ? null : { reason: r.reason };
|
|
16669
|
+
}
|
|
16670
|
+
var ISOLATION_REFUSAL_ALERT_REFRESH_MS = 10 * 6e4;
|
|
16671
|
+
var ISOLATION_REFUSAL_REAPER = "isolation-fail-closed";
|
|
16672
|
+
var IsolationRefusalAlerts = class {
|
|
16673
|
+
lastSent = /* @__PURE__ */ new Map();
|
|
16674
|
+
/**
|
|
16675
|
+
* Which code name each refused agent id has (CodeRabbit on #7695): the realtime
|
|
16676
|
+
* unassign callback knows only the agent id, so without this it cannot find the
|
|
16677
|
+
* window to clear, and a reassignment inside it would stay silent.
|
|
16678
|
+
*/
|
|
16679
|
+
codeByAgent = /* @__PURE__ */ new Map();
|
|
16680
|
+
/** Record that `agentId` is refused as `codeName`, so an id-only teardown can clear it. */
|
|
16681
|
+
remember(agentId, codeName) {
|
|
16682
|
+
if (agentId && codeName) this.codeByAgent.set(agentId, codeName);
|
|
16683
|
+
}
|
|
16684
|
+
/** True when the alert for this agent should be sent (first refusal, or a refresh is due). */
|
|
16685
|
+
shouldSend(codeName, nowMs) {
|
|
16686
|
+
const last = this.lastSent.get(codeName);
|
|
16687
|
+
if (last !== void 0 && nowMs - last < ISOLATION_REFUSAL_ALERT_REFRESH_MS) return false;
|
|
16688
|
+
this.lastSent.set(codeName, nowMs);
|
|
16689
|
+
return true;
|
|
16690
|
+
}
|
|
16691
|
+
/**
|
|
16692
|
+
* The send for this window FAILED: forget it, so the next refusal sends again rather
|
|
16693
|
+
* than waiting out a refresh window for an alert that never arrived.
|
|
16694
|
+
*/
|
|
16695
|
+
release(codeName) {
|
|
16696
|
+
this.lastSent.delete(codeName);
|
|
16697
|
+
}
|
|
16698
|
+
/** The agent spawned (or left the host): stop re-sending, so the alert can close. */
|
|
16699
|
+
clear(codeName) {
|
|
16700
|
+
this.lastSent.delete(codeName);
|
|
16701
|
+
}
|
|
16702
|
+
/** The agent left the host, known only by its id (the realtime unassign path). */
|
|
16703
|
+
clearAgent(agentId) {
|
|
16704
|
+
const codeName = this.codeByAgent.get(agentId);
|
|
16705
|
+
this.codeByAgent.delete(agentId);
|
|
16706
|
+
if (codeName) this.lastSent.delete(codeName);
|
|
16707
|
+
}
|
|
16708
|
+
/** Test seam. */
|
|
16709
|
+
isOpen(codeName) {
|
|
16710
|
+
return this.lastSent.has(codeName);
|
|
16711
|
+
}
|
|
16712
|
+
};
|
|
16713
|
+
async function sendRefusalAlertIfDue(alerts, codeName, nowMs, send2, agentId) {
|
|
16714
|
+
if (agentId) alerts.remember(agentId, codeName);
|
|
16715
|
+
if (!alerts.shouldSend(codeName, nowMs)) return "skipped";
|
|
16716
|
+
let delivered = false;
|
|
16717
|
+
try {
|
|
16718
|
+
delivered = await send2();
|
|
16719
|
+
} catch {
|
|
16720
|
+
delivered = false;
|
|
16721
|
+
}
|
|
16722
|
+
if (!delivered) alerts.release(codeName);
|
|
16723
|
+
return delivered ? "delivered" : "failed";
|
|
16724
|
+
}
|
|
16725
|
+
function isolationRefusalMessage(codeName, hostName, reason) {
|
|
16726
|
+
return `Refused to start agent '${codeName}' on host '${hostName}': AGT_ISOLATION=docker but the Docker runtime is unusable (reason=${reason}). Agents on an isolated host are never started unisolated (ENG-12183). Fix Docker or the agt-runtime image; the manager re-checks every minute and starts the agent once the runtime is usable. Agents already running in containers are unaffected.`;
|
|
16727
|
+
}
|
|
16728
|
+
function startWithIsolationBackstop(start, onRefused) {
|
|
16729
|
+
try {
|
|
16730
|
+
start();
|
|
16731
|
+
return void 0;
|
|
16732
|
+
} catch (err) {
|
|
16733
|
+
const e = err;
|
|
16734
|
+
if (e && e.name === "IsolationUnavailableError" && typeof e.reason === "string") return onRefused(e.reason);
|
|
16735
|
+
throw err;
|
|
16736
|
+
}
|
|
16737
|
+
}
|
|
16738
|
+
|
|
16415
16739
|
// src/lib/heartbeat-diagnostics-code-names.ts
|
|
16416
16740
|
function heartbeatDiagnosticsCodeNames(persistentSessionAgents, spawnOutcomeCodeNames) {
|
|
16417
16741
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -17114,10 +17438,12 @@ async function reportReaperEvent(agentId, reaper, action, reason) {
|
|
|
17114
17438
|
action,
|
|
17115
17439
|
reason
|
|
17116
17440
|
});
|
|
17441
|
+
return true;
|
|
17117
17442
|
} catch (err) {
|
|
17118
17443
|
log(
|
|
17119
17444
|
`[${reaper}] failed to report reaper-event (ENG-6184): ${err.message} \u2014 local reap still proceeded; the alert may be missed`
|
|
17120
17445
|
);
|
|
17446
|
+
return false;
|
|
17121
17447
|
}
|
|
17122
17448
|
}
|
|
17123
17449
|
var dangerousRmBackstop = new DangerousRmBackstop();
|
|
@@ -17126,7 +17452,7 @@ async function runDangerousRmBackstop(agentId, codeName, pane) {
|
|
|
17126
17452
|
try {
|
|
17127
17453
|
action = dangerousRmBackstop.observe(codeName, pane, Date.now());
|
|
17128
17454
|
if (!action || pane === null) return;
|
|
17129
|
-
const host =
|
|
17455
|
+
const host = hostname2();
|
|
17130
17456
|
const scrub = (s) => {
|
|
17131
17457
|
const r = redactPaneFrame(s);
|
|
17132
17458
|
return r.length > 400 ? `${r.slice(0, 399)}\u2026` : r;
|
|
@@ -17863,7 +18189,7 @@ var pendingDayRolloverReset = /* @__PURE__ */ new Set();
|
|
|
17863
18189
|
var dayRolloverInboundHold = /* @__PURE__ */ new Map();
|
|
17864
18190
|
var INBOUND_HOLD_EPISODE_GAP_MS = 12e4;
|
|
17865
18191
|
async function channelInboundActivityAgeSecondsFor(codeName) {
|
|
17866
|
-
const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-
|
|
18192
|
+
const { newestPendingInboundActivityMtimeMs } = await import("../responsiveness-probe-SC72APRB.js");
|
|
17867
18193
|
const newest = newestPendingInboundActivityMtimeMs(dirname11(paneLogPath(codeName)));
|
|
17868
18194
|
if (newest === null) return null;
|
|
17869
18195
|
return Math.max(0, Math.floor((Date.now() - newest) / 1e3));
|
|
@@ -17980,6 +18306,11 @@ async function selfUpdateDiskHold(force) {
|
|
|
17980
18306
|
const room = await ensureDiskForSelfUpdate({ ...deps, force, readStat: () => tightestDiskStat(installPaths) });
|
|
17981
18307
|
return room.ok ? room.release : "failed";
|
|
17982
18308
|
}
|
|
18309
|
+
async function selfUpdateAuthRefreshHold(force) {
|
|
18310
|
+
if (!await hostAuthRefreshHold.heldOrOpensWithin(SELF_UPDATE_AUTH_REFRESH_LEAD_MS)) return null;
|
|
18311
|
+
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]`);
|
|
18312
|
+
return "failed";
|
|
18313
|
+
}
|
|
17983
18314
|
async function selfUpdateDeviceStateHold(force) {
|
|
17984
18315
|
if (!await hostShouldHaveClaudeDeviceState()) return null;
|
|
17985
18316
|
const deviceState = deviceStateRotationGate.mayRotate(SELF_UPDATE_DEVICE_STATE_HOLD_KEY, Date.now());
|
|
@@ -18029,6 +18360,7 @@ function cachedAgentTimezoneFor(codeName) {
|
|
|
18029
18360
|
});
|
|
18030
18361
|
}
|
|
18031
18362
|
function performLazyDayRolloverReset(codeName, agentTimezone) {
|
|
18363
|
+
if (pendingDayRolloverReset.has(codeName) && hostAuthRefreshHold.heldFor(codeName)) return false;
|
|
18032
18364
|
const flagged = pendingDayRolloverReset.has(codeName);
|
|
18033
18365
|
const sessionHealthy = flagged && isSessionHealthy(codeName);
|
|
18034
18366
|
const staleForToday = flagged ? isStaleForToday(codeName, /* @__PURE__ */ new Date(), agentTimezone ?? void 0) : false;
|
|
@@ -18052,7 +18384,7 @@ function performLazyDayRolloverReset(codeName, agentTimezone) {
|
|
|
18052
18384
|
log(
|
|
18053
18385
|
`[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
18386
|
);
|
|
18055
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover");
|
|
18387
|
+
if (!stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover")) return false;
|
|
18056
18388
|
agentState.persistentSessionAgents.delete(codeName);
|
|
18057
18389
|
rotatePaneLogForDayRollover(codeName, log, agentTimezone);
|
|
18058
18390
|
pendingDayRolloverReset.delete(codeName);
|
|
@@ -18079,7 +18411,9 @@ function transcriptAgeSecondsFor(codeName) {
|
|
|
18079
18411
|
return transcriptActivityAgeSeconds(getProjectDir2(codeName), sessionId, /* @__PURE__ */ new Date());
|
|
18080
18412
|
}
|
|
18081
18413
|
var restartGateDeferStreaks = /* @__PURE__ */ new Map();
|
|
18414
|
+
var dashboardRestartsHeldLogged = /* @__PURE__ */ new Set();
|
|
18082
18415
|
function restartGateFor(codeName, reason) {
|
|
18416
|
+
if (reason !== void 0 && hostAuthRefreshHold.heldFor(codeName)) return "defer-auth-refresh";
|
|
18083
18417
|
if (!isGateableRestartReason(reason)) return "bypass";
|
|
18084
18418
|
const tzInputs = agentRestartTimezoneInputs.get(codeName);
|
|
18085
18419
|
const perAgentWindow = cachedMaintenanceWindow ? {
|
|
@@ -18252,6 +18586,7 @@ function readSpawnViewMcpConfig(codeName, projectDir) {
|
|
|
18252
18586
|
}
|
|
18253
18587
|
var sessionsSpawnedByThisProcess = /* @__PURE__ */ new Set();
|
|
18254
18588
|
var spawnCopyFailures = new SpawnCopyFailureTracker();
|
|
18589
|
+
var isolationRefusalAlerts = new IsolationRefusalAlerts();
|
|
18255
18590
|
function reportSpawnCopyFailure(codeName, f) {
|
|
18256
18591
|
const agentId = agentState.codeNameToAgentId.get(codeName);
|
|
18257
18592
|
if (!agentId) return;
|
|
@@ -18699,9 +19034,15 @@ function resolveAgentFramework(codeName) {
|
|
|
18699
19034
|
const frameworkId = agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
|
|
18700
19035
|
return getFramework(frameworkId);
|
|
18701
19036
|
}
|
|
19037
|
+
function handleRealtimeUnassign(agentId) {
|
|
19038
|
+
log(`[realtime] Agent ${agentId} unassigned`);
|
|
19039
|
+
clearAgentCaches(agentId, "");
|
|
19040
|
+
}
|
|
18702
19041
|
function clearAgentCaches(agentId, codeName) {
|
|
18703
19042
|
const channelCacheMutated = clearAgentState(agentId, codeName);
|
|
18704
19043
|
agentChannelTokens.delete(codeName);
|
|
19044
|
+
if (codeName) isolationRefusalAlerts.clear(codeName);
|
|
19045
|
+
isolationRefusalAlerts.clearAgent(agentId);
|
|
18705
19046
|
directChatChainStart.delete(agentId);
|
|
18706
19047
|
agentStatusLedger.forget(agentId);
|
|
18707
19048
|
blockedPromptCost.forget(codeName);
|
|
@@ -18759,7 +19100,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
|
|
|
18759
19100
|
var lastVersionCheckAt = 0;
|
|
18760
19101
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
18761
19102
|
var lastResponsivenessProbeAt = 0;
|
|
18762
|
-
var agtCliVersion = true ? "0.28.
|
|
19103
|
+
var agtCliVersion = true ? "0.28.1308" : "dev";
|
|
18763
19104
|
function resolveBrewPath(execFileSync5) {
|
|
18764
19105
|
try {
|
|
18765
19106
|
const out = execFileSync5("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -19768,6 +20109,11 @@ async function checkAndUpdateCliViaBrew(force = false) {
|
|
|
19768
20109
|
log(`[self-update] agt CLI update available: ${installed} \u2192 ${latest}. Upgrading via brew${force ? " (forced \u2014 Update CLI now)" : ""}...`);
|
|
19769
20110
|
const brewDiskHold = await selfUpdateDiskHold(force);
|
|
19770
20111
|
if (typeof brewDiskHold === "string") return brewDiskHold;
|
|
20112
|
+
const brewAuthRefreshHold = await selfUpdateAuthRefreshHold(force);
|
|
20113
|
+
if (brewAuthRefreshHold) {
|
|
20114
|
+
brewDiskHold();
|
|
20115
|
+
return brewAuthRefreshHold;
|
|
20116
|
+
}
|
|
19771
20117
|
const brewInstallHold = await selfUpdateDeviceStateHold(force);
|
|
19772
20118
|
if (brewInstallHold) {
|
|
19773
20119
|
brewDiskHold();
|
|
@@ -19967,6 +20313,11 @@ async function installAgtCliViaNpm(version, reasonLabel, force = false) {
|
|
|
19967
20313
|
const args = isRoot ? installArgs : ["-n", "npm", ...installArgs];
|
|
19968
20314
|
const npmDiskHold = await selfUpdateDiskHold(force);
|
|
19969
20315
|
if (typeof npmDiskHold === "string") return npmDiskHold;
|
|
20316
|
+
const npmAuthRefreshHold = await selfUpdateAuthRefreshHold(force);
|
|
20317
|
+
if (npmAuthRefreshHold) {
|
|
20318
|
+
npmDiskHold();
|
|
20319
|
+
return npmAuthRefreshHold;
|
|
20320
|
+
}
|
|
19970
20321
|
const npmInstallHold = await selfUpdateDeviceStateHold(force);
|
|
19971
20322
|
if (npmInstallHold) {
|
|
19972
20323
|
npmDiskHold();
|
|
@@ -20885,7 +21236,7 @@ function flushRestartedAgentDiagnostics(hostId, codeNames) {
|
|
|
20885
21236
|
if (codeNames.length === 0) return;
|
|
20886
21237
|
void (async () => {
|
|
20887
21238
|
try {
|
|
20888
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
21239
|
+
const { collectDiagnostics } = await import("../persistent-session-OUCTECWP.js");
|
|
20889
21240
|
await api.post("/host/heartbeat", {
|
|
20890
21241
|
host_id: hostId,
|
|
20891
21242
|
agent_diagnostics: collectDiagnostics(codeNames, quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -20931,16 +21282,18 @@ async function pollCycleInner() {
|
|
|
20931
21282
|
if (restartAfterUpgrade) return;
|
|
20932
21283
|
flushDeliveryBaselineIfDirty();
|
|
20933
21284
|
flushStuckStreaksIfChanged();
|
|
21285
|
+
await hostAuthRefreshHold.isHeld();
|
|
20934
21286
|
try {
|
|
20935
21287
|
await processRestartFlags({
|
|
20936
21288
|
log,
|
|
20937
21289
|
resolveFramework: (codeName) => agentFrameworkCache.get(codeName) ?? null,
|
|
20938
21290
|
stopSession: (codeName, flag) => {
|
|
20939
21291
|
const breakerReason = flag.source === "agent" ? "agent-requested" : "channel-restart-flag";
|
|
20940
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, breakerReason);
|
|
21292
|
+
if (!stopPersistentSessionAndForgetMcpBaseline(codeName, breakerReason)) return false;
|
|
20941
21293
|
agentState.persistentSessionAgents.delete(codeName);
|
|
20942
21294
|
claudeAuthTupleBySession.delete(codeName);
|
|
20943
21295
|
clearSessionPolicyBaseline(codeName);
|
|
21296
|
+
return true;
|
|
20944
21297
|
},
|
|
20945
21298
|
getTelegramTokens: (codeName) => {
|
|
20946
21299
|
const t = agentChannelTokens.get(codeName);
|
|
@@ -21028,7 +21381,7 @@ async function pollCycleInner() {
|
|
|
21028
21381
|
}
|
|
21029
21382
|
try {
|
|
21030
21383
|
const { detectHostSecurity } = await import("../host-security-KQYYZZVW.js");
|
|
21031
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
21384
|
+
const { collectDiagnostics } = await import("../persistent-session-OUCTECWP.js");
|
|
21032
21385
|
const recordedSinceHeartbeat = new Set(spawnOutcomesSinceHeartbeat.drain());
|
|
21033
21386
|
const diagCodeNames = heartbeatDiagnosticsCodeNames(agentState.persistentSessionAgents, recordedSinceHeartbeat);
|
|
21034
21387
|
const heartbeatSpawnOutcomeFor = spawnOutcomeIfRecorded(spawnOutcomeForDiagnostics, recordedSinceHeartbeat);
|
|
@@ -21329,7 +21682,7 @@ async function pollCycleInner() {
|
|
|
21329
21682
|
}
|
|
21330
21683
|
try {
|
|
21331
21684
|
const desiredClaudeCodeVersion = hbResp?.desired_claude_code_version?.trim();
|
|
21332
|
-
const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-
|
|
21685
|
+
const { maybeUpdateClaudeCode, shouldRunClaudeCodeUpdater } = await import("../claude-code-updater-OU4AEM5Y.js");
|
|
21333
21686
|
const securityFloor = currentSecurityFloor();
|
|
21334
21687
|
claudeUpdaterInFlight = true;
|
|
21335
21688
|
if (desiredClaudeCodeVersion && (claudePairLoop.busy || claudePairingInProgress())) {
|
|
@@ -21364,7 +21717,7 @@ async function pollCycleInner() {
|
|
|
21364
21717
|
collectPanelessActivityProbes,
|
|
21365
21718
|
getResponsivenessIntervalMs,
|
|
21366
21719
|
occupancyQualificationClassifications
|
|
21367
|
-
} = await import("../responsiveness-probe-
|
|
21720
|
+
} = await import("../responsiveness-probe-SC72APRB.js");
|
|
21368
21721
|
const probeIntervalMs = getResponsivenessIntervalMs();
|
|
21369
21722
|
if (now - lastResponsivenessProbeAt > probeIntervalMs) {
|
|
21370
21723
|
const probeCodeNames = [...agentState.persistentSessionAgents];
|
|
@@ -21481,7 +21834,7 @@ async function pollCycleInner() {
|
|
|
21481
21834
|
collectResponsivenessProbes,
|
|
21482
21835
|
livePendingInboundOldestAgeSeconds,
|
|
21483
21836
|
parkPendingInbound
|
|
21484
|
-
} = await import("../responsiveness-probe-
|
|
21837
|
+
} = await import("../responsiveness-probe-SC72APRB.js");
|
|
21485
21838
|
const { getProjectDir: wedgeProjectDir } = await import("../scheduler-engine-5PCBGRNY.js");
|
|
21486
21839
|
const wedgeNow = /* @__PURE__ */ new Date();
|
|
21487
21840
|
const liveAgents = agentState.persistentSessionAgents;
|
|
@@ -21553,10 +21906,11 @@ async function pollCycleInner() {
|
|
|
21553
21906
|
}
|
|
21554
21907
|
continue;
|
|
21555
21908
|
}
|
|
21909
|
+
const { execSync: es } = await import("child_process");
|
|
21910
|
+
if (hostAuthRefreshHold.heldFor(codeName)) continue;
|
|
21556
21911
|
try {
|
|
21557
21912
|
const newId = rotateSessionForWedge(codeName);
|
|
21558
21913
|
try {
|
|
21559
|
-
const { execSync: es } = await import("child_process");
|
|
21560
21914
|
es(`tmux kill-session -t ${tmuxSessionTarget(`agt-${codeName}`)} 2>/dev/null`, { stdio: "ignore" });
|
|
21561
21915
|
} catch {
|
|
21562
21916
|
}
|
|
@@ -21745,13 +22099,14 @@ async function pollCycleInner() {
|
|
|
21745
22099
|
}
|
|
21746
22100
|
continue;
|
|
21747
22101
|
}
|
|
22102
|
+
if (hostAuthRefreshHold.heldFor(codeName)) continue;
|
|
21748
22103
|
try {
|
|
21749
22104
|
const newId = rotateSessionForWedge(codeName);
|
|
21750
22105
|
try {
|
|
21751
22106
|
syncExecFile("tmux", ["kill-session", "-t", tmuxSessionTarget(`agt-${codeName}`)], { stdio: "ignore" });
|
|
21752
22107
|
} catch {
|
|
21753
22108
|
}
|
|
21754
|
-
stopPersistentSessionAndForgetMcpBaseline(
|
|
22109
|
+
const paneFatalTornDown = stopPersistentSessionAndForgetMcpBaseline(
|
|
21755
22110
|
codeName,
|
|
21756
22111
|
"pane-fatal-error",
|
|
21757
22112
|
void 0,
|
|
@@ -21767,7 +22122,8 @@ async function pollCycleInner() {
|
|
|
21767
22122
|
}
|
|
21768
22123
|
}
|
|
21769
22124
|
);
|
|
21770
|
-
|
|
22125
|
+
if (!paneFatalTornDown) continue;
|
|
22126
|
+
const { parkPendingInbound } = await import("../responsiveness-probe-SC72APRB.js");
|
|
21771
22127
|
const { parked, deadLettered } = parkPendingInbound(codeName, new Date(fatalNowMs));
|
|
21772
22128
|
paneFatalStreak.delete(codeName);
|
|
21773
22129
|
paneFatalRestarts.set(codeName, [...history, fatalNowMs]);
|
|
@@ -21798,7 +22154,7 @@ async function pollCycleInner() {
|
|
|
21798
22154
|
TRANSCRIPT_MOUNT_ESCALATION_REFRESH_MS,
|
|
21799
22155
|
bindSourceEscalations
|
|
21800
22156
|
} = await import("../transcript-mount-health-OHE6IVJV.js");
|
|
21801
|
-
const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-
|
|
22157
|
+
const { transcriptBindSourcesFor, ensureTranscriptBindSources } = await import("../persistent-session-OUCTECWP.js");
|
|
21802
22158
|
const mountConfig = resolveTranscriptMountConfig();
|
|
21803
22159
|
const liveAgents = agentState.persistentSessionAgents;
|
|
21804
22160
|
for (const tracked of [
|
|
@@ -21928,7 +22284,7 @@ async function pollCycleInner() {
|
|
|
21928
22284
|
continue;
|
|
21929
22285
|
}
|
|
21930
22286
|
try {
|
|
21931
|
-
stopPersistentSessionAndForgetMcpBaseline(
|
|
22287
|
+
const mountTornDown = stopPersistentSessionAndForgetMcpBaseline(
|
|
21932
22288
|
codeName,
|
|
21933
22289
|
"transcript-mount-orphaned",
|
|
21934
22290
|
void 0,
|
|
@@ -21943,6 +22299,7 @@ async function pollCycleInner() {
|
|
|
21943
22299
|
}
|
|
21944
22300
|
}
|
|
21945
22301
|
);
|
|
22302
|
+
if (!mountTornDown) continue;
|
|
21946
22303
|
containerPidCache.delete(codeName);
|
|
21947
22304
|
transcriptMountStreak.delete(codeName);
|
|
21948
22305
|
transcriptMountRestarts.set(codeName, [...history, mountNowMs]);
|
|
@@ -21963,7 +22320,7 @@ async function pollCycleInner() {
|
|
|
21963
22320
|
}
|
|
21964
22321
|
try {
|
|
21965
22322
|
const { scrapeMcpFailedBannerCount } = await import("../pane-mcp-banner-scraper-VR5QGP3J.js");
|
|
21966
|
-
const { probeSessionAuth } = await import("../session-auth-dead-
|
|
22323
|
+
const { probeSessionAuth } = await import("../session-auth-dead-MQR2SLW5.js");
|
|
21967
22324
|
const observations = [];
|
|
21968
22325
|
const pendingCacheCommits = [];
|
|
21969
22326
|
const modelApiErrorReportingOn = hostFlagStore().getBoolean("model-api-error-reporting");
|
|
@@ -22092,6 +22449,15 @@ async function pollCycleInner() {
|
|
|
22092
22449
|
}
|
|
22093
22450
|
}
|
|
22094
22451
|
if (!alreadyServiced) {
|
|
22452
|
+
if (hostAuthRefreshHold.heldFor(agent.code_name)) {
|
|
22453
|
+
const heldKey = `${agent.agent_id}@${requested}`;
|
|
22454
|
+
if (!dashboardRestartsHeldLogged.has(heldKey)) {
|
|
22455
|
+
dashboardRestartsHeldLogged.add(heldKey);
|
|
22456
|
+
log(`[auth-hold] dashboard restart for '${agent.code_name}' held until the Claude login refresh lands, not acked [ENG-12287]`);
|
|
22457
|
+
}
|
|
22458
|
+
continue;
|
|
22459
|
+
}
|
|
22460
|
+
dashboardRestartsHeldLogged.delete(`${agent.agent_id}@${requested}`);
|
|
22095
22461
|
const restartReason = agent.restart_reason ?? null;
|
|
22096
22462
|
log(
|
|
22097
22463
|
`[restart] Dashboard requested restart for '${agent.code_name}' at ${requested} (reason=${restartReason ?? "manual"})`
|
|
@@ -24590,6 +24956,10 @@ async function processAgent(agent, agentStates, managedToolkits) {
|
|
|
24590
24956
|
probe: probeTmuxSession,
|
|
24591
24957
|
stopOpencode: (code) => stopOpencodeSession(code, log),
|
|
24592
24958
|
stopClaudeCode: (code) => {
|
|
24959
|
+
if (hostAuthRefreshHold.heldFor(code)) {
|
|
24960
|
+
log(`[auth-hold] config-change reload restart for '${code}' held until the Claude login refresh lands [ENG-12287]`);
|
|
24961
|
+
return;
|
|
24962
|
+
}
|
|
24593
24963
|
try {
|
|
24594
24964
|
syncExecFile("tmux", ["kill-session", "-t", tmuxSessionTarget(`agt-${code}`)], { stdio: "ignore" });
|
|
24595
24965
|
} catch {
|
|
@@ -25797,6 +26167,7 @@ Retried to the limit after repeated stalls \u2014 needs a look.`).catch(() => {
|
|
|
25797
26167
|
acpSessions: []
|
|
25798
26168
|
});
|
|
25799
26169
|
}
|
|
26170
|
+
setHostPathMigrationDeferral(() => hostAuthRefreshHold.wasHeld());
|
|
25800
26171
|
function respawnConfirmedSince(result, codeName, laneStartedAt) {
|
|
25801
26172
|
if (isConfirmedRespawn(result)) return true;
|
|
25802
26173
|
const state10 = getSessionState(codeName);
|
|
@@ -25966,6 +26337,9 @@ function refreshLiveEgressAllowlist(agent, refreshData, modelPolicy) {
|
|
|
25966
26337
|
}
|
|
25967
26338
|
}
|
|
25968
26339
|
}
|
|
26340
|
+
function openRouterForAgentFrom(raw) {
|
|
26341
|
+
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;
|
|
26342
|
+
}
|
|
25969
26343
|
async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refreshData) {
|
|
25970
26344
|
const codeName = agent.code_name;
|
|
25971
26345
|
if ((agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK) === "claude-code" && !isSessionHealthy(codeName)) {
|
|
@@ -26007,15 +26381,28 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26007
26381
|
}
|
|
26008
26382
|
}
|
|
26009
26383
|
let stragglerGateRan = false;
|
|
26384
|
+
let grantedSingleStart = false;
|
|
26385
|
+
let subscriptionBacked = openRouterForAgentFrom(
|
|
26386
|
+
refreshData.openrouter ?? null
|
|
26387
|
+
) ? false : null;
|
|
26010
26388
|
const runStragglerGate = () => {
|
|
26011
26389
|
stragglerGateRan = true;
|
|
26390
|
+
if (!grantedSingleStart && subscriptionBacked !== false && hostAuthRefreshHold.wasInWindow()) {
|
|
26391
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26392
|
+
}
|
|
26393
|
+
const signalDeps = stragglerSignalDeps(hostAuthRefreshHold.wasHeld(), {
|
|
26394
|
+
killStraggler: killStragglerProcess,
|
|
26395
|
+
killHostStragglers,
|
|
26396
|
+
signalledHostPids,
|
|
26397
|
+
deferStreak: stragglerDeferStreak
|
|
26398
|
+
});
|
|
26012
26399
|
const gate = stragglerSpawnGate(codeName, {
|
|
26013
26400
|
probeProcess: probeSessionProcess,
|
|
26014
26401
|
probeTmux: (c) => probeTmuxSession(`agt-${c}`),
|
|
26015
26402
|
isDocker: (c) => effectiveIsolationMode(c) === "docker",
|
|
26016
|
-
killStraggler:
|
|
26403
|
+
killStraggler: signalDeps.killStraggler,
|
|
26017
26404
|
log,
|
|
26018
|
-
deferStreak:
|
|
26405
|
+
deferStreak: signalDeps.deferStreak,
|
|
26019
26406
|
// Obi Wan 417cd9e6ce9a: under 'reload-confirm', which /host/reaper-event
|
|
26020
26407
|
// accepts (REAPER_EVENT_ALLOWLIST); an unlisted reaper name is a 400 and
|
|
26021
26408
|
// the alert would never open.
|
|
@@ -26026,8 +26413,8 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26026
26413
|
// event (a signal SENT, not a confirmed exit: CodeRabbit on #7365), so
|
|
26027
26414
|
// prod can count them.
|
|
26028
26415
|
scanHostStragglers,
|
|
26029
|
-
killHostStragglers,
|
|
26030
|
-
signalledHostPids,
|
|
26416
|
+
killHostStragglers: signalDeps.killHostStragglers,
|
|
26417
|
+
signalledHostPids: signalDeps.signalledHostPids,
|
|
26031
26418
|
reportHostKill: (_code, root, signal, sent) => void reportReaperEvent(
|
|
26032
26419
|
agent.agent_id,
|
|
26033
26420
|
"reload-confirm",
|
|
@@ -26067,7 +26454,9 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26067
26454
|
})();
|
|
26068
26455
|
const frameworkId = agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
|
|
26069
26456
|
if (frameworkId === "opencode") {
|
|
26070
|
-
|
|
26457
|
+
const opencode = await ensureOpencodeRuntime(agent, refreshData, agentTimezone ?? null);
|
|
26458
|
+
if (opencode.spawnAttempted || opencode.sessionHealthyAfter) hostAuthRefreshHold.noteSubscriptionBacked(codeName, false);
|
|
26459
|
+
return opencode;
|
|
26071
26460
|
}
|
|
26072
26461
|
const channelConfigs = refreshData.channel_configs;
|
|
26073
26462
|
const { devChannels, pluginChannels } = resolveChannelLaunchFlags(
|
|
@@ -26077,12 +26466,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26077
26466
|
const channels = [...pluginChannels];
|
|
26078
26467
|
devChannels.push("server:direct-chat");
|
|
26079
26468
|
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;
|
|
26469
|
+
const openRouterForAgent = openRouterForAgentFrom(openRouterRaw);
|
|
26086
26470
|
const modelPolicy = parseModelPolicy(
|
|
26087
26471
|
refreshData.model_policy
|
|
26088
26472
|
);
|
|
@@ -26156,6 +26540,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26156
26540
|
detail: `${authFailure.reason} (${kind}): ${msg}`
|
|
26157
26541
|
};
|
|
26158
26542
|
}
|
|
26543
|
+
subscriptionBacked = claudeAuthMode === "subscription" && !openRouterForAgent;
|
|
26159
26544
|
if (claudeAuthMode === "openrouter" || openRouterForAgent) {
|
|
26160
26545
|
if (!openRouterForAgent) {
|
|
26161
26546
|
log(
|
|
@@ -26176,6 +26561,17 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26176
26561
|
return notAuthenticatedSkipOutcome();
|
|
26177
26562
|
}
|
|
26178
26563
|
}
|
|
26564
|
+
const healthyBeforeHold = isSessionHealthy(codeName);
|
|
26565
|
+
if (await hostAuthRefreshHold.isHeld({ claimStart: !healthyBeforeHold })) {
|
|
26566
|
+
if (isSessionHealthy(codeName)) refreshLiveEgressAllowlist(agent, refreshData, modelPolicy);
|
|
26567
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26568
|
+
}
|
|
26569
|
+
grantedSingleStart = !healthyBeforeHold && hostAuthRefreshHold.wasHeld();
|
|
26570
|
+
if (grantedSingleStart && probeSessionProcess(codeName) !== "dead") {
|
|
26571
|
+
hostAuthRefreshHold.returnStart();
|
|
26572
|
+
grantedSingleStart = false;
|
|
26573
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26574
|
+
}
|
|
26179
26575
|
} else if (!anthropicApiKey) {
|
|
26180
26576
|
log(`[persistent-session] Skipping '${codeName}' \u2014 api_key mode but no key returned from exchange`);
|
|
26181
26577
|
return {
|
|
@@ -26268,7 +26664,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26268
26664
|
);
|
|
26269
26665
|
} else {
|
|
26270
26666
|
restartNoticeDeliveredFor.delete(codeName);
|
|
26271
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, "auth-tuple-change", void 0, void 0, {
|
|
26667
|
+
const authTupleTornDown = stopPersistentSessionAndForgetMcpBaseline(codeName, "auth-tuple-change", void 0, void 0, {
|
|
26272
26668
|
reason: authTupleDiff.summary,
|
|
26273
26669
|
detail: {
|
|
26274
26670
|
auth_tuple: {
|
|
@@ -26278,6 +26674,7 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26278
26674
|
}
|
|
26279
26675
|
}
|
|
26280
26676
|
});
|
|
26677
|
+
if (!authTupleTornDown) return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26281
26678
|
agentState.persistentSessionAgents.delete(codeName);
|
|
26282
26679
|
restartTrigger = "auth-tuple";
|
|
26283
26680
|
}
|
|
@@ -26316,7 +26713,9 @@ async function ensurePersistentSessionUnchecked(agent, tasks, boardItems, refres
|
|
|
26316
26713
|
log(
|
|
26317
26714
|
`[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
26715
|
);
|
|
26319
|
-
stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover")
|
|
26716
|
+
if (!stopPersistentSessionAndForgetMcpBaseline(codeName, "day-rollover")) {
|
|
26717
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
26718
|
+
}
|
|
26320
26719
|
agentState.persistentSessionAgents.delete(codeName);
|
|
26321
26720
|
pendingDayRolloverReset.delete(codeName);
|
|
26322
26721
|
dayRolloverInboundHold.delete(codeName);
|
|
@@ -26531,6 +26930,25 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash21("sha256")
|
|
|
26531
26930
|
} catch (err) {
|
|
26532
26931
|
log(`[persistent-session] Failed to provision PreCompact hook for '${codeName}': ${err.message}`);
|
|
26533
26932
|
}
|
|
26933
|
+
const isoIntent = isolationMode(codeName);
|
|
26934
|
+
const startReadiness = isoIntent === "docker" ? await dockerStartReadinessAsync() : void 0;
|
|
26935
|
+
const isoRefusal = isolationSpawnRefusal(isoIntent, () => startReadiness ?? { ok: true });
|
|
26936
|
+
if (isoRefusal) {
|
|
26937
|
+
const message = isolationRefusalMessage(codeName, hostname2(), isoRefusal.reason);
|
|
26938
|
+
log(`[persistent-session] Skipping '${codeName}' (ENG-12183) - ${message}`);
|
|
26939
|
+
void sendRefusalAlertIfDue(
|
|
26940
|
+
isolationRefusalAlerts,
|
|
26941
|
+
codeName,
|
|
26942
|
+
Date.now(),
|
|
26943
|
+
() => reportReaperEvent(agent.agent_id, ISOLATION_REFUSAL_REAPER, "blocked", message),
|
|
26944
|
+
agent.agent_id
|
|
26945
|
+
);
|
|
26946
|
+
return {
|
|
26947
|
+
decision: "skipped-isolation-unavailable",
|
|
26948
|
+
spawnAttempted: false,
|
|
26949
|
+
sessionHealthyAfter: isSessionHealthy(codeName)
|
|
26950
|
+
};
|
|
26951
|
+
}
|
|
26534
26952
|
const sessionRunResult = await startRun({
|
|
26535
26953
|
agent_id: agent.agent_id,
|
|
26536
26954
|
source_type: "system",
|
|
@@ -26585,6 +27003,10 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash21("sha256")
|
|
|
26585
27003
|
return deferred;
|
|
26586
27004
|
}
|
|
26587
27005
|
}
|
|
27006
|
+
if (!grantedSingleStart && subscriptionBacked === true && hostAuthRefreshHold.wasInWindow()) {
|
|
27007
|
+
closeSessionRunForCode(codeName, "cancelled", "held: the host Claude login refresh window opened before the spawn (ENG-12287)");
|
|
27008
|
+
return authRefreshHeldOutcome(isSessionHealthy(codeName));
|
|
27009
|
+
}
|
|
26588
27010
|
let spawnCopyFailedNow = false;
|
|
26589
27011
|
const spawnMcpConfigPath = prepareSpawnMcpConfig({
|
|
26590
27012
|
codeName,
|
|
@@ -26604,9 +27026,10 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash21("sha256")
|
|
|
26604
27026
|
}
|
|
26605
27027
|
});
|
|
26606
27028
|
if (!spawnCopyFailedNow) spawnCopyFailures.noteSuccess(codeName);
|
|
26607
|
-
startPersistentSession({
|
|
27029
|
+
const lateRefusal = startWithIsolationBackstop(() => startPersistentSession({
|
|
26608
27030
|
codeName,
|
|
26609
27031
|
agentId: agent.agent_id,
|
|
27032
|
+
isolationReadiness: startReadiness,
|
|
26610
27033
|
projectDir,
|
|
26611
27034
|
mcpConfigPath: spawnMcpConfigPath,
|
|
26612
27035
|
claudeMdPath,
|
|
@@ -26686,10 +27109,29 @@ ${truncateForLog(ctx.tail)}` : `; pane_tail_hash=sha256:${createHash21("sha256")
|
|
|
26686
27109
|
// so the KEYS/VALUES can't diverge from what would have been persisted.
|
|
26687
27110
|
channelSpawnSecrets: shouldInjectChannelSecrets(agent.agent_id) ? collectChannelSpawnSecrets(channelConfigs) : void 0,
|
|
26688
27111
|
log
|
|
27112
|
+
}), (reason) => {
|
|
27113
|
+
closeSessionRunForCode(codeName, "failed", "isolation unavailable at start");
|
|
27114
|
+
const message = isolationRefusalMessage(codeName, hostname2(), reason);
|
|
27115
|
+
log(`[persistent-session] Skipping '${codeName}' (ENG-12183, at start) - ${message}`);
|
|
27116
|
+
void sendRefusalAlertIfDue(
|
|
27117
|
+
isolationRefusalAlerts,
|
|
27118
|
+
codeName,
|
|
27119
|
+
Date.now(),
|
|
27120
|
+
() => reportReaperEvent(agent.agent_id, ISOLATION_REFUSAL_REAPER, "blocked", message),
|
|
27121
|
+
agent.agent_id
|
|
27122
|
+
);
|
|
27123
|
+
return {
|
|
27124
|
+
decision: "skipped-isolation-unavailable",
|
|
27125
|
+
spawnAttempted: false,
|
|
27126
|
+
sessionHealthyAfter: isSessionHealthy(codeName)
|
|
27127
|
+
};
|
|
26689
27128
|
});
|
|
27129
|
+
if (lateRefusal) return lateRefusal;
|
|
27130
|
+
isolationRefusalAlerts.clear(codeName);
|
|
26690
27131
|
agentState.persistentSessionAgents.add(codeName);
|
|
26691
27132
|
claudeAuthTupleBySession.set(codeName, currentAuthTuple);
|
|
26692
27133
|
recordSessionPolicyBaseline(codeName, currentPolicyModel, currentPolicyId);
|
|
27134
|
+
hostAuthRefreshHold.noteSubscriptionBacked(agent.code_name, subscriptionBacked !== false);
|
|
26693
27135
|
denyWebFetchBySession.set(codeName, spawnDenyWebFetch);
|
|
26694
27136
|
persistDeliveryBaselineEntry("webFetch", agent.agent_id, webFetchBaselineValue(spawnDenyWebFetch));
|
|
26695
27137
|
seedSessionLaunchBaselines(codeName, projectDir, spawnMcpConfigPath);
|
|
@@ -27086,6 +27528,10 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27086
27528
|
}
|
|
27087
27529
|
return;
|
|
27088
27530
|
}
|
|
27531
|
+
if (await hostAuthRefreshHold.isHeld() && hostAuthRefreshHold.heldFor(codeName)) {
|
|
27532
|
+
log(`[restart-lane] restart for '${codeName}' held until the Claude login refresh lands; the poll services it after [ENG-12287]`);
|
|
27533
|
+
return;
|
|
27534
|
+
}
|
|
27089
27535
|
if (restartInFlight.has(agentId)) return;
|
|
27090
27536
|
restartInFlight.add(agentId);
|
|
27091
27537
|
let laneStartedAt = Date.now();
|
|
@@ -27095,7 +27541,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27095
27541
|
if (!refreshData) return;
|
|
27096
27542
|
const framework = refreshData.agent?.framework ?? agentFrameworkCache.get(codeName) ?? DEFAULT_FRAMEWORK;
|
|
27097
27543
|
const hostId = await getHostId();
|
|
27098
|
-
const parkForRestart = await import("../responsiveness-probe-
|
|
27544
|
+
const parkForRestart = await import("../responsiveness-probe-SC72APRB.js").then(
|
|
27099
27545
|
(m) => m.parkPendingInbound,
|
|
27100
27546
|
(err) => err
|
|
27101
27547
|
);
|
|
@@ -27119,6 +27565,10 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27119
27565
|
return;
|
|
27120
27566
|
}
|
|
27121
27567
|
}
|
|
27568
|
+
if (hostAuthRefreshHold.heldFor(codeName)) {
|
|
27569
|
+
log(`[restart-lane] restart for '${codeName}' held until the Claude login refresh lands; the poll services it after [ENG-12287]`);
|
|
27570
|
+
return;
|
|
27571
|
+
}
|
|
27122
27572
|
log(`[restart-lane] Fast restart for '${codeName}' at ${requestedAt}`);
|
|
27123
27573
|
const displayName = refreshData.agent?.display_name ?? codeName;
|
|
27124
27574
|
const wedgeStreakAtRestart = consecutiveWedgeCycles.get(codeName) ?? 0;
|
|
@@ -27172,7 +27622,7 @@ async function handleRestartDoorbell(agentId, requestedAt, restartReason) {
|
|
|
27172
27622
|
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
27623
|
void (async () => {
|
|
27174
27624
|
try {
|
|
27175
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
27625
|
+
const { collectDiagnostics } = await import("../persistent-session-OUCTECWP.js");
|
|
27176
27626
|
await api.post("/host/heartbeat", {
|
|
27177
27627
|
host_id: hostId,
|
|
27178
27628
|
agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -27225,7 +27675,7 @@ async function respawnAgentAfterMcpStop(codeName, reason) {
|
|
|
27225
27675
|
}
|
|
27226
27676
|
try {
|
|
27227
27677
|
const hostId = await getHostId();
|
|
27228
|
-
const { collectDiagnostics } = await import("../persistent-session-
|
|
27678
|
+
const { collectDiagnostics } = await import("../persistent-session-OUCTECWP.js");
|
|
27229
27679
|
await api.post("/host/heartbeat", {
|
|
27230
27680
|
host_id: hostId,
|
|
27231
27681
|
agent_diagnostics: collectDiagnostics([codeName], quarantineEntriesFor, claudeMdSizeFor, spawnOutcomeForDiagnostics, pidPressureFor, forwardedToolsFor, runtimeVersionFor, sessionActivityFor)
|
|
@@ -27272,10 +27722,7 @@ function ensureRealtimeAssignStarted(agentStates) {
|
|
|
27272
27722
|
triggerEarlyPoll(`agent ${payload.agent_id} assigned to this host`, payload.agent_id);
|
|
27273
27723
|
markAgentForFreshMemorySync(payload.agent_id);
|
|
27274
27724
|
},
|
|
27275
|
-
onUnassign: (payload) =>
|
|
27276
|
-
log(`[realtime] Agent ${payload.agent_id} unassigned`);
|
|
27277
|
-
clearAgentCaches(payload.agent_id, "");
|
|
27278
|
-
},
|
|
27725
|
+
onUnassign: (payload) => handleRealtimeUnassign(payload.agent_id),
|
|
27279
27726
|
log
|
|
27280
27727
|
});
|
|
27281
27728
|
realtimeAssignStarted = true;
|
|
@@ -28104,7 +28551,7 @@ async function processClaudePairSessions(agents) {
|
|
|
28104
28551
|
snapshotPairConfig,
|
|
28105
28552
|
// ENG-11659: result -> report body + the manager.log line that records it.
|
|
28106
28553
|
planPairStartReport
|
|
28107
|
-
} = await import("../claude-pair-runtime-
|
|
28554
|
+
} = await import("../claude-pair-runtime-H7A7ZOEW.js");
|
|
28108
28555
|
const { resetClaudeSignin, describeSigninResetForLog, describeSigninResetFailure } = await import("../claude-signin-reset-6IJMMVYG.js");
|
|
28109
28556
|
for (const pairId of pendingResp.cancelled_pair_ids ?? []) {
|
|
28110
28557
|
log(`[claude-pair] sweeping orphan tmux session for pair ${pairId.slice(0, 8)}`);
|
|
@@ -29569,6 +30016,7 @@ export {
|
|
|
29569
30016
|
claudeManagedSettingsPath,
|
|
29570
30017
|
claudePairLoopArmed,
|
|
29571
30018
|
claudePairingInProgress,
|
|
30019
|
+
clearAgentCaches,
|
|
29572
30020
|
coverageOf,
|
|
29573
30021
|
createManagedPruneLedger,
|
|
29574
30022
|
createManagedToolkitReader,
|
|
@@ -29585,6 +30033,7 @@ export {
|
|
|
29585
30033
|
forgetChannelSyncState,
|
|
29586
30034
|
forgetRealtimeRebindState,
|
|
29587
30035
|
gateTierTableWithheld,
|
|
30036
|
+
handleRealtimeUnassign,
|
|
29588
30037
|
hasRevokedResiduals,
|
|
29589
30038
|
holdRealtimeRebindInFlight,
|
|
29590
30039
|
inboundHoldMinutes,
|
|
@@ -29592,6 +30041,7 @@ export {
|
|
|
29592
30041
|
integrationRenderPending,
|
|
29593
30042
|
isOlderSemverTuple,
|
|
29594
30043
|
isPrereleaseVersion,
|
|
30044
|
+
isolationRefusalAlerts,
|
|
29595
30045
|
jitteredRealtimeRebindBackoffMs,
|
|
29596
30046
|
managedSettingsOwnership,
|
|
29597
30047
|
markAgentForFreshMemorySync,
|
|
@@ -29600,6 +30050,7 @@ export {
|
|
|
29600
30050
|
maybeUpgradeClaudeCode,
|
|
29601
30051
|
memoryManifestPath,
|
|
29602
30052
|
memoryManifests,
|
|
30053
|
+
openRouterForAgentFrom,
|
|
29603
30054
|
pruneRealtimeRebindState,
|
|
29604
30055
|
readCrossSessionBlockStatus,
|
|
29605
30056
|
realtimeRebindBackoffMs,
|