Skip to content

Several webAgent event emits miss the WebAgentEventData base fields (timestamp, iterationId) #490

@lmorchard

Description

@lmorchard

Summary

packages/core/src/webAgent.ts has several this.emit(...) call sites that do not supply the timestamp and iterationId fields the typed interfaces (and the generated JSON schema) declare as required on the base WebAgentEventData. Surfaced by Copilot on #489 at `webAgent.ts:1907` — TASK_COMPLETED — but applies more broadly.

Current state

  • The WebAgentEventEmitter (packages/core/src/events.ts:502-551) is a pass-through; it does NOT inject timestamp or iterationId middleware-style.
  • The private wrapper WebAgent.emit(type, data: any) at webAgent.ts:1993-1995 is also a pass-through and uses data: any, which masks the type mismatch from TypeScript.
  • Some emit sites supply iterationId (e.g., AGENT_STEP at webAgent.ts:538-541, TASK_VALIDATED at webAgent.ts:1397-1403); none I sampled supply timestamp. The TASK_COMPLETED emit at webAgent.ts:1901-1907 supplies neither.
  • Loggers (chalkConsole.ts, json.ts) consume TaskCompleteEventData and similar typed payloads — when consumers read data.timestamp or data.iterationId, they get undefined despite the type asserting otherwise.
  • The generated schema (packages/core/schemas/webagent-event.json) marks both fields as required on TaskCompleteEventData etc., so SSE/stream consumers (tabs-api, eval-judge, generated SDKs) may also be miscalibrated.
  • This is pre-existing — git blame shows the TASK_COMPLETED emit lacks those fields since commit 23011910 (Nick Chapman, 2025-08-11). It was not introduced by feat(core): wire validator history and surface validationOutcome (#429) #463 (PR1) or feat(core): surface validationOutcome on TASK_COMPLETED event (#429) #489 (PR2).

Why this matters

  • Wire-API surface mismatch: subscribers reading the typed shape will silently observe `undefined` where the schema promises a value. Downstream tooling that generates types from the schema (tabs-api, Stainless SDKs) will model the field as required-but-missing.
  • The misalignment is invisible at compile time because of `emit(type, data: any)`.

Suggested fixes (not part of this issue's contract)

A few options worth considering, none picked here:

  • Middleware in the emitter to auto-inject timestamp and iterationId from WebAgent instance state at emit time. Centralizes the fix; one change covers all emit sites.
  • Tighten emit() typing so data must satisfy the declared event-type's payload shape (drop `any`). Forces every existing emit site to supply the fields explicitly; surfaces every site that's currently noncompliant at build time.
  • Audit and fix per emit site without changing the wrapper. Mechanical, scoped, doesn't change the typing contract.

Scope

Out of scope for #489 (which deliberately only adds the optional validationOutcome field to TaskCompleteEventData). Filing as a separate follow-up so the trail is preserved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions