Skip to content

Commit 3ca925d

Browse files
mpstatonclaude
andcommitted
fix(search-and-add): auto-fire waits for the workspace socket — no more "workspace not connected" on first launch
The 🤖/🔍 click mounts the pane fresh; the envelope's auto-fire raced the WS connect and invoke() rejected with "workspace not connected — call workspace.connect() first" (bit the first crawl launch; the scan and term paths carried the same latent race). A fresh arrival now fires immediately when the socket is open and otherwise parks in pendingAutoFire until status flips open. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvYzx7vDWeafnkAi2nEQeb
1 parent 1d26f05 commit 3ca925d

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

apps/search-and-add/src/App.svelte

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,37 @@
128128
129129
// A fresh envelope (mount-time localStorage read counts, via arrival 0 vs
130130
// firedArrival -1) seeds the term and auto-fires exactly once. Later
131-
// operator edits + re-fires never re-trigger this.
131+
// operator edits + re-fires never re-trigger this. When the envelope
132+
// arrives at mount time the WS may still be connecting — invoke() would
133+
// reject with "workspace not connected" — so the auto-fire waits for the
134+
// socket via pendingAutoFire instead of racing it.
135+
let pendingAutoFire = $state(false);
136+
137+
function autoFire() {
138+
void (crawlMode ? crawl() : scanMode ? scan() : fire());
139+
}
140+
132141
$effect(() => {
133142
if (searchContext.arrival !== firedArrival || (firedArrival === -1 && req)) {
134143
firedArrival = searchContext.arrival;
135144
if (req) {
136145
term = req.seed_term;
137146
results = [];
138147
firedVia = null;
139-
void (crawlMode ? crawl() : scanMode ? scan() : fire());
148+
fireError = null;
149+
if (status === 'open') autoFire();
150+
else pendingAutoFire = true;
140151
}
141152
}
142153
});
143154
155+
$effect(() => {
156+
if (status === 'open' && pendingAutoFire) {
157+
pendingAutoFire = false;
158+
autoFire();
159+
}
160+
});
161+
144162
async function onAdd(url: string) {
145163
if (!req) throw new Error('no launch context — open a 🔍 from an entity card');
146164
// Crawl results carry the model's kind (and a stream's real name) —

0 commit comments

Comments
 (0)