agentxchain 2.155.65 → 2.155.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentxchain",
3
- "version": "2.155.65",
3
+ "version": "2.155.66",
4
4
  "description": "CLI for AgentXchain — governed multi-agent software delivery",
5
5
  "type": "module",
6
6
  "bin": {
@@ -30,7 +30,11 @@ import {
30
30
  } from '../turn-paths.js';
31
31
  import { verifyDispatchManifestForAdapter } from '../dispatch-manifest.js';
32
32
  import { hasMeaningfulStagedResult } from '../staged-result-proof.js';
33
- import { getClaudeSubprocessAuthIssue, isClaudeLocalCliRuntime } from '../claude-local-auth.js';
33
+ import {
34
+ getClaudeSubprocessAuthIssue,
35
+ hasClaudeAuthenticationFailureText,
36
+ isClaudeLocalCliRuntime,
37
+ } from '../claude-local-auth.js';
34
38
 
35
39
  const DIAGNOSTIC_ENV_KEYS = [
36
40
  'PATH',
@@ -43,7 +47,6 @@ const DIAGNOSTIC_ENV_KEYS = [
43
47
  const DIAGNOSTIC_STDERR_EXCERPT_LIMIT = 800;
44
48
  const DEFAULT_STARTUP_WATCHDOG_MS = 180_000;
45
49
  const DEFAULT_STARTUP_WATCHDOG_SIGKILL_GRACE_MS = 10_000;
46
- const CLAUDE_AUTH_FAILURE_RE = /authentication_failed|authentication_error|invalid authentication credentials|unauthorized|API Error:\s*401/i;
47
50
 
48
51
  /**
49
52
  * Launch a local CLI subprocess for a governed turn.
@@ -659,7 +662,7 @@ function appendDiagnostic(logs, label, payload) {
659
662
 
660
663
  function hasClaudeAuthFailureOutput(logs) {
661
664
  if (!Array.isArray(logs)) return false;
662
- return logs.some((line) => typeof line === 'string' && CLAUDE_AUTH_FAILURE_RE.test(line));
665
+ return logs.some((line) => hasClaudeAuthenticationFailureText(line));
663
666
  }
664
667
 
665
668
  function pickDiagnosticEnv(env) {
@@ -10,6 +10,7 @@ const CLAUDE_ENV_AUTH_KEYS = [
10
10
 
11
11
  const DEFAULT_SMOKE_PROBE_TIMEOUT_MS = 10_000;
12
12
  const DEFAULT_SMOKE_PROBE_STDIN = 'ok';
13
+ const CLAUDE_AUTH_FAILURE_RE = /authentication_failed|authentication_error|invalid authentication credentials|unauthorized|API Error:\s*401/i;
13
14
 
14
15
  function normalizeCommandTokens(runtime) {
15
16
  if (Array.isArray(runtime?.command)) {
@@ -32,6 +33,10 @@ export function isClaudeLocalCliRuntime(runtime) {
32
33
  return head === 'claude' || head.endsWith('/claude');
33
34
  }
34
35
 
36
+ export function hasClaudeAuthenticationFailureText(text) {
37
+ return typeof text === 'string' && CLAUDE_AUTH_FAILURE_RE.test(text);
38
+ }
39
+
35
40
  export function hasClaudeBareFlag(runtime) {
36
41
  return normalizeCommandTokens(runtime).includes('--bare');
37
42
  }
@@ -53,6 +53,10 @@ import {
53
53
  formatPhantomIntentSupersessionNotice,
54
54
  } from './intent-startup-migration.js';
55
55
  import { checkpointAcceptedTurn } from './turn-checkpoint.js';
56
+ import {
57
+ hasClaudeAuthenticationFailureText,
58
+ isClaudeLocalCliRuntime,
59
+ } from './claude-local-auth.js';
56
60
 
57
61
  const CONTINUOUS_SESSION_PATH = '.agentxchain/continuous-session.json';
58
62
  const PRODUCTIVE_TIMEOUT_RETRY_MAX_PER_RUN = 1;
@@ -309,6 +313,87 @@ function getBlockedCategory(state) {
309
313
  return state?.blocked_reason?.category || null;
310
314
  }
311
315
 
316
+ const CLAUDE_AUTH_RECOVERY_ACTION =
317
+ 'Refresh Claude credentials before resuming: export a valid ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN, then run agentxchain step --resume.';
318
+
319
+ function findRetainedClaudeAuthEscalation(root, state, config) {
320
+ if (!state || state.status !== 'blocked') return null;
321
+ if (state.blocked_reason?.category !== 'retries_exhausted') return null;
322
+ if (typeof state.blocked_on !== 'string' || !state.blocked_on.startsWith('escalation:retries-exhausted:')) {
323
+ return null;
324
+ }
325
+ const turnId = state.blocked_reason?.turn_id || state.escalation?.from_turn_id || null;
326
+ const activeTurns = state.active_turns || {};
327
+ const candidateIds = turnId && activeTurns[turnId] ? [turnId] : Object.keys(activeTurns);
328
+ for (const candidateId of candidateIds) {
329
+ const turn = activeTurns[candidateId];
330
+ if (!turn || turn.status !== 'failed') continue;
331
+ if (turn.last_rejection?.failed_stage !== 'dispatch') continue;
332
+ const runtime = config?.runtimes?.[turn.runtime_id];
333
+ if (!isClaudeLocalCliRuntime(runtime)) continue;
334
+ const stagingPath = join(root, getTurnStagingResultPath(candidateId));
335
+ if (existsSync(stagingPath)) continue;
336
+ const logPath = join(root, getDispatchLogPath(candidateId));
337
+ if (!existsSync(logPath)) continue;
338
+ let logText = '';
339
+ try {
340
+ logText = readFileSync(logPath, 'utf8');
341
+ } catch {
342
+ continue;
343
+ }
344
+ if (!hasClaudeAuthenticationFailureText(logText)) continue;
345
+ return { turn_id: candidateId, turn, previous_blocked_on: state.blocked_on };
346
+ }
347
+ return null;
348
+ }
349
+
350
+ function maybeReclassifyRetainedClaudeAuthEscalation(context, session, state, log = console.log) {
351
+ const { root, config } = context;
352
+ const candidate = findRetainedClaudeAuthEscalation(root, state, config);
353
+ if (!candidate) return null;
354
+
355
+ const blockedAt = new Date().toISOString();
356
+ const nextState = {
357
+ ...state,
358
+ status: 'blocked',
359
+ blocked_on: 'dispatch:claude_auth_failed',
360
+ blocked_reason: {
361
+ category: 'dispatch_error',
362
+ blocked_at: blockedAt,
363
+ turn_id: candidate.turn_id,
364
+ reclassified_from: {
365
+ blocked_on: state.blocked_on || null,
366
+ category: state.blocked_reason?.category || null,
367
+ },
368
+ recovery: {
369
+ typed_reason: 'dispatch_error',
370
+ owner: 'human',
371
+ recovery_action: CLAUDE_AUTH_RECOVERY_ACTION,
372
+ turn_retained: true,
373
+ detail: `claude_auth_failed: ${CLAUDE_AUTH_RECOVERY_ACTION}`,
374
+ },
375
+ },
376
+ escalation: null,
377
+ };
378
+
379
+ writeGovernedState(root, nextState);
380
+ emitRunEvent(root, 'retained_claude_auth_escalation_reclassified', {
381
+ run_id: nextState.run_id || session.current_run_id || null,
382
+ phase: nextState.phase || null,
383
+ status: 'blocked',
384
+ turn: { turn_id: candidate.turn_id, role_id: candidate.turn.assigned_role || null },
385
+ payload: {
386
+ turn_id: candidate.turn_id,
387
+ previous_blocked_on: candidate.previous_blocked_on,
388
+ blocked_on: nextState.blocked_on,
389
+ runtime_id: candidate.turn.runtime_id || null,
390
+ recovery_action: CLAUDE_AUTH_RECOVERY_ACTION,
391
+ },
392
+ });
393
+ log(`Reclassified retained Claude auth escalation for ${candidate.turn_id} as dispatch:claude_auth_failed.`);
394
+ return nextState;
395
+ }
396
+
312
397
  const RECOVERABLE_ACTIVE_TURN_STATUSES = new Set(['assigned', 'dispatched', 'starting', 'running']);
313
398
 
314
399
  function hasOnlyRecoverableActiveTurns(activeTurns = {}) {
@@ -1714,7 +1799,9 @@ export async function advanceContinuousRunOnce(context, session, contOpts, execu
1714
1799
 
1715
1800
  const startupGovernedState = loadProjectState(root, context.config);
1716
1801
  if (startupGovernedState?.status === 'blocked') {
1717
- const retried = await maybeAutoRetryContinuousBlocker(context, session, contOpts, startupGovernedState, log);
1802
+ const reclassifiedState = maybeReclassifyRetainedClaudeAuthEscalation(context, session, startupGovernedState, log);
1803
+ const effectiveBlockedState = reclassifiedState || startupGovernedState;
1804
+ const retried = await maybeAutoRetryContinuousBlocker(context, session, contOpts, effectiveBlockedState, log);
1718
1805
  if (retried) return retried;
1719
1806
  session.status = 'paused';
1720
1807
  writeContinuousSession(root, session);
@@ -1722,9 +1809,9 @@ export async function advanceContinuousRunOnce(context, session, contOpts, execu
1722
1809
  ok: true,
1723
1810
  status: 'blocked',
1724
1811
  action: 'still_blocked',
1725
- run_id: session.current_run_id || startupGovernedState.run_id || null,
1726
- recovery_action: getBlockedRecoveryAction(startupGovernedState),
1727
- blocked_category: getBlockedCategory(startupGovernedState),
1812
+ run_id: session.current_run_id || effectiveBlockedState.run_id || null,
1813
+ recovery_action: getBlockedRecoveryAction(effectiveBlockedState),
1814
+ blocked_category: getBlockedCategory(effectiveBlockedState),
1728
1815
  };
1729
1816
  }
1730
1817
 
@@ -48,6 +48,7 @@ export const VALID_RUN_EVENTS = [
48
48
  'ghost_retry_exhausted',
49
49
  'auto_retried_productive_timeout',
50
50
  'productive_timeout_retry_exhausted',
51
+ 'retained_claude_auth_escalation_reclassified',
51
52
  'state_reconciled_operator_commits',
52
53
  'operator_commit_reconcile_refused',
53
54
  'charter_materialization_required',