|
3 | 3 | * |
4 | 4 | * Tracks runtime and browser containers in the shared state DB. |
5 | 5 | */ |
6 | | -import fsSync from "node:fs"; |
7 | 6 | import type { Insertable, Selectable, Updateable } from "kysely"; |
8 | 7 | import { executeSqliteQuerySync, getNodeSqliteKysely } from "../../infra/kysely-sync.js"; |
9 | | -import { withOpenClawStateDatabaseReadOnly } from "../../state/openclaw-state-db-readonly.js"; |
| 8 | +import { withExistingOpenClawStateDatabaseReadOnly } from "../../state/openclaw-state-db-readonly.js"; |
10 | 9 | import { tableExists } from "../../state/openclaw-state-db-schema-helpers.js"; |
11 | 10 | import type { DB as OpenClawStateKyselyDatabase } from "../../state/openclaw-state-db.generated.js"; |
12 | 11 | import { runOpenClawStateWriteTransaction } from "../../state/openclaw-state-db.js"; |
13 | | -import { resolveOpenClawStateSqlitePath } from "../../state/openclaw-state-db.paths.js"; |
14 | 12 | import type { SandboxContainerEngineTarget } from "./container-engine.js"; |
15 | 13 |
|
16 | 14 | export type SandboxRegistryEntry = { |
@@ -181,58 +179,56 @@ function readRegistryRows( |
181 | 179 | kind: SandboxRegistryKind, |
182 | 180 | filter?: { backendId: string; scopeKey: string }, |
183 | 181 | ): SandboxRegistryRow[] { |
184 | | - if (!fsSync.existsSync(resolveOpenClawStateSqlitePath(process.env))) { |
185 | | - return []; |
186 | | - } |
187 | 182 | // CLI reads must not join the Gateway's writable SQLite lifecycle (#101290). |
188 | | - return withOpenClawStateDatabaseReadOnly(({ db }) => { |
189 | | - if (!tableExists(db, "sandbox_registry_entries")) { |
190 | | - return []; |
191 | | - } |
192 | | - const stateDb = getSandboxRegistryKysely(db); |
193 | | - let query = stateDb |
194 | | - .selectFrom("sandbox_registry_entries") |
195 | | - .selectAll() |
196 | | - .where("registry_kind", "=", kind); |
197 | | - if (filter) { |
198 | | - query = query |
199 | | - .where("session_key", "=", filter.scopeKey) |
200 | | - .where("backend_id", "=", filter.backendId); |
201 | | - } |
202 | | - return executeSqliteQuerySync( |
203 | | - db, |
204 | | - filter |
205 | | - ? query.orderBy("last_used_at_ms", "desc").orderBy("container_name", "asc") |
206 | | - : query.orderBy("container_name", "asc"), |
207 | | - ).rows; |
208 | | - }); |
| 183 | + return ( |
| 184 | + withExistingOpenClawStateDatabaseReadOnly(({ db }) => { |
| 185 | + if (!tableExists(db, "sandbox_registry_entries")) { |
| 186 | + return []; |
| 187 | + } |
| 188 | + const stateDb = getSandboxRegistryKysely(db); |
| 189 | + let query = stateDb |
| 190 | + .selectFrom("sandbox_registry_entries") |
| 191 | + .selectAll() |
| 192 | + .where("registry_kind", "=", kind); |
| 193 | + if (filter) { |
| 194 | + query = query |
| 195 | + .where("session_key", "=", filter.scopeKey) |
| 196 | + .where("backend_id", "=", filter.backendId); |
| 197 | + } |
| 198 | + return executeSqliteQuerySync( |
| 199 | + db, |
| 200 | + filter |
| 201 | + ? query.orderBy("last_used_at_ms", "desc").orderBy("container_name", "asc") |
| 202 | + : query.orderBy("container_name", "asc"), |
| 203 | + ).rows; |
| 204 | + }) ?? [] |
| 205 | + ); |
209 | 206 | } |
210 | 207 |
|
211 | 208 | function readRegistryRow( |
212 | 209 | kind: SandboxRegistryKind, |
213 | 210 | containerName: string, |
214 | 211 | ): SandboxRegistryRow | null { |
215 | | - if (!fsSync.existsSync(resolveOpenClawStateSqlitePath(process.env))) { |
216 | | - return null; |
217 | | - } |
218 | 212 | // CLI reads must not join the Gateway's writable SQLite lifecycle (#101290). |
219 | | - return withOpenClawStateDatabaseReadOnly(({ db }) => { |
220 | | - if (!tableExists(db, "sandbox_registry_entries")) { |
221 | | - return null; |
222 | | - } |
223 | | - const stateDb = getSandboxRegistryKysely(db); |
224 | | - return ( |
225 | | - executeSqliteQuerySync( |
226 | | - db, |
227 | | - stateDb |
228 | | - .selectFrom("sandbox_registry_entries") |
229 | | - .selectAll() |
230 | | - .where("registry_kind", "=", kind) |
231 | | - .where("container_name", "=", containerName) |
232 | | - .limit(1), |
233 | | - ).rows[0] ?? null |
234 | | - ); |
235 | | - }); |
| 213 | + return ( |
| 214 | + withExistingOpenClawStateDatabaseReadOnly(({ db }) => { |
| 215 | + if (!tableExists(db, "sandbox_registry_entries")) { |
| 216 | + return null; |
| 217 | + } |
| 218 | + const stateDb = getSandboxRegistryKysely(db); |
| 219 | + return ( |
| 220 | + executeSqliteQuerySync( |
| 221 | + db, |
| 222 | + stateDb |
| 223 | + .selectFrom("sandbox_registry_entries") |
| 224 | + .selectAll() |
| 225 | + .where("registry_kind", "=", kind) |
| 226 | + .where("container_name", "=", containerName) |
| 227 | + .limit(1), |
| 228 | + ).rows[0] ?? null |
| 229 | + ); |
| 230 | + }) ?? null |
| 231 | + ); |
236 | 232 | } |
237 | 233 |
|
238 | 234 | function insertRegistryRowIfMissing(row: SandboxRegistryInsert): void { |
|
0 commit comments