Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix: never use completion/message id as the conversation id (Bugbot)

shukieshahf2df69929e1c
diff --git a/browser-extension/README.md b/browser-extension/README.md
index 52e77b25..0793c8af 100644
--- a/browser-extension/README.md
+++ b/browser-extension/README.md
@@ -105,6 +105,12 @@ Beacon collector (prompt → response → tool calls → `runtime.jsonl` → S3
service worker for streaming would need additional interception (deferred).
- **Single capture path.** No DOM-scraping fallback yet; if a site changes its SSE wire format, the
adapter needs updating (the live-smoke drift alarm is designed to catch this).
+- **Telemetry integrity on the injected page.** The MAIN-world interceptor and any other page script
+ share the same JS world, so the ISOLATED content script cannot cryptographically distinguish the
+ extension's own `postMessage` events from forged ones. A malicious script already running on
+ claude.ai could therefore inject fabricated chat records into the local collector. Impact is
+ telemetry *integrity* only (no credential/code exposure). A proper fix is service-worker-driven
+ MAIN injection (`chrome.scripting`) with a per-tab nonce the page can't read; deferred for V0.
> **Fixtures.** `fixtures/claude/simple-turn.sse` is a **real, sanitized** claude.ai capture
> (via `npm run record:fixtures`); the adapter is verified against it. `with-tool-call.sse` is
diff --git a/browser-extension/src/adapters/claude.ts b/browser-extension/src/adapters/claude.ts
index dbd05e49..a6adf410 100644
--- a/browser-extension/src/adapters/claude.ts
+++ b/browser-extension/src/adapters/claude.ts
@@ -86,9 +86,11 @@ class ClaudeParser implements TurnParser {
case 'message_start': {
const m = obj.message ?? {};
if (typeof m.model === 'string') this.model = m.model;
+ // The completion/message id is a per-turn id — capture it for turnId,
+ // but never use it as the conversation/session id (that comes only from
+ // the URL/request body; using message.id would mis-correlate turns).
if (typeof m.uuid === 'string') this.messageId = m.uuid;
else if (typeof m.id === 'string') this.messageId = m.id;
- if (typeof m.id === 'string' && !this.sessionId) this.sessionId = m.id;
if (typeof m.usage?.input_tokens === 'number') this.inputTokens = m.usage.input_tokens;
break;
}
@@ -140,9 +142,11 @@ class ClaudeParser implements TurnParser {
toolCalls.push({ ...entry.tool, arguments: args });
}
}
- const sessionId = this.sessionId || `claude-${this.messageId || this.reqId}`;
- // Prefer the stable assistant message id; fall back to the interceptor's
- // per-page reqId only when message_start was never seen (degenerate case).
+ // Session id comes only from the conversation id (URL/body). If truly
+ // absent, use a clearly-synthetic per-stream id — never the message id.
+ const sessionId = this.sessionId || `claude-unknown-${this.reqId}`;
+ // Turn key prefers the stable assistant message id; falls back to the
+ // interceptor's per-page reqId only when message_start was never seen.
const turnKey = this.messageId || `r${this.reqId}`;
return {
site: 'claude_web',