memorix icon indicating copy to clipboard operation
memorix copied to clipboard

normalizeOpenCode() ignores session_id from hook payload

Open grodingo opened this issue 8 months ago • 1 comments

Bug

normalizeOpenCode() in src/hooks/normalizer.ts hardcodes sessionId: "", ignoring any session_id passed in the hook payload.

Expected

Like normalizeClaude() which reads payload.session_id ?? payload.sessionId, normalizeOpenCode() should read the session ID from the payload.

Impact

  • All OpenCode observations have empty session IDs
  • Cross-session context retrieval is degraded
  • Session grouping in dashboard/timeline doesn't work for OpenCode

Additional issue

The OpenCode plugin template (generateOpenCodePlugin()) doesn't generate or inject a session_id into hook payloads either. Both the normalizer and the template need fixing.

Suggested fix

normalizer.ts:

// Before
const result = { sessionId: "", cwd: payload.cwd ?? "" };

// After  
const result = { sessionId: payload.session_id ?? payload.sessionId ?? "", cwd: payload.cwd ?? "" };

Plugin template:

// Add at plugin load
const sessionId = `opencode-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;

// Inject in runHook()
payload.session_id = sessionId;

Environment

  • Memorix v1.0.0
  • OpenCode (latest)
  • Fedora Linux

grodingo avatar Mar 10 '26 15:03 grodingo

Both issues fixed in the upcoming release:

1. Normalizer fix
ormalizeOpenCode() now reads session_id from the payload instead of hardcoding empty string:

s sessionId: (payload.session_id as string) ?? (payload.sessionId as string) ?? '',

2. Plugin template fix generateOpenCodePlugin() now generates a stable session ID on plugin load and injects it into every hook payload:

`js const sessionId = opencode--;

async function runHook(payload) { payload.session_id = sessionId; // ... } `

If you already have the plugin installed, re-run memorix installHooks opencode to regenerate, or manually patch your .opencode/plugins/memorix.js.

The fix will be in the next npm release.

AVIDS2 avatar Mar 13 '26 15:03 AVIDS2