From cbe603703b96cbdea81e4c21b6b70a60717fcae4 Mon Sep 17 00:00:00 2001 From: Demian Hauptle Date: Wed, 8 Apr 2026 12:56:10 +0200 Subject: [PATCH] fix: relay Ask Proof comment to server ops endpoint invokeAgentOnSelection only wrote a ProseMirror mark into the local Yjs document. While a live collab session is active the server blocks projection repair (recent_live_collab_lease), so HTTP-polling agents cannot see marks written this way. This change adds a fire-and-forget POST to /api/agent/:slug/ops immediately after the local mark is created. The server ops table is written directly to SQLite, bypassing the Yjs-to-projection pipeline entirely, so any polling agent sees the Ask Proof request the moment it is submitted. The local markComment call is preserved so the mark still appears inline in the editor for the user. --- src/editor/index.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/editor/index.ts b/src/editor/index.ts index 86116fa..1b471d2 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -5414,6 +5414,30 @@ class ProofEditorImpl implements ProofEditor { if (selectedText.trim()) { // Create a comment with @proof mention to trigger the agent markComment(view, selectedText, actor, `@proof ${prompt}`, context.range); + + // Also POST to the server ops endpoint so the agent can poll it via HTTP. + // The local Yjs mark is not visible to HTTP readers while a live collab + // session is active (projection repair is blocked by the collab lease). + const slug = shareClient.getSlug(); + if (slug) { + const body = JSON.stringify({ + type: 'comment.add', + by: actor, + quote: selectedText, + text: `@proof ${prompt}`, + }); + fetch(`${shareClient.getApiBaseUrl()}/agent/${encodeURIComponent(slug)}/ops`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...shareClient.getShareAuthHeaders(), + }, + body, + }).catch((err) => { + console.warn('[invokeAgentOnSelection] Failed to POST comment to server ops:', err); + }); + } + captureEvent('agent_manual_request_queued', { trigger_type: 'comment', });