@evident-ai/cli 3.6.1-dev.3f69f39 → 3.6.1-dev.40fe1a0

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/index.js CHANGED
@@ -2135,14 +2135,15 @@ function printLink(options, url, reason) {
2135
2135
  printWarning(reason ?? "Open this authorization URL in your browser:");
2136
2136
  console.log(url.href);
2137
2137
  }
2138
- function printResult(options, proxyId, connectionId, error2, successMessage = "MCP connection authorized.") {
2138
+ function printResult(options, proxyId, connectionId, error2, successMessage = "MCP connection authorized.", reason) {
2139
2139
  if (options.json) {
2140
2140
  console.log(
2141
2141
  JSON.stringify({
2142
2142
  ok: !error2,
2143
2143
  proxy_id: proxyId,
2144
2144
  connection_id: connectionId,
2145
- ...error2 ? { error: error2 } : {}
2145
+ ...error2 ? { error: error2 } : {},
2146
+ ...reason ? { reason } : {}
2146
2147
  })
2147
2148
  );
2148
2149
  } else if (error2) {
@@ -2250,6 +2251,7 @@ async function authorizeMcpConnection(proxyId, connectionId, options = {}) {
2250
2251
  let closeFailureLogged = false;
2251
2252
  let failure;
2252
2253
  let successMessage = "MCP connection authorized.";
2254
+ let completionReason;
2253
2255
  const cancelController = new AbortController();
2254
2256
  const closeListener = (force = false) => {
2255
2257
  if (!server || closePromise) return closePromise ?? Promise.resolve();
@@ -2401,6 +2403,7 @@ async function authorizeMcpConnection(proxyId, connectionId, options = {}) {
2401
2403
  );
2402
2404
  if (completion.outcome === "success") {
2403
2405
  if (completion.reason === "tools_pending") {
2406
+ completionReason = completion.reason;
2404
2407
  page.phase = "tools_pending";
2405
2408
  reportProgress(
2406
2409
  options,
@@ -2439,11 +2442,12 @@ async function authorizeMcpConnection(proxyId, connectionId, options = {}) {
2439
2442
  failure ??= "The local callback listener could not be closed cleanly. Check for a lingering process and retry.";
2440
2443
  }
2441
2444
  }
2442
- printResult(options, proxyId, connectionId, failure, successMessage);
2445
+ printResult(options, proxyId, connectionId, failure, successMessage, completionReason);
2443
2446
  if (failure) process.exitCode = cancelController.signal.aborted ? 130 : 1;
2444
2447
  }
2445
2448
 
2446
2449
  // src/commands/run.ts
2450
+ import { randomUUID as randomUUID2 } from "node:crypto";
2447
2451
  import { chmodSync as chmodSync3, existsSync as existsSync3, readFileSync as readFileSync12, writeFileSync as writeFileSync9 } from "node:fs";
2448
2452
  import { homedir as homedir9 } from "node:os";
2449
2453
  import { isAbsolute as isAbsolute6, join as join17, parse, resolve as resolvePath2 } from "node:path";
@@ -2452,7 +2456,7 @@ import ora4 from "ora";
2452
2456
  import { select as select4 } from "@inquirer/prompts";
2453
2457
 
2454
2458
  // src/lib/telemetry.ts
2455
- var CLI_VERSION = (true ? "3.6.1-dev.3f69f39" : void 0) ?? process.env.npm_package_version ?? "unknown";
2459
+ var CLI_VERSION = (true ? "3.6.1-dev.40fe1a0" : void 0) ?? process.env.npm_package_version ?? "unknown";
2456
2460
  function getCliVersion() {
2457
2461
  return CLI_VERSION;
2458
2462
  }
@@ -4295,7 +4299,7 @@ function isRecord3(value) {
4295
4299
  }
4296
4300
  function isWatermark(value) {
4297
4301
  if (!isRecord3(value)) return false;
4298
- return typeof value.fingerprint === "string" && typeof value.uploaded_at === "string" && typeof value.key === "string" && (!("conversation_id" in value) || value.conversation_id === null || typeof value.conversation_id === "string");
4302
+ return typeof value.fingerprint === "string" && typeof value.uploaded_at === "string" && typeof value.key === "string" && (!("conversation_id" in value) || value.conversation_id === null || typeof value.conversation_id === "string") && (!("version_id" in value) || value.version_id === null || typeof value.version_id === "string") && (!("etag" in value) || value.etag === null || typeof value.etag === "string");
4299
4303
  }
4300
4304
  function isMissingFile3(error2) {
4301
4305
  return error2 instanceof Error && "code" in error2 && error2.code === "ENOENT";
@@ -4476,6 +4480,37 @@ function isJson(body) {
4476
4480
  return false;
4477
4481
  }
4478
4482
  }
4483
+ function parseArchivePutMetadata(stderr, onMetadataDecodeError) {
4484
+ const prefix = "ARCHIVE-PUT: outcome=ok ";
4485
+ const lines = stderr.split(/\r?\n/);
4486
+ for (let index = lines.length - 1; index >= 0; index -= 1) {
4487
+ const line = lines[index];
4488
+ if (line === void 0) continue;
4489
+ const prefixIndex = line.indexOf(prefix);
4490
+ if (prefixIndex === -1) continue;
4491
+ const record = line.slice(prefixIndex + prefix.length);
4492
+ const versionMatch = /(?:^|\s)version_id=(\S*)/.exec(record);
4493
+ const etagMatch = /(?:^|\s)etag=(\S*)/.exec(record);
4494
+ const decode = (value, field) => {
4495
+ if (value === void 0 || value === "") return null;
4496
+ try {
4497
+ return decodeURIComponent(value);
4498
+ } catch (error2) {
4499
+ onMetadataDecodeError?.(
4500
+ field,
4501
+ error2 instanceof URIError ? "uri-malformed" : "decode-failed"
4502
+ );
4503
+ return null;
4504
+ }
4505
+ };
4506
+ return {
4507
+ metadataReported: versionMatch !== null || etagMatch !== null,
4508
+ versionId: decode(versionMatch?.[1], "version_id"),
4509
+ etag: decode(etagMatch?.[1], "etag")
4510
+ };
4511
+ }
4512
+ return { metadataReported: false, versionId: null, etag: null };
4513
+ }
4479
4514
  async function uploadSessionArchive(key, body, options) {
4480
4515
  const bytes = Buffer.from(body);
4481
4516
  if (bytes.byteLength > MAX_SESSION_ARCHIVE_BYTES) {
@@ -4498,7 +4533,13 @@ async function uploadSessionArchive(key, body, options) {
4498
4533
  );
4499
4534
  }
4500
4535
  if (result.timedOut) return transportFailure(bytes.byteLength, "timeout");
4501
- if (result.code === 0) return { kind: "ok", bytes: bytes.byteLength };
4536
+ if (result.code === 0) {
4537
+ return {
4538
+ kind: "ok",
4539
+ bytes: bytes.byteLength,
4540
+ ...parseArchivePutMetadata(result.stderr, options.onMetadataDecodeError)
4541
+ };
4542
+ }
4502
4543
  if (result.code === EXIT_ARCHIVE_CONFIG_MISSING) {
4503
4544
  return { kind: "config-missing", bytes: bytes.byteLength };
4504
4545
  }
@@ -4716,6 +4757,14 @@ async function runSessionArchive({
4716
4757
  uploadFailures: 0,
4717
4758
  skippedBudget: 0,
4718
4759
  skippedBudgetIds: [],
4760
+ skippedChanged: 0,
4761
+ skippedChangedSessions: [],
4762
+ skippedUnknown: 0,
4763
+ skippedUnknownIds: [],
4764
+ inventoryNeverArchived: 0,
4765
+ inventoryPriorFailures: 0,
4766
+ inventoryKnownChanged: 0,
4767
+ outcomesReconciled: false,
4719
4768
  neverWatermarkedFailures: 0,
4720
4769
  unmappedIds: [],
4721
4770
  conflictedIds: [],
@@ -4732,6 +4781,8 @@ async function runSessionArchive({
4732
4781
  parent: 0
4733
4782
  },
4734
4783
  archivedSessionIds: [],
4784
+ uploadedSessions: [],
4785
+ unchangedSessions: [],
4735
4786
  failures: [],
4736
4787
  staleSince: null
4737
4788
  };
@@ -4755,17 +4806,44 @@ async function runSessionArchive({
4755
4806
  }
4756
4807
  summary.unresolved = summary.unmappedIds.length + summary.conflictedIds.length;
4757
4808
  summary.conflicts = summary.conflictedIds.length;
4809
+ const priorFailureIds = deps.priorFailureIds ?? /* @__PURE__ */ new Set();
4810
+ const knownChanged = /* @__PURE__ */ new Map();
4811
+ for (const session of sessions) {
4812
+ if (!deps.watermarks.has(session.id)) {
4813
+ knownChanged.set(session.id, "no-prior-archive");
4814
+ summary.inventoryNeverArchived++;
4815
+ } else if (priorFailureIds.has(session.id)) {
4816
+ knownChanged.set(session.id, "prior-attempt-failed");
4817
+ summary.inventoryPriorFailures++;
4818
+ }
4819
+ }
4820
+ summary.inventoryKnownChanged = knownChanged.size;
4758
4821
  const failedWatermarks = [];
4822
+ const priorFailureUploads = [];
4759
4823
  const recordFailedWatermark = (watermark) => {
4760
4824
  if (watermark) failedWatermarks.push(watermark.uploaded_at);
4761
4825
  else summary.neverWatermarkedFailures++;
4762
4826
  };
4827
+ const recordBudgetSkip = (startIndex) => {
4828
+ const skippedIds = ordered.slice(startIndex).map(({ id }) => id);
4829
+ summary.skippedBudgetIds.push(...skippedIds);
4830
+ summary.skippedBudget = summary.skippedBudgetIds.length;
4831
+ for (const sessionId of skippedIds) {
4832
+ const reason = knownChanged.get(sessionId);
4833
+ if (reason) {
4834
+ summary.skippedChangedSessions.push({ sessionId, reason });
4835
+ summary.skippedChanged++;
4836
+ } else {
4837
+ summary.skippedUnknownIds.push(sessionId);
4838
+ summary.skippedUnknown++;
4839
+ }
4840
+ }
4841
+ };
4763
4842
  for (let index = 0; index < ordered.length; index++) {
4764
4843
  const session = ordered[index];
4765
4844
  const remainingMs = Math.floor(deadline - now());
4766
4845
  if (remainingMs <= 0 || deps.signal?.aborted) {
4767
- summary.skippedBudgetIds.push(...ordered.slice(index).map(({ id }) => id));
4768
- summary.skippedBudget = summary.skippedBudgetIds.length;
4846
+ recordBudgetSkip(index);
4769
4847
  break;
4770
4848
  }
4771
4849
  const resolution = resolutions.get(session.id) ?? { reason: "unmapped" };
@@ -4790,8 +4868,7 @@ async function runSessionArchive({
4790
4868
  messages = await exportMessages(deps.client, session.id, exportBudget.signal);
4791
4869
  } catch (error2) {
4792
4870
  if (isBudgetExpired(deadline, now, deps.signal) || exportBudget.signal.aborted) {
4793
- summary.skippedBudgetIds.push(...ordered.slice(index).map(({ id }) => id));
4794
- summary.skippedBudget = summary.skippedBudgetIds.length;
4871
+ recordBudgetSkip(index);
4795
4872
  break;
4796
4873
  }
4797
4874
  summary.failed++;
@@ -4809,8 +4886,7 @@ async function runSessionArchive({
4809
4886
  exportBudget.dispose();
4810
4887
  }
4811
4888
  if (isBudgetExpired(deadline, now, deps.signal) || exportBudget.signal.aborted) {
4812
- summary.skippedBudgetIds.push(...ordered.slice(index).map(({ id }) => id));
4813
- summary.skippedBudget = summary.skippedBudgetIds.length;
4889
+ recordBudgetSkip(index);
4814
4890
  break;
4815
4891
  }
4816
4892
  try {
@@ -4829,12 +4905,21 @@ async function runSessionArchive({
4829
4905
  if (existing?.fingerprint === snapshot.content_fingerprint) {
4830
4906
  summary.unchanged++;
4831
4907
  summary.archivedSessionIds.push(session.id);
4908
+ summary.unchangedSessions.push({
4909
+ sessionId: session.id,
4910
+ fingerprint: snapshot.content_fingerprint,
4911
+ watermarkKey: existing.key,
4912
+ watermarkFingerprint: existing.fingerprint,
4913
+ watermarkVersionId: existing.version_id ?? null,
4914
+ watermarkEtag: existing.etag ?? null,
4915
+ watermarkUploadedAt: existing.uploaded_at
4916
+ });
4832
4917
  continue;
4833
4918
  }
4834
4919
  const uploadRemainingMs = Math.floor(deadline - now());
4835
4920
  if (uploadRemainingMs <= 0 || deps.signal?.aborted) {
4836
- summary.skippedBudgetIds.push(...ordered.slice(index).map(({ id }) => id));
4837
- summary.skippedBudget = summary.skippedBudgetIds.length;
4921
+ knownChanged.set(session.id, "fingerprint-differs");
4922
+ recordBudgetSkip(index);
4838
4923
  break;
4839
4924
  }
4840
4925
  summary.uploadAttempts++;
@@ -4843,7 +4928,8 @@ async function runSessionArchive({
4843
4928
  try {
4844
4929
  outcome = await upload(key, JSON.stringify(snapshot), {
4845
4930
  timeoutMs: Math.min(uploadRemainingMs, SESSION_ARCHIVE_UPLOAD_TIMEOUT_MS),
4846
- signal: uploadBudget.signal
4931
+ signal: uploadBudget.signal,
4932
+ onMetadataDecodeError: (field, reason) => deps.onMetadataDecodeError?.(field, reason, session.id)
4847
4933
  });
4848
4934
  } finally {
4849
4935
  uploadBudget.dispose();
@@ -4866,19 +4952,31 @@ async function runSessionArchive({
4866
4952
  });
4867
4953
  recordFailedWatermark(existing);
4868
4954
  if (uploadBudget.signal.aborted) {
4869
- summary.skippedBudgetIds.push(...ordered.slice(index + 1).map(({ id }) => id));
4870
- summary.skippedBudget = summary.skippedBudgetIds.length;
4955
+ recordBudgetSkip(index + 1);
4871
4956
  break;
4872
4957
  }
4873
4958
  continue;
4874
4959
  }
4875
4960
  summary.uploaded++;
4876
4961
  summary.archivedSessionIds.push(session.id);
4962
+ const uploadRecord = {
4963
+ sessionId: session.id,
4964
+ key,
4965
+ fingerprint: snapshot.content_fingerprint,
4966
+ versionId: outcome.versionId,
4967
+ etag: outcome.etag,
4968
+ metadataReported: outcome.metadataReported,
4969
+ retriedPriorFailure: priorFailureIds.has(session.id)
4970
+ };
4971
+ if (uploadRecord.retriedPriorFailure) priorFailureUploads.push(uploadRecord);
4972
+ else summary.uploadedSessions.push(uploadRecord);
4877
4973
  const watermark = {
4878
4974
  fingerprint: snapshot.content_fingerprint,
4879
4975
  uploaded_at: new Date(now()).toISOString(),
4880
4976
  key,
4881
- conversation_id: conversationId
4977
+ conversation_id: conversationId,
4978
+ version_id: outcome.versionId,
4979
+ etag: outcome.etag
4882
4980
  };
4883
4981
  try {
4884
4982
  writeWatermark(deps.watermarkPath, session.id, watermark, deps.watermarks);
@@ -4892,8 +4990,7 @@ async function runSessionArchive({
4892
4990
  }
4893
4991
  } catch (error2) {
4894
4992
  if (isBudgetExpired(deadline, now, deps.signal)) {
4895
- summary.skippedBudgetIds.push(...ordered.slice(index).map(({ id }) => id));
4896
- summary.skippedBudget = summary.skippedBudgetIds.length;
4993
+ recordBudgetSkip(index);
4897
4994
  break;
4898
4995
  }
4899
4996
  summary.failed++;
@@ -4906,10 +5003,115 @@ async function runSessionArchive({
4906
5003
  recordFailedWatermark(deps.watermarks.get(session.id));
4907
5004
  }
4908
5005
  }
5006
+ summary.uploadedSessions = [...priorFailureUploads, ...summary.uploadedSessions];
5007
+ for (const sessionId of summary.archivedSessionIds) priorFailureIds.delete(sessionId);
5008
+ for (const failure of summary.failures) {
5009
+ if (!failure.archived) priorFailureIds.add(failure.sessionId);
5010
+ }
5011
+ summary.outcomesReconciled = summary.uploaded + summary.unchanged + summary.failed + summary.skippedChanged + summary.skippedUnknown === summary.inspected;
4909
5012
  summary.staleSince = failedWatermarks.sort()[0] ?? null;
4910
5013
  return summary;
4911
5014
  }
4912
5015
 
5016
+ // src/lib/opencode/session-archive-manifest.ts
5017
+ var SESSION_ARCHIVE_MANIFEST_SCHEMA_VERSION = 1;
5018
+ function sessionArchiveManifestKey(keyPrefix, identity) {
5019
+ return `${keyPrefix.replace(/\/+$/, "")}/archive-audit/${identity.bootId}-${String(identity.passSequence).padStart(4, "0")}-${identity.phase}.json`;
5020
+ }
5021
+ function buildSessionArchiveManifest(identity, summary) {
5022
+ const failedSessions = summary?.failures.filter(({ archived }) => !archived) ?? [];
5023
+ const watermarkWriteFailures = new Set(
5024
+ summary?.failures.filter(({ archived }) => archived).map(({ sessionId }) => sessionId)
5025
+ );
5026
+ const sessions = summary ? [
5027
+ ...summary.uploadedSessions.map((upload) => ({
5028
+ id: upload.sessionId,
5029
+ outcome: "uploaded",
5030
+ archive_key: upload.key,
5031
+ fingerprint: upload.fingerprint,
5032
+ version_id: upload.versionId,
5033
+ etag: upload.etag,
5034
+ object_metadata_reported: upload.metadataReported,
5035
+ retried_prior_failure: upload.retriedPriorFailure,
5036
+ ...watermarkWriteFailures.has(upload.sessionId) ? { watermark_write_failed: true } : {}
5037
+ })),
5038
+ ...summary.unchangedSessions.map((unchanged) => ({
5039
+ id: unchanged.sessionId,
5040
+ outcome: "unchanged",
5041
+ fingerprint: unchanged.fingerprint,
5042
+ watermark_fingerprint: unchanged.watermarkFingerprint,
5043
+ watermark_key: unchanged.watermarkKey,
5044
+ watermark_version_id: unchanged.watermarkVersionId,
5045
+ watermark_etag: unchanged.watermarkEtag,
5046
+ watermark_uploaded_at: unchanged.watermarkUploadedAt
5047
+ })),
5048
+ ...failedSessions.map((failure) => ({
5049
+ id: failure.sessionId,
5050
+ outcome: "failed",
5051
+ failure_outcome: failure.outcome,
5052
+ ...failure.reason !== void 0 ? { reason: failure.reason } : {},
5053
+ ...failure.bytes !== void 0 ? { payload_bytes: failure.bytes } : {},
5054
+ ...failure.byteLimit !== void 0 ? { payload_limit_bytes: failure.byteLimit } : {},
5055
+ ...failure.messageCount !== void 0 ? { message_count: failure.messageCount } : {},
5056
+ ...failure.partCount !== void 0 ? { part_count: failure.partCount } : {},
5057
+ ...failure.exitCode !== void 0 ? { exit_code: failure.exitCode } : {}
5058
+ })),
5059
+ ...summary.skippedChangedSessions.map((skipped) => ({
5060
+ id: skipped.sessionId,
5061
+ outcome: "skipped-changed",
5062
+ reason: skipped.reason
5063
+ })),
5064
+ ...summary.skippedUnknownIds.map((sessionId) => ({
5065
+ id: sessionId,
5066
+ outcome: "skipped-unknown"
5067
+ }))
5068
+ ] : [];
5069
+ return {
5070
+ schema_version: SESSION_ARCHIVE_MANIFEST_SCHEMA_VERSION,
5071
+ runner_id: identity.runnerId,
5072
+ boot_id: identity.bootId,
5073
+ pass_sequence: identity.passSequence,
5074
+ phase: identity.phase,
5075
+ started_at: identity.startedAt,
5076
+ completed_at: identity.completedAt,
5077
+ budget_ms: identity.budgetMs,
5078
+ enumeration_complete: identity.enumerationComplete,
5079
+ enumeration_reason: identity.enumerationReason,
5080
+ watermark_file_present: identity.watermarkFilePresent,
5081
+ watermarks_loaded: identity.watermarksLoaded,
5082
+ inspected: summary?.inspected ?? 0,
5083
+ counts: {
5084
+ uploaded: summary?.uploaded ?? 0,
5085
+ unchanged: summary?.unchanged ?? 0,
5086
+ failed: failedSessions.length,
5087
+ skipped_changed: summary?.skippedChanged ?? 0,
5088
+ skipped_unknown: summary?.skippedUnknown ?? 0
5089
+ },
5090
+ outcomes_reconciled: summary?.outcomesReconciled ?? null,
5091
+ inventory_never_archived: summary?.inventoryNeverArchived ?? 0,
5092
+ inventory_prior_failures: summary?.inventoryPriorFailures ?? 0,
5093
+ sessions
5094
+ };
5095
+ }
5096
+ async function uploadSessionArchiveManifest({
5097
+ keyPrefix,
5098
+ identity,
5099
+ summary,
5100
+ timeoutMs,
5101
+ signal,
5102
+ onMetadataDecodeError,
5103
+ upload
5104
+ }) {
5105
+ const key = sessionArchiveManifestKey(keyPrefix, identity);
5106
+ const manifest = buildSessionArchiveManifest(identity, summary);
5107
+ const outcome = await (upload ?? uploadSessionArchive)(key, JSON.stringify(manifest), {
5108
+ timeoutMs,
5109
+ signal,
5110
+ onMetadataDecodeError
5111
+ });
5112
+ return { key, outcome };
5113
+ }
5114
+
4913
5115
  // src/lib/opencode/auth.ts
4914
5116
  function buildOpenCodeBasicAuthHeader(password) {
4915
5117
  return `Basic ${Buffer.from(["opencode", password].join(":")).toString("base64")}`;
@@ -18412,6 +18614,8 @@ var SESSION_CLEANUP_MAX_DELETES_PER_SWEEP = 100;
18412
18614
  var SESSION_CLEANUP_MAX_ISOLATED_DELETE_FAILURES = 2;
18413
18615
  var SESSION_CLEANUP_GIVE_UP_AFTER_FAILURES = 2;
18414
18616
  var MAX_SESSION_DELETE_BODY_LENGTH = 200;
18617
+ var SESSION_ARCHIVE_FAILURE_DIAGNOSTIC_BUDGET = 3;
18618
+ var SESSION_ARCHIVE_MANIFEST_BUDGET_MS = 500;
18415
18619
  function shouldWarnForReclaimSkip(reason) {
18416
18620
  if (reason !== "sqlite-unavailable" && reason !== "disk-exhaustion") return false;
18417
18621
  const version2 = /^v(\d+)\.(\d+)\.(\d+)$/.exec(process.version);
@@ -18435,18 +18639,52 @@ function logSessionArchiveActivity(state, phase, entry) {
18435
18639
  logActivity(state, {
18436
18640
  ...entry,
18437
18641
  source: "cli.session-archive",
18438
- metadata: { ...entry.metadata, phase }
18642
+ // The forwarder drops metadata beyond its 20-entry cap in insertion order.
18643
+ metadata: { phase, ...entry.metadata }
18439
18644
  });
18440
18645
  }
18441
- function logSessionArchiveSummary(state, phase, summary) {
18646
+ function logSessionArchiveMetadataDecodeFailure(state, phase, details) {
18647
+ const subject = details.sessionId ? `session ${details.sessionId}` : "audit manifest";
18648
+ logSessionArchiveActivity(state, phase, {
18649
+ type: "info",
18650
+ level: "warn",
18651
+ message: `Session archive: ${subject} upload returned malformed ${details.field} metadata; the upload succeeded without that value`,
18652
+ metadata: {
18653
+ outcome: "archive-upload-metadata-malformed",
18654
+ metadata_field: details.field,
18655
+ metadata_decode_reason: details.reason,
18656
+ ...details.sessionId ? { session_id: details.sessionId } : {},
18657
+ ...details.manifestKey ? { manifest_key: details.manifestKey } : {}
18658
+ }
18659
+ });
18660
+ }
18661
+ function logSessionArchiveSummary(state, phase, summary, reconciliation) {
18442
18662
  const everyUploadFailed = summary.uploadAttempts > 0 && summary.uploadFailures === summary.uploadAttempts;
18443
- const staleSince = everyUploadFailed && summary.staleSince !== null ? `; archive stale since ${summary.staleSince}` : "";
18444
18663
  const neverWatermarked = summary.neverWatermarkedFailures > 0 ? `; ${summary.neverWatermarkedFailures} failed session(s) had no prior successful upload` : "";
18445
18664
  const warning2 = summary.failed > 0 || summary.failures.length > 0 || everyUploadFailed || !summary.reconciliationComplete;
18665
+ if (!reconciliation.complete) {
18666
+ const failure = reconciliation.failures[0];
18667
+ const detail = failure.kind === "http" ? `HTTP ${failure.status} for chunk ${failure.chunk}` : failure.kind === "network" ? `network failure for chunk ${failure.chunk}: ${redactDiagnosticText(failure.message ?? "unknown error").slice(0, 200)}` : `invalid response for chunk ${failure.chunk}`;
18668
+ logSessionArchiveActivity(state, phase, {
18669
+ type: "info",
18670
+ level: "warn",
18671
+ message: `Session archive: binding reconciliation incomplete for runner ${state.agentId}; ${reconciliation.failures.length} chunk(s) failed (${detail}), unresolved sessions will not replace existing archives`,
18672
+ metadata: {
18673
+ outcome: "binding-reconciliation-incomplete",
18674
+ runner_id: state.agentId,
18675
+ failed_chunks: reconciliation.failures.length,
18676
+ first_failed_chunk: failure.chunk,
18677
+ first_failure_kind: failure.kind,
18678
+ ...failure.status !== void 0 ? { http_status: failure.status } : {}
18679
+ }
18680
+ });
18681
+ }
18446
18682
  logSessionArchiveActivity(state, phase, {
18447
18683
  type: "info",
18448
18684
  level: warning2 ? "warn" : "info",
18449
- message: `Session archive: inspected ${summary.inspected}, uploaded ${summary.uploaded}, unchanged ${summary.unchanged}, failed ${summary.failed}, skipped budget ${summary.skippedBudget}, unmapped ${summary.unmappedIds.length}, conflicts ${summary.conflicts}, reconciliation incomplete ${summary.reconciliationIncomplete}; bindings ledger ${summary.bindingSourceCounts.ledger}, watermark ${summary.bindingSourceCounts.watermark}, current ${summary.bindingSourceCounts.current}, invocation ${summary.bindingSourceCounts.invocation}, history ${summary.bindingSourceCounts.history}, parent ${summary.bindingSourceCounts.parent}` + staleSince + neverWatermarked,
18685
+ message: `Session archive: inspected ${summary.inspected}, uploaded ${summary.uploaded}, unchanged ${summary.unchanged}, failed ${summary.failed}, skipped budget ${summary.skippedBudget}, unmapped ${summary.unmappedIds.length}, conflicts ${summary.conflicts}, reconciliation incomplete ${summary.reconciliationIncomplete}; bindings ledger ${summary.bindingSourceCounts.ledger}, watermark ${summary.bindingSourceCounts.watermark}, current ${summary.bindingSourceCounts.current}, invocation ${summary.bindingSourceCounts.invocation}, history ${summary.bindingSourceCounts.history}, parent ${summary.bindingSourceCounts.parent}` + neverWatermarked,
18686
+ // Keep this summary at the forwarder's 20-entry metadata cap; phase is
18687
+ // prepended by logSessionArchiveActivity.
18450
18688
  metadata: {
18451
18689
  outcome: "archive-run-complete",
18452
18690
  sessions_inspected: summary.inspected,
@@ -18457,7 +18695,6 @@ function logSessionArchiveSummary(state, phase, summary) {
18457
18695
  uploads_failed: summary.uploadFailures,
18458
18696
  sessions_skipped_budget: summary.skippedBudget,
18459
18697
  sessions_unmapped: summary.unmappedIds.length,
18460
- sessions_unresolved: summary.unresolved,
18461
18698
  sessions_conflicted: summary.conflicts,
18462
18699
  sessions_reconciliation_incomplete: summary.reconciliationIncomplete,
18463
18700
  binding_reconciliation_complete: summary.reconciliationComplete,
@@ -18467,11 +18704,10 @@ function logSessionArchiveSummary(state, phase, summary) {
18467
18704
  bindings_from_invocation: summary.bindingSourceCounts.invocation,
18468
18705
  bindings_from_history: summary.bindingSourceCounts.history,
18469
18706
  bindings_from_parent: summary.bindingSourceCounts.parent,
18470
- sessions_without_prior_watermark: summary.neverWatermarkedFailures,
18471
- ...everyUploadFailed && summary.staleSince !== null ? { stale_since: summary.staleSince } : {}
18707
+ sessions_without_prior_watermark: summary.neverWatermarkedFailures
18472
18708
  }
18473
18709
  });
18474
- for (const failure of summary.failures) {
18710
+ const logFailure = (failure) => {
18475
18711
  const permanentSizeFailure = failure.reason === "too-large";
18476
18712
  const hasPayloadDetails = failure.bytes !== void 0 && failure.byteLimit !== void 0 && failure.messageCount !== void 0 && failure.partCount !== void 0;
18477
18713
  const payloadDetails = hasPayloadDetails ? `; payload bytes=${failure.bytes} limit=${failure.byteLimit} messages=${failure.messageCount} parts=${failure.partCount}` : "";
@@ -18494,7 +18730,9 @@ function logSessionArchiveSummary(state, phase, summary) {
18494
18730
  } : {}
18495
18731
  }
18496
18732
  });
18497
- }
18733
+ };
18734
+ const failuresToLog = phase === "sweep" ? summary.failures : summary.failures.slice(0, SESSION_ARCHIVE_FAILURE_DIAGNOSTIC_BUDGET);
18735
+ for (const failure of failuresToLog) logFailure(failure);
18498
18736
  if (summary.unmappedIds.length > 0) {
18499
18737
  logSessionArchiveActivity(state, phase, {
18500
18738
  type: "info",
@@ -18518,6 +18756,117 @@ function logSessionArchiveSummary(state, phase, summary) {
18518
18756
  });
18519
18757
  }
18520
18758
  }
18759
+ function hasSessionArchivePrerequisites(state) {
18760
+ return Boolean(
18761
+ state.opencodeClient && state.sessionArchiveConfig.keyPrefix && state.sessionArchiveWatermarkPath && state.agentId
18762
+ );
18763
+ }
18764
+ async function publishSessionArchiveAudit(state, phase, identity, summary, manifestWindowMs, manifestSignal, parentSignal) {
18765
+ if (!hasSessionArchivePrerequisites(state)) return;
18766
+ const manifestKey = sessionArchiveManifestKey(state.sessionArchiveConfig.keyPrefix, identity);
18767
+ let manifestDurable = false;
18768
+ let manifestVersionId = null;
18769
+ let failure = null;
18770
+ if (parentSignal.aborted) {
18771
+ failure = { kind: "not-attempted", reason: "pass-aborted" };
18772
+ } else if (manifestWindowMs <= 0) {
18773
+ failure = { kind: "not-attempted", reason: "no-manifest-budget" };
18774
+ } else {
18775
+ try {
18776
+ const result = await uploadSessionArchiveManifest({
18777
+ keyPrefix: state.sessionArchiveConfig.keyPrefix,
18778
+ identity,
18779
+ summary,
18780
+ timeoutMs: manifestWindowMs,
18781
+ signal: manifestSignal,
18782
+ upload: uploadSessionArchive,
18783
+ onMetadataDecodeError: (field, reason) => logSessionArchiveMetadataDecodeFailure(state, phase, {
18784
+ field,
18785
+ reason,
18786
+ manifestKey
18787
+ })
18788
+ });
18789
+ if (result.outcome.kind === "ok") {
18790
+ manifestDurable = true;
18791
+ manifestVersionId = result.outcome.versionId;
18792
+ } else {
18793
+ failure = {
18794
+ kind: result.outcome.kind,
18795
+ ..."reason" in result.outcome ? { reason: result.outcome.reason } : {},
18796
+ ..."exitCode" in result.outcome && result.outcome.exitCode !== void 0 ? { exitCode: result.outcome.exitCode } : {}
18797
+ };
18798
+ }
18799
+ } catch (error2) {
18800
+ const diagnostic = redactDiagnosticText(
18801
+ error2 instanceof Error ? error2.message : String(error2)
18802
+ ).replace(/[\r\n]+/g, " ").slice(0, 200);
18803
+ logSessionArchiveActivity(state, phase, {
18804
+ type: "info",
18805
+ level: "warn",
18806
+ message: `Session archive audit manifest upload threw for boot ${identity.bootId}, pass ${identity.passSequence}, phase ${phase}: ${diagnostic}`,
18807
+ metadata: {
18808
+ outcome: "archive-audit-manifest-upload-threw",
18809
+ boot_id: identity.bootId,
18810
+ pass_sequence: identity.passSequence
18811
+ }
18812
+ });
18813
+ failure = { kind: "thrown", reason: "upload-threw" };
18814
+ }
18815
+ }
18816
+ if (failure !== null) {
18817
+ logSessionArchiveActivity(state, phase, {
18818
+ type: "info",
18819
+ level: "warn",
18820
+ message: `Session archive audit manifest was not durable for ${phase} pass ${identity.passSequence}: ${failure.kind}${failure.reason ? ` (${failure.reason})` : ""}`,
18821
+ metadata: {
18822
+ outcome: "archive-audit-manifest-failed",
18823
+ boot_id: identity.bootId,
18824
+ pass_sequence: identity.passSequence,
18825
+ manifest_key: manifestKey,
18826
+ kind: failure.kind,
18827
+ ...failure.reason !== void 0 ? { reason: failure.reason } : {},
18828
+ ...failure.exitCode !== void 0 ? { exit_code: failure.exitCode } : {}
18829
+ }
18830
+ });
18831
+ }
18832
+ const sessionsInspected = summary?.inspected ?? 0;
18833
+ const sessionsUploaded = summary?.uploaded ?? 0;
18834
+ const sessionsUnchanged = summary?.unchanged ?? 0;
18835
+ const sessionsFailed = summary?.failed ?? 0;
18836
+ const sessionsSkippedChanged = summary?.skippedChanged ?? 0;
18837
+ const sessionsSkippedUnknown = summary?.skippedUnknown ?? 0;
18838
+ const outcomesReconciled = summary?.outcomesReconciled ?? null;
18839
+ const retries = summary?.uploadedSessions.filter(({ retriedPriorFailure }) => retriedPriorFailure).length ?? 0;
18840
+ const everyUploadFailed = summary !== null && summary.uploadAttempts > 0 && summary.uploadFailures === summary.uploadAttempts;
18841
+ const level = summary === null || !summary.outcomesReconciled || summary.skippedChanged > 0 ? "warn" : "info";
18842
+ const message = summary === null ? `Session archive audit: ${phase} pass could not enumerate the session store (${identity.enumerationReason ?? "unknown"}); no session was inspected` : `Session archive audit: inspected ${sessionsInspected}, uploaded ${sessionsUploaded}, unchanged ${sessionsUnchanged}, failed ${sessionsFailed}, skipped known changed ${sessionsSkippedChanged}, skipped unknown ${sessionsSkippedUnknown}; outcomes reconciled ${outcomesReconciled ? "yes" : "no"}; manifest ${manifestKey}`;
18843
+ logSessionArchiveActivity(state, phase, {
18844
+ type: "info",
18845
+ level,
18846
+ message,
18847
+ metadata: {
18848
+ outcome: "archive-outcome-audit",
18849
+ boot_id: identity.bootId,
18850
+ pass_sequence: identity.passSequence,
18851
+ enumeration_complete: identity.enumerationComplete,
18852
+ sessions_inspected: sessionsInspected,
18853
+ sessions_uploaded: sessionsUploaded,
18854
+ sessions_unchanged: sessionsUnchanged,
18855
+ sessions_failed: sessionsFailed,
18856
+ sessions_skipped_changed: sessionsSkippedChanged,
18857
+ sessions_skipped_unknown: sessionsSkippedUnknown,
18858
+ outcomes_reconciled: outcomesReconciled,
18859
+ manifest_durable: manifestDurable,
18860
+ manifest_key: manifestKey,
18861
+ manifest_version_id: manifestVersionId,
18862
+ watermark_file_present: identity.watermarkFilePresent,
18863
+ watermarks_loaded: identity.watermarksLoaded,
18864
+ uploads_retrying_prior_failures: retries,
18865
+ ...summary === null ? { enumeration_reason: identity.enumerationReason ?? "unknown" } : {},
18866
+ ...everyUploadFailed && summary?.staleSince !== null ? { stale_since: summary.staleSince } : {}
18867
+ }
18868
+ });
18869
+ }
18521
18870
  async function drainSessionDeletionReports(state) {
18522
18871
  const path = sessionDeletionReportPath(homedir9(), process.env);
18523
18872
  let delivered = 0;
@@ -18935,14 +19284,10 @@ function runSessionArchiveTask(state, phase, budgetMs, work) {
18935
19284
  }
18936
19285
  const controller = new AbortController();
18937
19286
  state.sessionArchiveAbortController = controller;
19287
+ let budgetExceeded = false;
18938
19288
  const timeout = setTimeout(() => {
19289
+ budgetExceeded = true;
18939
19290
  controller.abort();
18940
- logSessionArchiveActivity(state, phase, {
18941
- type: "info",
18942
- level: "warn",
18943
- message: `Session archive exceeded ${budgetMs}ms; remaining sessions were not confirmed archived`,
18944
- metadata: { outcome: "archive-budget-exceeded", budget_ms: budgetMs }
18945
- });
18946
19291
  }, budgetMs);
18947
19292
  const task = Promise.resolve().then(() => work(controller.signal)).catch((error2) => {
18948
19293
  logSessionArchiveActivity(state, phase, {
@@ -18953,6 +19298,19 @@ function runSessionArchiveTask(state, phase, budgetMs, work) {
18953
19298
  });
18954
19299
  return null;
18955
19300
  }).finally(() => {
19301
+ if (budgetExceeded) {
19302
+ logSessionArchiveActivity(state, phase, {
19303
+ type: "info",
19304
+ level: "warn",
19305
+ message: `Session archive exceeded ${budgetMs}ms; remaining sessions were not confirmed archived`,
19306
+ metadata: {
19307
+ outcome: "archive-budget-exceeded",
19308
+ budget_ms: budgetMs,
19309
+ boot_id: state.sessionArchiveBootId,
19310
+ pass_sequence: state.sessionArchivePassSequence
19311
+ }
19312
+ });
19313
+ }
18956
19314
  clearTimeout(timeout);
18957
19315
  if (state.sessionArchiveInFlight === task) {
18958
19316
  state.sessionArchiveInFlight = null;
@@ -18963,10 +19321,7 @@ function runSessionArchiveTask(state, phase, budgetMs, work) {
18963
19321
  return task;
18964
19322
  }
18965
19323
  async function runSessionArchiveBatch(state, phase, sessions, budgetMs, signal) {
18966
- const config = state.sessionArchiveConfig;
18967
- const client = state.opencodeClient;
18968
- const watermarkPath = state.sessionArchiveWatermarkPath;
18969
- if (!client || !config.keyPrefix || !watermarkPath || !state.agentId) {
19324
+ if (!hasSessionArchivePrerequisites(state)) {
18970
19325
  logSessionArchiveActivity(state, phase, {
18971
19326
  type: "info",
18972
19327
  level: "warn",
@@ -18975,6 +19330,9 @@ async function runSessionArchiveBatch(state, phase, sessions, budgetMs, signal)
18975
19330
  });
18976
19331
  return null;
18977
19332
  }
19333
+ const config = state.sessionArchiveConfig;
19334
+ const client = state.opencodeClient;
19335
+ const watermarkPath = state.sessionArchiveWatermarkPath;
18978
19336
  const bindings = readSessionBindings(
18979
19337
  sessionBindingLedgerPath(homedir9(), process.env),
18980
19338
  (message) => logSessionArchiveActivity(state, phase, {
@@ -18991,23 +19349,6 @@ async function runSessionArchiveBatch(state, phase, sessions, budgetMs, signal)
18991
19349
  sessions,
18992
19350
  signal
18993
19351
  });
18994
- if (!reconciliation.complete) {
18995
- const failure = reconciliation.failures[0];
18996
- const detail = failure.kind === "http" ? `HTTP ${failure.status} for chunk ${failure.chunk}` : failure.kind === "network" ? `network failure for chunk ${failure.chunk}: ${redactDiagnosticText(failure.message ?? "unknown error").slice(0, 200)}` : `invalid response for chunk ${failure.chunk}`;
18997
- logSessionArchiveActivity(state, phase, {
18998
- type: "info",
18999
- level: "warn",
19000
- message: `Session archive: binding reconciliation incomplete for runner ${state.agentId}; ${reconciliation.failures.length} chunk(s) failed (${detail}), unresolved sessions will not replace existing archives`,
19001
- metadata: {
19002
- outcome: "binding-reconciliation-incomplete",
19003
- runner_id: state.agentId,
19004
- failed_chunks: reconciliation.failures.length,
19005
- first_failed_chunk: failure.chunk,
19006
- first_failure_kind: failure.kind,
19007
- ...failure.status !== void 0 ? { http_status: failure.status } : {}
19008
- }
19009
- });
19010
- }
19011
19352
  const summary = await runSessionArchive({
19012
19353
  sessions,
19013
19354
  deps: {
@@ -19018,40 +19359,97 @@ async function runSessionArchiveBatch(state, phase, sessions, budgetMs, signal)
19018
19359
  projection: reconciliation.projection,
19019
19360
  reconciliationComplete: reconciliation.complete,
19020
19361
  watermarks: state.sessionArchiveWatermarks,
19362
+ priorFailureIds: state.sessionArchivePriorFailureIds,
19021
19363
  watermarkPath,
19022
19364
  signal,
19365
+ onMetadataDecodeError: (field, reason, sessionId) => logSessionArchiveMetadataDecodeFailure(state, phase, { field, reason, sessionId }),
19023
19366
  upload: uploadSessionArchive,
19024
19367
  exportMessages: exportSessionMessages,
19025
19368
  recordWatermark: recordUpload
19026
19369
  },
19027
19370
  budgetMs
19028
19371
  });
19029
- logSessionArchiveSummary(state, phase, summary);
19372
+ logSessionArchiveSummary(state, phase, summary, reconciliation);
19030
19373
  return summary;
19031
19374
  }
19032
19375
  async function runSessionArchiveFleet(state, phase, budgetMs, signal) {
19376
+ state.sessionArchivePassSequence++;
19033
19377
  const startedAt = Date.now();
19034
- const enumeration = await listAllSessions(state.port, state.opencodeClient ?? void 0, signal);
19035
- if (enumeration.sessions === null) {
19036
- const interrupted = signal.aborted;
19037
- logSessionArchiveActivity(state, phase, {
19038
- type: "info",
19039
- level: "warn",
19040
- message: interrupted ? "Session archive: enumeration was interrupted before the complete store was known; no session was marked archived" : `Session archive: could not enumerate the complete session store (${enumeration.reason}); no session was marked archived`,
19041
- metadata: {
19042
- outcome: interrupted ? "enumeration-interrupted" : "enumeration-refused",
19043
- ...!interrupted ? { reason: enumeration.reason } : {}
19378
+ const passDeadline = startedAt + budgetMs;
19379
+ const workDeadline = passDeadline - SESSION_ARCHIVE_MANIFEST_BUDGET_MS;
19380
+ const watermarksLoaded = state.sessionArchiveWatermarks.size;
19381
+ const workBudget = createBudgetSignal(signal, Math.max(0, workDeadline - Date.now()));
19382
+ let summary = null;
19383
+ let enumerationComplete = false;
19384
+ let enumerationReason = null;
19385
+ try {
19386
+ const enumeration = await listAllSessions(
19387
+ state.port,
19388
+ state.opencodeClient ?? void 0,
19389
+ workBudget.signal
19390
+ );
19391
+ if (enumeration.sessions === null) {
19392
+ enumerationComplete = false;
19393
+ enumerationReason = workBudget.signal.aborted ? "enumeration-interrupted" : enumeration.reason;
19394
+ const interrupted = workBudget.signal.aborted;
19395
+ logSessionArchiveActivity(state, phase, {
19396
+ type: "info",
19397
+ level: "warn",
19398
+ message: interrupted ? "Session archive: enumeration was interrupted before the complete store was known; no session was marked archived" : `Session archive: could not enumerate the complete session store (${enumerationReason}); no session was marked archived`,
19399
+ metadata: {
19400
+ outcome: interrupted ? "enumeration-interrupted" : "enumeration-refused",
19401
+ ...!interrupted ? { reason: enumerationReason } : {}
19402
+ }
19403
+ });
19404
+ } else {
19405
+ enumerationComplete = true;
19406
+ enumerationReason = null;
19407
+ const enumeratedIds = new Set(enumeration.sessions.map(({ id }) => id));
19408
+ for (const sessionId of state.sessionArchivePriorFailureIds) {
19409
+ if (!enumeratedIds.has(sessionId)) state.sessionArchivePriorFailureIds.delete(sessionId);
19044
19410
  }
19045
- });
19046
- return null;
19411
+ summary = await runSessionArchiveBatch(
19412
+ state,
19413
+ phase,
19414
+ enumeration.sessions,
19415
+ Math.max(0, workDeadline - Date.now()),
19416
+ workBudget.signal
19417
+ );
19418
+ }
19419
+ } finally {
19420
+ workBudget.dispose();
19047
19421
  }
19048
- return runSessionArchiveBatch(
19049
- state,
19050
- phase,
19051
- enumeration.sessions,
19052
- Math.max(0, budgetMs - (Date.now() - startedAt)),
19053
- signal
19054
- );
19422
+ const manifestWindowMs = Math.max(0, passDeadline - Date.now());
19423
+ const manifestBudget = createBudgetSignal(signal, manifestWindowMs);
19424
+ try {
19425
+ if (summary !== null || !enumerationComplete) {
19426
+ const identity = {
19427
+ runnerId: state.agentId,
19428
+ bootId: state.sessionArchiveBootId,
19429
+ passSequence: state.sessionArchivePassSequence,
19430
+ phase,
19431
+ startedAt: new Date(startedAt).toISOString(),
19432
+ completedAt: new Date(Date.now()).toISOString(),
19433
+ budgetMs,
19434
+ enumerationComplete,
19435
+ enumerationReason,
19436
+ watermarkFilePresent: state.sessionArchiveWatermarkFileLoaded,
19437
+ watermarksLoaded
19438
+ };
19439
+ await publishSessionArchiveAudit(
19440
+ state,
19441
+ phase,
19442
+ identity,
19443
+ summary,
19444
+ manifestWindowMs,
19445
+ manifestBudget.signal,
19446
+ signal
19447
+ );
19448
+ }
19449
+ } finally {
19450
+ manifestBudget.dispose();
19451
+ }
19452
+ return summary;
19055
19453
  }
19056
19454
  async function runSessionArchiveShutdownFlush(state, budgetMs) {
19057
19455
  const deadline = Date.now() + budgetMs;
@@ -19074,7 +19472,13 @@ async function runSessionArchiveShutdownFlush(state, budgetMs) {
19074
19472
  type: "info",
19075
19473
  level: "warn",
19076
19474
  message: `Session archive exceeded ${budgetMs}ms while stopping a prior run; remaining sessions were not confirmed archived`,
19077
- metadata: { outcome: "archive-budget-exceeded", budget_ms: budgetMs }
19475
+ metadata: {
19476
+ outcome: "archive-budget-exceeded",
19477
+ budget_ms: budgetMs,
19478
+ boot_id: state.sessionArchiveBootId,
19479
+ pass_sequence: state.sessionArchivePassSequence,
19480
+ manifest_written: false
19481
+ }
19078
19482
  });
19079
19483
  return null;
19080
19484
  }
@@ -19085,7 +19489,13 @@ async function runSessionArchiveShutdownFlush(state, budgetMs) {
19085
19489
  type: "info",
19086
19490
  level: "warn",
19087
19491
  message: `Session archive exceeded ${budgetMs}ms while stopping a prior run; remaining sessions were not confirmed archived`,
19088
- metadata: { outcome: "archive-budget-exceeded", budget_ms: budgetMs }
19492
+ metadata: {
19493
+ outcome: "archive-budget-exceeded",
19494
+ budget_ms: budgetMs,
19495
+ boot_id: state.sessionArchiveBootId,
19496
+ pass_sequence: state.sessionArchivePassSequence,
19497
+ manifest_written: false
19498
+ }
19089
19499
  });
19090
19500
  return null;
19091
19501
  }
@@ -19109,6 +19519,7 @@ function scheduleSessionArchive(state) {
19109
19519
  metadata: { outcome: "watermark-read-failed" }
19110
19520
  })
19111
19521
  );
19522
+ state.sessionArchiveWatermarkFileLoaded = state.sessionArchiveWatermarks.size > 0;
19112
19523
  logSessionArchiveActivity(state, "startup", {
19113
19524
  type: "info",
19114
19525
  message: `Session archive enabled (interval=${config.intervalMs}ms)`,
@@ -19618,9 +20029,13 @@ async function run(options) {
19618
20029
  ),
19619
20030
  sessionArchiveTimers: [],
19620
20031
  sessionArchiveWatermarks: /* @__PURE__ */ new Map(),
20032
+ sessionArchivePriorFailureIds: /* @__PURE__ */ new Set(),
19621
20033
  sessionArchiveWatermarkPath: null,
19622
20034
  sessionArchiveInFlight: null,
19623
20035
  sessionArchiveAbortController: null,
20036
+ sessionArchiveBootId: randomUUID2(),
20037
+ sessionArchivePassSequence: 0,
20038
+ sessionArchiveWatermarkFileLoaded: false,
19624
20039
  sessionDeleteFailures: /* @__PURE__ */ new Map(),
19625
20040
  claudeUsageTimer: null,
19626
20041
  claudeUsageRearm: null,