@happyvertical/smrt-jobs 0.61.3 → 0.61.5
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/AGENTS.md +3 -3
- package/dist/chunks/{runner-DdonPDQV.js → runner-Bt6JV6uO.js} +160 -25
- package/dist/chunks/runner-Bt6JV6uO.js.map +1 -0
- package/dist/index.js +13 -15
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +797 -500
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -1
- package/dist/schedule-runner.d.ts.map +1 -1
- package/dist/smrt-job-dedupe-slot.d.ts.map +1 -1
- package/dist/smrt-job-event.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +138 -132
- package/dist/smrt-knowledge.okf.md +6 -2
- package/dist/terminal-outcome.d.ts.map +1 -1
- package/dist/worker-liveness-thread.js +11 -3
- package/dist/worker-liveness-thread.js.map +1 -1
- package/dist/worker-liveness-ticker.d.ts +23 -8
- package/dist/worker-liveness-ticker.d.ts.map +1 -1
- package/dist/worker-liveness.d.ts +37 -7
- package/dist/worker-liveness.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/chunks/runner-DdonPDQV.js.map +0 -1
- package/dist/chunks/worker-liveness-C1Gjnhax.js +0 -58
- package/dist/chunks/worker-liveness-C1Gjnhax.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -29,7 +29,7 @@ has no tenant filter; opt into that sweep only in an authorized maintenance host
|
|
|
29
29
|
`ClaimReadyOptions` and `ListReadyOptions` accept the same tenant scope. Queue
|
|
30
30
|
lease advertising remains queue-level; it does not prove per-tenant availability.
|
|
31
31
|
|
|
32
|
-
1. `start()` calls `assertReady()` (fail fast if `_smrt_workers` unmigrated), registers a seeded `SmrtWorker` lease, and adds its worker key to the process-global live set — all **before** polling
|
|
32
|
+
1. `start()` checks the build migrate fingerprint, then calls `assertReady()` (fail fast if `_smrt_workers` unmigrated), registers a seeded `SmrtWorker` lease, and adds its worker key to the process-global live set — all **before** polling
|
|
33
33
|
2. Polls `claimReady()` to atomically claim at most the free slots (`concurrency - active`) of pending jobs (`runAt <= NOW`, ordered by `priority DESC, runAt ASC, created_at ASC, id ASC`). On PostgreSQL the candidates come from a `MATERIALIZED` CTE joined to the UPDATE; never claim with `WHERE id IN (SELECT … LIMIT n FOR UPDATE SKIP LOCKED)` — a nested-loop semi join rescans it per outer row and takes the whole backlog (#3145). The runner also never starts more than the free slots and returns any surplus claim to `pending` with its attempt restored
|
|
34
34
|
3. Claim sets `status='running'`, `workerId=<incarnation key>`, heartbeat/start timestamps, and increments `attempts`
|
|
35
35
|
4. Resolves class via `ObjectRegistry.getClass(objectType)`. Object-bound jobs
|
|
@@ -81,7 +81,7 @@ Recovery keys on **worker-process liveness**, never per-job heartbeat freshness
|
|
|
81
81
|
- **`SmrtWorker` / `_smrt_workers`**: one lease row per runner *incarnation* (`workerId` is per-incarnation unique via `createWorkerKey`, so a restart never looks like it still owns the previous crash's jobs). `leaseExpiresAt` is a `datetime` (an integer epoch-ms column overflows `int4`/`INT32` on Postgres/DuckDB). Stage 1 writes/compares it against the host clock — the same approach the old heartbeat recovery used, so it's no more skew-sensitive than the code it replaced.
|
|
82
82
|
- **`SmrtWorker.queues`** (nullable JSON `string[]`, #3902): the runner's configured `queues`, written at `registerWorker` and re-written on every lease renewal (main-loop and off-loop ticker). `SmrtWorkerCollection.liveWorkerKeysForQueue(queue)` returns fresh-lease workers that poll a queue; rows with `queues = null` (older runners, schedule runners) never match. Existing databases need `smrt db:migrate` (additive column) before an upgraded runner starts.
|
|
83
83
|
- **Process-global live set** (`worker-liveness.ts`, `globalThis.__smrtLiveWorkers`): checked synchronously, so it can't be starved by a blocked loop. Covers all same-process topologies.
|
|
84
|
-
- **Off-loop ticker** (`worker-liveness-ticker.ts` + `worker-liveness-thread.ts`):
|
|
84
|
+
- **Off-loop ticker** (`worker-liveness-ticker.ts` + `worker-liveness-thread.ts`): renews the lease off the main loop, only on a same-engine connection (SQLite through `db.reopenOptions()`, engine checked, #4978); otherwise main-loop renewal with one log. Details: [agents/worker-liveness.md](agents/worker-liveness.md).
|
|
85
85
|
- **Recovery rule** (both runners): a `running` job is orphaned iff its worker is *not alive* = not in the live set **and** no fresh `_smrt_workers` lease. The live set takes precedence over a stale lease. TaskRunner also never recovers a job in its own `activeJobs`. If `_smrt_workers` is absent, recovery skips lease checks (never mass-recovers). Recovery is swept at most once per lease tick, and terminal/recovery writes use `RETURNING id` (not `rowCount`, which DuckDB/JSON adapters always report as ≥1).
|
|
86
86
|
- **Lease clock**: the lease is compared against the host clock (same as the old heartbeat; fine with NTP + a 30s TTL). A dead process stops renewing and the lease expires within its TTL — that is how recovery detects death. (Instant cross-process detection via Postgres session advisory locks was prototyped on `@happyvertical/sql`'s `acquireSession()` but deferred — treating a free lock as proof-of-death false-recovers any worker legitimately in main-loop fallback mode.)
|
|
87
87
|
|
|
@@ -232,5 +232,5 @@ the framework retention sweep in `@happyvertical/smrt-core`.
|
|
|
232
232
|
- **Result storage**: `resultPointer` is just a string — app must implement result backend
|
|
233
233
|
- **Lazy builder**: `background()` returns builder — nothing happens until `enqueue()`
|
|
234
234
|
- **wait() is polling**: JobHandle.wait() polls DB every 100ms (configurable)
|
|
235
|
-
- **Migrate before start()**: `TaskRunner.start()` throws if `_smrt_workers` is missing — run `smrt db:migrate` after upgrading. Tables are never created at runtime.
|
|
235
|
+
- **Migrate before start()**: Both runners call core's `assertDatabaseMigratedForBuild` before polling (policy: [schema paths](../core/agents/schema-paths.md)). A missing or different record refuses production start; development warns, test databases are exempt, and the emergency override is logged. `TaskRunner.start()` throws if `_smrt_workers` is missing — run `smrt db:migrate` after upgrading. Tables are never created at runtime.
|
|
236
236
|
- **Recovery is liveness-based**: don't reintroduce heartbeat-threshold recovery; a blocked event loop must not look dead (see Worker liveness section, #1474)
|