@oxagen/cli 5.5.1-333 → 5.5.1-337

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.
Files changed (2) hide show
  1. package/oxagen.mjs +84 -16
  2. package/package.json +1 -1
package/oxagen.mjs CHANGED
@@ -34927,7 +34927,7 @@ import { readFileSync as readFileSync13 } from "node:fs";
34927
34927
  import { dirname as dirname14, resolve as resolve3 } from "node:path";
34928
34928
  import { fileURLToPath } from "node:url";
34929
34929
  function readVersion() {
34930
- if (true) return "5.5.1-333";
34930
+ if (true) return "5.5.1-337";
34931
34931
  try {
34932
34932
  const here = dirname14(fileURLToPath(import.meta.url));
34933
34933
  const pkg = JSON.parse(
@@ -49284,6 +49284,8 @@ function createContainedRunner(options) {
49284
49284
  sealed: async (sessionId, exitCode) => {
49285
49285
  ended = true;
49286
49286
  await end(sessionId, { reason: "other", exit_code: exitCode });
49287
+ if (sessionUuid2 !== void 0)
49288
+ await options.settleEnd?.(sessionUuid2);
49287
49289
  }
49288
49290
  });
49289
49291
  return { ...run3, exited: run3.exited.finally(release3) };
@@ -49291,6 +49293,8 @@ function createContainedRunner(options) {
49291
49293
  if (opened && !ended && launchedSessionId !== void 0) {
49292
49294
  try {
49293
49295
  await end(launchedSessionId, { reason: LAUNCH_FAILED_REASON });
49296
+ if (sessionUuid2 !== void 0)
49297
+ await options.settleEnd?.(sessionUuid2);
49294
49298
  } catch (failure5) {
49295
49299
  options.log(
49296
49300
  `sandbox: session ${launchedSessionId} stays open after its launch failed, because ending it failed: ${failure5 instanceof Error ? failure5.message : String(failure5)}`
@@ -72985,22 +72989,23 @@ async function initializeDaemon(options, server, port, ready, clock2) {
72985
72989
  pendingEndsPath,
72986
72990
  JSON.stringify([...pendingSessionEnds])
72987
72991
  );
72992
+ async function settlePendingEnd(ending, sessionUuid2) {
72993
+ await warmTerminalIndexes(sessionUuid2);
72994
+ await queues.host(async () => {
72995
+ if (pendingSessionEnds.get(sessionUuid2) !== ending) return;
72996
+ await recordHookOutcome(ending, sessionUuid2);
72997
+ persistState();
72998
+ pendingSessionEnds.delete(sessionUuid2);
72999
+ persistPendingEnds();
73000
+ });
73001
+ }
72988
73002
  const gitReads = createGitLane({
72989
73003
  registry: registry3,
72990
73004
  execAsync,
72991
73005
  now,
72992
73006
  inSession: (harnessSessionId, task) => queues.session(harnessSessionId, task),
72993
73007
  pendingSessionEnds,
72994
- settleEnding: async (ending, sessionUuid2) => {
72995
- await warmTerminalIndexes(sessionUuid2);
72996
- await queues.host(async () => {
72997
- if (pendingSessionEnds.get(sessionUuid2) !== ending) return;
72998
- await recordHookOutcome(ending, sessionUuid2);
72999
- persistState();
73000
- pendingSessionEnds.delete(sessionUuid2);
73001
- persistPendingEnds();
73002
- });
73003
- },
73008
+ settleEnding: settlePendingEnd,
73004
73009
  record: record2,
73005
73010
  preSessionCopies: paths.preSessionCopies
73006
73011
  });
@@ -74138,6 +74143,7 @@ async function initializeDaemon(options, server, port, ready, clock2) {
74138
74143
  refuseWhenStopping: false
74139
74144
  });
74140
74145
  },
74146
+ settleEnd: (sessionUuid2) => settleSandboxEnd(sessionUuid2),
74141
74147
  record: record2,
74142
74148
  model: modelProxy,
74143
74149
  modelPort: () => modelProxyListener.port(),
@@ -74815,6 +74821,58 @@ async function initializeDaemon(options, server, port, ready, clock2) {
74815
74821
  gitLane = lane;
74816
74822
  return lane;
74817
74823
  }
74824
+ async function settleSandboxEnd(sessionUuid2) {
74825
+ if (stopped2) return;
74826
+ let givenUp = false;
74827
+ const read2 = (async () => {
74828
+ for (let pass2 = 0; pass2 < SANDBOX_END_READ_PASSES && pendingSessionEnds.has(sessionUuid2) && !stopped2 && !givenUp; pass2 += 1) {
74829
+ requestGitRead(sessionUuid2, { force: true, reconcile: true });
74830
+ await startGitReads();
74831
+ }
74832
+ })();
74833
+ await settleWithin(read2, timers.sandboxEndReadMs);
74834
+ givenUp = true;
74835
+ const shipBy = Date.now() + timers.sandboxEndShipMs;
74836
+ const left = () => Math.max(0, shipBy - Date.now());
74837
+ const ending = pendingSessionEnds.get(sessionUuid2);
74838
+ if (ending !== void 0) {
74839
+ log(
74840
+ `sandbox: session ${sessionUuid2} ends without its final worktree read, which did not finish within ${timers.sandboxEndReadMs} ms`
74841
+ );
74842
+ const recorded = settlePendingEnd(ending, sessionUuid2).catch(
74843
+ (error2) => {
74844
+ log(
74845
+ `sandbox: could not record the end of session ${sessionUuid2}: ${error2 instanceof Error ? error2.message : String(error2)}; the control plane closes the run when the sandbox ends`
74846
+ );
74847
+ }
74848
+ );
74849
+ if (!await settleWithin(recorded, left())) {
74850
+ log(
74851
+ `sandbox: recording the end of session ${sessionUuid2} did not finish within its budget; it lands if the process lives long enough, and the control plane closes the run when the sandbox ends`
74852
+ );
74853
+ return;
74854
+ }
74855
+ }
74856
+ let shipGivenUp = false;
74857
+ const ship = (async () => {
74858
+ while (!stopped2 && !shipGivenUp) {
74859
+ await shipper.drain();
74860
+ if (wal.unshipped(1).length === 0) return;
74861
+ await new Promise((resolve29) => {
74862
+ setTimeout(resolve29, SANDBOX_END_SHIP_RETRY_MS).unref();
74863
+ });
74864
+ }
74865
+ })().catch((error2) => {
74866
+ log(
74867
+ `sandbox: shipping the end of session ${sessionUuid2} failed: ${error2 instanceof Error ? error2.message : String(error2)}`
74868
+ );
74869
+ });
74870
+ if (!await settleWithin(ship, left()))
74871
+ log(
74872
+ `sandbox: the end of session ${sessionUuid2} did not ship within its budget; the control plane closes the run when the sandbox ends`
74873
+ );
74874
+ shipGivenUp = true;
74875
+ }
74818
74876
  async function stage(name2, run3) {
74819
74877
  try {
74820
74878
  await run3();
@@ -75348,6 +75406,7 @@ async function initializeDaemon(options, server, port, ready, clock2) {
75348
75406
  * needs to observe the two independently.
75349
75407
  */
75350
75408
  flushGitReads: () => startGitReads(),
75409
+ settleSandboxEnd: (sessionUuid2) => settleSandboxEnd(sessionUuid2),
75351
75410
  drainSpool: () => queues.host(() => drainSpool()),
75352
75411
  queues,
75353
75412
  refreshBundle: () => refreshBundle({ force: true }),
@@ -75421,7 +75480,7 @@ async function initializeDaemon(options, server, port, ready, clock2) {
75421
75480
  }
75422
75481
  };
75423
75482
  }
75424
- var IDLE_COMMAND_POLL_FACTOR, DEFAULT_TIMERS, STATIC_TOKEN_RENEWAL_CHECK_MS, CERTIFICATE_RENEWAL_RETRY_MS, CHATGPT_LOGIN_CHECK_MS, MEMORY_SCAN_MS, CLOUD_GATEWAY_ORIGIN, CLOUD_GATEWAY_BASE_PATH, POOL_ROUTES, QUEUED_PROMPT_CLASS, TRACE_DRAIN_TIMEOUT_MS, RECORDER_EVENTS_KEPT, owedBodyPurgeSchema, objectSchema, spoolFileSchema, otlpResourceListSchema, otlpPayloadSchema, defaultExecAsync, STOPPING, STOPPED_EXEC, STATE_WRITE_DEFER_MS;
75483
+ var IDLE_COMMAND_POLL_FACTOR, DEFAULT_TIMERS, STATIC_TOKEN_RENEWAL_CHECK_MS, SANDBOX_END_READ_PASSES, SANDBOX_END_SHIP_RETRY_MS, CERTIFICATE_RENEWAL_RETRY_MS, CHATGPT_LOGIN_CHECK_MS, MEMORY_SCAN_MS, CLOUD_GATEWAY_ORIGIN, CLOUD_GATEWAY_BASE_PATH, POOL_ROUTES, QUEUED_PROMPT_CLASS, TRACE_DRAIN_TIMEOUT_MS, RECORDER_EVENTS_KEPT, owedBodyPurgeSchema, objectSchema, spoolFileSchema, otlpResourceListSchema, otlpPayloadSchema, defaultExecAsync, STOPPING, STOPPED_EXEC, STATE_WRITE_DEFER_MS;
75425
75484
  var init_daemon = __esm({
75426
75485
  "../../packages/tacho/src/collector/daemon.ts"() {
75427
75486
  "use strict";
@@ -75539,10 +75598,17 @@ var init_daemon = __esm({
75539
75598
  stopLaneMs: 1500,
75540
75599
  stopQueueMs: 1e3,
75541
75600
  stopDrainMs: 1500,
75601
+ // A sandbox bills while its run's end waits, and never starts again, so a
75602
+ // stop left behind is lost. A worktree read of a large clone takes a few
75603
+ // seconds, and one ingest round trip well under one.
75604
+ sandboxEndReadMs: 15e3,
75605
+ sandboxEndShipMs: 1e4,
75542
75606
  hookBundleWaitMs: 2e3,
75543
75607
  memoryStoreWatchMs: MEMORY_STORE_WATCH_MS
75544
75608
  };
75545
75609
  STATIC_TOKEN_RENEWAL_CHECK_MS = 60 * 6e4;
75610
+ SANDBOX_END_READ_PASSES = 4;
75611
+ SANDBOX_END_SHIP_RETRY_MS = 250;
75546
75612
  CERTIFICATE_RENEWAL_RETRY_MS = 15 * 6e4;
75547
75613
  CHATGPT_LOGIN_CHECK_MS = 10 * 6e4;
75548
75614
  MEMORY_SCAN_MS = 5 * 6e4;
@@ -83159,7 +83225,7 @@ var init_package = __esm({
83159
83225
  "package.json"() {
83160
83226
  package_default = {
83161
83227
  name: "@oxagen/cli",
83162
- version: "5.5.1-333",
83228
+ version: "5.5.1-337",
83163
83229
  description: "Oxagen governance CLI: spend, source tracking, grounding, credentials, and audit (agentic coding lives in the stella CLI)",
83164
83230
  type: "module",
83165
83231
  main: "./dist/index.js",
@@ -109057,11 +109123,13 @@ var init_run_list = __esm({
109057
109123
  * What sealed a wrapped session: `agent_stop`, its host's own end,
109058
109124
  * which the host's next `agent_start` on the chain reopens (ADR-172);
109059
109125
  * `idle_timeout`, the control plane closing a run that sent nothing for
109060
- * twelve hours, which the run's next event reopens; or `operator`, a
109061
- * person sealing it through `seal_run` (ADR-169), which is final. Null
109126
+ * twelve hours, which the run's next event reopens; `operator`, a
109127
+ * person locking it through `seal_run` (ADR-169), which is final; or
109128
+ * `sandbox_exit`, the control plane closing a sandbox run whose sandbox
109129
+ * exited before the host's stop arrived (ADR-9460), also final. Null
109062
109130
  * while the run is open.
109063
109131
  */
109064
- sealSource: external_exports.enum(["agent_stop", "idle_timeout", "operator"]).nullable().optional(),
109132
+ sealSource: external_exports.enum(["agent_stop", "idle_timeout", "operator", "sandbox_exit"]).nullable().optional(),
109065
109133
  /**
109066
109134
  * RFC 3339; when the run stopped, by the recorder's own clock: the stop
109067
109135
  * event's timestamp. For a session Oxagen closed for silence (`sealSource: idle_timeout`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxagen/cli",
3
- "version": "5.5.1-333",
3
+ "version": "5.5.1-337",
4
4
  "description": "Oxagen governance CLI: spend, source tracking, grounding, credentials, and audit (agentic coding lives in the stella CLI)",
5
5
  "type": "module",
6
6
  "bin": {