Skip to content

AgentRun events.jsonl records type=usage_recorded which is missing from AGENT_RUN_EVENT_TYPES → strict decode fails, desktop app won't start #1942

Description

@songlairui

Summary

The Maka Desktop app (v0.1.3, macOS) fails to start with:

AgentRun 99272103-6b74-4dd2-b367-b231bbe0b6c7 has a corrupt JSONL record at line 11: Invalid AgentRun event schema

Root cause

The run event ledger at workspaces/<ws>/sessions/<session>/runs/<run>/events.jsonl contains events whose type is usage_recorded, but usage_recorded is not in the AGENT_RUN_EVENT_TYPES enum in @maka/core (src/agent-run.ts). The strict read path (readEvents with strict=true in @maka/storage agent-run-store.ts) throws on any event whose type is not in the enum, which blocks app startup.

Verified locally:

  • Every event in the ledger is valid JSON — the failure is purely schema-level.
  • All 4 runs on this machine contain a usage_recorded event (at line 11 or 21), i.e. every run that completed a turn with token usage writes it. This means the app fails to start again after any new run — not a one-off corruption.
  • The string usage_recorded / "Token usage recorded" does not appear anywhere in the installed app bundle (app.asar + app.asar.unpacked + workers/), so the writer (likely the AI-SDK runtime or a recently updated agent runtime) and the validator (compiled schema enum) are out of sync.

Event shape that fails

Line 11 of the affected run (valid JSON, rejected by schema):

{"type":"usage_recorded","id":"ac9072a7-...","runId":"99272103-...","sessionId":"78d21d15-...","turnId":"300c9dab-...","ts":1785736878682,"message":"Token usage recorded","data":{...inputTokens/outputTokens/cacheHitInputTokens/cacheMissInputTokens/cacheMissInputSource/reasoningTokens/totalTokens/rawFinishReason/systemPromptHash/prefixHash/requestShapeHash/toolAvailability...}}

The data payload is the same token-usage accounting that runtime-events.jsonl records as a tokenUsage action on a system message (that file passes validation fine).

Impact

  • App is bricked at startup once any run has written a usage_recorded event (i.e. virtually every real run).
  • The event_corrupt tolerance path exists for non-strict reads, but startup uses strict mode and hard-fails.

Workaround (local)

Removing the usage_recorded line from each events.jsonl lets the app start again; remaining events form a valid ledger (run_created → … → run_completed).

Suggested fix

  • Add usage_recorded to AGENT_RUN_EVENT_TYPES (and its projection handling), or
  • Align the runtime writer so it emits an already-supported event (e.g. model_call_attempt_recorded), and/or
  • Make the startup path non-strict / quarantine unknown event types as event_corrupt instead of aborting.

Possibly related: #1679 (model-call accounting RFC) and #1418 (one undecodable file breaking startup).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions