@sagentlab/navarch-runtime 0.1.186 → 0.1.188

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/README.md CHANGED
@@ -631,7 +631,7 @@ unchanged across the deployment.
631
631
  | `NAVARCH_PROJECT_ID` | — | Alternative to `connect --project`. |
632
632
  | `NAVARCH_CONFIG_DIR` | `~/.navarch` | Per-instance state root. Equivalent to `--config-dir`; use a different directory for every agent on the same host. |
633
633
  | `NAVARCH_WORKSPACE_ROOT` | `<config dir>/sandboxes` | Persistent bare repo caches plus isolated per-session worktrees. Sessions that carry a repo-local GitHub token or resume an owner-assigned delivery branch clone their private repository from `repository-seeds/<project>.git`, so only new commits are downloaded. |
634
- | `NAVARCH_MAX_SESSIONS` | `5` | Local concurrent-session capacity cap — see `src/capacity.cts`. |
634
+ | `NAVARCH_MAX_SESSIONS` | `5` | Local concurrent-session capacity cap — see `src/capacity.cts`. Navi conversation turns run outside this cap (at most one extra agent process). |
635
635
  | `NAVARCH_CAPABILITIES` | `shell,browser-use` (`docker-sandbox,shell` in Docker mode) | Comma list reported at heartbeat/claim time. Docker mode does not advertise browser use until the configured image provides it. |
636
636
  | `NAVARCH_BROWSER_PROBE` | on | Advertise `browser-use` only after a startup headless-Chromium launch (host, plus each sandboxed runtime) succeeds. `off` trusts `NAVARCH_CAPABILITIES` without a check. |
637
637
  | `NAVARCH_OWNER_ZONE` | `sagentlab` | `sagentlab` or `customer-<slug>-premises` (project-plan.md §3.11). |
@@ -658,13 +658,13 @@ unchanged across the deployment.
658
658
  | `NAVARCH_CODEX_BIN` | `codex` | Path/name of the Codex CLI binary. |
659
659
  | `NAVARCH_CODEX_EXTRA_ARGS` | — | Comma list of extra CLI args appended after the generated MCP `-c` overrides and `--json` (Codex). |
660
660
  | `NAVARCH_ANTIGRAVITY_BIN` | `agy` | Path/name of the Antigravity CLI binary, version 1.3.1+. |
661
- | `NAVARCH_ANTIGRAVITY_EXTRA_ARGS` | — | Comma list: only `--agent`, `--model`, `--effort`, `--sandbox`, `--dangerously-skip-permissions`; protocol, deadline and resume flags are owned by Navarch. |
661
+ | `NAVARCH_ANTIGRAVITY_EXTRA_ARGS` | — | Comma list: only `--agent`, `--model`, `--effort` (`low` to `max`), `--sandbox`, `--dangerously-skip-permissions`; protocol, deadline and resume flags are owned by Navarch. A `--model` here must match the model the project or task selects, or the session fails. |
662
662
  | `NAVARCH_OPENCODE_BIN` | `opencode` | Path/name of the OpenCode CLI binary. |
663
663
  | `NAVARCH_OPENCODE_EXTRA_ARGS` | — | Comma list of extra CLI args appended after `run`, the prompt, and the generated `--format json` argument. Explicit `--format`, `--model`, or `--variant` values replace the corresponding per-session default. |
664
664
  | `NAVARCH_ACP_BIN` | `dsh` | Path/name of an Agent Client Protocol v1 stdio server. DeepSeek Harness is the default implementation. |
665
665
  | `NAVARCH_ACP_EXTRA_ARGS` | `--profile,acp` | Comma list of arguments used to start the ACP server. Override this together with `NAVARCH_ACP_BIN` for another ACP-compatible coding agent. |
666
666
  | `NAVARCH_QODER_BIN` | `qoder` | Path/name of the Qoder CLI binary. |
667
- | `NAVARCH_QODER_EXTRA_ARGS` | — | Comma list of extra CLI args appended after the unattended defaults (`--setting-sources`, `--permission-mode auto`, `--output-format json`). An explicit `--output-format`, `--permission-mode`, `--settings`, `--model`, or `--reasoning-effort` here replaces the per-session default. Qoder selects its own account models; pin one via `--model` here or `connect --model` to override. |
667
+ | `NAVARCH_QODER_EXTRA_ARGS` | — | Comma list of extra CLI args appended after the unattended defaults (`--setting-sources`, `--permission-mode auto`, `--output-format json`). An explicit `--output-format`, `--permission-mode`, `--settings`, `--model`, or `--reasoning-effort` here replaces the per-session default. Qoder selects its own account models unless the project or a task names one; `--model` here or `connect --model` pins one for this machine. |
668
668
  | `NAVARCH_MUSE_BIN` | `muse` | Path/name of the native Muse Code CLI. Requires authenticated experimental `muse serve` SDK access; the npm SDK does not install the CLI. See [Muse Code setup](../docs/navarch/muse-code.md). |
669
669
  | `NAVARCH_MUSE_EXTRA_ARGS` | — | Comma list of arguments passed to `muse serve`. Permission/sandbox bypass flags are rejected. Configure narrow native approval rules rather than enabling blanket approval. |
670
670
  | `NAVARCH_MCP_CONFIG_PATH` | — | Path to the platform MCP config passed as `--mcp-config`. |
@@ -887,8 +887,8 @@ export NAVARCH_AGENT=opencode
887
887
  export NAVARCH_AGENT=acp
888
888
 
889
889
  # Qoder — requires an authenticated `qoder` CLI (or NAVARCH_QODER_BIN pointing
890
- # at it). Model selection is account-owned; NAVARCH_QODER_EXTRA_ARGS or
891
- # `connect --model` can pin one explicitly.
890
+ # at it). The model comes from the project setting (default: the account's own
891
+ # selection); NAVARCH_QODER_EXTRA_ARGS or `connect --model` pins one here.
892
892
  export NAVARCH_AGENT=qoder
893
893
 
894
894
  # Muse Code (experimental, runtime 0.1.117+) — see the dedicated setup
@@ -927,14 +927,17 @@ profile on every claim. The runtime passes those values as per-session CLI
927
927
  overrides (`codex exec --model ... -c model_reasoning_effort=...`,
928
928
  `claude -p --model ... --effort ...`, `agy --model ...`, or `opencode run
929
929
  --model ... --variant ...`) and records the effective model, profile, and
930
- effort on completion. Antigravity uses the `default` sentinel to preserve the CLI account model;
931
- explicit low/medium/high effort is supported without inventing higher levels. OpenCode accepts any `provider/model`
930
+ effort on completion. Antigravity, Qoder, Muse Code and ACP use the `default` sentinel to keep the
931
+ agent's own model until the project or a task names one; an Antigravity slug carries its effort
932
+ level, so no separate effort is sent, and an ACP model the agent does not advertise fails the
933
+ session before the first prompt. OpenCode accepts any `provider/model`
932
934
  reference (the platform default is `opencode/x-preview-f-free`, Ox Alpha Free
933
935
  (Unlimited) on OpenCode Zen), or `default` to preserve the authenticated
934
- account's selection. ACP sessions use the agent's advertised default model and
935
- set the standard `reasoning_effort` configuration option when it is available.
936
- Muse uses the account-owned `default` model; Navarch adds no Muse project-model
937
- column or public model catalog. Its SDK integration is experimental and has no
936
+ account's selection. ACP sessions select a named model through the agent's
937
+ advertised model option and set the standard `reasoning_effort` configuration
938
+ option when it is available.
939
+ Muse uses the account-owned `default` model unless the project names a
940
+ `modelId`; there is no public model catalog. Its SDK integration is experimental and has no
938
941
  Navi conversation capability. Read [Muse Code setup and limitations](../docs/navarch/muse-code.md)
939
942
  before using private repositories, especially Muse Contributor data settings.
940
943
  Machine-wide extra arguments still configure other CLI behavior; dispatched
@@ -1325,7 +1328,8 @@ repositories without changing the query format.
1325
1328
  machine identity. `start` and `supervise` reuse that model, including after worker
1326
1329
  restarts. Their optional `--model` flag overrides the saved choice. The pin wins
1327
1330
  over the project's session model for the selected adapter only; switching agent
1328
- types does not reuse another adapter's pin. Reconnect without `--model` to return
1331
+ types does not reuse another adapter's pin. A model pinned on the task itself
1332
+ wins over the machine pin (runtime 0.1.187+). Reconnect without `--model` to return
1329
1333
  to project-controlled model selection. Older identities without a model keep
1330
1334
  using the control-plane execution policy.
1331
1335
 
@@ -158,7 +158,10 @@ async function runAcpAdapter(options) {
158
158
  });
159
159
  sessionId = created.sessionId;
160
160
  let configOptions = created.configOptions ?? [];
161
- configOptions = await setConfigOption(context, acp.methods.agent.session.setConfigOption, sessionId, configOptions, "model", options.model === "default" ? undefined : options.model);
161
+ configOptions = await setConfigOption(context, acp.methods.agent.session.setConfigOption, sessionId, configOptions, "model", options.model === "default" ? undefined : options.model,
162
+ // A named model is an explicit selection: running the agent's own
163
+ // default instead would be a silent substitution.
164
+ true);
162
165
  await setConfigOption(context, acp.methods.agent.session.setConfigOption, sessionId, configOptions, "reasoning_effort", options.reasoningEffort);
163
166
  // The probe saw protocol v1; an agent that now answers another version
164
167
  // takes no interrupt, which then waits for the turn boundary.
@@ -266,19 +269,34 @@ function collectUpdate(notification, messages, thoughts, setCostUsd) {
266
269
  setCostUsd(update.cost.amount);
267
270
  }
268
271
  }
