{"record":{"id":"531c8ea3989c047d","repo":"moeru-ai/airi","slug":"failed-to-handle-spark-emit-event","errorCode":null,"errorMessage":"Failed to handle spark:emit event:","messagePattern":"Failed to handle spark:emit event:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/stage-ui/src/stores/character/orchestrator/store.ts","lineNumber":288,"sourceCode":"\n    eventUnsubscribes.push(\n      modsServerChannelStore.onEvent('spark:notify', async (event) => {\n        try {\n          await handleIncomingSparkNotify(event)\n        }\n        catch (error) {\n          console.warn('Failed to handle spark:notify event:', error)\n        }\n      }),\n    )\n\n    eventUnsubscribes.push(\n      modsServerChannelStore.onEvent('spark:emit', async (event) => {\n        try {\n          await handleSparkEmit(event)\n        }\n        catch (error) {\n          console.warn('Failed to handle spark:emit event:', error)\n        }\n      }),\n    )\n\n    startTicker()\n  }\n\n  function dispose() {\n    stopTicker()\n\n    for (const unsubscribe of eventUnsubscribes) {\n      unsubscribe()\n    }\n\n    eventUnsubscribes.length = 0\n    initialized = false\n  }\n","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/stage-ui/src/stores/character/orchestrator/store.ts#L270-L306","documentation":"Twin of the spark:notify guard: the orchestrator's 'spark:emit' subscription catches any rejection from handleSparkEmit and logs it. spark:emit is the outbound path (a mod/character emitting an action or message), so a failure here means the emitted event could not be processed — payload validation, store mutation, or downstream dispatch threw.","triggerScenarios":"A mod calls spark emit with a payload the orchestrator cannot apply: unknown event type, missing fields, a store action throwing on the emitted data, or dispatch to a sink (UI/server channel) failing synchronously.","commonSituations":"Mod authored against a newer/older emit schema; emitting while the target session/store is disposed; character state missing a reference the emit tries to touch; duplicate event ids hitting a uniqueness assertion.","solutions":["Read the logged error and fix the mod's emit call or payload shape.","Align mod SDK and orchestrator versions so emit schemas match.","Avoid emitting during teardown — check store liveness in the mod or unsubscribe mods before dispose.","Add payload validation (Valibot schema) at the emit boundary so invalid events are rejected with a clear message."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const sparkEmitSchema = /* Valibot schema for emit payloads */\nfunction isSparkEmitPayload(event: unknown): boolean {\n  return sparkEmitSchema.safeParse(event).success\n}","typeGuard":null,"tryCatchPattern":"modsServerChannelStore.onEvent('spark:emit', async (event) => {\n  try {\n    await handleSparkEmit(event)\n  }\n  catch (error) {\n    console.warn('Failed to handle spark:emit event:', error)\n    // keep listener alive; report to mod author tooling\n  }\n})","preventionTips":["Version emit schemas and reject mismatched versions at the boundary.","Check store liveness before mutating on emit, especially during dispose.","Write Vitest coverage for emit payload edge cases in the orchestrator."],"tags":["orchestrator","spark","event-handler","mods","emit"],"backgroundTag":"event-handler-exception","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}