@stigmer/cli 3.41.0 → 3.41.1-dev.20261003133619.g58ac1f23a411

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 (64) hide show
  1. package/commands/config/context.js +3 -3
  2. package/commands/config/context.js.map +1 -1
  3. package/commands/resume.d.ts.map +1 -1
  4. package/commands/resume.js +12 -13
  5. package/commands/resume.js.map +1 -1
  6. package/commands/run.js +2 -2
  7. package/commands/run.js.map +1 -1
  8. package/config/config.d.ts +1 -1
  9. package/config/config.d.ts.map +1 -1
  10. package/config/keys.js +3 -3
  11. package/config/keys.js.map +1 -1
  12. package/config/resolve.d.ts +1 -1
  13. package/config/resolve.js +5 -5
  14. package/config/resolve.js.map +1 -1
  15. package/local/artifact.d.ts +28 -6
  16. package/local/artifact.d.ts.map +1 -1
  17. package/local/artifact.js +88 -13
  18. package/local/artifact.js.map +1 -1
  19. package/local/bootstrap.js +1 -1
  20. package/local/bootstrap.js.map +1 -1
  21. package/local/daemon/components.js +1 -1
  22. package/local/daemon/components.js.map +1 -1
  23. package/local/net/tcp.js +1 -1
  24. package/local/net/tcp.js.map +1 -1
  25. package/local/temporal/download.d.ts +12 -2
  26. package/local/temporal/download.d.ts.map +1 -1
  27. package/local/temporal/download.js +6 -2
  28. package/local/temporal/download.js.map +1 -1
  29. package/package.json +7 -7
  30. package/resources/run/prepare.d.ts +1 -1
  31. package/resources/run/prepare.js +4 -4
  32. package/resources/run/prepare.js.map +1 -1
  33. package/resources/run/resume.d.ts +0 -1
  34. package/resources/run/resume.d.ts.map +1 -1
  35. package/resources/run/resume.js +7 -4
  36. package/resources/run/resume.js.map +1 -1
  37. package/resources/run/workflow-stream.d.ts +9 -0
  38. package/resources/run/workflow-stream.d.ts.map +1 -1
  39. package/resources/run/workflow-stream.js +24 -4
  40. package/resources/run/workflow-stream.js.map +1 -1
  41. package/resources/stream/headless.d.ts +16 -0
  42. package/resources/stream/headless.d.ts.map +1 -1
  43. package/resources/stream/headless.js +33 -5
  44. package/resources/stream/headless.js.map +1 -1
  45. package/resources/usage.d.ts +2 -2
  46. package/resources/usage.d.ts.map +1 -1
  47. package/resources/usage.js +4 -4
  48. package/resources/usage.js.map +1 -1
  49. package/src/commands/config/context.ts +3 -3
  50. package/src/commands/resume.ts +11 -17
  51. package/src/commands/run.ts +2 -2
  52. package/src/config/config.ts +1 -1
  53. package/src/config/keys.ts +3 -3
  54. package/src/config/resolve.ts +5 -5
  55. package/src/local/artifact.ts +120 -15
  56. package/src/local/bootstrap.ts +1 -1
  57. package/src/local/daemon/components.ts +1 -1
  58. package/src/local/net/tcp.ts +1 -1
  59. package/src/local/temporal/download.ts +14 -4
  60. package/src/resources/run/prepare.ts +4 -4
  61. package/src/resources/run/resume.ts +7 -4
  62. package/src/resources/run/workflow-stream.ts +23 -3
  63. package/src/resources/stream/headless.ts +31 -4
  64. package/src/resources/usage.ts +4 -4
@@ -31,6 +31,12 @@ export interface HeadlessRenderer {
31
31
  resolveApproval(event: ApprovalNeededEvent): ApprovalAction;
32
32
  }
33
33
 
34
+ /**
35
+ * How long the driver keeps reading after the terminal snapshot, for the
36
+ * server to end the subscription, before it cancels the call itself.
37
+ */
38
+ export const SUBSCRIPTION_DRAIN_GRACE_MS = 2_000;
39
+
34
40
  /** The terminal outcome of a headless stream. */