269
- async function setConfigOption(context, method, sessionId, options, configId, desired) {
272
+ async function setConfigOption(context, method, sessionId, options, configId, desired,
273
+ /** Fail the session when the agent cannot apply `desired`, instead of keeping its own value. */
274
+ required = false) {
270
275
  if (!desired)
271
276
  return options;
272
277
  const expectedCategory = configId === "model" ? "model" : "thought_level";
273
278
  const option = options.find((candidate) => ((candidate.id === configId || candidate.category === expectedCategory)
274
279
  && candidate.type === "select"));
275
- if (!option || option.type !== "select")
280
+ if (!option || option.type !== "select") {
281
+ if (required) {
282
+ throw new Error(`The ACP agent offers no selectable ${configId}, so the selected ${configId} "${desired}" cannot be applied. `
283
+ + `Set the project's ACP agent model to default, or connect an agent that advertises it.`);
284
+ }
276
285
  return options;
286
+ }
277
287
  const choices = option.options.flatMap((candidate) => "group" in candidate ? candidate.options : [candidate]);
278
288
  const selected = choices.find((candidate) => candidate.value === desired || candidate.name === desired);
279
- if (!selected || selected.value === option.currentValue)
289
+ if (!selected) {
290
+ if (required) {
291
+ const offered = choices.slice(0, 20).map((candidate) => candidate.value).join(", ");
292
+ throw new Error(`The ACP agent does not offer ${configId} "${desired}". It offers: ${offered || "none"}${choices.length > 20 ? ", …" : ""}. `
293
+ + `Select one of these, or set the project's ACP agent model to default.`);
294
+ }
295
+ return options;
296
+ }
297
+ if (selected.value === option.currentValue)
280
298
  return options;
281
- const response = await context.request(method, { sessionId, configId, value: selected.value });
299
+ const response = await context.request(method, { sessionId, configId: option.id, value: selected.value });
282
300
  return response.configOptions ?? options;
283
301
  }
284
302
  async function readMcpServers(configPath, env) {
@@ -16,7 +16,10 @@ const antigravity_mcp_cjs_1 = require("./antigravity-mcp.cjs");
16
16
  const types_cjs_1 = require("./types.cjs");
17
17
  /** Documented agy 1.3.1 contract, not Gemini CLI's similarly named format.
18
18
  * https://antigravity.google/docs/cli/headless/
19
- * https://antigravity.google/docs/changelog (1.1.27, 1.1.28, 1.2.6, 1.2.10)
19
+ * https://antigravity.google/docs/changelog (1.1.27, 1.1.28, 1.2.6, 1.2.10, 1.2.11)
20
+ * `--model` takes a slug from `agy models`; headless mode exits non-zero on an
21
+ * unknown one instead of falling back. `--effort` is low to max "depending on
22
+ * the model", so the CLI, not this adapter, decides which levels a model takes.
20
23
  * One stdin user event + EOF per process; later lease-local turns may resume
21
24
  * only the exact validated AG conversation. No interactive approval protocol.
22
25
  */
@@ -118,13 +121,13 @@ function antigravityArgs(options) {
118
121
  }
119
122
  const model = options.model && options.model !== "default" ? options.model : values.get("--model");
120
123
  if (values.has("--model") && options.model && options.model !== "default" && values.get("--model") !== options.model)
121
- return "Antigravity model arguments conflict with the selected execution model.";
124
+ return `Antigravity model arguments conflict: NAVARCH_ANTIGRAVITY_EXTRA_ARGS names ${values.get("--model")} but the selected execution model is ${options.model}. Remove --model from the extra arguments or select the same model.`;
122
125
  if (model)
123
126
  values.set("--model", model);
124
127
  const effort = options.reasoningEffort ?? values.get("--effort");
125
128
  if (effort) {
126
- if (!["low", "medium", "high"].includes(effort))
127
- return "Antigravity supports low, medium or high reasoning effort only.";
129
+ if (!["low", "medium", "high", "xhigh", "max"].includes(effort))
130
+ return "Antigravity reasoning effort must be low, medium, high, xhigh or max.";
128
131
  if (values.has("--effort") && values.get("--effort") !== effort)
129
132
  return "Antigravity reasoning effort arguments conflict.";
130
133
  values.set("--effort", effort);
@@ -1,19 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.claudeConversationRunner = exports.ClaudeStreamParser = exports.CLAUDE_WORKSPACE_TOOLS = exports.CLAUDE_CONVERSATION_TOOLS = void 0;
3
+ exports.claudeConversationRunner = exports.ClaudeStreamParser = exports.CLAUDE_GIT_HISTORY_TOOLS = exports.CLAUDE_WORKSPACE_TOOLS = exports.CLAUDE_CONVERSATION_TOOLS = void 0;
4
4
  exports.claudeConversationArgs = claudeConversationArgs;
5
5
  exports.runClaudeConversationTurn = runClaudeConversationTurn;
6
+ const git_history_cjs_1 = require("../conversation/git-history.cjs");
6
7
  const conversation_process_cjs_1 = require("./conversation-process.cjs");
7
8
  /**
8
9
  * Read-only tools a Navi repository question may use. Anything not listed
9
- * (Bash, Edit, Write, WebFetch, Task, MCP tools) is absent from the model's
10
- * tool list, so a question cannot itself authorize a code change, PR,
11
- * deployment, or new task. Machine-wide NAVARCH_CLAUDE_EXTRA_ARGS are
10
+ * (Bash, Edit, Write, WebFetch, Task, operator and Navarch task MCP tools) is
11
+ * absent from the model's tool list, so a question cannot itself authorize a
12
+ * code change, PR, deployment, or new task. The one addition is the runtime's
13
+ * own read-only git history server. Machine-wide NAVARCH_CLAUDE_EXTRA_ARGS are
12
14
  * deliberately not applied here: they could add --dangerously-skip-permissions
13
15
  * or --allowedTools and widen this boundary.
14
16
  */
15
17
  exports.CLAUDE_CONVERSATION_TOOLS = "Read,Grep,Glob";
16
18
  exports.CLAUDE_WORKSPACE_TOOLS = "Read,Grep,Glob,Edit,Write,Bash";
19
+ /**
20
+ * The runtime's own git history queries (conversation/git-history.cts), named
21
+ * one by one. `--permission-mode default` refuses every MCP tool that is not
22
+ * listed, and a read-only turn is given no other MCP server.
23
+ */
24
+ exports.CLAUDE_GIT_HISTORY_TOOLS = git_history_cjs_1.GIT_HISTORY_TOOL_NAMES.map((tool) => `mcp__${git_history_cjs_1.GIT_HISTORY_SERVER_NAME}__${tool}`).join(",");
17
25
  /**
18
26
  * Incremental parser for `claude -p --output-format stream-json --verbose
19
27
  * --include-partial-messages`. Chunks may split a record anywhere. Text is
@@ -175,14 +183,19 @@ function claudeConversationArgs(options) {
175
183
  // The server holds the bounded history. A local Claude transcript would
176
184
  // be a second, unbounded private copy of the conversation.
177
185
  "--no-session-persistence",
178
- // No operator hooks, project settings or MCP servers (including the
179
- // lease-scoped Navarch task tools) in a conversation.
186
+ // No operator hooks, project settings or operator MCP servers (including
187
+ // the lease-scoped Navarch task tools) in a conversation. The only server
188
+ // a turn can get is the runtime's read-only git history, added below.
180
189
  "--setting-sources", "",
181
190
  "--strict-mcp-config",
182
191
  "--tools", options.mode === "workspace" ? exports.CLAUDE_WORKSPACE_TOOLS : exports.CLAUDE_CONVERSATION_TOOLS,
183
192
  // Same automatic permission review as host task sessions; never bypass permissions.
184
193
  "--permission-mode", options.mode === "workspace" ? "auto" : "default",
185
194
  ];
195
+ // A workspace turn has Bash and runs git itself.
196
+ if (options.mode !== "workspace" && options.gitHistory?.mcpConfigPath) {
197
+ args.push("--mcp-config", options.gitHistory.mcpConfigPath, "--allowedTools", exports.CLAUDE_GIT_HISTORY_TOOLS);
198
+ }
186
199
  if (options.settingsPath)
187
200
  args.push("--settings", options.settingsPath);
188
201
  if (options.model)
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.codexConversationRunner = exports.CodexConversationParser = void 0;
4
4
  exports.codexConversationArgs = codexConversationArgs;
5
+ const git_history_cjs_1 = require("../conversation/git-history.cjs");
5
6
  const conversation_process_cjs_1 = require("./conversation-process.cjs");
6
7
  /** Codex emits completed assistant messages; reasoning and command output stay local. */
7
8
  class CodexConversationParser {
@@ -69,12 +70,21 @@ function codexConversationArgs(options) {
69
70
  throw new Error("Codex chat requires a native checkout permission profile.");
70
71
  if (options.mode && options.mode !== "read_only" && options.mode !== "workspace")
71
72
  throw new Error("Unknown conversation mode.");
73
+ // One assignment replaces the whole table, so the operator's own MCP servers
74
+ // never reach a conversation. A read-only turn gets only the runtime's git
75
+ // history server: the sandbox has no network, and a blobless checkout cannot
76
+ // answer line-count or blame questions with plain `git`. A workspace turn
77
+ // runs git itself.
78
+ const history = options.mode !== "workspace" ? options.gitHistory : null;
79
+ const mcpServers = history
80
+ ? `{${git_history_cjs_1.GIT_HISTORY_SERVER_NAME}={url=${JSON.stringify(history.url)},bearer_token_env_var=${JSON.stringify(history.bearerTokenEnv)},tool_timeout_sec=300}}`
81
+ : "{}";
72
82
  return [
73
83
  "exec", "-", "--json", "--ephemeral", "--ignore-rules",
74
84
  ...options.codexGuardArgs,
75
85
  "-c", 'approval_policy="never"',
76
86
  "-c", `projects.${JSON.stringify(options.cwd)}.trust_level="untrusted"`,
77
- "-c", 'mcp_servers={}',
87
+ "-c", `mcp_servers=${mcpServers}`,
78
88
  "-c", 'features.multi_agent=false',
79
89
  "-c", 'web_search="disabled"',
80
90
  ...(options.model ? ["--model", options.model] : []),
@@ -20,10 +20,10 @@ function hasFlag(args, flag) {
20
20
  * parseClaudeJsonResult and its result text lands in the ordinary
21
21
  * exit-conditions path.
22
22
  *
23
- * Model selection is account-owned (`qoder --list-models`), so the claim-time
23
+ * The catalog is account-owned (`qoder --list-models`), so the claim-time
24
24
  * `"default"` sentinel (execution-policy.ts / session.cts) is passed through
25
- * as no `--model` flag; an explicit pin from `--model` at enroll or
26
- * NAVARCH_QODER_EXTRA_ARGS still reaches the CLI.
25
+ * as no `--model` flag; a model named by the project, a task pin, `--model` at
26
+ * enroll or NAVARCH_QODER_EXTRA_ARGS reaches the CLI.
27
27
  */
28
28
  async function runQoderAdapter(options) {
29
29
  if (options.signal?.aborted) {
@@ -52,8 +52,21 @@ async function runQoderAdapter(options) {
52
52
  args.push("--output-format", "json");
53
53
  }
54
54
  args.push(...options.extraArgs);
55
- if (options.model && options.model !== "default" && !hasFlag(options.extraArgs, "--model")) {
56
- args.push("--model", options.model);
55
+ if (options.model && options.model !== "default") {
56
+ const model = options.model;
57
+ const modelArgs = options.extraArgs.flatMap((arg, index) => arg === "--model" ? [options.extraArgs[index + 1]]
58
+ : arg.startsWith("--model=") ? [arg.slice("--model=".length)] : []);
59
+ if (modelArgs.some((value) => value !== model)) {
60
+ return {
61
+ exitCode: 1,
62
+ timedOut: false,
63
+ killedByLeaseLoss: false,
64
+ stdout: "",
65
+ stderr: `Qoder model arguments conflict with the selected model ${model}. Remove --model from NAVARCH_QODER_EXTRA_ARGS or select the same model.`,
66
+ };
67
+ }
68
+ if (modelArgs.length === 0)
69
+ args.push("--model", model);
57
70
  }
58
71
  if (options.reasoningEffort && !hasFlag(options.extraArgs, "--reasoning-effort")) {
59
72
  args.push("--reasoning-effort", options.reasoningEffort);
package/dist/capacity.cjs CHANGED
@@ -10,10 +10,15 @@ function computeAvailableCapacity(maxSessions, activeSessions) {
10
10
  * Tracks which session (lease) ids currently occupy a slot on this machine so
11
11
  * the heartbeat loop reports accurate available_capacity and the claim loop
12
12
  * never over-claims beyond NAVARCH_MAX_SESSIONS.
13
+ *
14
+ * Navi conversation turns are tracked outside that cap (`track`): an owner
15
+ * waiting on an answer is never queued behind task sessions, and a chat never
16
+ * takes a slot a task could claim. Drains still wait for them.
13
17
  */
14
18
  class CapacityTracker {
15
19
  maxSessions;
16
20
  active = new Set();
21
+ uncapped = new Set();
17
22
  idleWaiters = new Set();
18
23
  constructor(maxSessions) {
19
24
  this.maxSessions = maxSessions;
@@ -35,17 +40,28 @@ class CapacityTracker {
35
40
  }
36
41
  this.active.add(sessionId);
37
42
  }
43
+ /**
44
+ * Registers work that runs outside the session cap. It neither needs nor
45
+ * takes a slot, but `waitForIdle()` waits for its `release()`.
46
+ */
47
+ track(id) {
48
+ this.uncapped.add(id);
49
+ }
38
50
  release(sessionId) {
39
51
  this.active.delete(sessionId);
40
- if (this.active.size === 0) {
52
+ this.uncapped.delete(sessionId);
53
+ if (this.idle()) {
41
54
  for (const resolve of this.idleWaiters)
42
55
  resolve();
43
56
  this.idleWaiters.clear();
44
57
  }
45
58
  }
46
- /** Resolves once every acquired lease has finished and released its slot. */
59
+ idle() {
60
+ return this.active.size === 0 && this.uncapped.size === 0;
61
+ }
62
+ /** Resolves once every acquired lease and tracked turn has finished and released. */
47
63
  waitForIdle() {
48
- if (this.active.size === 0)
64
+ if (this.idle())
49
65
  return Promise.resolve();
50
66
  return new Promise((resolve) => this.idleWaiters.add(resolve));
51
67
  }
@@ -8,7 +8,6 @@ const index_cjs_1 = require("./adapters/index.cjs");
8
8
  const steering_cjs_1 = require("./steering.cjs");
9
9
  const log = (0, logger_cjs_1.createLogger)("claim");
10
10
  const MAX_CLAIM_BACKOFF_MS = 60_000;
11
- const pendingClaimSlot = "pending-claim-request";
12
11
  /**
13
12
  * Polls dispatch/claim on an interval, gated by available capacity
14
13
  * (implementation-plan.md WP-07 "Claim loop: poll dispatch, receive context
@@ -72,29 +71,18 @@ class ClaimLoop {
72
71
  // the dispatcher records it on the lease and excludes it from review
73
72
  // tasks of PRs this session authors.
74
73
  const sessionId = (0, node_crypto_1.randomUUID)();
75
- // Hold the slot for the duration of the claim request. Navi conversation
76
- // turns also take slots; without this reservation one could take the last
77
- // slot while the control plane is granting a lease, stranding that lease.
78
- const availableCapacity = this.capacity.available();
79
- this.capacity.acquire(pendingClaimSlot);
80
- let claimed;
81
- try {
82
- // The record is the primary adapter's. When the control plane assigns
83
- // another advertised runtime, the session corrects it on its first
84
- // lease heartbeat (session.cts).
85
- const steeringCapabilities = (0, steering_cjs_1.liveSteeringCapabilities)((0, index_cjs_1.selectAdapter)(this.config.agentType), this.config);
86
- claimed = await this.api.claim({
87
- available_capacity: availableCapacity,
88
- capabilities: this.config.capabilities,
89
- agent_type: this.config.agentType,
90
- runtimes: this.config.runtimes,
91
- ...(steeringCapabilities ? { steering_capabilities: steeringCapabilities } : {}),
92
- session_id: sessionId,
93
- });
94
- }
95
- finally {
96
- this.capacity.release(pendingClaimSlot);
97
- }
74
+ // The record is the primary adapter's. When the control plane assigns
75
+ // another advertised runtime, the session corrects it on its first
76
+ // lease heartbeat (session.cts).
77
+ const steeringCapabilities = (0, steering_cjs_1.liveSteeringCapabilities)((0, index_cjs_1.selectAdapter)(this.config.agentType), this.config);
78
+ const claimed = await this.api.claim({
79
+ available_capacity: this.capacity.available(),
80
+ capabilities: this.config.capabilities,
81
+ agent_type: this.config.agentType,
82
+ runtimes: this.config.runtimes,
83
+ ...(steeringCapabilities ? { steering_capabilities: steeringCapabilities } : {}),
84
+ session_id: sessionId,
85
+ });
98
86
  if (this.consecutiveFailures > 0) {
99
87
  log.info(`claim polling recovered after ${this.consecutiveFailures} failed attempt(s)`);
100
88
  }
package/dist/cli.cjs CHANGED
@@ -447,7 +447,8 @@ async function startCommand(flags) {
447
447
  runtimeShutdown.abort();
448
448
  // Mirror warming can outlive its conversation's capacity slot. Wait for
449
449
  // its killed process and private-cache cleanup before exiting too.
450
- void Promise.all([capacity.waitForIdle(), conversationLoop.drain()])
450
+ void Promise.all([claimLoop.drain(), conversationLoop.drain()])
451
+ .then(() => capacity.waitForIdle())
451
452
  .then(() => process.exit(service_cjs_1.CREDENTIALS_REJECTED_EXIT_CODE));
452
453
  }, browserProbe);
453
454
  updateCoordinatorRef.current = new update_coordinator_cjs_1.RuntimeUpdateCoordinator({