@kabmo-labs/kabmo 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kabmo-labs/kabmo",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Web console and diagnostic workbench for AI coding agents — Elysia + Preact on Bun.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",
@@ -243,6 +243,7 @@ export function useChatTimeline({
243
243
  spawnWorktreeRef: spawn.worktreePathRef,
244
244
  abortControllerRef,
245
245
  setInputValue,
246
+ reportActionError,
246
247
  setSearchParams,
247
248
  });
248
249
 
@@ -5,224 +5,31 @@
5
5
 
6
6
  /** The send path's first half: composing and executing a send —
7
7
  * optimistic bubble, generating flag, queue fallback, and follow-up delivery.
8
- * Split verbatim from `send.test.ts` so both files stay under the repo's
9
- * 350-line ceiling; the head file keeps the steer/interrupt cases. */
8
+ * The steer/interrupt cases live in `send.test.ts` and the refusal-report
9
+ * cases in `send-refusal.test.ts`; the harness all three share is
10
+ * `send.test-util.ts`. Every file stays under the repo's 350-line ceiling. */
10
11
 
11
- import { afterEach, beforeAll, afterAll, beforeEach, describe, expect, test } from 'bun:test';
12
- import { Window } from 'happy-dom';
13
- import { h, render } from 'preact';
14
- import { act } from 'preact/test-utils';
15
- import type { ChatMessageData, OmpAgentHandle } from '@/shared/types';
12
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
16
13
  import {
17
- useChatTimelineSend,
18
- type ChatTimelineSendDeps,
19
- type ChatTimelineSendResult,
20
- } from '@/client/hooks/chat/timeline/send';
21
- import {
22
- type SessionSeed,
23
- } from '@/client/hooks/chat/timeline/session-load';
24
-
25
- const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
26
- /** The runner's own globals, restored on teardown so later files still have them. */
27
- const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
28
-
29
- /** The runner's own fetch, reached through `Bun` so a stub leaked onto the global cannot be mistaken for it. */
30
- const originalFetch = Bun.fetch;
31
- let container: HTMLElement;
14
+ act,
15
+ installDomGlobals,
16
+ makeSendHarness,
17
+ originalFetch,
18
+ requests,
19
+ restoreDomGlobals,
20
+ stubComposerFetch,
21
+ } from '@/client/hooks/chat/timeline/send.test-util';
32
22
 
33
23
  beforeAll(() => {
34
- const win = new Window({ url: 'http://localhost' });
35
- const target = globalThis as unknown as Record<string, unknown>;
36
- for (const key of DOM_GLOBALS) {
37
- if (!(key in native)) native[key] = target[key];
38
- target[key] = (win as unknown as Record<string, unknown>)[key];
39
- }
24
+ installDomGlobals();
40
25
  });
41
26
  afterAll(() => {
42
- const target = globalThis as unknown as Record<string, unknown>;
43
- for (const key of DOM_GLOBALS) {
44
- if (native[key] === undefined) delete target[key];
45
- else target[key] = native[key];
46
- }
27
+ restoreDomGlobals();
47
28
  });
48
29
  afterEach(() => {
49
- if (container) render(null, container);
50
- container?.remove();
51
30
  globalThis.fetch = originalFetch;
52
31
  });
53
32
 