35
41
  export interface HeadlessResult {
36
42
  readonly phase: string;
@@ -52,20 +58,41 @@ export interface HeadlessStreamDeps {
52
58
  * Drive the stream to a terminal phase and return the outcome. Aborting (Ctrl-C)
53
59
  * resolves cleanly with an empty result; a dropped stream renders a stream_error
54
60
  * and returns its message.
61
+ *
62
+ * The subscription never outlives the drive (#1522). After the terminal
63
+ * snapshot the driver keeps reading, ignoring what follows, until the server
64
+ * ends the subscription, which it does on a terminal phase: an HTTP/2 stream
65
+ * whose unread frames are left in its buffer is never destroyed, and an open
66
+ * stream holds the session, and with it the process, alive after the run has
67
+ * finished. Leaving the loop early, or aborting the call once the server has
68
+ * already closed its side, does not release it. A server that does not end the
69
+ * stream within SUBSCRIPTION_DRAIN_GRACE_MS is cancelled, and the subscription
70
+ * is subscribed with a signal of the driver's own (joined to the caller's),
71
+ * aborted on every way out.
55
72
  */
56
73
  export async function runHeadlessStream(deps: HeadlessStreamDeps): Promise<HeadlessResult> {
57
74
  const differ = new SnapshotDiffer();
75
+ const subscription = new AbortController();
76
+ let outcome: HeadlessResult | undefined;
77
+ let grace: ReturnType<typeof setTimeout> | undefined;
58
78
  try {
59
- for await (const snapshot of deps.subscribe(deps.signal)) {
60
- const terminal = await drainSnapshot(differ.next(snapshot), deps);
61
- if (terminal !== undefined) return terminal;
79
+ for await (const snapshot of deps.subscribe(AbortSignal.any([deps.signal, subscription.signal]))) {
80
+ if (outcome !== undefined) continue;
81
+ outcome = await drainSnapshot(differ.next(snapshot), deps);
82
+ if (outcome !== undefined) {
83
+ grace = setTimeout(() => subscription.abort(), SUBSCRIPTION_DRAIN_GRACE_MS);
84
+ }
62
85
  }
63
- return { phase: "", error: "" };
86
+ return outcome ?? { phase: "", error: "" };
64
87
  } catch (err) {
88
+ if (outcome !== undefined) return outcome;
65
89
  if (deps.signal.aborted) return { phase: "", error: "" };
66
90
  const message = classifyStreamError(err, deps.sessionId);
67
91
  deps.renderer.render({ kind: "streamError", error: message });
68
92
  return { phase: "", error: message };
93
+ } finally {
94
+ clearTimeout(grace);
95
+ subscription.abort();
69
96
  }
70
97
  }
71
98
 
@@ -41,21 +41,21 @@ export async function getSessionUsageReport(client: Stigmer, sessionId: string):
41
41
  export async function getAgentUsageReport(
42
42
  client: Stigmer,
43
43
  agentId: string,
44
- orgId: string,
44
+ org: string,
45
45
  range: DateRange,
46
46
  ): Promise<GetAgentUsageReportOutput> {
47
47
  return client.agentExecution.getAgentUsageReport(
48
- create(GetAgentUsageReportInputSchema, { agentId, orgId, fromDate: range.from, toDate: range.to }),
48
+ create(GetAgentUsageReportInputSchema, { agentId, org, fromDate: range.from, toDate: range.to }),
49
49
  );
50
50
  }
51
51
 
52
52
  export async function getOrgUsageReport(
53
53
  client: Stigmer,
54
- orgId: string,
54
+ org: string,
55
55
  range: DateRange,
56
56
  ): Promise<GetOrgUsageReportOutput> {
57
57
  return client.agentExecution.getOrgUsageReport(
58
- create(GetOrgUsageReportInputSchema, { orgId, fromDate: range.from, toDate: range.to }),
58
+ create(GetOrgUsageReportInputSchema, { org, fromDate: range.from, toDate: range.to }),
59
59
  );
60
60
  }
61
61