Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (round 11): omit pending convId, single-settle CLI promise

Adam Eivy24a5e450d1a9
diff --git a/client/src/pages/Ask.jsx b/client/src/pages/Ask.jsx
index caf11b3091..00671568f1 100644
--- a/client/src/pages/Ask.jsx
+++ b/client/src/pages/Ask.jsx
@@ -4,6 +4,11 @@ import { Send, Loader2, MessageCircle, Trash2, Pin, Brain, Calendar, Target, Boo
import * as api from '../services/api';
import toast from '../components/ui/Toast';
+// Mirrors the server-side ID_RE in askConversations.js — used to skip
+// forwarding the optimistic 'pending' placeholder (which would 400) while
+// still letting any real persisted id pass through.
+const CONV_ID_RE = /^ask_[a-z0-9]+_[a-f0-9]+$/;
+
export const ASK_MODES = [
{ id: 'ask', label: 'Ask', help: 'Answer as yourself, grounded in your own notes and goals.' },
{ id: 'advise', label: 'Advise', help: 'Coach you using your goals and constraints — push back where they conflict.' },
@@ -275,13 +280,18 @@ export default function Ask() {
: { id: 'pending', title: trimmed.slice(0, 80), mode, turns: [optimisticUserTurn], createdAt: nowIso, updatedAt: nowIso },
);
- let serverConvId = activeConv?.id;
+ // Only forward conversationId when it's a real persisted id. The
+ // optimistic 'pending' placeholder (set when sending in a fresh
+ // conversation) would fail server-side regex validation as a 400; in that
+ // case we omit the field so the server creates a new conversation.
+ const persistedConvId = activeConv?.id && CONV_ID_RE.test(activeConv.id) ? activeConv.id : undefined;
+ let serverConvId = persistedConvId;
let collectedSources = [];
let answer = '';
let persistedTurn = null;
await api.streamAskTurn(
- { conversationId: activeConv?.id, question: trimmed, mode },
+ { conversationId: persistedConvId, question: trimmed, mode },
{
signal: controller.signal,
onEvent: ({ event, data }) => {
diff --git a/server/services/askService.js b/server/services/askService.js
index 8e01cc9b0a..a9c52676b6 100644
--- a/server/services/askService.js
+++ b/server/services/askService.js
@@ -497,21 +497,47 @@ async function* streamCompletion(provider, model, prompt, signal) {
shell: false,
windowsHide: true,
});
+
+ // Single settlement gate — the timer, the abort listener, and the close
+ // handler are all racing each other. Without a settled flag, SIGKILL on a
+ // platform that doesn't kill the child synchronously would let the timer
+ // fire later and try to settle a Promise that's already done.
+ let settled = false;
+ let timer = null;
+ const cleanup = () => {
+ if (timer) { clearTimeout(timer); timer = null; }
+ signal?.removeEventListener('abort', onAbort);
+ };
+ const settle = (fn, value) => {
+ if (settled) return;
+ settled = true;
+ cleanup();
+ fn(value);
+ };
+
child.stdout.on('data', (d) => { buf += d.toString(); });
child.stderr.on('data', (d) => { buf += d.toString(); });
- const timer = setTimeout(() => { child.kill('SIGKILL'); reject(new Error('CLI timed out')); }, provider.timeout || 300000);
- const onAbort = () => { child.kill('SIGKILL'); reject(new Error('aborted')); };
+
+ timer = setTimeout(() => {
+ child.kill('SIGKILL');
+ settle(reject, new Error('CLI timed out'));
+ }, provider.timeout || 300000);
+
+ function onAbort() {
+ child.kill('SIGKILL');
+ settle(reject, new Error('aborted'));
+ }
if (signal) {
if (signal.aborted) { onAbort(); return; }
signal.addEventListener('abort', onAbort, { once: true });
}
+
child.on('close', (code) => {
- clearTimeout(timer);
- signal?.removeEventListener('abort', onAbort);
- if (code === 0) resolve(buf);
- else reject(new Error(`CLI exited ${code}: ${buf.slice(0, 500)}`));
+ if (code === 0) settle(resolve, buf);
+ else settle(reject, new Error(`CLI exited ${code}: ${buf.slice(0, 500)}`));
});
- child.on('error', (err) => { clearTimeout(timer); signal?.removeEventListener('abort', onAbort); reject(err); });
+ child.on('error', (err) => { settle(reject, err); });
+
// Pipe the prompt in via stdin so we never blow the OS argv limit on
// long retrieval-augmented prompts.
child.stdin.on('error', () => { /* child may close stdin first; the close handler resolves */ });