@sagentlab/navarch-runtime 0.1.149 → 0.1.150

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.
@@ -5,6 +5,14 @@ const exit_conditions_cjs_1 = require("./exit-conditions.cjs");
5
5
  const DEFAULT_CAPACITY_COOLDOWN_MS = 15 * 60 * 1000;
6
6
  const RESET_GRACE_MS = 30 * 1000;
7
7
  const MAX_RESET_SEARCH_MINUTES = 48 * 60;
8
+ /**
9
+ * Account capacity wording. Claude Code says "You've hit your session limit"
10
+ * or "You've hit your weekly limit · resets 11am (America/New_York)"; OpenCode
11
+ * and Codex say "usage limit" or "rate limit".
12
+ */
13
+ const CAPACITY_PATTERN = /\b(?:session|usage|rate|weekly|daily|monthly|hourly|5-hour)\s+limit\b|\bhit your (?:[\w.-]+ ){0,3}limit\b|\btoo many requests\b/i;
14
+ /** Claude Code's account-limit lead: "You've hit your weekly limit". */
15
+ const CLAUDE_ACCOUNT_LIMIT = /^you(?:'|’)ve hit your (?:[\w.-]+ ){0,3}limit\b/i;
8
16
  /**
9
17
  * Detects a provider-side capacity response that applies beyond one task
10
18
  * lease. Claude Code reports account session exhaustion as a successful CLI
@@ -14,15 +22,22 @@ const MAX_RESET_SEARCH_MINUTES = 48 * 60;
14
22
  function detectAdapterCapacityLimit(result, nowMs = Date.now()) {
15
23
  const parsed = (0, exit_conditions_cjs_1.parseClaudeJsonResult)(result.stdout) ??
16
24
  (0, exit_conditions_cjs_1.parseClaudeJsonResult)(result.stderr);
17
- if (!result.capacityError && parsed?.api_error_status !== 429)
25
+ // A structured error result is written by the CLI, not the agent. Claude
26
+ // Code does not mark every account limit with a 429 status, so a structured
27
+ // error result with no API status also counts when its text is Claude
28
+ // Code's own "You've hit your … limit". Another explicit status (401, 403)
29
+ // is a different failure.
30
+ const detail = (result.capacityError ?? (typeof parsed?.result === "string" ? parsed.result : "")).trim();
31
+ const structured = parsed?.api_error_status === 429 ||
32
+ (parsed?.is_error === true && parsed.api_error_status == null && CLAUDE_ACCOUNT_LIMIT.test(detail));
33
+ if (!result.capacityError && !structured)
18
34
  return null;
19
- const detail = result.capacityError ?? parsed?.result ?? "";
20
- if (!/\b(?:session|usage|rate)\s+limit\b|\btoo many requests\b/i.test(detail)) {
35
+ if (!CAPACITY_PATTERN.test(detail))
21
36
  return null;
22
- }
23
37
  return {
24
38
  retryAtMs: parseResetTime(detail, nowMs) ??
25
39
  nowMs + DEFAULT_CAPACITY_COOLDOWN_MS,
40
+ detail: detail.length > 300 ? `${detail.slice(0, 299)}…` : detail,
26
41
  };
27
42
  }
28
43
  /**
@@ -10,7 +10,12 @@ const exit_conditions_cjs_1 = require("./exit-conditions.cjs");
10
10
  *
11
11
  * - Claude Code: "Failed to authenticate: OAuth session expired and could not
12
12
  * be refreshed", "OAuth token has expired", "Invalid API key · Please run
13
- * /login", "Not logged in · Please run /login", 401 authentication_error.
13
+ * /login", "Not logged in · Please run /login", 401 authentication_error,
14
+ * and an organization that turned subscription access off: "Your
15
+ * organization has disabled Claude subscription access for Claude Code · Use
16
+ * an Anthropic API key instead, or ask your admin to enable access". No
17
+ * retry on the same machine can fix that either; a person must change the
18
+ * account or the login.
14
19
  * - Codex: "Your access token could not be refreshed because your refresh
15
20
  * token has expired/was already used", "Not logged in", "Please run `codex
16
21
  * login`", token_expired / refresh_token_* error codes.
@@ -25,6 +30,7 @@ const AGENT_AUTH_PATTERNS = [
25
30
  /\brefresh token (?:has expired|was already used|is invalid|expired)\b/i,
26
31
  /\b(?:refresh_token_(?:expired|reused|invalidated)|token_expired)\b/i,
27
32
  /\bauthentication_error\b/i,
33
+ /\bhas disabled claude subscription access\b/i,
28
34
  ];
29
35
  function matchingLine(text) {
30
36
  for (const line of text.split("\n")) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AGENT_MODEL_UNAVAILABLE_PREFIX = exports.AGENT_AUTH_FAILURE_PREFIX = void 0;
3
+ exports.AGENT_MODEL_UNAVAILABLE_PREFIX = exports.AGENT_CAPACITY_FAILURE_PREFIX = exports.AGENT_AUTH_FAILURE_PREFIX = void 0;
4
+ exports.capacityFailureReport = capacityFailureReport;
4
5
  exports.agentAuthFailureReport = agentAuthFailureReport;
5
6
  exports.agentModelUnavailableReport = agentModelUnavailableReport;
6
7
  exports.parseClaudeJsonResult = parseClaudeJsonResult;
@@ -22,6 +23,20 @@ exports.mapExitCondition = mapExitCondition;
22
23
  * `provider.agent_auth`).
23
24
  */
24
25
  exports.AGENT_AUTH_FAILURE_PREFIX = "Coding agent authentication failed";
26
+ /**
27
+ * Leading text of every report for a turn the provider refused because the
28
+ * account is out of capacity (a session, weekly or usage limit). The control
29
+ * plane recognizes it, requeues the task without spending a retry and pauses
30
+ * this machine's claims until the time after "until"
31
+ * (lib/navarch/failure-attribution.ts `provider.agent_capacity`).
32
+ */
33
+ exports.AGENT_CAPACITY_FAILURE_PREFIX = "Session stopped: provider capacity exhausted";
34
+ function capacityFailureReport(detail, retryAtMs) {
35
+ const until = retryAtMs !== undefined && Number.isFinite(retryAtMs)
36
+ ? ` until ${new Date(retryAtMs).toISOString()}`
37
+ : "";
38
+ return `${exports.AGENT_CAPACITY_FAILURE_PREFIX}${until}. ${detail}`;
39
+ }
25
40
  function agentAuthFailureReport(detail) {
26
41
  return `${exports.AGENT_AUTH_FAILURE_PREFIX}: ${detail} ` +
27
42
  "Log the coding agent in again on this machine (`claude /login`, `codex login`, an interactive `agy` session, or open `muse` and run `/login`), then resume the agent.";
@@ -248,7 +263,7 @@ const REVIEW_FIX_MARKER_LINE = /^[ \t]*Review fix delivered: [a-f0-9]{40}(?=\s|$
248
263
  * this package cannot import it. A report without a marker is unchanged.
249
264
  */
250
265
  function leadWithReviewFixMarker(report) {
251
- const marker = REVIEW_FIX_MARKER_LINE.exec(report);
266
+ const marker = REVIEW_FIX_MARKER_LINE.exec(report) ?? /^[ \t]*Review metadata delivered: [a-f0-9]{40} [1-9][0-9]*(?=\s|$)/im.exec(report);
252
267
  if (!marker || !report.slice(0, marker.index).trim())
253
268
  return report;
254
269
  const lineEnd = report.indexOf("\n", marker.index);
@@ -386,7 +401,7 @@ function mapExitCondition(result) {
386
401
  return {
387
402
  leaseOutcome: "failed",
388
403
  exitStatus: "failed",
389
- reportSummary: summarize(`Session stopped: provider capacity exhausted. ${result.capacityError}`) +
404
+ reportSummary: summarize(capacityFailureReport(result.capacityError, result.capacityRetryAtMs)) +
390
405
  (result.checkpointPath ? ` Local recovery checkpoint: ${result.checkpointPath}` : "") +
391
406
  (result.retainedWorktreePath ? ` Recovery worktree retained: ${result.retainedWorktreePath}` : ""),
392
407
  evidenceUrls,
package/dist/session.cjs CHANGED
@@ -1066,6 +1066,14 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
1066
1066
  reportActivity("finishing");
1067
1067
  const capacityLimit = (0, adapter_capacity_cjs_1.detectAdapterCapacityLimit)(turnResult);
1068
1068
  if (capacityLimit) {
1069
+ // Claude Code reports an account limit as a structured result, not as
1070
+ // an adapter capacity error. Name it in the report with the reset
1071
+ // time, so the control plane requeues the task without spending a
1072
+ // retry and pauses this machine until then.
1073
+ turnResult.capacityError ??= capacityLimit.detail;
1074
+ turnResult.capacityRetryAtMs = capacityLimit.retryAtMs;
1075
+ log.warn(`session ${leaseId}: provider capacity exhausted until ` +
1076
+ `${new Date(capacityLimit.retryAtMs).toISOString()}: ${capacityLimit.detail}`);
1069
1077
  await checkpointForRecovery(turnResult);
1070
1078
  sessionOutcome.claimCooldownUntil = Math.max(sessionOutcome.claimCooldownUntil ?? 0, capacityLimit.retryAtMs);
1071
1079
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.149",
3
+ "version": "0.1.150",
4
4
  "description": "Navarch machine-side session manager: claims delivery tasks and runs them through local coding agents.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",