@terreno/mcp 57.10.1 → 57.11.0
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/docs/upgrades/57.11.0.md +80 -0
- package/dist/docs/versioned/next/explanation/durable-agent-harness.md +17 -4
- package/dist/docs/versioned/next/explanation/local-first-data.md +1 -0
- package/dist/docs/versioned/next/how-to/README.md +1 -0
- package/dist/docs/versioned/next/how-to/call-external-apis.md +1 -1
- package/dist/docs/versioned/next/how-to/migrate-rtk-to-syncdb.md +31 -1
- package/dist/docs/versioned/next/how-to/preview-demo.md +7 -3
- package/dist/docs/versioned/next/how-to/run-harness-on-multiple-instances.md +93 -0
- package/dist/docs/versioned/next/implementationPlans/durable-agent-harness.md +1 -1
- package/dist/docs/versioned/next/reference/ai-harness.md +105 -12
- package/dist/docs/versioned/next/reference/api.md +64 -2
- package/dist/docs/versioned/next/reference/environment-variables.md +1 -1
- package/dist/docs/versioned/next/reference/lifecycle-plugin.md +11 -0
- package/dist/docs/versioned/next/reference/syncdb.md +156 -6
- package/dist/docs/versioned/next/reference/ui.md +6 -5
- package/dist/docs/versioned/next/tasks/durable-agent-harness.md +4 -2
- package/package.json +3 -3
- package/src/docs/upgrades/57.11.0.md +80 -0
- package/src/docs/versioned/next/explanation/durable-agent-harness.md +17 -4
- package/src/docs/versioned/next/explanation/local-first-data.md +1 -0
- package/src/docs/versioned/next/how-to/README.md +1 -0
- package/src/docs/versioned/next/how-to/call-external-apis.md +1 -1
- package/src/docs/versioned/next/how-to/migrate-rtk-to-syncdb.md +31 -1
- package/src/docs/versioned/next/how-to/preview-demo.md +7 -3
- package/src/docs/versioned/next/how-to/run-harness-on-multiple-instances.md +93 -0
- package/src/docs/versioned/next/implementationPlans/durable-agent-harness.md +1 -1
- package/src/docs/versioned/next/reference/ai-harness.md +105 -12
- package/src/docs/versioned/next/reference/api.md +64 -2
- package/src/docs/versioned/next/reference/environment-variables.md +1 -1
- package/src/docs/versioned/next/reference/lifecycle-plugin.md +11 -0
- package/src/docs/versioned/next/reference/syncdb.md +156 -6
- package/src/docs/versioned/next/reference/ui.md +6 -5
- package/src/docs/versioned/next/tasks/durable-agent-harness.md +4 -2
|
@@ -10,6 +10,7 @@ Local-first data layer for Terreno frontends. A TinyBase `MergeableStore` on dev
|
|
|
10
10
|
- [createSyncDb configuration](#createsyncdb-configuration)
|
|
11
11
|
- [SyncDb client methods](#syncdb-client-methods)
|
|
12
12
|
- [React hooks](#react-hooks)
|
|
13
|
+
- [Query windows](#query-windows)
|
|
13
14
|
- [Codegen](#codegen)
|
|
14
15
|
- [Conflict API](#conflict-api)
|
|
15
16
|
- [Sync status API](#sync-status-api)
|
|
@@ -25,7 +26,8 @@ Local-first data layer for Terreno frontends. A TinyBase `MergeableStore` on dev
|
|
|
25
26
|
- `createSyncDb`, `SyncDb`, `SyncDbConfig`, `MutateArgs`
|
|
26
27
|
- `betterAuthAdapter`, `bridgeBetterAuthReactClient`, `AuthProvider`
|
|
27
28
|
- `listConflicts`, `wipeLocalData`, `generateMutationId`
|
|
28
|
-
-
|
|
29
|
+
- Queries: `QueryFieldNotAllowedError`, `ListRequestError`, `WhereFilter`, `SortSpec`, `WindowQuery`, `QueryWindowState`, `QueryWindows`, `compileWhere`, `DEFAULT_WINDOW_PAGE_SIZE`
|
|
30
|
+
- React (`@terreno/syncdb/react`): `SyncDbProvider`, `useEntity`, `useQuery`, `useEntityIds`, `useWindowQuery`, `useMutate`, `useSyncStatus`, `useConflicts`, `useSyncDebugLog`, `createCollectionHooks`
|
|
29
31
|
- CLI: `terreno-syncdb-codegen` (generates `SYNC_COLLECTIONS` + friendly hooks from OpenAPI)
|
|
30
32
|
- Testing (`@terreno/syncdb/testing`): `createFakeTransport`
|
|
31
33
|
|
|
@@ -165,6 +167,7 @@ be passed to `betterAuthAdapter` directly.
|
|
|
165
167
|
| `name` | `string` | — (required) | Persisted database name |
|
|
166
168
|
| `collections` | `string[]` | — (required) | Collection names to sync (local tables + subscriptions) |
|
|
167
169
|
| `windowCollections` | `string[]` | `[]` | Collections that join `{collection}\|admin`, skip snapshots/reconcile, and hydrate only known REST membership ids |
|
|
170
|
+
| `queryCollections` | `Array<string \| {collection, path?, fullSync?}>` | `[]` | Collections too large to sync whole (or `fullSync: true` to keep snapshot sync and add windows). No snapshot/reconcile paging; rows arrive through [query windows](#query-windows) against the `modelRouter` list endpoint (`path`, default `/{collection}`) plus live deltas on the user's normal streams. Each entry must also be in `collections` and not in `windowCollections`. |
|
|
168
171
|
| `organizationIdProvider` | `() => string \| undefined` | — | Read at send time: sets `X-Organization-Id` on HTTP sync calls and `organizationId` on socket mutate payloads |
|
|
169
172
|
| `authProvider` | `AuthProvider` | — (required) | `{getToken, getUserId, onAuthChange, refresh?}` |
|
|
170
173
|
| `baseUrl` | `string` | — | Server origin; required unless both `transport` and `httpChannel` are injected |
|
|
@@ -200,6 +203,7 @@ be passed to `betterAuthAdapter` directly.
|
|
|
200
203
|
| `mutate({collection, operation, id?, data?})` | Optimistic local write + durable outbox enqueue + fire-and-forget replay. Returns `{mutationId, id}`. |
|
|
201
204
|
| `reconcile()` | HTTP snapshot catch-up for every known stream; runs tombstone compaction on success. Also runs automatically on (re)connect, on a rate-limited seq-jump hint, and on the periodic timer; each `sync:subscribed` confirmation additionally pages just the streams it names. |
|
|
202
205
|
| `hydrateWindow({collection, ids, restRows?})` | Admin window upsert: REST rows (optional) land immediately; every requested id is also fetched from `GET /sync/entities` before this resolves so seq/deleted metadata is canonical for immediate update/delete. A `{collection}|admin` delta that lands while the fetch is in flight wins, so hydration never rewinds a row to an older seq. Unknown ids are ignored. |
|
|
206
|
+
| `queryWindows` | Server query windows for `queryCollections`: `fetchWindow({query, nextPage?})`, `getWindow(query)`, `retain(query)` → release, `refetchRetained()`, `pruneUnretained()`, `subscribe(cb)`, `keyFor(query)`. See [Query windows](#query-windows). |
|
|
203
207
|
| `forceResync()` | Purge every known stream locally and re-bootstrap from cursor 0 (outbox/conflicts untouched). Returns `{ok, reason?, streams, purged, repaired}`. After discovery and each stream bootstrap it waits for in-flight `start`/`stop`/auth-change work, then abandons with `reason: "superseded"` when that work switched users or generations. |
|
|
204
208
|
| `replayOutbox()` | Drain queued mutations for the current user now. |
|
|
205
209
|
| `resolveConflict({mutationId, strategy})` | Apply `"useServer"` or `"keepMine"` to a recorded conflict. |
|
|
@@ -271,13 +275,26 @@ Subscribe to a single entity. Re-renders when that row changes. `isPending` is t
|
|
|
271
275
|
|
|
272
276
|
```typescript
|
|
273
277
|
const todos = useQuery<Todo>("todos", {
|
|
274
|
-
|
|
275
|
-
sort:
|
|
276
|
-
|
|
278
|
+
where: {completed: false, created: {$gte: since}},
|
|
279
|
+
sort: "-created",
|
|
280
|
+
limit: 20,
|
|
277
281
|
});
|
|
282
|
+
|
|
283
|
+
// Callbacks still work and combine with `where`:
|
|
284
|
+
const mine = useQuery<Todo>("todos", {filter: (t) => t.ownerId === userId, sort: byCreatedDesc});
|
|
278
285
|
```
|
|
279
286
|
|
|
280
|
-
Returns decoded entity data arrays. Tombstones excluded unless `includeDeleted: true`.
|
|
287
|
+
Returns decoded entity data arrays from the local store. Tombstones excluded unless `includeDeleted: true`.
|
|
288
|
+
|
|
289
|
+
| Option | Type | Description |
|
|
290
|
+
|--------|------|-------------|
|
|
291
|
+
| `where` | `WhereFilter` | Mongo-style filter: equality, dot paths, `$eq` `$ne` `$gt` `$gte` `$lt` `$lte` `$in` `$nin` `$exists`, `$and` / `$or`. An array field matches when any element equals the value. Compared by value, so inline objects are fine. Throws for operators only the server can run (`$search`, `$regex`). |
|
|
292
|
+
| `filter` | `(data) => boolean` | Arbitrary predicate, applied after `where`. |
|
|
293
|
+
| `sort` | `SortSpec \| comparator` | `"-created name"`, `{created: "descending"}`, or `(a, b) => number`. |
|
|
294
|
+
| `limit` | `number` | Keep the first N rows after filter and sort. |
|
|
295
|
+
| `includeDeleted` | `boolean` | Include tombstones. |
|
|
296
|
+
|
|
297
|
+
Filter and sort run in JS — memoize `filter`/comparator callbacks when collections are large.
|
|
281
298
|
|
|
282
299
|
### `useEntityIds(collection, options?)`
|
|
283
300
|
|
|
@@ -288,6 +305,38 @@ return ids.map((id) => <TodoRow key={id} id={id} />);
|
|
|
288
305
|
|
|
289
306
|
Same options as `useQuery`, but returns only ordered ids with **referential stability** — the array identity changes only when membership or order changes, not on field updates. Pair with per-row `useEntity` for large lists.
|
|
290
307
|
|
|
308
|
+
### `useWindowQuery(collection, options?)`
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
const {data, isLoading, isFetching, hasMore, fetchNextPage, refetch, total, error} =
|
|
312
|
+
useWindowQuery<Message>("messages", {
|
|
313
|
+
where: {threadId, deleted: false},
|
|
314
|
+
sort: "-created",
|
|
315
|
+
pageSize: 30,
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Server-filtered list over a `queryCollections` collection. See [Query windows](#query-windows).
|
|
320
|
+
|
|
321
|
+
| Option | Type | Default | Description |
|
|
322
|
+
|--------|------|---------|-------------|
|
|
323
|
+
| `where` | `WhereFilter` | — | Sent as qs list params (`status[$in][0]=open`). Fields must be in the route's `queryFields`. |
|
|
324
|
+
| `sort` | `SortSpec` | route default | Server `sort`; also orders the local view. |
|
|
325
|
+
| `pageSize` | `number` | `50` | Server `limit` per page (capped by the route's `maxLimit`). |
|
|
326
|
+
| `skip` | `boolean` | `false` | Do not retain or fetch (e.g. a required param is missing). |
|
|
327
|
+
| `liveMatch` | `boolean` | `true` | Show cached rows that newly match `where` inside the loaded range. |
|
|
328
|
+
|
|
329
|
+
| Result | Description |
|
|
330
|
+
|--------|-------------|
|
|
331
|
+
| `data` / `ids` | This window's rows in view order. |
|
|
332
|
+
| `isLoading` | No membership yet (first fetch in flight). Cached membership renders with `isLoading: false`. |
|
|
333
|
+
| `isFetching` | Any request for this window is in flight. |
|
|
334
|
+
| `isError` / `error` | Last request failed (cached rows still render). |
|
|
335
|
+
| `errorCode` | Server error code of the last failure; `"query-param-not-allowed"` means a `where` field is missing from `queryFields`. |
|
|
336
|
+
| `hasMore` / `total` | From the list response's `more` / `total`. |
|
|
337
|
+
| `fetchNextPage()` | Append the next server page. |
|
|
338
|
+
| `refetch()` | Reload every loaded page in one request, replacing membership. |
|
|
339
|
+
|
|
291
340
|
### `useMutate(collection)`
|
|
292
341
|
|
|
293
342
|
```typescript
|
|
@@ -331,7 +380,7 @@ Returns the `SyncDb` instance from context (escape hatch for imperative calls li
|
|
|
331
380
|
|
|
332
381
|
### `createCollectionHooks`
|
|
333
382
|
|
|
334
|
-
Factory used by `terreno-syncdb-codegen` and by hand-written custom collections. Returns
|
|
383
|
+
Factory used by `terreno-syncdb-codegen` and by hand-written custom collections. Returns six operation hooks (`useListQuery`, `useWindowQuery`, `useReadQuery`, `useCreateMutation`, `useUpdateMutation`, `useDeleteMutation`). Generated SDKs rename them to friendly names (`useTodos`, `useTodosWindow`, `useTodo`, `useCreateTodo`, …). `useWindowQuery` works only for collections listed in `queryCollections`. Mutation hooks return `[trigger]`; triggers apply locally and return `{mutationId, id}` synchronously. Optional `retries` maps to `maxAttempts` (`false` → 1, a number → that many, omitted → engine default).
|
|
335
384
|
|
|
336
385
|
```typescript
|
|
337
386
|
export const {useListQuery: useNotes, useCreateMutation: useCreateNote} =
|
|
@@ -340,6 +389,107 @@ export const {useListQuery: useNotes, useCreateMutation: useCreateNote} =
|
|
|
340
389
|
});
|
|
341
390
|
```
|
|
342
391
|
|
|
392
|
+
## Query windows
|
|
393
|
+
|
|
394
|
+
Use query windows when a collection is too large to sync whole (messages, events, audit
|
|
395
|
+
rows). They match what an RTK list query did — `where`, `sort`, `limit`, `page`, `more`,
|
|
396
|
+
`total` — but keep the data local-first and deduplicated.
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
export const syncDb = createSyncDb({
|
|
400
|
+
collections: ["todos", "messages"],
|
|
401
|
+
queryCollections: [{collection: "messages", path: "/messages"}],
|
|
402
|
+
// ...
|
|
403
|
+
});
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
**Membership, not copies.** A window is one list query against the collection's
|
|
407
|
+
`modelRouter` list endpoint. Its result is an ordered id list stored in the reserved
|
|
408
|
+
`_queryWindows` table. Each row lands once in the collection's entity table, keyed by id.
|
|
409
|
+
Two windows that overlap share those rows:
|
|
410
|
+
|
|
411
|
+
- A delta, mutation, or refetch for a shared row writes the store once; every window that
|
|
412
|
+
lists the row re-renders from it.
|
|
413
|
+
- Each window lists only its own members. Window B never shows rows that only window A
|
|
414
|
+
fetched.
|
|
415
|
+
|
|
416
|
+
**Live membership.** When `where` is locally evaluable (see `useQuery`'s `where`), a window
|
|
417
|
+
also:
|
|
418
|
+
|
|
419
|
+
- hides a member whose fields stop matching (an unpinned message leaves the "pinned" window);
|
|
420
|
+
- shows cached rows that newly match (a live delta, or a local create) when they sort inside
|
|
421
|
+
the loaded range. With more pages unloaded, a row that sorts after the last loaded row
|
|
422
|
+
waits for `fetchNextPage()`. Without a `sort` and with more pages, only local creates are
|
|
423
|
+
admitted.
|
|
424
|
+
|
|
425
|
+
A full fetch also records cached rows that matched `where` locally but that the server did
|
|
426
|
+
not return (deleted, changed, or no longer visible while this device was offline). They stay
|
|
427
|
+
out of the view until a newer delta or a local edit changes them, so stale cached data never
|
|
428
|
+
resurrects a row.
|
|
429
|
+
|
|
430
|
+
Set `liveMatch: false` to show server membership only. Operators only the server runs
|
|
431
|
+
(`$search`) also fall back to server membership.
|
|
432
|
+
|
|
433
|
+
**Fetching.** The first `retain` of a window in a session fetches it; persisted membership
|
|
434
|
+
renders meanwhile, so windows work offline. Concurrent fetches of the same window share one
|
|
435
|
+
request; a refetch and a `fetchNextPage()` on one window run one after the other. Retained
|
|
436
|
+
windows refetch on reconnect and after `forceResync()` — query collections
|
|
437
|
+
skip snapshot catch-up, so this is how deltas missed offline are recovered. Windows not on
|
|
438
|
+
screen at that moment refetch the next time they are shown. Window fetches
|
|
439
|
+
started before a `stop()` or user switch are discarded.
|
|
440
|
+
|
|
441
|
+
**Seq.** List rows that carry `_syncSeq` (the `syncPlugin` field) are written with that seq.
|
|
442
|
+
Rows without it (a `responseHandler` that strips it) are re-read from `GET /sync/entities` so
|
|
443
|
+
a later mutation never sends a stale `baseVersion`. Rows with a pending outbox mutation, or
|
|
444
|
+
with a newer seq from a delta, are never overwritten. A list `responseHandler` must return the
|
|
445
|
+
same shape as the sync serializer; otherwise list rows and delta rows differ.
|
|
446
|
+
|
|
447
|
+
**Missing `queryFields`.** Every `where` field must be in the route's `queryFields`. The
|
|
448
|
+
server answers 400 `query-param-not-allowed` naming the field, the model, and the allowed
|
|
449
|
+
list. syncdb turns it into `QueryFieldNotAllowedError` (`field`, `allowedQueryFields`,
|
|
450
|
+
`model`), logs it with `console.error`, sets the window's `errorCode` to
|
|
451
|
+
`"query-param-not-allowed"`, and rejects `fetchWindow` / `refetch` / `fetchNextPage` with it.
|
|
452
|
+
Other list failures throw `ListRequestError` (`status`, `code`, `detail`).
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
import {QueryFieldNotAllowedError} from "@terreno/syncdb";
|
|
456
|
+
|
|
457
|
+
try {
|
|
458
|
+
await refetch();
|
|
459
|
+
} catch (error) {
|
|
460
|
+
if (error instanceof QueryFieldNotAllowedError) {
|
|
461
|
+
// error.field === "title", error.allowedQueryFields === ["completed", "created", "ownerId"]
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
**`maxLimit` and pipelining.** `modelRouter` clamps `limit` to the route's `maxLimit` and
|
|
467
|
+
echoes the applied value. Window requests always send `page` (so the server never logs a
|
|
468
|
+
truncated unpaginated list). When a fetch needs more rows than one request returns — a
|
|
469
|
+
`refetch()` after several `fetchNextPage()` calls, or a `pageSize` above `maxLimit` — syncdb
|
|
470
|
+
learns the cap from the echoed `limit` and splits the range into sequential page requests
|
|
471
|
+
of `maxLimit` rows starting at the aligned page that contains the range, trimming the extra
|
|
472
|
+
rows, so offsets stay exact. Each pipelined fetch logs a
|
|
473
|
+
`console.warn` naming the row count, the cap, and the request count. Fix it by loading fewer
|
|
474
|
+
pages, lowering `pageSize`, or raising `maxLimit` on the route.
|
|
475
|
+
|
|
476
|
+
**Fully synced collections.** `queryCollections: [{collection: "todos", fullSync: true}]`
|
|
477
|
+
keeps normal snapshot sync and also enables windows, for server-side filtering, paging, and
|
|
478
|
+
totals over a collection that is already local. See `example-frontend/app/todo-windows.tsx`.
|
|
479
|
+
|
|
480
|
+
**Limits.**
|
|
481
|
+
|
|
482
|
+
- `refetch()` with several pages loaded reloads `pageSize × pages` rows (see below).
|
|
483
|
+
- Page appends dedupe ids. A delete between page loads can shift offsets and skip one row
|
|
484
|
+
until the next refetch.
|
|
485
|
+
- `null` in `where` is rejected (qs would send the string `"null"`); use `{$exists: false}`.
|
|
486
|
+
A top-level `{$in: []}` returns an empty window without a request; an empty array anywhere
|
|
487
|
+
else throws instead of silently widening the query.
|
|
488
|
+
- Rows stay in the entity table after their windows unmount. `start()` prunes persisted
|
|
489
|
+
membership of unretained windows not fetched for 7 days (`pruneStale`);
|
|
490
|
+
`pruneUnretained()` drops all unretained membership. Rows are dropped by leave-purge,
|
|
491
|
+
tombstone compaction, or a wipe.
|
|
492
|
+
|
|
343
493
|
## Codegen
|
|
344
494
|
|
|
345
495
|
`terreno-syncdb-codegen` is a bin of `@terreno/syncdb`. It reads OpenAPI, discovers list operations with `x-terreno-sync`, and writes typed hooks plus `SYNC_COLLECTIONS`.
|
|
@@ -725,11 +725,12 @@ Master-detail layout. Pass `listViewData` plus `renderListViewItem` for the list
|
|
|
725
725
|
screens the detail replaces the list until the user goes back.
|
|
726
726
|
|
|
727
727
|
`desktopChildrenMinWidth` opts into a minimum pixel width for each desktop child when there
|
|
728
|
-
are one or two children. `
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
728
|
+
are one or two children. `childColumnRounding` sets the border radius on each detail child
|
|
729
|
+
column container (defaults to `md`, 4px); the list column is excluded. `narrowViewportChildLabels`
|
|
730
|
+
opts into a labeled full-width pager on the narrow viewport. `narrowBelowWidth` uses that
|
|
731
|
+
viewport when the window is at or below the given pixel width; when omitted, the narrow
|
|
732
|
+
viewport follows `isNarrowViewport()`. These props are web only; the native `SplitPage`
|
|
733
|
+
ignores them. See `SplitPageProps` for when each prop applies and what is ignored.
|
|
733
734
|
`IconButton`'s `backgroundOpacity` tints only that button's background.
|
|
734
735
|
|
|
735
736
|
```typescript
|
|
@@ -131,21 +131,23 @@ created in 1.1 and extended by every later task — never deferred.
|
|
|
131
131
|
|
|
132
132
|
## Phase 2 — Multi-instance
|
|
133
133
|
|
|
134
|
-
- [
|
|
134
|
+
- [x] **Task 2.0**: `InProcessRunner` concurrency
|
|
135
135
|
- Delivers: `new InProcessRunner({concurrency})` (default 8) runs up to N claimed tasks at once, each with its own lease and heartbeat; a slow phase no longer delays other tasks' wakes; `stop()` waits for all in-flight phases
|
|
136
136
|
- Files: `ai/src/harness/runners/inProcessRunner.ts`, tests
|
|
137
137
|
- Blocked by: 1.12
|
|
138
138
|
- Skills: `terreno-backend-api`
|
|
139
139
|
- Docs: reference "Runners" (concurrency option, ordering guarantees)
|
|
140
140
|
- Acceptance: bun test — a phase blocked on a gate does not prevent a second task from completing; never more than N concurrent; no task runs twice concurrently
|
|
141
|
+
- Shipped: fake-context cases in `ai/src/harness/runners/inProcessRunner.test.ts` (default 8, gate, peak, stop waits for all, invalid concurrency) and real-Mongo cases in `ai/src/harness/concurrency.test.ts` (blocked task does not hold up a second; 7 two-phase tasks at concurrency 3 peak at exactly 3 with no task running twice). Roast: PASS (2026-10-04; 76 targeted tests, three mutation checks red)
|
|
141
142
|
|
|
142
|
-
- [
|
|
143
|
+
- [x] **Task 2.1**: `JobsRunner`
|
|
143
144
|
- Delivers: `@terreno/ai/harness/jobsRunner` with optional peer `@terreno/jobs`; job `terreno.harness.phase` keyed `taskId:phase:attempt`; harness task lease + heartbeat is the authority; importing the root `@terreno/ai` never loads jobs
|
|
144
145
|
- Files: `ai/src/harness/runners/jobsRunner.ts`, `ai/package.json`, tests
|
|
145
146
|
- Blocked by: 2.0
|
|
146
147
|
- Skills: `terreno-backend-api`
|
|
147
148
|
- Docs: reference "Runners"; how-to "Run on multiple instances"
|
|
148
149
|
- Acceptance: AC11 — two workers race one phase; exactly one commit; stale owner rejected; knip clean without jobs installed
|
|
150
|
+
- Shipped: `ai/src/harness/runners/jobsRunner.test.ts` (two-worker race, stale-lease commit rejected, re-dispatch of a dead job, root imports never reach `@terreno/jobs`). Drift: the job key is `taskId:phase:attempt:claims` — `claims` (new `HarnessTask` counter) gives a phase revisited by an event wake or crash replay its own job, since jobs idempotency keys are permanent. Built before Task 2.0; it does not depend on `InProcessRunner` concurrency. Roast: PASS (2026-10-04; 17 targeted tests, ai suite 1185/0, knip clean, two mutation checks red)
|
|
149
151
|
|
|
150
152
|
- [ ] **Task 2.2**: Runs admin screen
|
|
151
153
|
- Delivers: task list/tree with status filters, abort, resolve-interrupted (retry/abort/complete + reason), link to trace
|
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"@modelcontextprotocol/node": "^2.0.0",
|
|
12
12
|
"@modelcontextprotocol/server": "^2.0.0",
|
|
13
13
|
"@sentry/bun": "^10.39.0",
|
|
14
|
-
"@terreno/api": "57.
|
|
15
|
-
"@terreno/blocks": "57.
|
|
14
|
+
"@terreno/api": "57.11.0",
|
|
15
|
+
"@terreno/blocks": "57.11.0",
|
|
16
16
|
"express": "^5.2.1",
|
|
17
17
|
"luxon": "^3.7.2",
|
|
18
18
|
"minisearch": "^7.2.0",
|
|
@@ -105,5 +105,5 @@
|
|
|
105
105
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
106
106
|
},
|
|
107
107
|
"type": "module",
|
|
108
|
-
"version": "57.
|
|
108
|
+
"version": "57.11.0"
|
|
109
109
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Upgrading to 57.11.0
|
|
2
|
+
|
|
3
|
+
**Action required:** Yes
|
|
4
|
+
**Affected packages:** @terreno/ai, @terreno/api
|
|
5
|
+
|
|
6
|
+
## Summary
|
|
7
|
+
|
|
8
|
+
`InProcessRunner` now runs up to eight harness tasks at once. List filters on a field that is not in `queryFields` return 400 before request validation, so that filter can no longer be stripped and ignored. Slack channel helpers and syncdb query windows are opt-in.
|
|
9
|
+
|
|
10
|
+
## Breaking changes
|
|
11
|
+
|
|
12
|
+
### InProcessRunner runs tasks in parallel
|
|
13
|
+
|
|
14
|
+
**What changed**
|
|
15
|
+
|
|
16
|
+
`new InProcessRunner()` runs up to 8 claimed tasks at once. Each task has its own lease. `stop()` waits for every in-flight task. Turns inside one conversation stay serial. Model calls run in parallel, so provider rate limits, cost, and stream-counter transaction retries all go up.
|
|
17
|
+
|
|
18
|
+
**Why**
|
|
19
|
+
|
|
20
|
+
A single slow model call was blocking every other task on that process.
|
|
21
|
+
|
|
22
|
+
**Migration**
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// Before: one claimed task at a time
|
|
26
|
+
const runner = new InProcessRunner();
|
|
27
|
+
|
|
28
|
+
// After: keep that behavior
|
|
29
|
+
const runner = new InProcessRunner({concurrency: 1});
|
|
30
|
+
|
|
31
|
+
// Or accept the new default (8)
|
|
32
|
+
const runner = new InProcessRunner();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### List filters outside queryFields are no longer ignored
|
|
36
|
+
|
|
37
|
+
**What changed**
|
|
38
|
+
|
|
39
|
+
`GET` list on `modelRouter` checks every filter against `queryFields` before OpenAPI query validation. A field that is not listed returns 400 `query-param-not-allowed`. The body names the field, the model, and `meta.allowedQueryFields`. `@terreno/syncdb` raises `QueryFieldNotAllowedError` for the same response. Pagination params `limit`, `page`, and `sort` are unchanged.
|
|
40
|
+
|
|
41
|
+
**Why**
|
|
42
|
+
|
|
43
|
+
Query validation could strip an unknown filter and still return 200, so the client thought the filter applied.
|
|
44
|
+
|
|
45
|
+
**Migration**
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Before: ?title=ship could be stripped and the list still returned 200
|
|
49
|
+
modelRouter("/todos", Todo, {queryFields: ["completed", "ownerId"]});
|
|
50
|
+
|
|
51
|
+
// After: add the field, or stop sending it
|
|
52
|
+
modelRouter("/todos", Todo, {queryFields: ["completed", "ownerId", "title"]});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A 400 looks like:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"status": 400,
|
|
60
|
+
"code": "query-param-not-allowed",
|
|
61
|
+
"title": "Query parameter not allowed",
|
|
62
|
+
"meta": {"queryParam": "title", "model": "Todo", "allowedQueryFields": ["completed", "ownerId"]}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Deprecations
|
|
67
|
+
|
|
68
|
+
None
|
|
69
|
+
|
|
70
|
+
## New capabilities
|
|
71
|
+
|
|
72
|
+
- `JobsRunner` from `@terreno/ai/harness/jobsRunner` runs each harness phase as a `@terreno/jobs` job (`terreno.harness.phase`) so more than one instance can share the work. `@terreno/jobs` is an optional peer. `HarnessTask.claims` defaults to 0 and needs no migration. See `docs/how-to/run-harness-on-multiple-instances.md`.
|
|
73
|
+
- `@terreno/api` Slack helpers use the existing `SLACK_BOT_TOKEN`: `createSlackPrivateChannel`, `inviteSlackUsersToChannel`, `postSlackMessage`, and `findSlackChannelByName`. The bot needs `groups:write`, `groups:write.invites`, `channels:write.invites`, `chat:write`, `channels:read`, and `groups:read`. A taken channel name returns 409.
|
|
74
|
+
- `@terreno/syncdb` query windows: set `queryCollections`, then use `client.queryWindows` or `useWindowQuery` (and generated `use{Collection}Window` hooks) for server-filtered, paged lists. `useQuery` and `useEntityIds` accept the same Mongo-style `where`, string sort, and `limit` for local queries. `fullSync: true` adds windows without turning off snapshot sync.
|
|
75
|
+
|
|
76
|
+
## Verification
|
|
77
|
+
|
|
78
|
+
- Apps that construct `InProcessRunner` with no options: confirm parallel model calls are acceptable, or pass `{concurrency: 1}`.
|
|
79
|
+
- Hit one list route with a filter field that is not in `queryFields` and confirm 400 `query-param-not-allowed` instead of a 200 that ignored the filter.
|
|
80
|
+
- `bun run compile` and `bun run lint` at the app root.
|
|
@@ -47,8 +47,11 @@ agents, tools, and conversations (see [The agent loop](#the-agent-loop)), subage
|
|
|
47
47
|
extensions, hooks, and memos (see [Extensions, hooks, and memos](#extensions-hooks-and-memos)),
|
|
48
48
|
events, waits, and approvals with the admin inbox, the SSE event stream, and version
|
|
49
49
|
pinning. The example backend's `clinic.intakeSummary` runs all of it end to end, including
|
|
50
|
-
a crash drill: [Build a durable workflow](../how-to/build-a-durable-workflow.md).
|
|
51
|
-
|
|
50
|
+
a crash drill: [Build a durable workflow](../how-to/build-a-durable-workflow.md).
|
|
51
|
+
|
|
52
|
+
Phase 2 so far: `InProcessRunner` concurrency (up to 8 tasks at once by
|
|
53
|
+
default) and the `JobsRunner`, which runs each phase as a `@terreno/jobs` job across many
|
|
54
|
+
instances. The Runs admin screen is still to come.
|
|
52
55
|
|
|
53
56
|
## Why the audit span shares the checkpoint transaction
|
|
54
57
|
|
|
@@ -237,8 +240,18 @@ tasks. Switching runners needs no data migration.
|
|
|
237
240
|
|
|
238
241
|
| Runner | Status | Ownership |
|
|
239
242
|
| --- | --- | --- |
|
|
240
|
-
| `InProcessRunner` | Shipped | One process holds the `HarnessOwner` lease and
|
|
241
|
-
| `JobsRunner` |
|
|
243
|
+
| `InProcessRunner` | Shipped | One process holds the `HarnessOwner` lease and runs up to `concurrency` (default 8) claimed tasks at once, each under its own task lease; others wait on standby and take over on lease expiry. |
|
|
244
|
+
| `JobsRunner` | Shipped | Every instance dispatches runnable tasks as `terreno.harness.phase` jobs; a job claims its task, runs one phase, and hands the task back. The task lease is the authority. |
|
|
245
|
+
|
|
246
|
+
Why the jobs runner runs **one** phase per job: a phase is the unit that commits, so it is
|
|
247
|
+
the natural unit of work to spread across instances and to bound by a request or job
|
|
248
|
+
timeout. Why the task lease and not the job lock decides who commits: a jobs lock can
|
|
249
|
+
expire while a long phase still runs, and a queue can deliver a job twice. Both are
|
|
250
|
+
harmless here, because the claim is an atomic fenced update and every commit checks the
|
|
251
|
+
lease token. Why the job key carries `claims`: `taskId:phase:attempt` alone repeats when a
|
|
252
|
+
task returns to the same phase without a failure (an event wake or a crash replay), and a
|
|
253
|
+
permanent idempotency key would then swallow the new visit. `claims` changes on every
|
|
254
|
+
claim, so each visit gets one job.
|
|
242
255
|
|
|
243
256
|
## Version pinning
|
|
244
257
|
|
|
@@ -39,6 +39,7 @@ Terreno 57.
|
|
|
39
39
|
3. **Encryption at rest (web)** — Web persistence uses AES-GCM via the default `createServerKeyProvider`; understand key fetch and `onDecryptFailure` for support flows.
|
|
40
40
|
4. **Key lifecycle on logout** — Call `syncDb.stop()` and consider `wipeLocalData` when the authenticated user changes so one account does not read another's local store.
|
|
41
41
|
5. **Backend sync registration** — Every synced collection needs `syncPlugin`, `isDeletedPlugin`, and a `sync` block on `modelRouter`, plus `SyncApp` and `RealtimeApp` on the server. Optional `sync.adminBroadcast: true` also emits `sync:delta` to `{collection}|admin`. Admin clients subscribe with `mode: "window"` (`createSyncDb({windowCollections})`) so they do not snapshot or reconcile that collection; they call `hydrateWindow` (REST membership ids + `GET /sync/entities`). Pass the same `accessControl` into `SyncApp` that `AdminApp` uses so `{collection}|admin` requires `admin:access`. `AdminApp.register` also installs that model's admin list/read/`queryFilter` on the admin window so hydrate and live `|admin` deltas match `/admin` REST. Without RBAC, `user.admin` is enough for the shell gate. Live deltas on that stream apply only to ids already in the window; Refresh is a REST re-query plus `hydrateWindow`.
|
|
42
|
+
6. **Collections too large to sync whole** — List them in `createSyncDb({queryCollections})`. They skip snapshot bootstrap; screens load server-filtered *query windows* (`useWindowQuery`) from the `modelRouter` list endpoint. A window stores only membership (ordered ids); rows live once in the shared entity table. Overlapping windows therefore share rows — one delta updates both views — while each view lists only its own query's members, plus cached rows that newly match its `where` inside the loaded range. Live deltas still arrive on the user's normal streams; windows on screen refetch on reconnect to cover deltas missed offline.
|
|
42
43
|
|
|
43
44
|
## Tradeoffs
|
|
44
45
|
|
|
@@ -37,6 +37,7 @@ Problem-oriented, practical steps. Use these when you know what you want to do.
|
|
|
37
37
|
- [Develop an AI feature](ai-feature-development.md) — Dataset → prompt → evaluators → experiment → production label → live traces (SOP)
|
|
38
38
|
- [Observe LLM calls](observe-llm-calls.md) — Register ObservabilityApp, primaries, price map, sampleRate
|
|
39
39
|
- [Build a durable workflow](build-a-durable-workflow.md) — Phased harness task with an agent, a human sign-off, and a once-only side effect (`clinic.intakeSummary`)
|
|
40
|
+
- [Run the harness on multiple instances](run-harness-on-multiple-instances.md) — `JobsRunner`: harness phases as `@terreno/jobs` jobs on every instance
|
|
40
41
|
- [Ship a new task version](ship-a-new-task-version.md) — Change a durable harness task without stranding in-flight runs
|
|
41
42
|
- [GitHub issue lifecycle](github-issue-lifecycle.md) — Create pick-ready issues, Pick ⇄ Roast, or unattended `status:ready-for-dev` pickup
|
|
42
43
|
- [Call external APIs](call-external-apis.md) — Authenticated HTTP client, retries, and error normalization for third-party integrations
|
|
@@ -94,7 +94,7 @@ Note the hook's output classification also feeds the client's retry decision —
|
|
|
94
94
|
|
|
95
95
|
- **Your own backend's routes** — use the generated `@terreno/rtk` SDK (frontend) or call the function directly (backend).
|
|
96
96
|
- **SDK-managed transport** (Twilio, googleapis) — don't fight the SDK's HTTP layer; adopt only `normalizeApiError`/`withApiErrorHandling` for consistent failure handling.
|
|
97
|
-
- **Webhook notifiers** — `sendToSlack`/`sendToGoogleChat`/`sendToZoom`
|
|
97
|
+
- **Webhook notifiers** — `sendToSlack`/`sendToGoogleChat`/`sendToZoom` post to a fixed webhook. Slack channel creation, invites, and bot posts use `createSlackPrivateChannel`, `inviteSlackUsersToChannel`, and `postSlackMessage` with `SLACK_BOT_TOKEN`. See [Webhooks & Notifications](../reference/api.md#webhooks--notifications).
|
|
98
98
|
|
|
99
99
|
## Related
|
|
100
100
|
|
|
@@ -152,7 +152,37 @@ import {useQuery} from "@terreno/syncdb/react";
|
|
|
152
152
|
const todos = useQuery<Todo>("todos", {filter: (t) => !t.completed});
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
`filter` / `sort` run in JS
|
|
155
|
+
`where` / `filter` / `sort` / `limit` run in JS over the local store. Tombstones are excluded unless `{includeDeleted: true}`.
|
|
156
|
+
|
|
157
|
+
### Filtered, sorted, and paged list args
|
|
158
|
+
|
|
159
|
+
RTK list args map to the same syntax. Pick the hook by collection size:
|
|
160
|
+
|
|
161
|
+
| RTK | Whole collection synced (`collections`) | Too large to sync whole (`queryCollections`) |
|
|
162
|
+
|-----|------------------------------------------|----------------------------------------------|
|
|
163
|
+
| `useGetMessagesQuery({threadId})` | `useQuery("messages", {where: {threadId}})` | `useWindowQuery("messages", {where: {threadId}})` |
|
|
164
|
+
| `{status: {$in: ["open", "pending"]}}` | `where: {status: {$in: [...]}}` | same |
|
|
165
|
+
| `{sort: "-created"}` | `sort: "-created"` | same |
|
|
166
|
+
| `{limit: 20}` | `limit: 20` | `pageSize: 20` |
|
|
167
|
+
| `{page: 2}` / load more | grow `limit` | `fetchNextPage()` |
|
|
168
|
+
| `data.more` / `data.total` | — | `hasMore` / `total` |
|
|
169
|
+
| `isLoading` / `isFetching` / `refetch` | not needed | `isLoading` / `isFetching` / `refetch` |
|
|
170
|
+
| `{skip: !threadId}` | not needed | `skip: !threadId` |
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import {useWindowQuery} from "@terreno/syncdb/react";
|
|
174
|
+
|
|
175
|
+
const {data: messages, hasMore, fetchNextPage, isLoading} = useWindowQuery<Message>("messages", {
|
|
176
|
+
where: {threadId},
|
|
177
|
+
sort: "-created",
|
|
178
|
+
pageSize: 30,
|
|
179
|
+
skip: !threadId,
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Windows with different filters keep separate result lists but share one local row per
|
|
184
|
+
document, so an edit to a message shown in two windows updates once. See
|
|
185
|
+
[Query windows](../reference/syncdb.md#query-windows).
|
|
156
186
|
|
|
157
187
|
### Delete this RTK read code
|
|
158
188
|
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# Preview a component demo
|
|
2
2
|
|
|
3
|
-
Open a component demo and change the shareable query. The preview
|
|
4
|
-
dev component routes
|
|
3
|
+
Open a component demo and change the shareable query. The preview controls sit in the
|
|
4
|
+
navigation header on demo and dev component routes: dropdowns for theme, viewport, and
|
|
5
|
+
background, plus a settings button (sliders icon) that opens a modal for right-to-left,
|
|
6
|
+
reduced motion, locale, and the share query. In windows narrower than 768px every
|
|
7
|
+
preview control moves into that modal; the Dev/Demo mode link stays in the header. `?embed=1` applies the same query and hides
|
|
8
|
+
the controls.
|
|
5
9
|
|
|
6
10
|
```text
|
|
7
11
|
/demo/Button?theme=dark&viewport=375&background=inverse&locale=en-US&rtl=1&reducedMotion=1
|
|
@@ -16,4 +20,4 @@ dev component routes. `?embed=1` applies the same query and hides the bar.
|
|
|
16
20
|
| `rtl` | `1` sets document direction to `rtl` on web |
|
|
17
21
|
| `reducedMotion` | `1` sets `data-reduced-motion="1"` on the document element |
|
|
18
22
|
|
|
19
|
-
Reload keeps the query. The
|
|
23
|
+
Reload keeps the query. The settings modal shows the current query when any value is not the default. Choosing a control's default removes that key from the URL. Leaving the component route restores the app theme and, on web, document direction and reduced motion. Custom palettes stay on `/palette`.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Run the harness on multiple instances
|
|
2
|
+
|
|
3
|
+
Run durable harness tasks on every instance of a scaled-out backend (for example several
|
|
4
|
+
Cloud Run instances). Swap the default `InProcessRunner`, where one process drains every
|
|
5
|
+
task, for `JobsRunner`, which runs each phase as a `@terreno/jobs` job. API:
|
|
6
|
+
[AI harness reference → JobsRunner](../reference/ai-harness.md#jobsrunner). Why it is safe:
|
|
7
|
+
[Durable agent harness → Runners](../explanation/durable-agent-harness.md#runners).
|
|
8
|
+
|
|
9
|
+
You need a working harness (see [Build a durable workflow](build-a-durable-workflow.md)) and
|
|
10
|
+
a MongoDB replica set. Task data does not change, so you can switch runners without a
|
|
11
|
+
migration.
|
|
12
|
+
|
|
13
|
+
## 1. Install the jobs package (1 minute)
|
|
14
|
+
|
|
15
|
+
`@terreno/jobs` is an optional peer of `@terreno/ai`. Add it to the app:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @terreno/jobs
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 2. Open the harness with a JobsRunner (5 minutes)
|
|
22
|
+
|
|
23
|
+
Create the `JobsApp` first, hand it to the runner, and register it on the app. Build the
|
|
24
|
+
app before the harness starts: `harness.start()` throws when no `JobsApp` is registered.
|
|
25
|
+
The runner defines the `terreno.harness.phase` job on it.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import {Harness} from "@terreno/ai/harness";
|
|
29
|
+
import {JobsRunner} from "@terreno/ai/harness/jobsRunner";
|
|
30
|
+
import {TerrenoApp} from "@terreno/api";
|
|
31
|
+
import {JobsApp} from "@terreno/jobs";
|
|
32
|
+
|
|
33
|
+
const jobs = new JobsApp();
|
|
34
|
+
const harness = await Harness.open({
|
|
35
|
+
registry: [intakeSummary, summarizer],
|
|
36
|
+
runner: new JobsRunner({jobs}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const app = new TerrenoApp({userModel: User}).register(jobs);
|
|
40
|
+
// ...register HarnessApp and your routes, then build or start the server.
|
|
41
|
+
app.start();
|
|
42
|
+
|
|
43
|
+
await harness.start();
|
|
44
|
+
await jobs.startWorker();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Shut down in the reverse order so phases in flight finish:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
await harness.stop(); // stops dispatching, waits for this instance's phases
|
|
51
|
+
await jobs.stopWorker();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 3. Run the same code on every instance
|
|
55
|
+
|
|
56
|
+
Every instance runs the same startup. Each one:
|
|
57
|
+
|
|
58
|
+
- scans for runnable tasks and enqueues one job per runnable phase (duplicates collapse on
|
|
59
|
+
the job's idempotency key),
|
|
60
|
+
- runs phase jobs from the shared jobs queue, and
|
|
61
|
+
- sweeps task leases that expired because an instance died.
|
|
62
|
+
|
|
63
|
+
No instance is special, and none waits on standby.
|
|
64
|
+
|
|
65
|
+
## 4. Check it works (2 minutes)
|
|
66
|
+
|
|
67
|
+
1. Start two backend processes against the same database (different `PORT`s).
|
|
68
|
+
2. Create a task (for the example backend, run `startClinicalIntake`).
|
|
69
|
+
3. Open the admin **Jobs** screen. Each phase shows as its own `terreno.harness.phase` job
|
|
70
|
+
with payload `{taskId}`.
|
|
71
|
+
4. Kill one process mid-phase. Within one lease (`leaseDuration`, default 30 s) the other
|
|
72
|
+
process replays a `replay: "safe"` phase, or parks any other phase as `interrupted`.
|
|
73
|
+
|
|
74
|
+
## Tune it
|
|
75
|
+
|
|
76
|
+
| Want | Set |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| Faster pickup of new work | `new JobsRunner({jobs, pollInterval: {milliseconds: 200}})` and `new JobsApp({pollIntervalMs: 200})` |
|
|
79
|
+
| Faster crash recovery | A shorter `leaseDuration` with `heartbeatInterval` about a third of it |
|
|
80
|
+
| Phases longer than the jobs lock TTL | Nothing: the task lease, renewed by heartbeats, decides who commits |
|
|
81
|
+
|
|
82
|
+
## Troubleshoot
|
|
83
|
+
|
|
84
|
+
- **Jobs fail with `harness-runner-stopped`.** A jobs worker runs on an instance whose
|
|
85
|
+
harness is not started. Start the harness before `jobs.startWorker()`. The jobs worker
|
|
86
|
+
retries the job, so no task is lost.
|
|
87
|
+
- **`harness.start()` throws "JobsRunner needs a registered JobsApp".** The dispatcher
|
|
88
|
+
enqueues through the registered jobs service, and `TerrenoApp` registers plugins when it
|
|
89
|
+
builds. Call `app.start()` (or `build()`) before `harness.start()`.
|
|
90
|
+
- **A task stays `pending`.** Check that its `name@version` is in the registry of the
|
|
91
|
+
running instances. A runner only dispatches registered versions.
|
|
92
|
+
- **Pick one runner per database.** Mixing them is safe (every claim and commit is fenced),
|
|
93
|
+
but an `InProcessRunner` owner then claims tasks itself and runs them to a stop.
|
|
@@ -140,7 +140,7 @@ On resume, a task whose status is `running` with an expired lease was interrupte
|
|
|
140
140
|
| Runner | Ownership | Use |
|
|
141
141
|
|---|---|---|
|
|
142
142
|
| `InProcessRunner` (default) | One process holds the `HarnessOwner` lease (heartbeat). A second process gets `standby` and takes over on lease expiry. Polls runnable tasks; wakes on `runAt` and events. | Local agents, single-instance apps, tests |
|
|
143
|
-
| `JobsRunner` (`@terreno/ai/harness/jobsRunner`, optional peer `@terreno/jobs`) | Each runnable phase → job `terreno.harness.phase`, idempotency key `taskId:phase:attempt
|
|
143
|
+
| `JobsRunner` (`@terreno/ai/harness/jobsRunner`, optional peer `@terreno/jobs`) | Each runnable phase → job `terreno.harness.phase`, idempotency key `taskId:phase:attempt:claims` (`claims` counts claims, so a phase revisited by an event wake or crash replay gets a new job; jobs idempotency keys are permanent). Handler acquires the task lease (fenced, heartbeat) and runs one phase. The task lease, not the job lock, is the authority. | Multi-instance Cloud Run |
|
|
144
144
|
|
|
145
145
|
### Ownership tree
|
|
146
146
|
|