54
- /** Composer autocomplete reads; answer with "no agents" so prompts pass through. */
55
- function stubComposerFetch() {
56
- globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
57
- requests.push({ url: String(input), method: init?.method ?? 'GET', body: init?.body === undefined ? null : String(init.body) });
58
- return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
59
- }) as typeof fetch;
60
- }
61
-
62
- const requests: Array<{ url: string; method: string; body: string | null }> = [];
63
-
64
- function makeMessages(): { messages: ChatMessageData[]; setLocalMessages: ChatTimelineSendDeps['setLocalMessages'] } {
65
- const messages: ChatMessageData[] = [];
66
- return {
67
- messages,
68
- setLocalMessages: (next) => {
69
- const resolved = typeof next === 'function' ? next(messages) : next;
70
- messages.splice(0, messages.length, ...resolved);
71
- },
72
- };
73
- }
74
-
75
- /** Everything the send path pushed onto the agent, plus the canned outcomes. */
76
- interface AgentCalls {
77
- prompts: Array<{ text: string; images: unknown; options: unknown }>;
78
- newPrompts: Array<{ text: string; cwd: string; options: unknown }>;
79
- models: Array<[string, string]>;
80
- levels: string[];
81
- interrupts: Array<{ text: string; images: unknown }>;
82
- sendPromptOk: boolean;
83
- /** omp's typed mid-turn refusal (nothing delivered, safe to queue). */
84
- sendPromptBusy: boolean;
85
- spawnResult: { sessionId: string; model?: { provider: string; modelId: string } } | null;
86
- }
87
-
88
- interface AgentRecorder {
89
- calls: AgentCalls;
90
- agent: OmpAgentHandle;
91
- }
92
-
93
- function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
94
- const calls: AgentCalls = {
95
- prompts: [],
96
- newPrompts: [],
97
- models: [],
98
- levels: [],
99
- interrupts: [],
100
- sendPromptOk: true,
101
- sendPromptBusy: false,
102
- spawnResult: null,
103
- ...overrides,
104
- };
105
- const agent = {
106
- sendPrompt: async (text: string, images: unknown, options: unknown) => {
107
- calls.prompts.push({ text, images, options });
108
- return { ok: calls.sendPromptOk, busy: calls.sendPromptBusy };
109
- },
110
- sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
111
- calls.newPrompts.push({ text, cwd, options });
112
- return calls.spawnResult;
113
- },
114
- steerOmpRun: async (text: string, images: unknown) => {
115
- calls.interrupts.push({ text, images });
116
- return { ok: calls.sendPromptOk, busy: false };
117
- },
118
- setModel: async (provider: string, modelId: string) => {
119
- calls.models.push([provider, modelId]);
120
- },
121
- setThinkingLevel: async (level: string) => {
122
- calls.levels.push(level);
123
- },
124
- } as unknown as OmpAgentHandle;
125
- return { calls, agent };
126
- }
127
-
128
- interface SendHarness {
129
- sends: ChatTimelineSendResult;
130
- deps: ChatTimelineSendDeps;
131
- agent: AgentRecorder;
132
- state: { messages: ChatMessageData[] };
133
- persisted: ChatMessageData[][];
134
- generating: boolean[];
135
- drafts: string[];
136
- params: string[];
137
- seeds: SessionSeed[];
138
- spawnSelectionRef: { current: { plan: boolean; goal: boolean } | null };
139
- adoptedSessionIdRef: { current: string | null };
140
- }
141
-
142
- function makeSendHarness(options: {
143
- isOmpSession?: boolean;
144
- folders?: any[];
145
- selectedFolderId?: number | null;
146
- sessionId?: string | null;
147
- agent?: Partial<AgentCalls> | AgentRecorder;
148
- deferredPick?: { current: any };
149
- } = {}): SendHarness {
150
- const { messages, setLocalMessages } = makeMessages();
151
- // `options.agent` is either overrides for the recorder's `AgentCalls` or
152
- // the finished recorder itself; the two forms are told apart by shape.
153
- const agent: AgentRecorder =
154
- options.agent && 'calls' in options.agent
155
- ? options.agent
156
- : makeAgent(options.agent);
157
- const persisted: ChatMessageData[][] = [];
158
- const generating: boolean[] = [];
159
- const drafts: string[] = [];
160
- const params: string[] = [];
161
- const seeds: SessionSeed[] = [];
162
- const spawnSelectionRef = { current: { plan: true, goal: false } };
163
- const spawnWorktreeRef = { current: null as string | null };
164
- const adoptedSessionIdRef = { current: null };
165
- const deps: ChatTimelineSendDeps = {
166
- folders: options.folders ?? [],
167
- selectedFolderId: options.selectedFolderId ?? null,
168
- sessionId: options.sessionId === undefined ? 'sess-1' : options.sessionId,
169
- isOmpSession: options.isOmpSession ?? true,
170
- appSettings: {},
171
- ompAgent: agent.agent,
172
- setLocalMessages,
173
- persistMessages: (msgs) => {
174
- persisted.push(msgs);
175
- },
176
- setGenerating: (v) => {
177
- generating.push(v);
178
- },
179
- setGeneratingVerb: () => {},
180
- scrollToBottom: () => {},
181
- jumpToBottom: () => {},
182
- aiPlaceholderIdRef: { current: null },
183
- adoptedSessionIdRef,
184
- optimisticUserIdRef: { current: null },
185
- pendingUserDisplaysRef: { current: [] },
186
- seedSession: (seed) => {
187
- seeds.push(seed);
188
- },
189
- pendingComposerModelRef: { current: null },
190
- pendingThinkingLevelRef: { current: null },
191
- deferredComposerPickRef: options.deferredPick ?? { current: null },
192
- accessModeRef: { current: 'always-ask' },
193
- spawnSelectionRef,
194
- spawnWorktreeRef,
195
- abortControllerRef: { current: null },
196
- setInputValue: (v) => {
197
- drafts.push(v);
198
- },
199
- setSearchParams: (fn) => {
200
- params.push(fn(new URLSearchParams('sessionId=new-1')).toString());
201
- },
202
- };
203
- let sends: ChatTimelineSendResult | null = null;
204
- const Probe = () => {
205
- sends = useChatTimelineSend(deps);
206
- return h('div', { id: 'send-probe' });
207
- };
208
- container ??= document.body.appendChild(document.createElement('div'));
209
- render(h(Probe, {}), container as HTMLElement);
210
- return {
211
- sends: sends as unknown as ChatTimelineSendResult,
212
- deps,
213
- agent,
214
- state: { messages },
215
- persisted,
216
- generating,
217
- drafts,
218
- params,
219
- seeds,
220
- spawnSelectionRef,
221
- adoptedSessionIdRef,
222
- };
223
- }
224
-
225
-
226
33
  describe('executeSend', () => {
227
34
  beforeEach(() => {
228
35
  requests.length = 0;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * How the send path REPORTS a refusal.
8
+ *
9
+ * The optimistic bubbles are rolled back either way, so without a report the
10
+ * operator's turn simply VANISHES — which is the reported "gagal kirim prompt":
11
+ * the send did not go out and nothing said why. The server's own reason (a
12
+ * child that could not start, a session another process owns) is what makes
13
+ * the difference between "it failed" and "here is what to do".
14
+ *
15
+ * Split from `send-execute.test.ts` (which owns composing and executing a
16
+ * send) so both files stay under the repo's 350-line ceiling; the harness is
17
+ * shared through `send.test-util.ts`.
18
+ */
19
+
20
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
21
+ import { act, installDomGlobals, makeSendHarness, originalFetch, requests, restoreDomGlobals, stubComposerFetch } from '@/client/hooks/chat/timeline/send.test-util';
22
+
23
+ beforeAll(() => {
24
+ installDomGlobals();
25
+ });
26
+ afterAll(() => {
27
+ restoreDomGlobals();
28
+ });
29
+ afterEach(() => {
30
+ globalThis.fetch = originalFetch;
31
+ });
32
+
33
+ describe('a refused send', () => {
34
+ beforeEach(() => {
35
+ requests.length = 0;
36
+ stubComposerFetch();
37
+ });
38
+
39
+ test("reports the server's own reason", async () => {
40
+ const h1 = makeSendHarness({
41
+ agent: { sendPromptOk: false, sendPromptError: 'omp exited (code 1): Could not restore model a/b' },
42
+ });
43
+ await act(async () => {
44
+ await h1.sends.executeSend('hello', []);
45
+ });
46
+ expect(h1.reported).toEqual(['Prompt not sent: omp exited (code 1): Could not restore model a/b']);
47
+ });
48
+
49
+ test('still reports a refusal that carries no reason', async () => {
50
+ const h1 = makeSendHarness({ agent: { sendPromptOk: false } });
51
+ await act(async () => {
52
+ await h1.sends.executeSend('hello', []);
53
+ });
54
+ expect(h1.reported).toEqual(['Prompt not sent: the session refused it']);
55
+ });
56
+
57
+ test('is rolled back as well as reported', async () => {
58
+ const h1 = makeSendHarness({ agent: { sendPromptOk: false } });
59
+ await act(async () => {
60
+ await h1.sends.executeSend('hello', []);
61
+ });
62
+ expect(h1.state.messages).toEqual([]);
63
+ });
64
+
65
+ test('a DELIVERED send reports nothing', async () => {
66
+ const h1 = makeSendHarness();
67
+ await act(async () => {
68
+ await h1.sends.executeSend('hello', []);
69
+ });
70
+ expect(h1.reported).toEqual([]);
71
+ });
72
+ });
@@ -187,6 +187,7 @@ function makeSendHarness(options: {
187
187
  setInputValue: (v) => {
188
188
  drafts.push(v);
189
189
  },
190
+ reportActionError: () => {},
190
191
  setSearchParams: (fn) => {
191
192
  params.push(fn(new URLSearchParams('sessionId=new-1')).toString());
192
193
  },
@@ -0,0 +1,245 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The shared harness behind the two halves of the send path's test suite
8
+ * (`send-execute.test.ts` for composing/executing, `send-refusal.test.ts` for
9
+ * how a REFUSAL is reported).
10
+ *
11
+ * Split out of the test files because both need the same recorder and the same
12
+ * mounted `useChatTimelineSend` probe, and because copying it into a second
13
+ * file is how the two ends drift — the recorder is what a case asserts on, so
14
+ * a copy that lost a field would make a test pass for the wrong reason.
15
+ */
16
+
17
+ import { Window } from 'happy-dom';
18
+ import { h, render } from 'preact';
19
+ import { act } from 'preact/test-utils';
20
+ import type { ChatMessageData, OmpAgentHandle } from '@/shared/types';
21
+ import {
22
+ useChatTimelineSend,
23
+ type ChatTimelineSendDeps,
24
+ type ChatTimelineSendResult,
25
+ } from '@/client/hooks/chat/timeline/send';
26
+ import type { SessionSeed } from '@/client/hooks/chat/timeline/session-load';
27
+
28
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
29
+
30
+ let installed: { restore: () => void } | null = null;
31
+
32
+ /**
33
+ * Give the file a DOM. Idempotent per process, and the restore puts the
34
+ * runner's own globals back so later files are unaffected.
35
+ */
36
+ export function installDomGlobals(): void {
37
+ if (installed) return;
38
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
39
+ const win = new Window({ url: 'http://localhost' });
40
+ const target = globalThis as unknown as Record<string, unknown>;
41
+ for (const key of DOM_GLOBALS) {
42
+ native[key] = target[key];
43
+ target[key] = (win as unknown as Record<string, unknown>)[key];
44
+ }
45
+ installed = {
46
+ restore: () => {
47
+ for (const key of DOM_GLOBALS) {
48
+ if (native[key] === undefined) delete target[key];
49
+ else target[key] = native[key];
50
+ }
51
+ installed = null;
52
+ },
53
+ };
54
+ }
55
+
56
+ export function restoreDomGlobals(): void {
57
+ installed?.restore();
58
+ }
59
+
60
+ /** The runner's own fetch, reached through `Bun` so a leaked stub cannot be mistaken for it. */
61
+ export const originalFetch = Bun.fetch;
62
+
63
+ export const requests: Array<{ url: string; method: string; body: string | null }> = [];
64
+
65
+ /** Composer autocomplete reads; answer with "no agents" so prompts pass through. */
66
+ export function stubComposerFetch(): void {
67
+ globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
68
+ requests.push({ url: String(input), method: init?.method ?? 'GET', body: init?.body === undefined ? null : String(init.body) });
69
+ return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
70
+ }) as typeof fetch;
71
+ }
72
+
73
+ function makeMessages(): { messages: ChatMessageData[]; setLocalMessages: ChatTimelineSendDeps['setLocalMessages'] } {
74
+ const messages: ChatMessageData[] = [];
75
+ return {
76
+ messages,
77
+ setLocalMessages: (next) => {
78
+ const resolved = typeof next === 'function' ? next(messages) : next;
79
+ messages.splice(0, messages.length, ...resolved);
80
+ },
81
+ };
82
+ }
83
+
84
+ /** Everything the send path pushed onto the agent, plus the canned outcomes. */
85
+ export interface AgentCalls {
86
+ prompts: Array<{ text: string; images: unknown; options: unknown }>;
87
+ newPrompts: Array<{ text: string; cwd: string; options: unknown }>;
88
+ models: Array<[string, string]>;
89
+ levels: string[];
90
+ interrupts: Array<{ text: string; images: unknown }>;
91
+ sendPromptOk: boolean;
92
+ /** omp's typed mid-turn refusal (nothing delivered, safe to queue). */
93
+ sendPromptBusy: boolean;
94
+ /** The server-supplied reason, when the send was refused. */
95
+ sendPromptError: string | undefined;
96
+ spawnResult: { sessionId: string; model?: { provider: string; modelId: string } } | null;
97
+ }
98
+
99
+ export interface AgentRecorder {
100
+ calls: AgentCalls;
101
+ agent: OmpAgentHandle;
102
+ }
103
+
104
+ export function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
105
+ const calls: AgentCalls = {
106
+ prompts: [],
107
+ newPrompts: [],
108
+ models: [],
109
+ levels: [],
110
+ interrupts: [],
111
+ sendPromptOk: true,
112
+ sendPromptBusy: false,
113
+ sendPromptError: undefined,
114
+ spawnResult: null,
115
+ ...overrides,
116
+ };
117
+ const agent = {
118
+ sendPrompt: async (text: string, images: unknown, options: unknown) => {
119
+ calls.prompts.push({ text, images, options });
120
+ return { ok: calls.sendPromptOk, busy: calls.sendPromptBusy, error: calls.sendPromptError };
121
+ },
122
+ sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
123
+ calls.newPrompts.push({ text, cwd, options });
124
+ return calls.spawnResult;
125
+ },
126
+ steerOmpRun: async (text: string, images: unknown) => {
127
+ calls.interrupts.push({ text, images });
128
+ return { ok: calls.sendPromptOk, busy: false, error: calls.sendPromptError };
129
+ },
130
+ setModel: async (provider: string, modelId: string) => {
131
+ calls.models.push([provider, modelId]);
132
+ },
133
+ setThinkingLevel: async (level: string) => {
134
+ calls.levels.push(level);
135
+ },
136
+ } as unknown as OmpAgentHandle;
137
+ return { calls, agent };
138
+ }
139
+
140
+ export interface SendHarness {
141
+ sends: ChatTimelineSendResult;
142
+ deps: ChatTimelineSendDeps;
143
+ agent: AgentRecorder;
144
+ state: { messages: ChatMessageData[] };
145
+ persisted: ChatMessageData[][];
146
+ generating: boolean[];
147
+ drafts: string[];
148
+ /** Every message the send path REPORTED (the toast channel). */
149
+ reported: string[];
150
+ params: string[];
151
+ seeds: SessionSeed[];
152
+ spawnSelectionRef: { current: { plan: boolean; goal: boolean } | null };
153
+ adoptedSessionIdRef: { current: string | null };
154
+ }
155
+
156
+ export function makeSendHarness(options: {
157
+ folders?: unknown[];
158
+ selectedFolderId?: number | null;
159
+ sessionId?: string | null;
160
+ isOmpSession?: boolean;
161
+ agent?: AgentRecorder | Partial<AgentCalls>;
162
+ deferredPick?: { current: unknown };
163
+ } = {}): SendHarness {
164
+ installDomGlobals();
165
+ const { messages, setLocalMessages } = makeMessages();
166
+ // `options.agent` is either overrides for the recorder's `AgentCalls` or
167
+ // the finished recorder itself; the two forms are told apart by shape.
168
+ const agent: AgentRecorder =
169
+ options.agent && 'calls' in options.agent
170
+ ? options.agent
171
+ : makeAgent(options.agent);
172
+ const persisted: ChatMessageData[][] = [];
173
+ const generating: boolean[] = [];
174
+ const drafts: string[] = [];
175
+ const reported: string[] = [];
176
+ const params: string[] = [];
177
+ const seeds: SessionSeed[] = [];
178
+ const spawnSelectionRef = { current: { plan: true, goal: false } };
179
+ const spawnWorktreeRef = { current: null as string | null };
180
+ const adoptedSessionIdRef = { current: null };
181
+ const deps: ChatTimelineSendDeps = {
182
+ folders: (options.folders ?? []) as ChatTimelineSendDeps['folders'],
183
+ selectedFolderId: options.selectedFolderId ?? null,
184
+ sessionId: options.sessionId === undefined ? 'sess-1' : options.sessionId,
185
+ isOmpSession: options.isOmpSession ?? true,
186
+ appSettings: {},
187
+ ompAgent: agent.agent,
188
+ setLocalMessages,
189
+ persistMessages: (msgs) => {
190
+ persisted.push(msgs);
191
+ },
192
+ setGenerating: (v) => {
193
+ generating.push(v);
194
+ },
195
+ setGeneratingVerb: () => {},
196
+ scrollToBottom: () => {},
197
+ jumpToBottom: () => {},
198
+ aiPlaceholderIdRef: { current: null },
199
+ adoptedSessionIdRef,
200
+ optimisticUserIdRef: { current: null },
201
+ pendingUserDisplaysRef: { current: [] },
202
+ seedSession: (seed) => {
203
+ seeds.push(seed);
204
+ },
205
+ pendingComposerModelRef: { current: null },
206
+ pendingThinkingLevelRef: { current: null },
207
+ deferredComposerPickRef: (options.deferredPick ?? { current: null }) as ChatTimelineSendDeps['deferredComposerPickRef'],
208
+ accessModeRef: { current: 'always-ask' },
209
+ spawnSelectionRef,
210
+ spawnWorktreeRef,
211
+ abortControllerRef: { current: null },
212
+ setInputValue: (v) => {
213
+ drafts.push(v);
214
+ },
215
+ reportActionError: (message: string) => {
216
+ reported.push(message);
217
+ },
218
+ setSearchParams: (fn) => {
219
+ params.push(fn(new URLSearchParams('sessionId=new-1')).toString());
220
+ },
221
+ };
222
+ let sends: ChatTimelineSendResult | null = null;
223
+ const Probe = () => {
224
+ sends = useChatTimelineSend(deps);
225
+ return h('div', { id: 'send-probe' });
226
+ };
227
+ const container = document.body.appendChild(document.createElement('div'));
228
+ render(h(Probe, {}), container as HTMLElement);
229
+ return {
230
+ sends: sends as unknown as ChatTimelineSendResult,
231
+ deps,
232
+ agent,
233
+ state: { messages },
234
+ persisted,
235
+ generating,
236
+ drafts,
237
+ reported,
238
+ params,
239
+ seeds,
240
+ spawnSelectionRef,
241
+ adoptedSessionIdRef,
242
+ };
243
+ }
244
+
245
+ export { act };
@@ -187,6 +187,7 @@ function makeSendHarness(options: {
187
187
  setInputValue: (v) => {
188
188
  drafts.push(v);
189
189
  },
190
+ reportActionError: () => {},
190
191
  setSearchParams: (fn) => {
191
192
  params.push(fn(new URLSearchParams('sessionId=new-1')).toString());
192
193
  },
@@ -70,6 +70,10 @@ export interface ChatTimelineSendDeps {
70
70
  deferredComposerPickRef: DeferredModelStore;
71
71
  abortControllerRef: { current: AbortController | null };
72
72
  setInputValue: (v: string) => void;
73
+ /** Surface a refused send. The optimistic bubbles are rolled back either
74
+ * way; without this the operator's turn simply VANISHES, which is the
75
+ * "prompt failed to send" report this exists to answer. */
76
+ reportActionError: (message: string) => void;
73
77
  setSearchParams: (fn: (prev: URLSearchParams) => URLSearchParams, opts?: { replace?: boolean }) => void;
74
78
  }
75
79
 
@@ -114,6 +118,7 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
114
118
  spawnWorktreeRef,
115
119
  abortControllerRef,
116
120
  setInputValue,
121
+ reportActionError,
117
122
  setSearchParams,
118
123
  } = deps;
119
124
 
@@ -233,6 +238,11 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
233
238
  aiPlaceholderIdRef.current = null;
234
239
  optimisticUserIdRef.current = null;
235
240
  setGenerating(false);
241
+ // And SAY so. The rollback alone left the operator's turn vanishing
242
+ // with no explanation, which is the reported "gagal kirim prompt": the
243
+ // server's reason (a dead child, a session another process owns) was
244
+ // computed and then dropped on the floor.
245
+ reportActionError(`Prompt not sent: ${result.error ?? 'the session refused it'}`);
236
246
  }
237
247
  return result;
238
248
  }
