@tangle-network/agent-provider-tangle 3.6.0 → 3.6.1

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.
@@ -9,6 +9,54 @@ const handles = new WeakMap();
9
9
  const blockedNames = new Set([".ssh", ".config", ".claude", ".codex", ".opencode", ".env", ".env.local", ".npmrc", ".sidecar"]);
10
10
  const MAX_ENTRIES = 100_000;
11
11
  const MAX_EVENTS = 100_000;
12
+ // How long a replay may go without its start marker once the stream is open. The Sidecar sends
13
+ // no replay markers when an execution has buffered nothing yet, so this bounds that case.
14
+ const REPLAY_START_GRACE_MS = 15_000;
15
+ /**
16
+ * The execution's events as the Sidecar had buffered them when this capture started.
17
+ *
18
+ * The Sidecar answers a cursor replay with its buffer between `history.replay.start` and
19
+ * `history.replay.end`, then follows the live turn, and the SDK returns only on the turn's `done`
20
+ * or `error`. Read to the end, a capture of a running turn waited for the turn to finish: in the
21
+ * 2026-10-04 trace proof every 2-minute copy blocked until its turn ended or the Lab's 180 s bound
22
+ * aborted it, and 6.2 minutes of live turns stored no copy at all. A settled execution's buffer
23
+ * already ends with its `done` or `error`, so it replays as before.
24
+ */
25
+ async function* bufferedExecutionEvents(session, executionId, signal) {
26
+ const replay = new AbortController();
27
+ const forward = () => replay.abort(signal?.reason);
28
+ if (signal?.aborted)
29
+ forward();
30
+ else
31
+ signal?.addEventListener("abort", forward, { once: true });
32
+ let grace;
33
+ let empty = false;
34
+ try {
35
+ for await (const event of session.events({ since: "0", executionId, signal: replay.signal })) {
36
+ if (event.type === "connection.established" && grace === undefined) {
37
+ grace = setTimeout(() => {
38
+ empty = true;
39
+ replay.abort(new DOMException("Tangle replay buffer is empty", "AbortError"));
40
+ }, REPLAY_START_GRACE_MS);
41
+ grace.unref?.();
42
+ }
43
+ if (event.type === "history.replay.start")
44
+ clearTimeout(grace);
45
+ yield event;
46
+ if (event.type === "history.replay.end")
47
+ return;
48
+ }
49
+ }
50
+ catch (error) {
51
+ if (!empty || signal?.aborted)
52
+ throw error;
53
+ }
54
+ finally {
55
+ clearTimeout(grace);
56
+ signal?.removeEventListener("abort", forward);
57
+ }
58
+ signal?.throwIfAborted();
59
+ }
12
60
  // Match the Sidecar request limit without accumulating 100 large JSON payloads.
13
61
  const WORKSPACE_BATCH_FILES = 100;
14
62
  const WORKSPACE_BATCH_BYTES = 8 * 1024 * 1024;
@@ -295,7 +343,7 @@ async function captureSandboxEvidence(box, options, writer) {
295
343
  const events = new EvidenceJsonArray(undefined, async function* () {
296
344
  for (const executionId of executionIds) {
297
345
  eventCountsByExecutionId[executionId] = 0;
298
- for await (const event of session.events({ since: "0", executionId, signal: options.signal })) {
346
+ for await (const event of bufferedExecutionEvents(session, executionId, options.signal)) {
299
347
  options.signal?.throwIfAborted();
300
348
  if (counts.events >= MAX_EVENTS)
301
349
  throw new Error("Tangle event replay limit exceeded");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",