Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): preserve tracing capture boundaries on retention and resume (#4720)

Colton Padden9f3a634e5b3a
diff --git a/.changeset/tidy-tracing-capture.md b/.changeset/tidy-tracing-capture.md
new file mode 100644
index 000000000..bce3c59d9
--- /dev/null
+++ b/.changeset/tidy-tracing-capture.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Snapshot retained tracing arguments and errors so later mutations cannot introduce private content into telemetry or checkpoints. Apply accepted delegation capture ceilings when re-entering durable turns, including through `resume()`.
diff --git a/packages/tracing/README.md b/packages/tracing/README.md
index c43c9757f..e1017c19b 100644
--- a/packages/tracing/README.md
+++ b/packages/tracing/README.md
@@ -86,7 +86,9 @@ Handles expose execution, attributes, completion, and identity.
`run(execute, ceiling)` limits captured content for work inside the run without
changing what the operation already recorded. Content any operation receives
while the run is active, such as an existing tool's arguments, result, or error,
-is held to that ceiling. Re-entering a durable turn with a narrower `capture`
+is held to that ceiling. Retained tool arguments and errors are snapshotted when
+accepted; later mutations of the original objects do not change captured content.
+Re-entering a durable turn with a narrower `capture`
narrows the turn and its open operations and drops retained content the new
decision declines. `recordError(error)` records a
failure without ending the operation, for example when a tool's work fails in a
@@ -170,6 +172,8 @@ Bind the sender only to approved destinations. It rejects redirects. The receive
validates the bounded `x-agent-tracing` header before calling your trust callback.
Metadata is not authorization: verify authenticated provenance and the expected
caller, parent run, and call. Rejected metadata does not change application work.
+An accepted handoff's capture ceiling also applies when `turn()` or `resume()`
+re-enters an existing durable turn.
## Durable turns
diff --git a/packages/tracing/src/agent-tracing.ts b/packages/tracing/src/agent-tracing.ts
index 30a36d8b5..0e20c48e0 100644
--- a/packages/tracing/src/agent-tracing.ts
+++ b/packages/tracing/src/agent-tracing.ts
@@ -180,6 +180,8 @@ export function createAgentTracing(input: AgentTracingOptions): AgentTracing {
context: ExecutionContext | undefined,
capture?: CaptureDecision,
): Promise<LiveTurn | undefined> {
+ const ceiling = currentAgentHandoff()?.capture;
+ capture = capture === undefined ? ceiling : intersectCapture(capture, ceiling);
const saved = checkpointer === undefined ? undefined : await loadCheckpoint(key);
if (
cached !== undefined &&
diff --git a/packages/tracing/src/core/scopes.ts b/packages/tracing/src/core/scopes.ts
index fcd1ffe11..021a74bd6 100644
--- a/packages/tracing/src/core/scopes.ts
+++ b/packages/tracing/src/core/scopes.ts
@@ -1,4 +1,5 @@
import { randomBytes } from "node:crypto";
+import { boundedTraceError } from "../adapters/serialization.js";
import { createSpanWriter, type TraceOperation } from "./writer.js";
import { usageAttributes } from "./attributes.js";
import {
@@ -122,6 +123,15 @@ export function createScopes(input: {
} catch {}
};
+ function snapshotContent(value: unknown): unknown {
+ const json = serializer.json(value);
+ try {
+ return json === undefined ? undefined : JSON.parse(json);
+ } catch {
+ return undefined;
+ }
+ }
+
function reserve(
data: ScopeData,
key: string,
@@ -450,7 +460,8 @@ export function createScopes(input: {
kind: known.kind ?? next.options.kind,
// Earlier arguments were recorded with consent; new ones need it now.
arguments:
- known.arguments ?? (current().recordInputs ? next.options.arguments : undefined),
+ known.arguments ??
+ (current().recordInputs ? snapshotContent(next.options.arguments) : undefined),
},
},
actualCapture,
@@ -659,7 +670,11 @@ export function createScopes(input: {
terminalResult = {
...terminalResult,
failed: true,
- error: current().recordOutputs ? error : undefined,
+ error: current().recordOutputs
+ ? error instanceof Error
+ ? boundedTraceError(error)
+ : snapshotContent(error)
+ : undefined,
errorCode: errorType ?? (error instanceof Error ? error.name : undefined),
};
if (operation !== undefined) operation.fail(terminalResult.error, terminalResult.errorCode);
diff --git a/packages/tracing/src/durable.integration.test.ts b/packages/tracing/src/durable.integration.test.ts
index 8026ad774..fd23cae27 100644
--- a/packages/tracing/src/durable.integration.test.ts
+++ b/packages/tracing/src/durable.integration.test.ts
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { context } from "@opentelemetry/api";
+import { createAgentDelegationTransport } from "@eve/tracing/delegation";
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
import {
BasicTracerProvider,
@@ -258,7 +259,7 @@ describe("content capture after a narrower decision", () => {
.map((span) => ({ attributes: span.attributes, events: span.events }));
return JSON.stringify(spans) + JSON.stringify([...entries.values()]);
};
- return { tracing, turn, attempt, exported };
+ return { tracing, turn, attempt, exported, checkpointer, entries, exporter };
}
it("keeps an existing tool's failure out when its parent's run declines outputs", async () => {
@@ -304,6 +305,102 @@ describe("content capture after a narrower decision", () => {
expect(await exported()).not.toContain("private note");
});
+ it("snapshots arguments accepted from a second tool report", async () => {
+ const { turn, attempt, exported } = await setup();
+ const tool = await attempt.tool({ callId: "lookup", name: "lookup" });
+ const arguments_ = { note: { text: "Alice's approved note" } };
+ await attempt.tool({ callId: "lookup", name: "lookup", arguments: arguments_ });
+ attempt.run(() => {
+ arguments_.note.text = "Alice's private note";
+ }, NO_INPUTS);
+ await attempt.tool({ callId: "lookup", name: "lookup" });
+ const approval = await tool.approval({ requestId: "approval" });
+ expect(await exported()).toContain("approved note");
+ expect(await exported()).not.toContain("private note");
+ await approval.complete();
+ await tool.complete();
+ await attempt.complete();
+ await turn.complete();
+ expect(await exported()).toContain("approved note");
+ expect(await exported()).not.toContain("private note");
+ });
+
+ it.each(["Error", "object"] as const)(
+ "snapshots a retained %s before later mutation",
+ async (kind) => {
+ const { turn, attempt, exported } = await setup();
+ const tool = await attempt.tool({ callId: "lookup", name: "lookup" });
+ const error =
+ kind === "Error"
+ ? new Error("Alice's approved note")
+ : { message: "Alice's approved note" };
+ tool.recordError(error);
+ tool.run(() => {
+ error.message = "Alice's private note";
+ if (error instanceof Error) error.stack = "Alice's private stack";
+ }, NO_OUTPUTS);
+ const approval = await tool.approval({ requestId: "approval" });
+ expect(await exported()).toContain("approved note");
+ expect(await exported()).not.toContain("private");
+ await approval.complete();
+ await tool.complete();
+ await attempt.complete();
+ await turn.complete();
+ expect(await exported()).toContain("approved note");
+ expect(await exported()).not.toContain("private");
+ },
+ );
+
+ it.each([
+ ["cached", "turn"],
+ ["restored", "turn"],
+ ["cached", "resume"],
+ ["restored", "resume"],
+ ] as const)("honors a remote capture decline on a %s %s", async (state, entrypoint) => {
+ const { tracing, turn, attempt, checkpointer, entries, exporter, exported } = await setup();
+ const tool = await attempt.tool({ callId: "lookup", name: "lookup" });
+ const receiver = state === "cached" ? tracing : worker(checkpointer, exporter);
+ const transport = createAgentDelegationTransport();
+ const headers = new Headers({
+ "x-agent-tracing": JSON.stringify({
+ caller: { traceId: "a".repeat(32), spanId: "b".repeat(16), traceFlags: 1 },
+ conversationId: identity.conversationId,
+ parentRunId: "caller-run",
+ parentCallId: "caller-call",
+ agentName: "support",
+ capture: METADATA,
+ }),
+ });
+ const reentered = await transport.receive(
+ headers,
+ () => true,
+ () =>
+ entrypoint === "turn"
+ ? receiver.turn({ agentName: "support", identity, sequence: 0, capture: ALL })
+ : receiver.resume({ identity }),
+ );
+ expect(reentered!.reference).toEqual(turn.reference);
+ const resumedAttempt = reentered!.findAttempt({ stepIndex: 0, attempt: 0 })!;
+ const resumedTool = await resumedAttempt.tool({
+ callId: "lookup",
+ name: "lookup",
+ arguments: { note: "Bob's private address" },
+ });
+ expect(resumedTool.reference).toEqual(tool.reference);
+ const approval = await resumedTool.approval({ requestId: "approval" });
+ expect(JSON.stringify([...entries.values()])).not.toContain("private address");
+ await approval.complete({ response: "Alice's private response" });
+ await resumedTool.complete({ output: "Alice's private result" });
+ await resumedAttempt.complete();
+ await reentered!.complete();
+ await receiver.forceFlush();
+ const output = await exported();
+ expect(output).not.toContain("private");
+ expect(exporter.getFinishedSpans().some((span) => span.name === "execute_tool lookup")).toBe(
+ true,
+ );
+ });
+
it("narrows a cached turn re-entered with less capture", async () => {
const { tracing, exported } = await setup();
const reentered = await tracing.turn({