@@ -14,6 +14,7 @@ import { pathExists } from '@/server/lib/omp/core/paths';
14
14
  import { kabmoExtensionArgs } from '@/server/lib/omp/extensions/locator';
15
15
  import { ensureTitleModelOverlay, titleModelOverlayPath } from '@/server/lib/omp/session/title-model-overlay.server';
16
16
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
17
+ import type { SelectedModel } from '@/shared/types/models';
17
18
 
18
19
  export interface AgentEvent {
19
20
  type: string;
@@ -279,7 +280,11 @@ export async function resolveSpawnCwd(recordedCwd?: string | null): Promise<stri
279
280
  * reaches omp's title generation: the child watches that path, so
280
281
  * `rename-with-ai` rewrites the `tiny` role for the duration of one request.
281
282
  * See `session/title-model-overlay.server.ts`. */
282
- export function buildSessionSpawnArgs(sessionFile: string, approvalMode?: ApprovalMode): string[] {
283
+ export function buildSessionSpawnArgs(
284
+ sessionFile: string,
285
+ approvalMode?: ApprovalMode,
286
+ resumeModel?: SelectedModel,
287
+ ): string[] {
283
288
  const args: string[] = [];
284
289
  ensureTitleModelOverlay();
285
290
  args.push('--config', titleModelOverlayPath());
@@ -289,6 +294,15 @@ export function buildSessionSpawnArgs(sessionFile: string, approvalMode?: Approv
289
294
  // resume/fork prompts.
290
295
  args.push('--resume', sessionFile);
291
296
  }
297
+ // The model the session is RESTORED with. omp restores the model its
298
+ // transcript's last `model_change` names, and it does NOT fall back when
299
+ // that model is no longer in the registry: the child exits(1) with
300
+ // "Could not restore model <provider>/<id>" and every command to the
301
+ // session fails with it. `--model` names a model that DOES resolve, so a
302
+ // session whose recorded model is gone still starts.
303
+ if (resumeModel?.provider && resumeModel.modelId) {
304
+ args.push('--model', `${resumeModel.provider}/${resumeModel.modelId}`);
305
+ }
292
306
  if (approvalMode) {
293
307
  // Spawn-time only: omp exposes no RPC command to change the tool-approval
294
308
  // mode, so the flag is the sole lever. It works with or without --resume.
@@ -346,5 +346,5 @@ export class AgentSessionWrapper {
346
346
  }
347
347
  }
348
348
 
349
- export { getRpcSession, startRpcSession, prewarmRpcSession, startNewRpcSession } from '@/server/lib/omp/rpc/session-registry';
349
+ export { getRpcSession, startRpcSession, startNewRpcSession } from '@/server/lib/omp/rpc/session-registry';
350
350
  export { getSpawnApprovalMode, getSpawnModeEnv, reconcileSpawnApprovalMode } from '@/server/lib/omp/rpc/spawn-provenance';