Skip to content

[Bug]: Duplicate kind field in traceSpanSchema silently drops memory and trigger span types #39

@rishab11250

Description

@rishab11250

Bug Description

The traceSpanSchema Zod schema in packages/contracts/src/index.ts declares the kind field twice. Zod applies schemas sequentially, so the second definition overwrites the first. The first definition includes all 9 span kinds (workflow, agent, tool, llm, queue, memory, trigger, retry, replay), but the second definition omits 'memory' and 'trigger'. Any trace span with kind: 'memory' or kind: 'trigger' fails Zod validation and is silently dropped — no error is raised.

This was introduced by PR #34 which added a new comprehensive kind line but kept the old narrower one below it.

Prerequisites

  • I have verified that this issue has not already been reported.
  • I have checked the documentation and believe this is a genuine malfunction, not a configuration error.
  • I am using the latest stable release or the main branch of PulseStack.

Steps to Reproduce

  1. Open packages/contracts/src/index.ts.
  2. Observe two kind declarations in traceSpanSchema at lines 74 and 76-84.
  3. Run the following validation:
import { traceSpanSchema } from '@pulsestack/contracts';

const rest = {
  spanId: 'span_1',
  parentSpanId: null,
  traceId: 'trace_1',
  executionId: 'exec_1',
  workflowId: 'wf_1',
  name: 'test',
  status: 'running',
  startedAt: new Date().toISOString(),
  endedAt: null,
  attributes: {},
  error: null,
};

traceSpanSchema.parse({ kind: 'memory', ...rest }); // FAILS
traceSpanSchema.parse({ kind: 'trigger', ...rest }); // FAILS

Expected Behavior

Both kind: 'memory' and kind: 'trigger' should parse successfully. The inferred TypeScript type TraceSpan should include all 9 span kinds.

Actual Behavior

Line 74 declares all 9 kinds, but lines 76-84 overwrite it with a narrower set missing 'memory' and 'trigger':

// Line 74 — comprehensive
kind: z.enum(['workflow', 'agent', 'tool', 'llm', 'queue', 'memory', 'trigger', 'retry', 'replay']),

// Lines 76-84 — overwrites line 74, missing 'memory' and 'trigger'
kind: z.enum([
    'workflow',
    'agent',
    'tool',
    'llm',
    'queue',
    'retry',
    'replay',
]),

The inferred type also excludes them:

export type TraceSpan = z.infer<typeof traceSpanSchema>;
// 'memory' and 'trigger' are NOT in the type

Diagnostic Information

Environment Details

Additional Context

This causes silent data loss in the tracing subsystem — memory-agent spans and trigger spans are never recorded. The fix is to remove lines 76-84, keeping only the comprehensive definition at line 74.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions