@yuriai/web 0.1.23 → 0.1.25
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/dist/assets/{AssistantView-Cl8dtJE-.js → AssistantView-DkkL7s7i.js} +3 -3
- package/dist/assets/{DiagramView-zXlQky2c.js → DiagramView-DOMsCmU-.js} +1 -1
- package/dist/assets/{MarkdownRenderer-C1PXw_8U.js → MarkdownRenderer-AN4GlC9h.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-CWVOJcvk.js → MarkdownRendererImpl-CsUiqm29.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-BwkPAY1P.js → MarkstreamRendererImpl-DjXQ9X9C.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-B4ZBK4cl.js → MobileDetailNavigation-DFB8rg9g.js} +1 -1
- package/dist/assets/{MobileShareBridge-B5LUJJ99.js → MobileShareBridge-C_jmYsbd.js} +1 -1
- package/dist/assets/{MobileTabPageHeader-CkUhuZP6.js → MobileTabPageHeader-CMBzNZBy.js} +1 -1
- package/dist/assets/{MultiRunWindow-CqNrUij5.js → MultiRunWindow-DxMv9jKP.js} +1 -1
- package/dist/assets/{OverlayScrollbar-eBG-DXgX.js → OverlayScrollbar-CWK4F7aC.js} +1 -1
- package/dist/assets/{SettingsView-vZx4AKc1.js → SettingsView-BEq5cvqg.js} +1 -1
- package/dist/assets/{SettingsWindow-Rqxks-AG.js → SettingsWindow-9bYkuKIe.js} +1 -1
- package/dist/assets/{TerminalView-CGYEbWpv.js → TerminalView-COipduNh.js} +1 -1
- package/dist/assets/{ToolOutputDialog-B24XEhve.js → ToolOutputDialog-BjDrr974.js} +1 -1
- package/dist/assets/{appThemeRegistry-DD8LRHDT.js → appThemeRegistry-iidW7at3.js} +1 -1
- package/dist/assets/{capgoAdapter-BCy22KX-.js → capgoAdapter-0DA9TWMV.js} +1 -1
- package/dist/assets/{dropdown-menu.styles-BqAI_N66.js → dropdown-menu.styles-3mrmi5fY.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-CnxrRlNO.js → fileMentionTouchSelection-EkYevl92.js} +1 -1
- package/dist/assets/{gitApi-D3cHH50Y.js → gitApi-VD_SyM5W.js} +1 -1
- package/dist/assets/{insertionBoundaries-19EJsmCA.js → insertionBoundaries-ClmJX_-D.js} +1 -1
- package/dist/assets/{main-BO2UnYBd.js → main--YSyKf8-.js} +2 -2
- package/dist/assets/{main-b2a4ZRXC.js → main-Bsg4OQ34.js} +4 -4
- package/dist/assets/{mcpQueries-BBt1ELI8.js → mcpQueries-DYzvdfmI.js} +1 -1
- package/dist/assets/{miniChat-BpvsuSKB.js → miniChat-kz5eiEfP.js} +2 -2
- package/dist/assets/{mobile-CyklTbWh.js → mobile-hiPGrOul.js} +2 -2
- package/dist/assets/{mobileBackNavigation-Df81BnZ5.js → mobileBackNavigation-COcmVsJC.js} +1 -1
- package/dist/assets/{multirun-BrpKcjYv.js → multirun-Ra40sNkO.js} +1 -1
- package/dist/assets/{native-config-C3EM05Jz.js → native-config-lUVS3vdZ.js} +1 -1
- package/dist/assets/{platform-CCTs9UKZ.js → platform-BT4vb0rs.js} +2 -2
- package/dist/assets/{projectMeta-DOs0HlSf.js → projectMeta-DViOvoUL.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-DaeIwT-e.js → renderElectronMiniChatApp-BWISO2T9.js} +2 -2
- package/dist/assets/{renderMobileApp-C-Rhiqyk.js → renderMobileApp-ucbAF6Ej.js} +4 -4
- package/dist/assets/{runtimeConfig-CQ3TyMLm.js → runtimeConfig-BdRmjg3v.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-CINPdy23.js → runtimeEndpointReset-D6LiKcAj.js} +1 -1
- package/dist/assets/{scheduledTaskNavigation-FME9NQYP.js → scheduledTaskNavigation-meXpw7b3.js} +1 -1
- package/dist/assets/{sessionChangeSummary-DYp-0K8f.js → sessionChangeSummary-DNE_sFSd.js} +1 -1
- package/dist/assets/{sessionLookup-BMSCT9Y1.js → sessionLookup-76lCzcL6.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-DiXAHgws.js → sortable-tabs-strip-Qxgcs21u.js} +1 -1
- package/dist/assets/{speechSettingsQueries-Ci2kILTe.js → speechSettingsQueries-DIrdNQ5r.js} +1 -1
- package/dist/assets/{terminalApi-DhXTmxps.js → terminalApi-bFOdIit8.js} +1 -1
- package/dist/assets/{textarea-BZhmG_bD.js → textarea-bZ1VMrmO.js} +1 -1
- package/dist/assets/{types-Du8LnIGl.js → types-CjeWmPyo.js} +1 -1
- package/dist/assets/{useAppFontEffects-C-CZuq33.js → useAppFontEffects-BO_mYJwk.js} +5 -5
- package/dist/assets/{useDesktopWindowControlsLayout-C8BGnh2S.js → useDesktopWindowControlsLayout-Xmk-iiF6.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-B85HOZow.js → useEffectiveDirectory-i9j_KNIu.js} +1 -1
- package/dist/assets/{useFontPreferences-CMyrMAmq.js → useFontPreferences-Daujs94n.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-_8410bpu.js → useMobileNavigationStore-_DBQumPX.js} +4 -4
- package/dist/assets/{useWorkerHighlightedLines-D4HmbcHr.js → useWorkerHighlightedLines-DqPxA031.js} +1 -1
- package/dist/index.html +7 -7
- package/dist/mini-chat.html +7 -7
- package/dist/mobile.html +7 -7
- package/package.json +1 -1
- package/server/index.js +1 -12
- package/server/lib/content-search/DOCUMENTATION.md +29 -13
- package/server/lib/content-search/event-ingest.integration.test.js +52 -0
- package/server/lib/content-search/event-repair.test.js +48 -0
- package/server/lib/content-search/index.js +3 -2
- package/server/lib/content-search/runtime.js +51 -10
- package/server/lib/content-search/runtime.test.js +72 -1
- package/server/lib/content-search/service.js +19 -2
- package/server/lib/opencode/lifecycle.js +19 -1
- package/server/lib/question-auto-delegate/DOCUMENTATION.md +5 -1
- package/server/lib/question-auto-delegate/core.d.ts +2 -2
- package/server/lib/question-auto-delegate/runtime.js +11 -27
- package/server/lib/question-auto-delegate/runtime.test.js +25 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +5 -0
- package/server/lib/scheduled-tasks/runtime.js +16 -0
- package/server/lib/scheduled-tasks/runtime.test.js +33 -0
|
@@ -22,6 +22,7 @@ export function createContentSearchService({ dbPath }) {
|
|
|
22
22
|
CREATE TABLE IF NOT EXISTS search_message(id INTEGER PRIMARY KEY, runtime TEXT, session TEXT, message TEXT, role TEXT, created REAL, body TEXT, UNIQUE(runtime,session,message));
|
|
23
23
|
CREATE INDEX IF NOT EXISTS search_message_scope ON search_message(runtime,session);
|
|
24
24
|
CREATE TABLE IF NOT EXISTS search_coverage(runtime TEXT PRIMARY KEY, started_at REAL NOT NULL, completed_at REAL, since REAL, verified_at REAL);
|
|
25
|
+
CREATE TABLE IF NOT EXISTS search_dirty(runtime TEXT, id TEXT, revision INTEGER NOT NULL, PRIMARY KEY(runtime,id));
|
|
25
26
|
CREATE VIRTUAL TABLE IF NOT EXISTS search_fts USING fts5(body, content='search_message', content_rowid='id', tokenize='trigram');
|
|
26
27
|
CREATE TRIGGER IF NOT EXISTS search_insert AFTER INSERT ON search_message BEGIN
|
|
27
28
|
INSERT INTO search_fts(rowid,body) VALUES(new.id,new.body); END;
|
|
@@ -35,23 +36,39 @@ export function createContentSearchService({ dbPath }) {
|
|
|
35
36
|
if (!sessionColumns.some((column) => column.name === 'indexed_at')) {
|
|
36
37
|
db.exec('ALTER TABLE search_session ADD COLUMN indexed_at REAL');
|
|
37
38
|
}
|
|
39
|
+
if (!db.prepare('PRAGMA table_info(search_coverage)').all().some((column) => column.name === 'event_identity_repaired')) {
|
|
40
|
+
db.exec('ALTER TABLE search_coverage ADD COLUMN event_identity_repaired INTEGER NOT NULL DEFAULT 0');
|
|
41
|
+
}
|
|
38
42
|
const remove = db.prepare('DELETE FROM search_message WHERE runtime=? AND session=?');
|
|
39
43
|
const write = db.prepare('INSERT INTO search_message(runtime,session,message,role,created,body) VALUES(?,?,?,?,?,?)');
|
|
40
44
|
const removeSession = db.transaction((runtime, id) => {
|
|
41
45
|
remove.run(runtime, id);
|
|
42
46
|
db.prepare('DELETE FROM search_session WHERE runtime=? AND id=?').run(runtime, id);
|
|
47
|
+
db.prepare('DELETE FROM search_dirty WHERE runtime=? AND id=?').run(runtime, id);
|
|
43
48
|
});
|
|
44
49
|
return {
|
|
50
|
+
markDirty(runtime, id) {
|
|
51
|
+
db.prepare('INSERT INTO search_dirty(runtime,id,revision) VALUES(?,?,1) ON CONFLICT(runtime,id) DO UPDATE SET revision=revision+1').run(runtime, id);
|
|
52
|
+
},
|
|
53
|
+
pending(runtime) {
|
|
54
|
+
return db.prepare('SELECT id,revision FROM search_dirty WHERE runtime=?').all(runtime);
|
|
55
|
+
},
|
|
56
|
+
acknowledge(runtime, id, revision) {
|
|
57
|
+
return db.prepare('DELETE FROM search_dirty WHERE runtime=? AND id=? AND revision=?').run(runtime, id, revision).changes > 0;
|
|
58
|
+
},
|
|
45
59
|
coverage(runtime) {
|
|
46
60
|
return db.prepare('SELECT started_at AS indexStartedAt, completed_at AS indexCompletedAt, since AS coveredSince, verified_at AS verifiedAt FROM search_coverage WHERE runtime=?').get(runtime)
|
|
47
61
|
?? { indexStartedAt: null, indexCompletedAt: null, coveredSince: null, verifiedAt: null };
|
|
48
62
|
},
|
|
63
|
+
needsEventIdentityRepair(runtime) {
|
|
64
|
+
return db.prepare('SELECT event_identity_repaired FROM search_coverage WHERE runtime=?').get(runtime)?.event_identity_repaired !== 1;
|
|
65
|
+
},
|
|
49
66
|
beginInitialization(runtime, timestamp) {
|
|
50
67
|
db.prepare(`INSERT INTO search_coverage(runtime,started_at) VALUES(?,?)
|
|
51
68
|
ON CONFLICT(runtime) DO NOTHING`).run(runtime, timestamp);
|
|
52
69
|
},
|
|
53
70
|
completeInitialization(runtime, since, timestamp) {
|
|
54
|
-
db.prepare(`UPDATE search_coverage SET completed_at=COALESCE(completed_at,?), since=?, verified_at
|
|
71
|
+
db.prepare(`UPDATE search_coverage SET completed_at=COALESCE(completed_at,?), since=?, verified_at=?, event_identity_repaired=1 WHERE runtime=?`)
|
|
55
72
|
.run(timestamp, since, timestamp, runtime);
|
|
56
73
|
},
|
|
57
74
|
replaceSession: db.transaction((runtime, session, records, since = null, indexedAt = Date.now()) => {
|
|
@@ -73,7 +90,7 @@ export function createContentSearchService({ dbPath }) {
|
|
|
73
90
|
prune: db.transaction((runtime, since, ids) => {
|
|
74
91
|
db.prepare('DELETE FROM search_message WHERE runtime=? AND created<?').run(runtime, since);
|
|
75
92
|
db.prepare('UPDATE search_session SET since=MAX(since,?) WHERE runtime=? AND since IS NOT NULL').run(since, runtime);
|
|
76
|
-
for (const row of db.prepare('SELECT id FROM search_session WHERE runtime=?').all(runtime)) {
|
|
93
|
+
if (ids) for (const row of db.prepare('SELECT id FROM search_session WHERE runtime=?').all(runtime)) {
|
|
77
94
|
if (!ids.has(row.id)) removeSession(runtime, row.id);
|
|
78
95
|
}
|
|
79
96
|
}),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import net from 'node:net';
|
|
3
4
|
import { registerManagedProcess, unregisterManagedProcess, reapOrphanedProcesses } from './managed-process-registry.js';
|
|
4
5
|
import { evaluateOpenCodeHealthBody } from './opencode2-pin.js';
|
|
@@ -592,6 +593,23 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
592
593
|
* @param {object | null | undefined} migrationGate
|
|
593
594
|
* @param {number | null | undefined} expectedGeneration
|
|
594
595
|
*/
|
|
596
|
+
// Health checks run every 15s; spawnSync `--version` blocks the event loop.
|
|
597
|
+
// Re-read only when the binary file is replaced (upgrade changes mtime/size).
|
|
598
|
+
let cliVersionCache = { key: '', version: null };
|
|
599
|
+
const readCliVersionCached = (binaryPath) => {
|
|
600
|
+
let key;
|
|
601
|
+
try {
|
|
602
|
+
const stat = fs.statSync(binaryPath);
|
|
603
|
+
key = `${binaryPath}\0${stat.mtimeMs}\0${stat.size}`;
|
|
604
|
+
} catch {
|
|
605
|
+
return readOpenCode2BinaryVersion(binaryPath) || null;
|
|
606
|
+
}
|
|
607
|
+
if (cliVersionCache.key === key) return cliVersionCache.version;
|
|
608
|
+
const version = readOpenCode2BinaryVersion(binaryPath) || null;
|
|
609
|
+
if (version) cliVersionCache = { key, version };
|
|
610
|
+
return version;
|
|
611
|
+
};
|
|
612
|
+
|
|
595
613
|
const refreshRuntimeContractFromProbe = (
|
|
596
614
|
probe,
|
|
597
615
|
migrationGate = state.v1Migration,
|
|
@@ -608,7 +626,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
608
626
|
const binaryPath = typeof process.env.OPENCODE_BINARY === 'string'
|
|
609
627
|
? process.env.OPENCODE_BINARY.trim()
|
|
610
628
|
: '';
|
|
611
|
-
const cliVersion = binaryPath ? (
|
|
629
|
+
const cliVersion = binaryPath ? readCliVersionCached(binaryPath) : null;
|
|
612
630
|
const contract = evaluateRuntimeContract({
|
|
613
631
|
serveVersion: probe?.version ?? null,
|
|
614
632
|
cliVersion,
|
|
@@ -98,7 +98,11 @@ form IO and core, restoring `/api` for origin-only upstream URLs.
|
|
|
98
98
|
|
|
99
99
|
## Reconcile
|
|
100
100
|
|
|
101
|
-
- Inventory =
|
|
101
|
+
- Inventory = live upstream Locations (`GET /api/debug/location`) + observed request/event dirs.
|
|
102
|
+
Forms live in Location memory, so other directories cannot hold pending forms;
|
|
103
|
+
a scoped `form.list` there would boot a Location that upstream never evicts.
|
|
104
|
+
Never enumerate settings projects or session-index directories. An unreadable
|
|
105
|
+
live set is an inventory failure, not an empty catalog.
|
|
102
106
|
- Track `successfulDirectories`; only those may settle missing requests.
|
|
103
107
|
- Unscoped list discovers unknowns only; never means “all directories empty”.
|
|
104
108
|
- Unscoped / directory-less pending triggers `ensureSessionLineage(sessionID, hint, requestID)`
|
|
@@ -181,8 +181,8 @@ export interface QuestionAutoDelegateIO {
|
|
|
181
181
|
body: unknown,
|
|
182
182
|
sessionID: string,
|
|
183
183
|
): Promise<QuestionAutoDelegateUpstreamResult>;
|
|
184
|
-
/**
|
|
185
|
-
listDirectories(): Promise<string[]>;
|
|
184
|
+
/** Live upstream Location directories for reconnect/start reconcile; null when unreadable. */
|
|
185
|
+
listDirectories(): Promise<string[] | null>;
|
|
186
186
|
/**
|
|
187
187
|
* Persist-backed enabled flag.
|
|
188
188
|
* - `true` / `false` when readable (absent key ⇒ default true)
|
|
@@ -28,9 +28,6 @@ export function createQuestionAutoDelegateRuntime({
|
|
|
28
28
|
buildOpenCodeUrl,
|
|
29
29
|
getOpenCodeAuthHeaders,
|
|
30
30
|
readSettingsFromDiskMigrated,
|
|
31
|
-
sanitizeProjects,
|
|
32
|
-
/** Optional: session-index / worktree inventory directories. */
|
|
33
|
-
listIndexedDirectories,
|
|
34
31
|
broadcastGlobalUiEvent,
|
|
35
32
|
broadcastYuriEvent,
|
|
36
33
|
fetchImpl = fetch,
|
|
@@ -124,32 +121,19 @@ export function createQuestionAutoDelegateRuntime({
|
|
|
124
121
|
return null;
|
|
125
122
|
}
|
|
126
123
|
},
|
|
124
|
+
/**
|
|
125
|
+
* Forms live in Location memory, so only live Locations can hold pending
|
|
126
|
+
* forms. A scoped `/form` on any other directory boots a full Location
|
|
127
|
+
* that upstream never evicts; never list projects or indexed directories.
|
|
128
|
+
* @returns {Promise<string[]|null>} null when the live set is unreadable.
|
|
129
|
+
*/
|
|
127
130
|
async listDirectories() {
|
|
131
|
+
const result = await upstream('/debug/location');
|
|
132
|
+
if (!result.ok || !Array.isArray(result.body)) return null;
|
|
128
133
|
const dirs = new Set();
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
? (sanitizeProjects(settings?.projects ?? []) || [])
|
|
133
|
-
: (Array.isArray(settings?.projects) ? settings.projects : []);
|
|
134
|
-
for (const project of projects) {
|
|
135
|
-
const path = asTrimmedString(project?.path);
|
|
136
|
-
if (path) dirs.add(path);
|
|
137
|
-
}
|
|
138
|
-
} catch {
|
|
139
|
-
// Project list failure is not fatal when index inventory exists.
|
|
140
|
-
}
|
|
141
|
-
if (typeof listIndexedDirectories === 'function') {
|
|
142
|
-
try {
|
|
143
|
-
const indexed = await listIndexedDirectories();
|
|
144
|
-
if (Array.isArray(indexed)) {
|
|
145
|
-
for (const directory of indexed) {
|
|
146
|
-
const path = asTrimmedString(directory);
|
|
147
|
-
if (path) dirs.add(path);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
} catch {
|
|
151
|
-
// ignore index failures — core marks partial when inventory empty+failed
|
|
152
|
-
}
|
|
134
|
+
for (const entry of result.body) {
|
|
135
|
+
const path = asTrimmedString(entry?.directory);
|
|
136
|
+
if (path) dirs.add(path);
|
|
153
137
|
}
|
|
154
138
|
return Array.from(dirs);
|
|
155
139
|
},
|
|
@@ -26,6 +26,7 @@ const setup = async (pending = []) => {
|
|
|
26
26
|
let onEvent;
|
|
27
27
|
const fetchImpl = vi.fn(async (url, options) => {
|
|
28
28
|
const path = url.pathname;
|
|
29
|
+
if (path === '/api/debug/location') return Response.json([{ directory: '/project' }]);
|
|
29
30
|
if (path === '/api/form') return Response.json({ data: pending });
|
|
30
31
|
if (path === '/api/session/ses_test') return Response.json({ data: { id: 'ses_test', location: { directory: '/project' } } });
|
|
31
32
|
if (path === '/api/session/ses_test/form/frm_question') return Response.json({ data: form });
|
|
@@ -52,6 +53,30 @@ const setup = async (pending = []) => {
|
|
|
52
53
|
};
|
|
53
54
|
};
|
|
54
55
|
|
|
56
|
+
it('reconciles only live Locations and never boots project or indexed directories', async () => {
|
|
57
|
+
vi.useFakeTimers();
|
|
58
|
+
const fetchImpl = vi.fn(async (url) => {
|
|
59
|
+
if (url.pathname === '/api/debug/location') return Response.json([{ directory: '/live' }]);
|
|
60
|
+
if (url.pathname === '/api/form') return Response.json({ data: [] });
|
|
61
|
+
return Response.json({ error: 'Not found' }, { status: 404 });
|
|
62
|
+
});
|
|
63
|
+
const runtime = createQuestionAutoDelegateRuntime({
|
|
64
|
+
globalEventHub: { subscribeEvent: () => () => {} },
|
|
65
|
+
buildOpenCodeUrl: (path) => `http://opencode.test/api${path}`,
|
|
66
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
67
|
+
readSettingsFromDiskMigrated: async () => ({ projects: [{ path: '/project' }, { path: '/other' }] }),
|
|
68
|
+
fetchImpl,
|
|
69
|
+
pauseStore: createQuestionPauseStore(pauseDirectory),
|
|
70
|
+
});
|
|
71
|
+
runtimes.push(runtime);
|
|
72
|
+
runtime.start();
|
|
73
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
74
|
+
const scoped = fetchImpl.mock.calls
|
|
75
|
+
.map(([url]) => url.searchParams.get('location[directory]'))
|
|
76
|
+
.filter(Boolean);
|
|
77
|
+
expect(scoped).toEqual(['/live']);
|
|
78
|
+
});
|
|
79
|
+
|
|
55
80
|
it('auto-delegates a native question form after exactly 30 seconds without a UI', async () => {
|
|
56
81
|
const { emit, posts, runtime } = await setup();
|
|
57
82
|
emit('form.created', { sessionID: form.sessionID, form });
|
|
@@ -220,6 +220,7 @@ executions and rows without a session; missing session association is not proof
|
|
|
220
220
|
of execution failure. Such rows remain unresolved rather than inventing a result.
|
|
221
221
|
Recovery checks live `session.active` before examining terminal messages or Host
|
|
222
222
|
goal state. Active, unavailable, malformed, and incomplete results remain pending.
|
|
223
|
+
A session OpenCode confirms deleted (`SessionNotFoundError`) settles as `error`.
|
|
223
224
|
Only confirmed terminal evidence finalizes history, with duration through the
|
|
224
225
|
time recovery observes completion. It neither dispatches a new prompt nor sends
|
|
225
226
|
a second completion notification.
|
|
@@ -358,6 +359,10 @@ Every actual run (timer or manual):
|
|
|
358
359
|
after multiple incomplete idle probes.
|
|
359
360
|
- `session.active` / `message.list` failures stay **unknown** (keep
|
|
360
361
|
polling under the watchdog); they never masquerade as idle success.
|
|
362
|
+
Exception: a declared `SessionNotFoundError` (or HTTP 404) from
|
|
363
|
+
`message.list` / `session.get` is confirmed terminal evidence and
|
|
364
|
+
finalizes as `error: 'session not found'`, so recovery stops polling
|
|
365
|
+
deleted sessions. Transport failures never match.
|
|
361
366
|
- Assistant `error` (and terminal finish `error` / `length` /
|
|
362
367
|
`content-filter`) finalizes as `error`.
|
|
363
368
|
- Goal-enabled runs: settle via Host goal terminal status when the store
|
|
@@ -400,6 +400,15 @@ const extractGoalFromSession = (session) => {
|
|
|
400
400
|
* must be a real terminal (finish tool-calls / incomplete / model-switch ≠
|
|
401
401
|
* success). History rows are never rewritten here.
|
|
402
402
|
*/
|
|
403
|
+
const SESSION_NOT_FOUND_ERROR = 'session not found';
|
|
404
|
+
|
|
405
|
+
// Real `@opencode/client` throws declared errors by `_tag`; transport failures never match.
|
|
406
|
+
const isSessionNotFoundError = (error) => {
|
|
407
|
+
if (!error || typeof error !== 'object') return false;
|
|
408
|
+
if ((error._tag ?? error.name) === 'SessionNotFoundError') return true;
|
|
409
|
+
return Number(error.status ?? error.statusCode ?? error.response?.status) === 404;
|
|
410
|
+
};
|
|
411
|
+
|
|
403
412
|
const snapshotSessionOutcome = async ({
|
|
404
413
|
client,
|
|
405
414
|
sessionID,
|
|
@@ -474,6 +483,9 @@ const snapshotSessionOutcome = async ({
|
|
|
474
483
|
}
|
|
475
484
|
} catch (error) {
|
|
476
485
|
if (signal?.aborted) throw error;
|
|
486
|
+
if (isSessionNotFoundError(error)) {
|
|
487
|
+
return { outcome: 'error', error: SESSION_NOT_FOUND_ERROR };
|
|
488
|
+
}
|
|
477
489
|
}
|
|
478
490
|
}
|
|
479
491
|
return { outcome: 'busy' };
|
|
@@ -490,6 +502,10 @@ const snapshotSessionOutcome = async ({
|
|
|
490
502
|
}
|
|
491
503
|
} catch (error) {
|
|
492
504
|
if (signal?.aborted) throw error;
|
|
505
|
+
// Upstream confirmed the session is gone: terminal, or recovery polls it forever.
|
|
506
|
+
if (isSessionNotFoundError(error)) {
|
|
507
|
+
return { outcome: 'error', error: SESSION_NOT_FOUND_ERROR };
|
|
508
|
+
}
|
|
493
509
|
}
|
|
494
510
|
|
|
495
511
|
return { outcome: 'busy' };
|
|
@@ -223,6 +223,39 @@ describe('scheduled-tasks history recovery', () => {
|
|
|
223
223
|
}
|
|
224
224
|
});
|
|
225
225
|
|
|
226
|
+
it('settles running history whose session was deleted upstream and stops polling it', async () => {
|
|
227
|
+
vi.useFakeTimers();
|
|
228
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'scheduled-missing-'));
|
|
229
|
+
const store = createScheduledTaskRunHistoryStore({ dbPath: path.join(dir, 'runs.sqlite') });
|
|
230
|
+
for (const id of ['missing', 'offline']) {
|
|
231
|
+
store.startRun({ id, projectId: 'project-1', taskId: id, startedAt: Date.now() - 1000 });
|
|
232
|
+
store.attachSession(id, `ses_${id}`);
|
|
233
|
+
}
|
|
234
|
+
const messageList = vi.fn(async ({ sessionID }) => {
|
|
235
|
+
if (sessionID === 'ses_missing') {
|
|
236
|
+
throw Object.assign(new Error('SessionNotFoundError'), { _tag: 'SessionNotFoundError', name: 'SessionNotFoundError', sessionID });
|
|
237
|
+
}
|
|
238
|
+
throw new TypeError('fetch failed');
|
|
239
|
+
});
|
|
240
|
+
makeOpenCodeV2Client.mockReturnValue({ session: { active: vi.fn(async () => ({})) }, message: { list: messageList } });
|
|
241
|
+
const runtime = createRuntime(vi.fn(async () => ({ task: null })), { runHistoryStore: store });
|
|
242
|
+
try {
|
|
243
|
+
await runtime.start();
|
|
244
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
245
|
+
const runs = () => Object.fromEntries(store.listRuns().runs.map((run) => [run.id, run]));
|
|
246
|
+
expect(runs().missing).toMatchObject({ status: 'error', error: 'session not found' });
|
|
247
|
+
expect(runs().offline.status).toBe('running');
|
|
248
|
+
await vi.advanceTimersByTimeAsync(10_000);
|
|
249
|
+
expect(messageList.mock.calls.filter(([args]) => args.sessionID === 'ses_missing')).toHaveLength(1);
|
|
250
|
+
expect(runs().offline.status).toBe('running');
|
|
251
|
+
} finally {
|
|
252
|
+
runtime.stop();
|
|
253
|
+
store.close();
|
|
254
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
255
|
+
vi.useRealTimers();
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
226
259
|
it('discards recovery results arriving after stop', async () => {
|
|
227
260
|
let resolveMessages;
|
|
228
261
|
const messages = new Promise((resolve) => { resolveMessages = resolve; });
|