Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): preserve local subagent trace content (#2949)

Chad Hietala3cccd71a58e1
diff --git a/.changeset/preserve-subagent-trace-content.md b/.changeset/preserve-subagent-trace-content.md
new file mode 100644
index 000000000..bd6e649df
--- /dev/null
+++ b/.changeset/preserve-subagent-trace-content.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Preserve inherited channel audience metadata when local subagents persist adapter state. Public parent traces now continue capturing local child inputs and outputs while destination-specific redaction remains independent.
diff --git a/packages/eve/src/execution/channel-context.ts b/packages/eve/src/execution/channel-context.ts
index 883166ecd..7492c8964 100644
--- a/packages/eve/src/execution/channel-context.ts
+++ b/packages/eve/src/execution/channel-context.ts
@@ -11,13 +11,18 @@ export function setChannelContext(
readonly channelName?: string;
} = {},
): void {
+ const existing = ctx.get(ChannelInstrumentationKey);
+ const projection = buildChannelInstrumentationProjection({
+ adapter,
+ channelName: options.channelName,
+ existingKind: existing?.kind,
+ });
ctx.set(ChannelKey, adapter);
- ctx.set(
- ChannelInstrumentationKey,
- buildChannelInstrumentationProjection({
- adapter,
- channelName: options.channelName,
- existingKind: ctx.get(ChannelInstrumentationKey)?.kind,
- }),
- );
+ ctx.set(ChannelInstrumentationKey, {
+ ...projection,
+ metadata:
+ adapter.instrumentation?.metadata === undefined && existing !== undefined
+ ? existing.metadata
+ : projection.metadata,
+ });
}
diff --git a/packages/eve/src/execution/runtime-context.test.ts b/packages/eve/src/execution/runtime-context.test.ts
index 1c0ad0125..94799a58f 100644
--- a/packages/eve/src/execution/runtime-context.test.ts
+++ b/packages/eve/src/execution/runtime-context.test.ts
@@ -12,6 +12,7 @@ import {
SessionKey,
ScheduleIdKey,
} from "#context/keys.js";
+import { setChannelContext } from "#execution/channel-context.js";
import { buildRunContext } from "#execution/runtime-context.js";
function createTestSession(
@@ -274,7 +275,7 @@ describe("buildRunContext", () => {
it("grafts parent metadata onto the child's own kind", () => {
const parentProjection = {
kind: "channel:slack",
- metadata: { threadTs: "1234.5678", userId: "U123" },
+ metadata: { audience: "public" as const, threadTs: "1234.5678", userId: "U123" },
};
const ctx = buildRunContext({
bundle: createMinimalBundle(),
@@ -290,7 +291,18 @@ describe("buildRunContext", () => {
const result = ctx.get(ChannelInstrumentationKey)!;
expect(result.kind).toBe("subagent");
- expect(result.metadata).toEqual({ threadTs: "1234.5678", userId: "U123" });
+ expect(result.metadata).toEqual({
+ audience: "public",
+ threadTs: "1234.5678",
+ userId: "U123",
+ });
+
+ setChannelContext(ctx, { kind: "subagent", state: { persisted: true } });
+ expect(ctx.get(ChannelInstrumentationKey)?.metadata).toEqual({
+ audience: "public",
+ threadTs: "1234.5678",
+ userId: "U123",
+ });
});
it("uses the adapter's own projection when channelMetadata is not provided", () => {
diff --git a/packages/eve/src/instrumentation/runtime.test.ts b/packages/eve/src/instrumentation/runtime.test.ts
index 0242e7b0a..563b50e3b 100644
--- a/packages/eve/src/instrumentation/runtime.test.ts
+++ b/packages/eve/src/instrumentation/runtime.test.ts
@@ -7,6 +7,7 @@ import {
ParentTraceContextKey,
SessionTraceSeedKey,
} from "#context/keys.js";
+import { setChannelContext } from "#execution/channel-context.js";
import type { InstrumentationHooks } from "#instrumentation/lifecycle.js";
import {
bindInstrumentationRuntime,
@@ -593,6 +594,29 @@ describe("bindInstrumentationRuntime", () => {
});
});
+ it("retains content after a local subagent adapter refresh", async () => {
+ const ctx = createContext("public");
+ ctx.set(SessionTraceSeedKey, {
+ decision: { action: "record", recordInputs: true, recordOutputs: true },
+ spanId: "1".repeat(16),
+ traceFlags: 1,
+ traceId: "2".repeat(32),
+ });
+
+ setChannelContext(ctx, { kind: "subagent", state: { persisted: true } });
+
+ expect(ctx.get(ChannelInstrumentationKey)?.metadata.audience).toBe("public");
+ expect(
+ await readTelemetry(
+ bindInstrumentationRuntime(
+ createRuntime({ capturesContent: true, publish: vi.fn() }),
+ ctx,
+ boundSession,
+ ),
+ ),
+ ).toMatchObject({ recordInputs: true, recordOutputs: true });
+ });
+
it("derives a legacy seed decision from trace flags", async () => {
const policy = vi.fn(() => true);
const ctx = createContext();