Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): keep top-level sessions in an independent trace (#2290)

Chad Hietalac2bfee1ee005
diff --git a/.changeset/parented-session-markers.md b/.changeset/parented-session-markers.md
new file mode 100644
index 000000000..ec2066f7f
--- /dev/null
+++ b/.changeset/parented-session-markers.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Keep top-level sessions in an independent `agent.session` trace while preserving shared trace context for local and remote subagents.
diff --git a/packages/eve/src/public/channels/eve-session-routes.test.ts b/packages/eve/src/public/channels/eve-session-routes.test.ts
index 9ca305b54..cdf24dc42 100644
--- a/packages/eve/src/public/channels/eve-session-routes.test.ts
+++ b/packages/eve/src/public/channels/eve-session-routes.test.ts
@@ -69,12 +69,7 @@ describe("eve ID-addressed session routes", () => {
});
expect(createSession).toHaveBeenCalledWith(
expect.objectContaining({
- parentTraceContext: {
- isRemote: true,
- spanId: "2".repeat(16),
- traceFlags: 1,
- traceId: "1".repeat(32),
- },
+ parentTraceContext: undefined,
}),
);
expect(createSession).toHaveBeenCalledWith(
@@ -93,6 +88,47 @@ describe("eve ID-addressed session routes", () => {
expect(createSession).toHaveBeenCalledTimes(1);
});
+ it("continues a remote-agent trace for callback sessions", async () => {
+ const createSession = vi.fn().mockResolvedValue({
+ events: new ReadableStream(),
+ sessionId: "wrun_A",
+ });
+ const args = attachRouteSessionCreator(createArgs(), createSession);
+
+ const response = await route("POST", "/eve/v1/session")(
+ new Request("https://eve.test/eve/v1/session", {
+ body: JSON.stringify({
+ callback: {
+ callId: "call-1",
+ subagentName: "research",
+ token: "tok123",
+ url: "https://caller.example.com/eve/v1/callback/tok123",
+ },
+ message: "hello",
+ mode: "conversation",
+ }),
+ headers: {
+ "content-type": "application/json",
+ traceparent: `00-${"1".repeat(32)}-${"2".repeat(16)}-01`,
+ },
+ method: "POST",
+ }),
+ args,
+ );
+
+ expect(response.status).toBe(202);
+ expect(createSession).toHaveBeenCalledWith(
+ expect.objectContaining({
+ parentTraceContext: {
+ isRemote: true,
+ spanId: "2".repeat(16),
+ traceFlags: 1,
+ traceId: "1".repeat(32),
+ },
+ }),
+ );
+ });
+
it("rejects input responses on session creation", async () => {
const createSession = vi.fn();
const args = attachRouteSessionCreator(createArgs(), createSession);
diff --git a/packages/eve/src/public/channels/eve.ts b/packages/eve/src/public/channels/eve.ts
index beba71adf..8c5de0df7 100644
--- a/packages/eve/src/public/channels/eve.ts
+++ b/packages/eve/src/public/channels/eve.ts
@@ -256,7 +256,12 @@ export function eveChannel(input: EveChannelInput): EveChannel {
const body = parseCreateBody(payload);
if (body instanceof Response) return body;
- const parentTraceContext = parseTraceparent(req.headers.get("traceparent"));
+ // Top-level sessions own their trace. Callback sessions are delegated
+ // remote agents and intentionally continue the dispatching agent trace.
+ const parentTraceContext =
+ body.callback === undefined
+ ? undefined
+ : parseTraceparent(req.headers.get("traceparent"));
const policyRejection = checkUploadPolicy(body, uploadPolicy);
if (policyRejection !== null) return policyRejection;