@ultimat3/cli 31.48.0 → 31.49.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/CLAUDE.md +30 -23
- package/README.md +96 -4
- package/package.json +29 -29
- package/src/api-registration.ts +28 -14
- package/src/app-load.ts +6 -1
- package/src/app-root.ts +7 -1
- package/src/clean-services.ts +142 -0
- package/src/cmd-auth.ts +3 -0
- package/src/cmd-clean-spec.ts +10 -3
- package/src/cmd-clean.ts +23 -9
- package/src/cmd-db-backfill.ts +6 -0
- package/src/cmd-db-branch.ts +10 -4
- package/src/cmd-db-recount.ts +5 -12
- package/src/cmd-db-rollback.ts +77 -0
- package/src/cmd-db-spec.ts +18 -2
- package/src/cmd-db-status.ts +5 -10
- package/src/cmd-db.ts +105 -33
- package/src/cmd-deploy-verify.ts +14 -6
- package/src/cmd-docs-topic.ts +94 -0
- package/src/cmd-docs.ts +15 -1
- package/src/cmd-doctor.ts +109 -41
- package/src/cmd-drill.ts +80 -18
- package/src/cmd-env.ts +30 -8
- package/src/cmd-errors-app.ts +63 -0
- package/src/cmd-errors.ts +50 -14
- package/src/cmd-generate.ts +17 -4
- package/src/cmd-heavy-spec.ts +9 -1
- package/src/cmd-heavy.ts +111 -27
- package/src/cmd-jobs.ts +27 -1
- package/src/cmd-merge-driver-spec.ts +12 -0
- package/src/cmd-merge-driver.ts +95 -0
- package/src/cmd-new.ts +23 -3
- package/src/cmd-policy-spec.ts +9 -1
- package/src/cmd-policy.ts +72 -17
- package/src/cmd-stop.ts +18 -4
- package/src/cmd-tasks-run.ts +87 -0
- package/src/cmd-tasks-spec.ts +10 -3
- package/src/cmd-tasks.ts +8 -5
- package/src/cmd-test.ts +2 -1
- package/src/cmd-upgrade-spec.ts +8 -1
- package/src/cmd-upgrade.ts +15 -1
- package/src/cmd-verify.ts +9 -41
- package/src/codemods/agents-doc-row.ts +73 -0
- package/src/codemods/define-error-leaf.ts +37 -12
- package/src/codemods/docs-many-agents.ts +11 -15
- package/src/codemods/docs-worker-commands.ts +26 -0
- package/src/codemods/index.ts +4 -0
- package/src/codemods/merge-drivers.ts +66 -0
- package/src/command.ts +3 -0
- package/src/db-applied-edits.ts +117 -0
- package/src/db-dev-wire.ts +18 -0
- package/src/db-diagnostics.ts +5 -10
- package/src/db-generate.ts +82 -7
- package/src/db-migrate-pass.ts +51 -0
- package/src/db-migrate-through-dev.ts +209 -0
- package/src/db-rollback-consent.ts +128 -0
- package/src/db-rollback-pass.ts +76 -0
- package/src/db-seed-generate.ts +5 -1
- package/src/db-seed.ts +7 -1
- package/src/deploy-verify-findings.ts +3 -0
- package/src/deploy-verify-grade.ts +3 -0
- package/src/deploy-verify-processes.ts +32 -0
- package/src/dev-boot.ts +3 -0
- package/src/dev-db-migrate.ts +155 -0
- package/src/dev-db-rollback.ts +33 -0
- package/src/dev-db-settled.ts +22 -0
- package/src/dev-lock-errors.ts +78 -0
- package/src/dev-lock-holder-dir.ts +64 -0
- package/src/dev-lock-live.ts +44 -0
- package/src/dev-lock.ts +59 -84
- package/src/dev-policy.ts +11 -8
- package/src/dev-rebuild-schema.ts +116 -13
- package/src/dev-rebuild.ts +13 -4
- package/src/dev-route-table.ts +7 -0
- package/src/dispatch.ts +21 -1
- package/src/doctor-api-listing.ts +114 -0
- package/src/doctor-guarded.ts +41 -0
- package/src/doctor-port.ts +90 -17
- package/src/doctor-probe.ts +36 -5
- package/src/doctor-processes-probe.ts +127 -0
- package/src/doctor-processes.ts +136 -0
- package/src/doctor-warnings.ts +17 -0
- package/src/error-codes-agents.ts +35 -0
- package/src/error-codes-processes.ts +30 -0
- package/src/error-codes-tooling.ts +2 -0
- package/src/error-codes.ts +12 -13
- package/src/errors-suite.ts +27 -0
- package/src/errors.ts +18 -22
- package/src/exercise-registration.ts +4 -3
- package/src/framework-env.ts +7 -3
- package/src/generate-files.ts +1 -0
- package/src/generate-grant-findings.ts +7 -5
- package/src/generate-grants.ts +9 -8
- package/src/generate-kinds.ts +30 -6
- package/src/generate-roles-file.ts +30 -0
- package/src/generate-slice-policy.ts +3 -3
- package/src/guards.ts +2 -2
- package/src/heavy-env.ts +2 -0
- package/src/heavy-errors.ts +18 -0
- package/src/heavy-holders.ts +78 -0
- package/src/heavy-ledger.ts +56 -14
- package/src/heavy-pressure.ts +104 -0
- package/src/heavy.ts +31 -13
- package/src/i18n-registration.ts +22 -2
- package/src/island-harness.ts +2 -2
- package/src/job-budget.ts +4 -2
- package/src/job-registration.ts +64 -8
- package/src/jobs-queue-known.ts +43 -0
- package/src/mcp-errors-agents.ts +20 -0
- package/src/mcp-errors-doctor.ts +27 -0
- package/src/mcp-errors-processes.ts +23 -0
- package/src/mcp-errors.ts +15 -29
- package/src/mcp-host.ts +2 -2
- package/src/merge-driver-catalog.ts +58 -0
- package/src/merge-driver-config.ts +43 -0
- package/src/merge-driver-lines.ts +140 -0
- package/src/merge-state.ts +105 -0
- package/src/messages-db.ts +22 -1
- package/src/messages-processes.ts +13 -0
- package/src/messages-upgrade.ts +6 -0
- package/src/messages.ts +54 -4
- package/src/output-findings.ts +48 -21
- package/src/parse.ts +37 -6
- package/src/policy-facts.ts +38 -21
- package/src/policy-row.ts +99 -0
- package/src/port-pair-free.ts +28 -0
- package/src/registry-lines.ts +110 -0
- package/src/registry.ts +2 -0
- package/src/retain-sweep.ts +1 -1
- package/src/role-replicator.ts +4 -1
- package/src/role-select.ts +86 -0
- package/src/role-start.ts +13 -55
- package/src/role-sync.ts +10 -5
- package/src/runtime-cache-frame.ts +46 -0
- package/src/runtime-cache-ttl.ts +23 -0
- package/src/runtime-cache.ts +33 -16
- package/src/runtime-database-ssl.ts +84 -0
- package/src/runtime-idempotency-scope.ts +16 -2
- package/src/runtime-jobs-share.ts +52 -0
- package/src/runtime-jobs.ts +43 -12
- package/src/runtime-queue.ts +18 -3
- package/src/runtime-services.ts +8 -1
- package/src/schema-drift.ts +19 -2
- package/src/schema-dump-drift.ts +4 -1
- package/src/serve-boot-probe.ts +30 -2
- package/src/serve-boot.ts +11 -1
- package/src/serve-env.ts +39 -3
- package/src/serve.ts +61 -10
- package/src/stop-run-start.ts +12 -0
- package/src/supervise-boot.ts +61 -0
- package/src/supervise-cgroup.ts +84 -0
- package/src/supervise-child.ts +206 -0
- package/src/supervise-count.ts +244 -0
- package/src/supervise-errors.ts +83 -0
- package/src/supervise-facts.ts +40 -0
- package/src/supervise-messages.ts +84 -0
- package/src/supervise-policy.ts +46 -0
- package/src/supervise-pool.ts +10 -0
- package/src/supervise-probe.ts +158 -0
- package/src/supervise-run.ts +54 -0
- package/src/supervise.ts +383 -0
- package/src/templates/generate-purge.ts +6 -6
- package/src/templates/guard-animated-layout-property.ts +2 -2
- package/src/templates/guard-bare-error.ts +1 -1
- package/src/templates/guard-error-declared.ts +2 -2
- package/src/templates/guard-focus-visible.ts +1 -1
- package/src/templates/guard-image-dimensions.ts +2 -2
- package/src/templates/guard-island-mount-clears.ts +1 -1
- package/src/templates/guard-native-confirm.ts +1 -1
- package/src/templates/guard-raw-breakpoint.ts +2 -2
- package/src/templates/guard-raw-colour.ts +2 -2
- package/src/templates/guard-raw-fetch.ts +1 -1
- package/src/templates/guard-raw-interval.ts +1 -1
- package/src/templates/guard-raw-length.ts +3 -3
- package/src/templates/guard-raw-motion.ts +1 -1
- package/src/templates/guard-raw-shadow.ts +1 -1
- package/src/templates/guard-raw-z-index.ts +1 -1
- package/src/templates/guard-released-forms.ts +54 -8
- package/src/templates/guard-repo-await-in-loop.ts +1 -1
- package/src/templates/guard-repo-raw-sql.ts +4 -4
- package/src/templates/guard-repo-unbounded.ts +1 -1
- package/src/templates/guard-runtime-pin.ts +1 -1
- package/src/templates/guard-semantic-interactive.ts +2 -2
- package/src/templates/guard-unbounded-fanout.ts +1 -1
- package/src/templates/guard-undeclared-custom-property.ts +3 -3
- package/src/templates/guard-undefined-style-class.ts +3 -3
- package/src/templates/guard-unzoned-date.ts +3 -3
- package/src/templates/query-slice.ts +82 -0
- package/src/templates/query.ts +76 -30
- package/src/templates/resource-page.ts +3 -2
- package/src/templates/scaffold-bin.ts +2 -0
- package/src/templates/scaffold-claude-commands.ts +6 -0
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +47 -7
- package/src/templates/scaffold-docs.ts +7 -3
- package/src/templates/scaffold-gitattributes.ts +18 -1
- package/src/templates/scaffold-helm-templates.ts +9 -0
- package/src/templates/scaffold-repo.ts +4 -1
- package/src/templates/scaffold-test-services.ts +33 -11
- package/src/templates/shapes/offline.ts +0 -7
- package/src/templates/shapes/realtime.ts +2 -6
- package/src/templates/sign-in-action-tests.ts +6 -4
- package/src/templates/sign-in-challenge.ts +62 -0
- package/src/templates/sign-in-oidc-mfa.ts +31 -0
- package/src/templates/sign-in-oidc.ts +11 -3
- package/src/templates/sign-in-password.ts +18 -56
- package/src/test-shards.ts +114 -34
- package/src/test-verdict.ts +79 -0
- package/src/test-workers.ts +15 -0
- package/src/upgrade-gate-codemods.ts +5 -3
- package/src/upgrade-gate.ts +19 -1
- package/src/upgrade-merge-drivers.ts +25 -0
- package/src/upgrade-report.ts +18 -4
- package/src/upgrade-scope.ts +62 -0
- package/src/verify-checks.ts +2 -8
- package/src/verify-coverage-run.ts +4 -1
- package/src/verify-live.ts +38 -14
- package/src/verify-only.ts +67 -0
- package/src/verify-progress.ts +7 -3
- package/src/verify-run.ts +20 -2
- package/src/verify-services-stack.ts +165 -0
- package/src/verify-services.ts +84 -2
- package/src/verify-test-run.ts +6 -7
- package/src/verify-tests.ts +8 -2
- package/src/verify-typecheck.ts +25 -2
- package/wiki/Actions.md +2 -1
- package/wiki/Admin-Dashboard.md +2 -2
- package/wiki/Agents.md +5 -5
- package/wiki/Auth.md +15 -5
- package/wiki/Bare-VM.md +1 -1
- package/wiki/CI-Parallel-Gate.md +2 -1
- package/wiki/CLI-Reference.md +107 -40
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Client-Navigation.md +1 -1
- package/wiki/Configuration.md +10 -9
- package/wiki/Deployment.md +44 -4
- package/wiki/Entities-And-Migrations.md +5 -1
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +2 -2
- package/wiki/Home.md +1 -1
- package/wiki/I18n.md +5 -3
- package/wiki/Installation.md +12 -11
- package/wiki/Jobs-And-Workflows.md +24 -4
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +8 -5
- package/wiki/Many-Agents.md +69 -2
- package/wiki/Migrations-And-Backfills.md +18 -0
- package/wiki/Notify.md +1 -1
- package/wiki/Observability.md +13 -0
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +10 -1
- package/wiki/Routes-And-Render-Modes.md +1 -1
- package/wiki/Scheduled-Tasks.md +4 -1
- package/wiki/Testing.md +7 -4
- package/wiki/Timezones-And-Dates.md +5 -1
- package/wiki/Troubleshooting.md +1 -0
- package/wiki/Tutorial-01-First-App.md +3 -3
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
- package/wiki/Upgrading.md +37 -0
package/wiki/Deployment.md
CHANGED
|
@@ -128,7 +128,7 @@ helm upgrade app docker/helm --set roles.worker.retireSeconds=7200 \
|
|
|
128
128
|
--set drain.workerDeadlineSeconds=7500 # 2 h worker; `x deploy --method helm` sets both itself
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
**`x verify` holds the job to it**: a job whose declared `timeout` exceeds the worker's budget (`drain.workerRetireMs` when above 0, else `drain.workerDeadlineMs`, else `drain.deadlineMs`) reds the `manifest` step with `X_JOB_OUTLASTS_DRAIN`, naming the job, its limit and the budget. A job with no `timeout` is not graded.
|
|
131
|
+
**`x verify` holds the job to it**: a job whose declared `timeout` exceeds the worker's budget (`drain.workerRetireMs` when above 0, else when the drain cancels a held job: `drain.workerDeadlineMs`, else `drain.deadlineMs`, less the later hooks' reserve and the 2 s cut-off margin — 21 s of 25 s, `As of 2026-11-19`) reds the `manifest` step with `X_JOB_OUTLASTS_DRAIN`, naming the job, its limit and the budget. A job with no `timeout` is not graded.
|
|
132
132
|
|
|
133
133
|
**Compose stays SIGTERM with `stop_grace_period`**: it has no `preStop`, and a SIGKILL mid-job is worse than a handed-back claim, so size `stop_grace_period` to the drain as below. It is the single-node rung, and makes no such claim → [scale ladder](https://github.com/developerz-ai/ultimate/blob/main/docs/idea/17-scale-ladder.md).
|
|
134
134
|
|
|
@@ -304,15 +304,53 @@ services:
|
|
|
304
304
|
|
|
305
305
|
**The `/app/.x` tmpfs is owned by the image's user** (`As of 30.0.0`): `'/app/.x:uid=1000,gid=1000'` in the scaffold (its `USER 1000:1000`), `uid=65532` in the framework's specimen (distroless `nonroot`). A tmpfs mounts root-owned under `read_only: true`, so before this every role refused at boot with `X_STORAGE_UNWRITABLE … EACCES mkdir '/app/.x/storage'`. An app scaffolded earlier edits that one line.
|
|
306
306
|
|
|
307
|
-
> **`web` and `sync` are one
|
|
307
|
+
> **`web` and `sync` are one container each, and the file says so** `As of 2026-11`. Both publish a host port, one host port has exactly one binder, so both declare `replicas: 1` — a ceiling that is declared rather than discovered when the second container dies on `port is already allocated`. One container is no longer one core: it runs one process per declared CPU on one port ([Processes per container](#processes-per-container)). `worker`, `scheduler` and `replicator` publish nothing; `worker` scales freely.
|
|
308
308
|
>
|
|
309
309
|
> | Want | Do |
|
|
310
310
|
> |---|---|
|
|
311
|
-
> | more `web`/`sync` on the same box |
|
|
311
|
+
> | more cores for `web`/`sync` on the same box | raise the service's `cpus:` (and `mem_limit` at 256 MiB per process): the container runs that many processes on its one port |
|
|
312
|
+
> | more `web`/`sync` containers on the same box | delete their `ports:` lines, add a reverse proxy of your choosing to the compose file, point it at the service names — compose DNS resolves each to every replica |
|
|
312
313
|
> | more `web`/`sync`, full stop | the Helm chart below, which carries a per-role HPA and an Ingress |
|
|
313
314
|
>
|
|
314
315
|
> The framework ships neither proxy: a proxy image in `docker-compose.prod.yml` is a dependency every app inherits and a second answer to "how does traffic reach a role" beside the chart's Ingress. This is the rung-1 ceiling → [`docs/idea/17-scale-ladder.md`](https://github.com/developerz-ai/ultimate/blob/main/docs/idea/17-scale-ladder.md).
|
|
315
316
|
|
|
317
|
+
## Processes per container
|
|
318
|
+
|
|
319
|
+
**A production container runs one process per declared CPU, on one port** `As of 2026-11`. The process the platform starts becomes a supervisor: it opens `METRICS_PORT`, spawns N copies of the same entry point (`ULTIMATE_CHILD=<i>/<N>` in each), and the children share the role's port through `SO_REUSEPORT` — the kernel hands each new connection to one of them. One process per core is how a serving path uses a second core: a process runs its requests, jobs and sockets on one JavaScript thread (a `Worker` beside it — `transformImageBytes`' raster worker — takes work off that thread, never requests).
|
|
320
|
+
|
|
321
|
+
**Production containers only.** `x dev`, the test runner and every environment other than `production` and `staging` run one process; a count set there is ignored with one `info` line, never refused (a `.env` shared with production must not stop a laptop).
|
|
322
|
+
|
|
323
|
+
**`ULTIMATE_PROCESSES`** = `auto` (the default, also unset or blank) or a positive whole number, per service. Anything else is `X_PROCESSES_INVALID`. The boot names the count and the clamp that bound it in one line: `ultimate processes` with `count`, `binding` and each clamp's value.
|
|
324
|
+
|
|
325
|
+
`auto` is the minimum of:
|
|
326
|
+
|
|
327
|
+
| Clamp (`binding`) | Value |
|
|
328
|
+
|---|---|
|
|
329
|
+
| `environment` | 1 outside `production` / `staging` |
|
|
330
|
+
| `platform` | 1 off Linux: Bun ignores `reusePort` on macOS and Windows |
|
|
331
|
+
| `role` | 1 for `scheduler`, `replicator`, `migrate` (a lease row, a replication slot, run-once) |
|
|
332
|
+
| `cpu` | the cgroup's CPU quota in whole CPUs, floored, at least 1 (`cpus: '1.5'` → 1), and no more than `navigator.hardwareConcurrency`. **No quota declared (`cpu.max` = `max`) → 1**, whatever the host has |
|
|
333
|
+
| `memory` | `floor((memory limit − 32 MiB) / 256 MiB)`, at least 1; no bound when unlimited |
|
|
334
|
+
| `pool` | `DATABASE_POOL_MAX`, else the role's profile (web 20, sync 10, worker 8): every child needs a connection |
|
|
335
|
+
| `shared-state` | 1 if any per-process state would split: the `lru` cache tier with neither `NATS_URL` nor `REDIS_URL`/`VALKEY_URL`, a `runtime.ts` store whose `scope` is not `'shared'`, the embedded database (no `DATABASE_URL`), `sync` without `NATS_URL` or a crossing transport |
|
|
336
|
+
| `image` | 1 when the image carries no prebuilt store (`X_IMAGE_NOT_PREBUILT`): each child would compile the islands |
|
|
337
|
+
|
|
338
|
+
An explicit count is honoured and checked: 1 always runs; above 1 it is refused for a singleton role (`X_PROCESSES_ROLE_SINGLETON`), off Linux (`X_PROCESSES_UNBALANCED`), over per-process state (`X_PROCESSES_UNSHARED_STATE`) and above the pool (`X_PROCESSES_OVER_POOL`); above the memory fit it runs with a `warn` line. A child whose boot is refused for a reason the same image and environment meet again — a missing or malformed variable (`X_ENV_MISSING`, `X_ROLE_UNKNOWN`, `X_PORT_INVALID`), `X_CONFIG_INVALID`, a secrets or seal key that does not match, an unresolved import, every `X_PROCESSES_*` refusal — is not restarted: it logs `ultimate child refused to boot` with its own code and fix, the siblings drain and the container exits 1 at once (`FATAL_BOOT_CODES`, `packages/cli/src/supervise-child.ts`). What can heal by itself — a database, Redis or NATS still starting, migrations not yet applied, a port still held — is restarted with backoff. A child that exits unexpectedly 5 times in 5 minutes is `X_PROCESS_CRASH_LOOP`: the siblings drain and the container exits 1 for the platform to restart.
|
|
339
|
+
|
|
340
|
+
**Per container, never per process**: `DATABASE_POOL_MAX` (each child gets its `childShare`, so the container's connections do not grow with N), `jobs.concurrency` and `jobs.maxInFlight` (split the same way; a queue whose total is below N is served only by children with index < total, so `concurrency: 1` stays serial across the container). Each worker child holds its own LISTEN session: connections per container = pool + N for `worker`. `x doctor` prints both per role; `x deploy verify` reports N registry rows per worker container (`data.queues.containers`). Per-process still, and so N× per container: `perTenant` / `ratePerTenant` job caps and the per-actor socket caps — as with N containers today.
|
|
341
|
+
|
|
342
|
+
| What | Rule |
|
|
343
|
+
|---|---|
|
|
344
|
+
| `cpus:` | the knob `auto` reads. The shipped compose files declare `web: '2'`, `sync: '1'`, `worker: '1'` per replica (raise it for CPU-heavy queues), `scheduler: '0.5'`, and the framework's `replicator: '0.5'` (the scaffold writes no `replicator` service) |
|
|
345
|
+
| memory | 256 MiB per child plus headroom. Measured private memory of a reference-app web child: 104–106 MiB idle, 227 MiB peak under load; worker and sync 97–100 MiB idle; the supervisor about 3 MiB (`As of 2026-11`, Bun 1.4.4, Linux) |
|
|
346
|
+
| `init: true` | on every service. Bun as PID 1 never reaps an orphaned grandchild (zombies stay) and ignores SIGTERM until a handler is installed (`docker stop` waited out its grace and SIGKILLed); Docker's init fixes both |
|
|
347
|
+
| `sysctls: { net.ipv4.tcp_migrate_req: 1 }` | **an opt-in, commented out** on `web` and `sync` in the shipped files, never active: on a kernel older than Linux 5.14 (RHEL 8, Ubuntu 20.04, Amazon Linux 2) the knob does not exist and Docker refuses to create the container. Uncomment it on a host ≥ 5.14 where the container runs more than one process: closing a shared-port listener — a drain, a crash — otherwise resets every connection still queued on it (93–109 of 200 reset with the host default 0, 0 of 200 with the sysctl; per network namespace). At N = 1 it buys nothing. `x doctor` warns when N > 1 and the knob exists and reads 0 |
|
|
348
|
+
| a proxy in front | nginx and Caddy defaults need nothing: under load an HTTP/1.1 proxy opens one upstream connection per in-flight request, and CPU-bound work split 24–26 % per child at N=4. The upstream needs **at least 4 × N concurrent connections at peak**: with about 2N or fewer long-lived connections some child often gets none (balancing is per connection, by hash) and 20–40 % of throughput is lost. Do not cap upstream connections near N (`max_conns`, a tunnel with a fixed connection count). An HTTP/2-multiplexed upstream (one connection) is **unsupported for N > 1**: unmeasured, and the worst case puts everything on one child |
|
|
349
|
+
| probes | the supervisor answers `METRICS_PORT`: `/healthz` (alive, not in a crash loop), `/readyz` (at least one child ready, every other one ready or draining, the container not stopping), `/metrics` (every child's, merged with a `child` label → [Observability](Observability)). The image's `HEALTHCHECK` on `$PORT/readyz` reaches one child at random. A child opens no boot probe on the shared port: a plain bind would refuse its siblings (EADDRINUSE) and a shared one would take real traffic to answer 503 |
|
|
350
|
+
| drain | SIGTERM, SIGINT and SIGUSR2 (worker retire) go to every child at once; each child's budget starts at its `draining` acknowledgement (a CPU-saturated child heard the signal 1.9–5.2 s late, measured) and it is SIGKILLed 2 s past it; one outer ceiling, the longest budget + 6 s from the signal, bounds the container. Children drain in parallel, so `stop_grace_period` and `terminationGracePeriodSeconds` do not change. Exit 0 if every child exited 0, 70 if any hit its drain deadline |
|
|
351
|
+
|
|
352
|
+
What it buys, measured (`As of 2026-11`, Bun 1.4.4, Linux, 8 cores, a box shared with other agents — read the ratios, not the absolutes): a handler burning ~2 ms of CPU went from 523 rps at N=1 to 1,485–1,711 at N=4 (2.9–3.3×); the reference app spends 0.24–0.34 CPU-ms per request and one process saturates one core at 3.4–4.7k rps, so `web` sits in the CPU-bound row. A pure-wait handler gains nothing until one process saturates (~50k rps here). The full table: [`docs/idea/17-scale-ladder.md`](https://github.com/developerz-ai/ultimate/blob/main/docs/idea/17-scale-ladder.md).
|
|
353
|
+
|
|
316
354
|
## Helm
|
|
317
355
|
|
|
318
356
|
**`x new` writes it**, `As of 2026-08-19` — `docker/helm`, one `Deployment` per role, 8 files: `Chart.yaml`, `values.yaml` and 6 templates. There is still no `--helm` flag on `x build`; the chart is a scaffold artifact like `docker/Dockerfile`, not a build target.
|
|
@@ -326,6 +364,8 @@ services:
|
|
|
326
364
|
| `replicator` | none — `replicas: 1` | 1 | owns the slot; `strategy: Recreate`, because a surged pod can only stand by unready and `maxUnavailable: 0` would never retire the holder |
|
|
327
365
|
| `migrate` | n/a | — | pre-install/pre-upgrade `Job` hook; blocks the release on failure |
|
|
328
366
|
|
|
367
|
+
**One process per pod**: both charts set `ULTIMATE_PROCESSES: "1"` on every role (`env.ULTIMATE_PROCESSES` in values wins). Per-pod parallelism is the HPA's; the chart sets CPU requests and no limits, so `auto` already resolves to 1 there — the pin makes the count explicit, and a CPU limit added later cannot raise it.
|
|
368
|
+
|
|
329
369
|
CPU autoscaling is wrong for `sync` and `worker`: a node holding 80k idle sockets is near-zero CPU and near-capacity, and a worker blocked on a slow HTTP call is idle CPU with a growing backlog. The framework **declares** both series — `connections` and `queue_demand`, with `rps` derived from the monotonic `http_requests_total` — and `SCALING_METRICS` maps each role's signal to its series so the chart and the role table cannot drift. `As of 2026-08` every role serves `/metrics` on `METRICS_PORT` (default 9090) and `http`/`realtime`/`jobs` call the recorders, so the signals exist. **The chart's half is closed in 2.0.0**: `values.yaml` declares `metricsPort: 9090`, `_helpers.tpl` emits a container port named `metrics` on every role but `migrate`, `service.yaml` publishes it by name and `templates/servicemonitor.yaml` ships the scrape target. `serviceMonitor.enabled` is `auto`: the object renders wherever the cluster serves the Prometheus operator's kind and is skipped where it does not, so `helm install` never fails on an unknown kind — and `templates/alert-rules.yaml` ships the mechanism alerts the same way (`alerts.enabled: auto`). One thing remains, and it is not the chart's: turning scraped series into the `Pods` metrics an HPA reads needs a **custom-metrics adapter**. Do not hand-add a metrics container port — the chart already emits one and a duplicate is rejected by the API server → [Observability](Observability).
|
|
330
370
|
|
|
331
371
|
`x deploy --method helm` works in a fresh app `As of 2026-08-19`: the command implements helm
|
|
@@ -419,7 +459,7 @@ Then reopen the pooler's server connections: a role setting applies at login.
|
|
|
419
459
|
| Role | Under `DATABASE_POOLER=transaction` |
|
|
420
460
|
|---|---|
|
|
421
461
|
| `web`, `sync`, `scheduler` | runs |
|
|
422
|
-
| `worker` | runs on the poll: no wake, pickup within `idlePollMaxMs`, `jobs.wake.unverified` once. For the wake, a direct or session-pooled `DATABASE_URL` and `DATABASE_POOLER` unset or `session` for that role |
|
|
462
|
+
| `worker` | runs on the poll: no wake, pickup within `idlePollMaxMs`, `jobs.wake.unverified` once. For the wake, a direct or session-pooled `DATABASE_URL` and `DATABASE_POOLER` unset or `session` for that role. A proven wake is re-proven every 10 s (`reproveEveryMs`): a session that stops delivering logs `jobs.wake.lost` and the worker returns to the 2 s poll |
|
|
423
463
|
| `migrate`, `replicator`, `x db migrate` | `X_DB_POOLER_SESSION_REQUIRED`, before a socket: point `DATABASE_URL` at the server's own port and unset the switch for that role |
|
|
424
464
|
|
|
425
465
|
`x doctor --json` reports the bound as the session reads it (`data.statementBound`). A bound that
|
|
@@ -179,6 +179,10 @@ constructs where the two engines disagree are **refused at declaration**:
|
|
|
179
179
|
| `\s` `\S` | `'\u00a0'` is whitespace to JS, not to Postgres | `[ \t\n\r\f\v]` |
|
|
180
180
|
| `\A` `\Z` | anchors in Postgres, letters in JS | `^` `$` |
|
|
181
181
|
| `\1`–`\9`, `(?<name>…)`, `(?i)`, `[[:alpha:]]`, a non-ASCII range endpoint | backreference, named group, embedded flag, POSIX class, collation-ordered range | a predicate |
|
|
182
|
+
| a surrogate escape `\uD800`–`\uDFFF` (any astral character written in a regex literal) | JS matches the pair as one character, Postgres reads two code points no text holds — its CHECK refused every row. `As of 2026-11-19` | a predicate |
|
|
183
|
+
| a repetition bound above 255 (`{256}`) | Postgres refuses the migration: invalid repetition count. `As of 2026-11-19` | a smaller bound, or a predicate on `length` |
|
|
184
|
+
| a `-` straight after a range or `\d`/`\D` inside a class, not last (`[a-z-9]`, `[\d-z]`) | Postgres refuses an invalid range; JS reads a literal `-`. `As of 2026-11-19` | `-` last in the class: `[a-z9-]` |
|
|
185
|
+
| a quantified lookaround (`(?=…)*`, `(?!…){2}`) | JS allows it (Annex B), Postgres refuses the operand. `As of 2026-11-19` | the lookaround unquantified |
|
|
182
186
|
|
|
183
187
|
The refusal is `X_INVARIANT_VIOLATED` at `entity()` time — before a migration exists — and names the
|
|
184
188
|
construct, its index, both readings, and the portable spelling where there is one. The subset is
|
|
@@ -1386,7 +1390,7 @@ Rule: `.search(term)` on a chain asks the INSTALLED `SearchIndex` — one search
|
|
|
1386
1390
|
| Index | How `.search(term)` answers |
|
|
1387
1391
|
|---|---|
|
|
1388
1392
|
| the built-in Postgres one (default) | inside the statement, its `matches` predicate over the `.searchable()` columns — the same SQL as before the port; costs a write nothing |
|
|
1389
|
-
| an external one (`searchIndex` in `apps/<app>/runtime.ts`: Meilisearch, Typesense, the app's adapter) | ids first, then the chain reads those rows — tenancy, soft delete, order and cursor still apply, so a hit can never widen what the chain sees |
|
|
1393
|
+
| an external one (`searchIndex` in `apps/<app>/runtime.ts`: Meilisearch, Typesense, the app's adapter) | ids first, then the chain reads those rows — tenancy, soft delete, order and cursor still apply, so a hit can never widen what the chain sees. Asked one tenant at a time: the chain's `eq` on the tenant column, else the actor's org. Inside `crossTenant()` an `andWhere('<tenant>', 'in', [...])` asks it once per listed tenant, and a chain naming no tenant is `X_INVARIANT_VIOLATED` — before `As of 2026-11-19` it silently answered the actor's org alone |
|
|
1390
1394
|
|
|
1391
1395
|
| Fact | Detail |
|
|
1392
1396
|
|---|---|
|
package/wiki/FAQ.md
CHANGED
|
@@ -97,7 +97,7 @@ Yes. CI runs exactly `x verify` — no bespoke pipeline steps, because a check t
|
|
|
97
97
|
|
|
98
98
|
### Do I need Docker to develop?
|
|
99
99
|
|
|
100
|
-
No. `x dev` uses embedded PGlite, in-process events, and a local directory in place of S3. `bunx create-ultimate myapp && cd myapp && bun run setup && bun run dev` — no Docker install, no `.env` scavenger hunt. `bun run setup` is
|
|
100
|
+
No. `x dev` uses embedded PGlite, in-process events, and a local directory in place of S3. `bunx create-ultimate myapp && cd myapp && bun run setup && bun run dev` — no Docker install, no `.env` scavenger hunt. `bun run setup` is seven steps — `bun install`, `x merge-driver install`, an `.env.development.local` touch, `x db gen "initial"`, `x db migrate`, `x db seed`, `x manifest` — and is not optional: `x new` installs nothing ([Getting started](Getting-Started), [Bare VM](Bare-VM)). The compose files exist for parity debugging and CI jobs that want real services ([Deployment](Deployment)).
|
|
101
101
|
|
|
102
102
|
### Do I need Redis or NATS?
|
|
103
103
|
|
package/wiki/Getting-Started.md
CHANGED
|
@@ -7,8 +7,8 @@ bunx create-ultimate myapp && cd myapp && bun run setup && bun run dev
|
|
|
7
7
|
Building a blog or an API rather than a dashboard? Add `--shape blog` or `--shape api` to the
|
|
8
8
|
first command: [Shapes](Shapes) says what each writes and leaves out.
|
|
9
9
|
|
|
10
|
-
**Four commands, and `bun run setup` is one of them.** It is the scaffold's own script,
|
|
11
|
-
`bun install`, an `.env.development.local` touch, `x db gen "initial"` when
|
|
10
|
+
**Four commands, and `bun run setup` is one of them.** It is the scaffold's own script, seven steps —
|
|
11
|
+
`bun install`, `x merge-driver install`, an `.env.development.local` touch, `x db gen "initial"` when
|
|
12
12
|
`packages/db/migrations` holds no `.sql`, `x db migrate`, `x db seed`, `x manifest` — idempotent, so
|
|
13
13
|
re-running it after a pull is safe. The last step is not optional either: `x.manifest.json` is a
|
|
14
14
|
projection of the loaded app, nothing else ever runs the command, and `x verify`'s `manifest` step
|
package/wiki/Home.md
CHANGED
|
@@ -53,7 +53,7 @@ Those facts are repeated on several pages because the wiki is plain markdown wit
|
|
|
53
53
|
|
|
54
54
|
## Tutorials
|
|
55
55
|
|
|
56
|
-
Follow in order. Each page states what it was executed against in its own first line — tutorial 1 its own measurement. `As of 2026-11-03`, 2–4 were re-run by hand, whole, in the app tutorial 1 leaves, and 5 with Docker up to the point a real host is needed. `scripts/tutorial-run.ts` (workflow `tutorial-run.yml`, on `main`) runs 1–4 in order and never 5; it has not yet run green. A workaround for a gap fixed since has been removed rather than left to mislead.
|
|
56
|
+
Follow in order. Each page states what it was executed against in its own first line — tutorial 1 its own measurement. `As of 2026-11-03`, 2–4 were re-run by hand, whole, in the app tutorial 1 leaves, and 5 with Docker up to the point a real host is needed. `scripts/tutorial-run.ts` (workflow `tutorial-run.yml`, on `main` and weekly since 2026-11-19) runs 1–4 in order and never 5; it has not yet run green. A workaround for a gap fixed since has been removed rather than left to mislead.
|
|
57
57
|
|
|
58
58
|
| Page | You end with |
|
|
59
59
|
|---|---|
|
package/wiki/I18n.md
CHANGED
|
@@ -118,8 +118,10 @@ translator over it (`As of 2026-10`):
|
|
|
118
118
|
| page (server) | `catalogSubset(t, ['app.post.likes'])` from `@ultimat3/i18n`; `uiCatalog(t)` from `@ultimat3/ui` for every `ui.*` key |
|
|
119
119
|
| island | `subsetTranslator(props.strings)` from `@ultimat3/i18n/subset`; `<UiProvider t={subsetTranslator(props.ui)}>` |
|
|
120
120
|
|
|
121
|
-
The slice carries every plural variant of each key
|
|
122
|
-
island
|
|
121
|
+
The slice carries every plural variant of each key and every `_select_*` / `_ordinal_*` family
|
|
122
|
+
member (`packages/i18n/src/subset.ts`, `As of 2026-11`; before, an island rendered `⟦key⟧` for a
|
|
123
|
+
select or ordinal the server rendered). A key it lacks renders `⟦key⟧` in the island exactly as on
|
|
124
|
+
the server.
|
|
123
125
|
|
|
124
126
|
**A form's validation messages key on the issue's `rule`**, never on its English `message` — the
|
|
125
127
|
framework's diagnostic text changes without a semver signal, the rule names do not
|
|
@@ -182,7 +184,7 @@ A dynamic call contributes its static head (`plans.`) as a runtime-key prefix, s
|
|
|
182
184
|
| Static export | `x build --target static` renders each `site/` page once per routed locale, in that locale's context: `index.html` (`lang="es-co"`), `en/index.html` (`lang="en"`), `en/precios/index.html`. Every static host serves `/en/precios` from that layout with no rewrite |
|
|
183
185
|
| Cookie | `x_locale`, written only by an explicit language switcher |
|
|
184
186
|
| Unsupported tag | skipped, not thrown — a stale cookie must never 500 a page. `assertSupportedLocale` throws `X_LOCALE_UNSUPPORTED` where an unknown tag is a caller bug |
|
|
185
|
-
| Direction | `currentDirection()` returns `'rtl'` for `ar`, `he`, `fa`, `ur`, … and is written to `<html dir
|
|
187
|
+
| Direction | `currentDirection()` returns `'rtl'` for `ar`, `he`, `fa`, `ur`, … and is written to `<html dir>`. An explicit script subtag decides first: `az-Arab` is `rtl`, `ks-Deva` `ltr`. Bare `ku` is `ltr` (Kurmanji, Latin script); Kurdish in Arabic script is `ku-Arab` or `ckb` (`isRtl`, `packages/core/src/locale-direction.ts`, `As of 2026-11`) |
|
|
186
188
|
|
|
187
189
|
| API | From | Answers |
|
|
188
190
|
|---|---|---|
|
package/wiki/Installation.md
CHANGED
|
@@ -47,16 +47,17 @@ TypeScript that Bun executes, no bash and no WSL — and `bun run dev` and `bun
|
|
|
47
47
|
|
|
48
48
|
**`bun run setup` is not optional.** `x new` writes files and installs nothing, so `cd myapp && x dev`
|
|
49
49
|
stops on `X_BUILD_FAILED` naming `bun install` (measured `As of 2026-08-23`; this page said
|
|
50
|
-
otherwise until then). `bun run setup` is
|
|
50
|
+
otherwise until then). `bun run setup` is seven steps, idempotent and safe to re-run:
|
|
51
51
|
|
|
52
52
|
| # | Step | Why it is in the script |
|
|
53
53
|
|---|---|---|
|
|
54
54
|
| 1 | `bun install` | `x new` writes files and installs nothing |
|
|
55
|
-
| 2 |
|
|
56
|
-
| 3 |
|
|
57
|
-
| 4 | `x db
|
|
58
|
-
| 5 | `x db
|
|
59
|
-
| 6 | `x
|
|
55
|
+
| 2 | `x merge-driver install` | git keeps merge drivers in `.git/config`, which no clone inherits: [Merging two features](Many-Agents#merging-two-features) |
|
|
56
|
+
| 3 | touch `.env.development.local` | per-box secrets, gitignored, wins over the committed `.env.development` |
|
|
57
|
+
| 4 | `x db gen "initial"` | skipped when `packages/db/migrations` already holds a `.sql` — `x db gen` is that directory's only writer |
|
|
58
|
+
| 5 | `x db migrate` | applies them, then diffs the live schema against the ledger |
|
|
59
|
+
| 6 | `x db seed` | run through the CLI, never `bun run`: the CLI owns the connection, so it reaches the same embedded database the migration just wrote to |
|
|
60
|
+
| 7 | `x manifest` | `x.manifest.json` is a projection of the loaded app, so `x new` cannot write it. Nothing else ever ran the command, and `x verify`'s `manifest` step now refuses its absence with `X_MANIFEST_MISSING` |
|
|
60
61
|
|
|
61
62
|
Every flag, from the registry — `bun run x -- help new`, or `x help new` in an app. There are six,
|
|
62
63
|
each with a default, so **`x new` asks nothing**: an agent cannot answer a prompt and is never given
|
|
@@ -118,18 +119,18 @@ Boot parses this before any listener binds. Failure costs ~40ms and exit 1 — n
|
|
|
118
119
|
|
|
119
120
|
```
|
|
120
121
|
X_ENV_MISSING: required environment variables are missing or invalid
|
|
121
|
-
cause: STRIPE_KEY missing; NATS_URL is not
|
|
122
|
-
fix:
|
|
122
|
+
cause: STRIPE_KEY is missing (expected a non-empty string); NATS_URL is not an absolute URL (received a string of 4 characters)
|
|
123
|
+
fix: echo 'STRIPE_KEY=<value>' >> .env.development.local # STRIPE_KEY: a non-empty string; also malformed, where grep -n -e '^NATS_URL=' .env* finds them: NATS_URL (an absolute URL)
|
|
123
124
|
```
|
|
124
125
|
|
|
125
|
-
The
|
|
126
|
+
The fix is the line to add, in the file this environment loads: `.env.development.local` in development, `.env.test.local` under test, `.env.production` for a deploy (`envFileFor`, [`packages/core/src/env.ts`](https://github.com/developerz-ai/ultimate/blob/main/packages/core/src/env.ts)). Several missing keys are one `printf '%s\n' 'A=<value>' 'B=<value>' >> <file>`; a malformed key is found where it is set (`grep -n -e '^KEY=' .env*`). The cause names each value's shape, never its content. A `fix` on one `envSchema` entry overrides it for that key. `As of 2026-11-19`.
|
|
126
127
|
|
|
127
128
|
| Property | Behavior |
|
|
128
129
|
|---|---|
|
|
129
130
|
| Access | `env.STRIPE_KEY` is typed. A `process.env` read outside the schema is a lint error |
|
|
130
131
|
| Per-role | a role requires only the keys it uses — `ROLE=worker` does not fail on a missing `VAPID` |
|
|
131
132
|
| Repair | `x env example` regenerates `.env.example` from the schema; copy the keys it names into `.env.development.local` in dev, or into your platform's secret store in production. There is **no** `x env --fix` — `x env` declares `check` and `example` and no flags, so `x env check --fix` dies at the parser with `X_CLI_BAD_FLAG` |
|
|
132
|
-
| CI | `x verify`'s `manifest` step holds `.env.example` to the schema's projection (`X_ENV_EXAMPLE_DRIFT`); `x env check` is not a gate step — run it against the deploy's own environment (`ULTIMATE_ENV=production x env check`), where it also reports the framework's deploy-required secrets |
|
|
133
|
+
| CI | `x verify`'s `manifest` step holds `.env.example` to the schema's projection (`X_ENV_EXAMPLE_DRIFT`); `x env check` is not a gate step — run it against the deploy's own environment (`ULTIMATE_ENV=production x env check`), where it also reports the framework's deploy-required secrets. With no `ULTIMATE_ENV` or `NODE_ENV` set it checks as development (as `x dev` runs), except under `CI`, where it checks as production (`As of 2026-11-19`) |
|
|
133
134
|
| Provenance | `/_x` → **Env** shows every resolved key and which source it came from |
|
|
134
135
|
|
|
135
136
|
## What Bun natives replace
|
|
@@ -194,7 +195,7 @@ server itself rather than counted here. The core of it:
|
|
|
194
195
|
| `verify.run` | guessing whether the work is shippable |
|
|
195
196
|
| `logs.tail` | scrollback archaeology |
|
|
196
197
|
|
|
197
|
-
Read tools are unrestricted in dev; write tools are scoped to branch environments. The dev server is never exposed under `ROLE=web`. `db.query` refuses a batch, a write keyword anywhere at statement level (a data-modifying CTE included), a locking clause, `EXPLAIN ANALYZE
|
|
198
|
+
Read tools are unrestricted in dev; write tools are scoped to branch environments. The dev server is never exposed under `ROLE=web`. `db.query` refuses a batch, a write keyword anywhere at statement level (a data-modifying CTE included), a locking clause, `EXPLAIN ANALYZE` (or `ANALYSE`), and the banned function families matched by prefix (`pg_read_*`, `pg_ls_*`, `lo_*`, `pg_advisory_*`, `pg_sleep*`, `set_config`, `pg_copy_*`, `pg_sync_replication_*`, `pg_backup_*`, `pg_start_backup`, `pg_stop_backup`, `pg_restore_*`, `pg_clear_*`, …) — `X_MCP_QUERY_REJECTED`, before the host sees the string. Use `x mcp` for a standalone server (CI, remote agents). Editor config: Biome is the only formatter/linter — one binary, one config, no ESLint or Prettier.
|
|
198
199
|
|
|
199
200
|
## Upgrading and removal
|
|
200
201
|
|
|
@@ -256,9 +256,9 @@ export const syncCrm = job({
|
|
|
256
256
|
| `concurrency: { key, limit }` | max simultaneous runs **sharing one key** — "one run per account" | the same lease rows, one set per `key(input)`. `key` answers a non-empty string of at most 200 characters; `limit` is a whole number, 1 or more |
|
|
257
257
|
| `concurrency.whenBusy` | what a claim over the cap does. `'wait'` (default): the run stays queued, no attempt burned. `'fail'`: the run settles **`failed`** with `X_JOB_KEY_BUSY`, its body never runs, nothing retries it, and it is not a dead letter | the worker, at claim. A plain number always waits |
|
|
258
258
|
| `limiter: vendorApi` | a **named fleet budget** several jobs share — "the payment provider takes 10 calls a second and 4 at once, whichever job makes them". Declare `export const vendorApi = limiter('vendor-api', { rate: { limit: 10, windowMs: 1_000 }, concurrency: 4 })` ONCE at module scope and import it into every `job({ limiter })`. `rate` is at most `limit` starts in any `windowMs` (sliding, no burst past it); `concurrency` is runs holding it at once. Either or both. `As of 2026-11-14` | the installed driver's `JobDriver.leases` — `x_job_leases` rows keyed `limiter:<name>:rate` (one per start, TTL the window) and `:concurrency` (one per held slot, renewed, released at the end) — gated around the BODY, ahead of the first `step.run`. A run over it throws `X_RATE_LIMITED`, deferred to when the oldest start lapses (1 s for a full concurrency cap) with the attempt **uncounted**. A start is an entry before any step completed or suspended: a resume after `step.sleep`/`waitForEvent`, or a retry past a completed step, spends no rate; a retry after a failed first step spends again. The slot's TTL and renewal are the worker's (visibility timeout, heartbeat, `schedule`). Whole numbers ≥ 1, `rate.limit` and `concurrency` ≤ 1,000, one set of numbers per name: `X_JOB_DECLARATION_INVALID`. No lease store: `X_JOB_CONCURRENCY_UNENFORCEABLE` at worker start. `.describe().limiter` is `{ name, rate, concurrency }`. Pinned by `limiter.live.test.ts` (two replicas, one Postgres) |
|
|
259
|
-
| per-process rate | starts per window, per tenant, in ONE worker | `concurrencyLimiter({ ratePerTenant })` on the worker — **per process**, multiplied by the replica count; a fleet budget is `limiter` above. A start is a body that ran: a claim handed back over `job.concurrency`, or refused by its key, spends none |
|
|
259
|
+
| per-process rate | starts per window, per tenant, in ONE worker | `concurrencyLimiter({ ratePerTenant })` on the worker — **per process**, multiplied by the replica count and by each container's processes; a fleet budget is `limiter` above. A start is a body that ran: a claim handed back over `job.concurrency`, or refused by its key, spends none |
|
|
260
260
|
| a budget keyed by **request data** (per customer, per API key) | one bucket per key every worker spends | `@ultimat3/http`'s limiter over the store the boot installs on every role, as the body's FIRST lines, ahead of the first `step.run`: `const vendor = rateLimiter({ config, store: installedRateLimitStore() }); assertRateLimitScope(config, vendor); await vendor.assert(key, bucket)`, with `config = resolveRateLimitConfig({ scope: 'shared', buckets: { vendor: toBucket('<job>', { limit, windowMs }) }, defaultBucket: 'vendor' })` at module scope. `assertRateLimitScope` refuses one process' memory under `'shared'` (`X_RATE_LIMIT_NOT_SHARED`). A refusal is `X_RATE_LIMITED`, deferred uncounted like `limiter`'s. Pinned by `rate-recipe.job.test.ts` |
|
|
261
|
-
| `maxInFlight` | max simultaneous runs in **one worker
|
|
261
|
+
| `maxInFlight` | max simultaneous runs in **one worker container**, across every queue it serves — Sidekiq's `concurrency`; a container running N processes splits it across them (`As of 2026-11`). `jobs.maxInFlight` in `app.config.ts`, or `jobWorker({ maxInFlight })`; unset, no process cap | read before every claim, so a worker at the cap claims nothing; each run that ends frees one claim at once. The per-queue `jobs.concurrency` slots still bound each queue under it. A pass splits its room over the queues (`ceil(room / queues left)`), hands what an empty queue leaves to the next, and starts after the last queue served — no queue starves. `worker.stats().maxInFlight`, gauges `job_worker_in_flight` / `job_worker_capacity`. `0`, fractional, `NaN`, `Infinity`: `X_INVARIANT` / `X_CONFIG_INVALID` |
|
|
262
262
|
| `maxPending` | back-pressure: an enqueue onto a queue already holding that many `ready` + `delayed` rows is `X_JOB_BACKLOG_FULL`, a 429 (`JobBacklogFullError`); an `enqueueMany` that would cross it is refused whole, nothing written. Omitted, no ceiling. `As of 2026-11-12` | one capped count before the write (`JobDriver.backlog`, `SQL_BACKLOG`), on the direct and the staged path, plus the rows the caller's own transaction already staged for the queue (a key staged twice counts once). An enqueue that adds no row — a dedupe, or a replace onto the key's live holder (`JobDriver.holds`, asked only once full) — is never refused. Soft, not a quota: concurrent producers can overshoot by their number, and committed rows the relay has not yet published are counted by nobody. A driver with no `backlog` refuses a job declaring it at enqueue (`X_INVARIANT`) |
|
|
263
263
|
| `queue` | named pool; the `worker` role runs one pool per config (`WORKER_QUEUES=default,integrations`) | worker pool sizing, see [Deployment](Deployment) |
|
|
264
264
|
| priority | **a separate queue**, never a field: `queue: 'urgent'` on the job, and workers whose `WORKER_QUEUES` lists it (with its own `jobs.concurrency` slots, or a pool of its own). Inside one queue the claim takes the earliest `runAt` first, and nothing reorders it. `As of 2026-11`: no `priority` column — it would widen the claim index of the hottest table for an order a second queue already gives, and isolates better (a flood of low-priority work cannot hold the slots) | the claim, per queue |
|
|
@@ -272,6 +272,25 @@ export const syncCrm = job({
|
|
|
272
272
|
|
|
273
273
|
A job over a tenant, queue or global cap, or over a `'wait'` concurrency cap, is **deferred, never dropped** — it stays queued with a later `runAt`. `whenBusy: 'fail'` is the one declared exception. `'wait'` holds the cap and states no order: a later enqueue can start first.
|
|
274
274
|
|
|
275
|
+
### CPU-bound handlers
|
|
276
|
+
|
|
277
|
+
**A synchronous section blocks every job in its process, and their lease renewals with it** `As of 2026-11`. `jobs.concurrency` slots are async slots on one JavaScript thread; while a handler computes, nothing else in that process runs — no I/O completes, no claim, no renewal (the heartbeat fires every `visibilityTimeoutMs / 3`, 10 s by default), and the `/healthz` on the same thread answers late.
|
|
278
|
+
|
|
279
|
+
| Synchronous for | What happens |
|
|
280
|
+
|---|---|
|
|
281
|
+
| under 10 s | every other job in the process stalls for that long |
|
|
282
|
+
| 10–30 s | renewals for **every** in-flight job of the process arrive late; the loop's heartbeat can turn `/healthz` 503 |
|
|
283
|
+
| 30 s or more | `visible_at` passes: another worker claims the row and **the job runs twice**. When the first process yields it sees the lease lost, aborts `ctx.signal` and refuses further step writes — but side effects outside steps already happened, and every other job of that process lapsed too |
|
|
284
|
+
|
|
285
|
+
Processes contain it: a container with `cpus: '2'` runs two worker processes ([Processes per container](Deployment#processes-per-container)), each with its share of the container's `jobs.concurrency`, and a burn in one leaves the other's jobs and renewals running. Pinned by `runtime-jobs-processes.live.test.ts` (Linux, a real Postgres): two jobs burning 1.5 s of CPU each run at the same time, one per process, where one process runs them back to back (5.4 s of wall time for the pair, on a loaded box); and an I/O job on the other process renews its lease at least three times during a burn, none lost.
|
|
286
|
+
|
|
287
|
+
| For CPU-heavy work | Do |
|
|
288
|
+
|---|---|
|
|
289
|
+
| a queue of its own | `queue: 'heavy'` on the job, a worker service with `WORKER_QUEUES=heavy` and its own `cpus:` |
|
|
290
|
+
| slots per container | `jobs.concurrency: { heavy: <processes> }`: one slot per process, so a burn stalls only itself |
|
|
291
|
+
| chunks | break the section into chunks and `await lease.renew()` between them ([Observability](#observability)), or `step.run` per chunk |
|
|
292
|
+
| a longer lease | raise `visibilityTimeoutMs` above the longest synchronous section, knowing a crashed worker's jobs wait that long to be re-run |
|
|
293
|
+
|
|
275
294
|
### A lock — `withLock()`
|
|
276
295
|
|
|
277
296
|
`withLock(key, fn, { ttl, wait?, poll?, store?, signal? })`: one holder fleet-wide, held as one slot `lock:<key>` in the job driver's `LeaseStore` (`x_job_leases` on Postgres) — no table of its own, no Redis. `fn` receives `{ key, token, signal }`. `As of 2026-11-09`.
|
|
@@ -478,6 +497,7 @@ export const syncAccount = job({
|
|
|
478
497
|
| at most one notification per queue per 250 ms | Postgres serialises every notifying commit behind one lock. A row its slot kept silent is found by the woken worker's next pass, one `pollIntervalMs` later — never worse than a fixed 250 ms poll |
|
|
479
498
|
| the poll is the guarantee | a notification is lost with the session that would have carried it; the driver re-dials and the poll covers the gap. With the wake proven the poll is a rest of up to 60 s, cut to the 2 s poll within one 2 s slice once the session is lost |
|
|
480
499
|
| the wake has to be proven | a probe sent through the pool must come back on the session: `jobs.wake.live`. If it does not — PgBouncer in `pool_mode = transaction` delivers no notification — the log says `jobs.wake.unverified` once and the ceiling stays 2 s. Give the `worker` role a direct or session-pooled `DATABASE_URL` ([`docs/ops/04-datastores.md`](https://github.com/developerz-ai/ultimate/blob/main/docs/ops/04-datastores.md#pooling-and-the-trap-under-it)) |
|
|
500
|
+
| a proven wake is proven again | every `reproveEveryMs` (10 s) one notification per channel that wakes no loop. A session that stops delivering with no re-dial (half-open) announces nothing; not back within `verifyTimeoutMs` (5 s) of the SEND, the wake is un-proven, `jobs.wake.lost` (`warn`) is logged and the loops return to the 2 s poll until a notification crosses again (`jobs.wake.live`). A pool that has not sent the proof by then is no verdict: a saturated pool cannot be told from a dead session, so the wake stays proven and the proof is sent again, with its own window, once the pool answers. `startQueueWake`, `packages/jobs/src/queue-wake.ts`, `As of 2026-11` |
|
|
481
501
|
| a queue pause | read by the claim statement itself, so it holds from each worker's next claim; a resume announces the queue |
|
|
482
502
|
|
|
483
503
|
## Exports and imports — `exportRows()` and `importRows()`
|
|
@@ -882,14 +902,14 @@ Three implementations ship, `As of 2026-11-18`: `postgresJobDriver()`, `redisJob
|
|
|
882
902
|
| Driver | Status `As of 2026-11-18` | When | Trade-off |
|
|
883
903
|
|---|---|---|---|
|
|
884
904
|
| `postgres` (default) | **shipped** | always, up to ~thousands of jobs/sec. `x dev` runs it too, against the embedded PGlite | outbox is free (same DB, same tx); `SELECT ... FOR UPDATE SKIP LOCKED` claiming; zero extra infra |
|
|
885
|
-
| `redis` | **shipped** | a queue off the database, `jobs: redisJobDriver()` | one Lua script per operation; no `introspect`, `backfills` or `leases`, so a job declaring `concurrency` refuses `jobWorker().start()` (`X_JOB_CONCURRENCY_UNENFORCEABLE`); the outbox still stages in Postgres |
|
|
905
|
+
| `redis` | **shipped** | a queue off the database, `jobs: redisJobDriver()` | one Lua script per operation; no `introspect`, `backfills` or `leases`, so a job declaring `concurrency` refuses `jobWorker().start()` (`X_JOB_CONCURRENCY_UNENFORCEABLE`); the outbox still stages in Postgres. `As of 2026-11-19`: failed, dead and expired rows, their steps and debounce fences expire after `deadTtlMs` (default 90 days, pg's `jobs.deadRetentionMs`; `redisJobDriver({ deadTtlMs: 0 })` keeps them forever), and with no `clock` injected every lease, retry, settle debt and gauge is measured on the Redis server's clock (`TIME`), as pg's `now()` — skewed pods can no longer both hold one job |
|
|
886
906
|
| `memory` | **shipped**; there is no config value for any driver | tests and fixtures, through `memoryJobDriver()` | in-process; nothing survives a restart — which is why it was never a safe drain target |
|
|
887
907
|
|
|
888
908
|
**There is no `jobs.driver`, and 5.0.0 is where it went.** It accepted `'postgres' | 'redis' | 'nats'` and had **no reader anywhere** — boot always built `postgresJobDriver`, stated in [`packages/jobs/src/driver.ts`](https://github.com/developerz-ai/ultimate/blob/main/packages/jobs/src/driver.ts)'s own header. So setting it to `redis` changed nothing at all and you silently got Postgres, which is the more dangerous behaviour because nothing reports it. From 5.0.0 to 24.x a stale key still rode through untyped; **25.0.0 refuses it** at `defineConfig`, naming the driver seam. Deleting it from `app.config.ts` is the whole of the upgrade.
|
|
889
909
|
|
|
890
910
|
**The seam that does work is `jobs:` in `export const runtime = { … }`** (`apps/<app>/runtime.ts`; 31.0.0 deleted `setJobDriver`) — swap the driver, zero job-code change, which is what the interface buys; a test swaps one for itself with `await swapAdapter('jobs', driver)` from `@ultimat3/testing`. Every swappable backend works this way: [Adapters](Adapters). `redisJobDriver()` is the second durable driver (`As of 2026-10`, #710): `jobs: redisJobDriver()` on core's `redisClient()` — while Redis is down an `enqueue` is `X_DRIVER_UNAVAILABLE` at once, never a wait — imported from `@ultimat3/jobs/redis`, held to the same conformance suite as Postgres, without the operator surface (`x jobs show`, `retry`, `cancel`), backfill bookkeeping or fleet-wide `concurrency` — [`packages/jobs/README.md`](https://github.com/developerz-ai/ultimate/blob/main/packages/jobs/README.md#drivers) has the table. There is no NATS jobs driver.
|
|
891
911
|
|
|
892
|
-
**`x jobs` has no `drain`, `As of 2026-11-15`.** It was planned from 25.0.0 and left the registry ([Known gaps](Known-Gaps#open-by-decision)): moving in-flight rows between drivers is a migration no command owns. To stop a queue for maintenance, `x jobs pause <queue
|
|
912
|
+
**`x jobs` has no `drain`, `As of 2026-11-15`.** It was planned from 25.0.0 and left the registry ([Known gaps](Known-Gaps#open-by-decision)): moving in-flight rows between drivers is a migration no command owns. To stop a queue for maintenance, `x jobs pause <queue>` (a queue the app does not serve is refused `X_CLI_BAD_FLAG` with the nearest name, `As of 2026-11-19` — before, a typo paused nothing and reported success), then `x jobs list --queue <queue> --state running --json` until it is empty. Its two former `--to` values, `redis` and `nats`, were all-throw stubs — until 2026-10 a drain leased the whole pending batch for five minutes, failed every enqueue and nacked it back, nothing moved, and no worker could claim those jobs meanwhile. 25.0.0 deleted the stubs and the unreachable drain body. A drain that returns is new code, and owes the lesson of `--to memory`, a target until 2026-09: `memoryJobDriver()` is a `Map` inside the command's own process, so the drain enqueued each job into it, acked the durable row off the source, printed `ok: true`, and lost every copy when the command exited.
|
|
893
913
|
|
|
894
914
|
So the framework ships no cross-driver migration procedure: moving queued jobs from one driver to another is the application's to do.
|
|
895
915
|
|
package/wiki/Known-Gaps.md
CHANGED
|
@@ -46,7 +46,7 @@ Each of these is a defect, or a target, somebody has already argued about, and t
|
|
|
46
46
|
|---|---|
|
|
47
47
|
| `x token`'s `grant` | removed from the registry `As of 2026-11-15`, where it was planned and exited `X_NOT_IMPLEMENTED`; now `X_CLI_UNKNOWN_COMMAND`, exit 1 as before. A key's scopes are fixed when it is issued (`AuthApiKeyRecord.scopes`, never widened; `ApiKeyStore` has no update), so a grant is a new key: `x token create --scopes post:read,post:write --json`, then `x token revoke <old-id>`. A second verb for that pair would be the second path axiom 1 refuses |
|
|
48
48
|
| `x db`'s `studio` | removed from the registry `As of 2026-11-15`, where it was planned and exited `X_NOT_IMPLEMENTED`; now `X_CLI_UNKNOWN_COMMAND`, exit 1 as before. The schema browser is the `/_x` db panel (`x dev`): schema, rows and a guarded SQL console. `X_DB_STUDIO_FAILED` stays reserved and unthrown; the old `bunx drizzle-kit studio` shell-out was a second schema engine for one subcommand |
|
|
49
|
-
| `x jobs`'s `drain` | removed from the registry `As of 2026-11-15`, where it was planned and exited `X_NOT_IMPLEMENTED`; now `X_CLI_UNKNOWN_COMMAND`, exit 1 as before. 25.0.0 deleted the drain body with the all-throw Redis and NATS stubs, and moving in-flight rows between drivers is a migration no command owns. To stop a queue for maintenance: `x jobs pause <queue
|
|
49
|
+
| `x jobs`'s `drain` | removed from the registry `As of 2026-11-15`, where it was planned and exited `X_NOT_IMPLEMENTED`; now `X_CLI_UNKNOWN_COMMAND`, exit 1 as before. 25.0.0 deleted the drain body with the all-throw Redis and NATS stubs, and moving in-flight rows between drivers is a migration no command owns. To stop a queue for maintenance: `x jobs pause <queue>` (a queue the app does not serve is refused, `As of 2026-11-19`), then `x jobs list --queue <queue> --state running --json` until it is empty |
|
|
50
50
|
| A local write that died after its last rename is listed with no content type until the key is written again | `As of 2026-10`. `localDriver` commits in four steps (marker, sidecar, bytes, clear marker) and a marker left behind means "re-check this pair". `get()` and `stat()` do re-check against the bytes and answer correctly; `list()` never reads bytes, so it reports that object with no `contentType` and `etag: ''` — honest, and it stays that way until the next `put()` of that key. `stream()` returns bytes only and checks nothing. Two files cannot be committed in one step without changing the on-disk layout |
|
|
51
51
|
| A `delete_resource` preview checks only the policy's actor half | `As of 2026-10-18`. Without `live: true` the framework answers a preview without running the action, so the part of a policy that reads the input never runs; a preview can be granted for a call the commit then refuses. Running the policy would mean running the action. An action that needs an exact preview declares `live` in its input and answers its own |
|
|
52
52
|
| `localDriver` cannot hold a key and a key beneath it (`a` and `a/b`) | `As of 2026-10`. An object is a file at its key, and a POSIX path is a file or a directory. The second `put()` is refused by code (`X_STORAGE_KEY_CONFLICT`) where it used to be a bare `ENOTDIR`; `s3Driver` and `memoryStorageDriver` hold both. Storing objects under suffixed names would lift it, at the price of a layout migration for every existing root — and the keys `grantUpload` and `scopedKey` build never nest an object under another, so the limit is met only by hand-built keys |
|
package/wiki/MCP-And-AI.md
CHANGED
|
@@ -43,7 +43,7 @@ The whole catalog, spelled exactly as each tool must be called; `bunx x mcp tool
|
|
|
43
43
|
| executes code | `tests.run`, `verify.run`, `ui.shot`, `ui.island`, `ui.inspect`, `ui.interact` | scope `dev:test`; all six declare `destructive: true`, so none is metered as read chatter — the four `ui.*` tools launch a browser |
|
|
44
44
|
| write | `db.migrate` | scope `db:migrate`, **branch environments only** |
|
|
45
45
|
|
|
46
|
-
None of them is exposed in `ROLE=web`. `db.query` accepts one statement, whose leading keyword must be `SELECT`/`WITH`/`EXPLAIN`/`SHOW`/`TABLE`/`VALUES` — necessary, never sufficient. Batches, any write keyword at statement level (a data-modifying CTE included), locking clauses (`FOR UPDATE`/`FOR SHARE`), `EXPLAIN ANALYZE
|
|
46
|
+
None of them is exposed in `ROLE=web`. `db.query` accepts one statement, whose leading keyword must be `SELECT`/`WITH`/`EXPLAIN`/`SHOW`/`TABLE`/`VALUES` — necessary, never sufficient. Batches, any write keyword at statement level (a data-modifying CTE included), locking clauses (`FOR UPDATE`/`FOR SHARE`), `EXPLAIN ANALYZE` (and its `ANALYSE` spelling), and whole function families matched by prefix of the called name, quoted and schema-qualified spellings included — file access (`pg_read_*`, `pg_ls_*`, `lo_*`, `dblink`), locks (`pg_advisory_*`), session settings (`set_config`), sleeps (`pg_sleep*`), catalog writes (`pg_import_*`, `pg_restore_*`, `pg_clear_*`), replication and backup control (`pg_copy_*`, `pg_sync_replication_*`, `pg_backup_*`, `pg_start_backup`, `pg_stop_backup`; `As of 2026-11-19`) and the functions that run a query handed to them as text (`query_to_xml*`, `cursor_to_xml*`, `table_to_xml*`, `schema_to_xml*`, `database_to_xml*`, `ts_stat`, `ts_rewrite`) — are **refused**, not discouraged — `X_MCP_QUERY_REJECTED`, enforced before the host sees the string. What the scan cannot read is refused, never decoded: a Unicode-escaped quoted identifier (`U&"…"`) is `X_MCP_QUERY_REJECTED` (`As of 2026-10`). A keyword is matched as Postgres lexes an identifier, so a column `set2` is a column, not `SET`. Its Postgres SELECT-only role is conditional on the connection's own rights; the answer's `guards` array names the defences that engaged. `db.migrate` refuses a target that is not a branch database — `X_MCP_NOT_BRANCH_DB`.
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
### Client config
|
|
@@ -536,7 +536,7 @@ The reference app's `draftReview` (`examples/dummy/apps/web/mcp-tools.ts`) queue
|
|
|
536
536
|
|
|
537
537
|
**From a markdown folder.** `recipes: await markdownRecipes({ dir: join(import.meta.dir, 'docs') })` reads one `*.md` per recipe and serves its body verbatim. The file name is the recipe name. `title:` and `description:` come from `---` frontmatter, else from the first `# ` heading and the paragraph under it. A fence tagged `call` holds one step, `tool {"arg": "value"}`, and is checked at boot like any `step.example`. A whole `"<postId>"` value is a placeholder, so any value passes at boot. A `docs://recipes/<name>` link in the text that names no recipe is `X_MCP_RECIPE_LINK_DANGLING`.
|
|
538
538
|
|
|
539
|
-
**Searching.** `docs({})` lists what this caller can follow. `docs({ name })` and `docs({ uri })` read one recipe. `docs({ q })` inlines the best match, scoring 3 for each word in the name or title, 2 in the description and 1 in the body. On a miss it names the nearest recipes, so a caller with any visible recipe never gets an empty answer.
|
|
539
|
+
**Searching.** `docs({})` lists what this caller can follow. `docs({ name })` and `docs({ uri })` read one recipe. `docs({ q })` inlines the best match (`q` at most 1,000 characters, else `X_INPUT_INVALID`; a miss compares its first 16 words, 64 characters each, for the nearest — `As of 2026-11-19`), scoring 3 for each word in the name or title, 2 in the description and 1 in the body. On a miss it names the nearest recipes, so a caller with any visible recipe never gets an empty answer.
|
|
540
540
|
|
|
541
541
|
**Per caller.** `extraRecipes: (caller) => recipes` adds the caller's own recipes, such as a tenant's runbooks. They are listed as `source: 'caller'` on `docs`, and on `resources/list` and `resources/read` to that caller only. They are not checked at boot. A recipe that names a tool the caller cannot call is not shown.
|
|
542
542
|
|
|
@@ -552,6 +552,9 @@ Remote MCP tools as this app's actions — the app's `policy`, rate limit, confi
|
|
|
552
552
|
| Reviewed | `allow` is required; `lock` is the committed `tools.lock.json` written by `x mcp lock <name>`; `x mcp lock <name> --check` writes nothing and fails on drift |
|
|
553
553
|
| Drift | a missing, re-described or re-shaped tool is `X_MCP_REMOTE_TOOL_CHANGED` — at declaration against the lock, before the first call against the live server |
|
|
554
554
|
| Wire | `outbound()` (`dial: 'public'` by default, deadline, size cap); modern era first, then legacy `initialize` + `Mcp-Session-Id`; JSON or SSE answers |
|
|
555
|
+
| Era fallback | the legacy handshake only when the first modern call is refused for its era: a `400`/`404`/`405`, JSON-RPC `-32022`/`-32601`/`-32600`/`-32602`, or a body that is no answer. Never on a `429`, `408` or `403`, a refusal of the moment. Concurrent first calls share one handshake; a failed handshake leaves the era undecided, so the next call tries again (`eraRefusal`, `packages/mcp/src/remote-client.ts`, `As of 2026-11`) |
|
|
556
|
+
| Paging | `listTools()` follows `nextCursor` for at most 50 pages; a cursor still open past that is `X_MCP_REMOTE_REFUSED`, `meta.failure: 'malformed'`, never a truncated list |
|
|
557
|
+
| Cancel | a legacy server hears `notifications/cancelled` for the aborted call's own request id, and only when the request was already sent |
|
|
555
558
|
| Untrusted | the answer arrives as `{ untrusted, isError }`, fenced `<untrusted source="mcp:<name>/<tool>">`, middle-cut past `maxResultChars`; invisible format characters stripped, then every `<` (and full-width `<`, small `﹤`) written `<` — no spelling of `</untrusted>` survives |
|
|
556
559
|
| Exposed | `expose` defaults to `false`: the actions are this app's, not its `/mcp`'s, so `include: 'exposed'` leaves them out; they are declared `agents: true`, so this app's own `agent()`s are offered them anyway. `expose: true` opts one remote server in, and this app's `/mcp` then answers for a third party's tools |
|
|
557
560
|
| Re-checked | the live list is held to the lock before the first call, on every `list_changed`, and again once a verdict is `reverifyMs` old (default 3,600,000) — a remote that changes silently is caught within the hour |
|
|
@@ -576,13 +579,13 @@ Remote MCP tools as this app's actions — the app's `policy`, rate limit, confi
|
|
|
576
579
|
|
|
577
580
|
1. `begin(serverUrl)` reads the server's RFC 9728 protected-resource document, then its authorization server's RFC 8414 metadata. It answers `{ authorizeUrl, handshake }`, with PKCE S256 from `@ultimat3/auth` and `resource` per RFC 8707.
|
|
578
581
|
2. Redirect the person to `authorizeUrl`. Keep `handshake` server-side, in the person's session.
|
|
579
|
-
3. On the callback, `exchange(handshake, { code, state })` answers `{ accessToken, refreshToken, expiresIn }`. `refresh(handshake, refreshToken)` answers the same shape
|
|
582
|
+
3. On the callback, `exchange(handshake, { code, state })` answers `{ accessToken, refreshToken, expiresIn }`. `refresh(handshake, refreshToken)` answers the same shape; when the server's answer carries no `refresh_token`, `refresh` answers the one it was passed (RFC 6749 §6), never `null`.
|
|
580
583
|
4. Store the tokens per connection. Return the access token from `mcpTools({ auth })`, which is read on every call, so a rotated token is never cached.
|
|
581
584
|
|
|
582
585
|
`begin` refuses, as `X_MCP_REMOTE_REFUSED`, metadata it cannot trust: a document that is not a URL,
|
|
583
586
|
resource metadata naming another resource (RFC 9728 §3.3), authorization-server metadata answering
|
|
584
587
|
for another issuer (RFC 8414 §3.3), no PKCE S256, and an `authorization_endpoint` or `token_endpoint`
|
|
585
|
-
that is not `https:` — `http:` only on a loopback host (`localhost`, `127.0.0.1`, `[::1]`, RFC 8252).
|
|
588
|
+
that is not `https:` — `http:` only on a loopback host (`localhost`, `127.0.0.1`, `[::1]`, RFC 8252). The same rule holds for the server URL and the authorization-server issuer, checked before either's metadata is fetched (`As of 2026-11-19`).
|
|
586
589
|
`authorizeUrl` is handed to a person as a link, so a `javascript:` endpoint would run in the app's
|
|
587
590
|
origin. `As of 31.15.0`.
|
|
588
591
|
|
|
@@ -856,7 +859,7 @@ pgvector in the same Postgres. No second datastore.
|
|
|
856
859
|
| Embeddings | an `Embedder` value, never an entity option: `remoteEmbedder({ name, dimension, baseUrl? })` speaks the `/v1/embeddings` shape (`EMBEDDINGS_API_KEY`), `hashEmbedder()` is the offline default |
|
|
857
860
|
| Writing | `indexDocument({ store, embedder, document })` chunks, embeds, upserts and prunes the stale tail; a sweep over many rows is the app's `backfill()` calling it per page |
|
|
858
861
|
| Index | HNSW: `postgresVectorStore({ name, dimension }).ddl()` prints the table and both indexes, pasted into a migration by the app |
|
|
859
|
-
| Hybrid search | one `query` primitive fusing pgvector cosine + Postgres FTS with Reciprocal Rank Fusion; weights are config |
|
|
862
|
+
| Hybrid search | one `query` primitive fusing pgvector cosine + Postgres FTS with Reciprocal Rank Fusion; weights are config. The lexical leg (`searchText`, `hybrid`) matches **any** word of the query, one `phraseto_tsquery` per whitespace-separated word OR-ed, as `memoryVectorStore()` does (`As of 2026-11-19`; before, every word had to match, so a whole question matched nothing). Nothing typed is query syntax: `"quoted phrase"`, `-word` and `or` are plain text, and an identifier the parser splits (`x_vector_drift`) still matches as one phrase |
|
|
860
863
|
| Filtering | tenant + policy filters applied **in SQL**, so vector search cannot leak across tenants; a store with no tenant bound, read inside a request acting for an org, is `X_VECTOR_UNSCOPED` — a backfill opts in with `scope: UNSCOPED` |
|
|
861
864
|
| HNSW recall | a search returns `k` hits for a small tenant on a large shared table: on pgvector ≥ 0.8 it runs with `hnsw.iterative_scan = relaxed_order`, before that with `hnsw.ef_search` raised to `max(40, k × 10)`, capped at 1,000 — the setting scoped to a read-only transaction the search opens (2–3 round trips), or to the caller's own, put back after (`pg-vector-recall.ts`). Without it pgvector took the 40 nearest rows and filtered afterwards, so a tenant holding a small share of the table got fewer than `k`, often none. `As of 31.15.0` |
|
|
862
865
|
| Re-embed | `indexDocument` again: every chunk is embedded on each call, so a job decides when text changed |
|
package/wiki/Many-Agents.md
CHANGED
|
@@ -32,13 +32,78 @@ Every entry is an `flock(2)`, and a holder hands the locked descriptor to the co
|
|
|
32
32
|
x heavy status # who runs, who waits, load, memory
|
|
33
33
|
x heavy status --json
|
|
34
34
|
x heavy run --label suite --mb 4096 -- bun run test # any command, in any repository
|
|
35
|
+
x heavy run --max-wait 300 -- bun run test # give up after 5 minutes in the queue
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
A waiter prints one line on stderr saying its position
|
|
38
|
+
**A waiter needs nothing from you: leave it running, it starts by itself.** It prints one line on stderr saying its position, who holds the memory and that, and again only when that changes, so `--json` output stays one document. Killing a waiter loses its place, so a harness with a short command timeout should run the command in the background. To bound the wait, `x heavy run --max-wait <seconds>` stops with `X_HEAVY_WAIT_EXPIRED` and exit 75, without starting the command; `0` is one attempt.
|
|
39
|
+
|
|
40
|
+
`x heavy status` names each reservation's processes. After `kill -9` of a wrapper it reads `wrapper pid N exited, command pid M`: M is what still holds the memory, and `--json` carries the same as `wrapperAlive` and `childPids`.
|
|
41
|
+
|
|
42
|
+
`x heavy run` passes the exit code through and forwards stop signals. A process started inside a reservation inherits it (`ULTIMATE_HEAVY_HOLD`) and never queues behind its own parent. Time spent queued does not count against an `x verify` step's deadline.
|
|
43
|
+
|
|
44
|
+
## Merging two features
|
|
45
|
+
|
|
46
|
+
**Two branches that each ran `x g resource` merge with no hand edit.** `bun run setup` installs the drivers (`x merge-driver install`); `.gitattributes` says which file takes which. `As of 2026-11-19`.
|
|
47
|
+
|
|
48
|
+
| Files | On a merge | After it |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `apps/web/api/index.ts`, `apps/web/exercise.ts`, `apps/web/shared/roles.ts`, `packages/db/src/client.ts` | what both sides **added** is kept, sorted, so either merge direction writes the same bytes | nothing |
|
|
51
|
+
| `packages/i18n/catalogs/*.json` | three-way by key | nothing |
|
|
52
|
+
| `x.manifest.json`, `openapi.json` | our copy is kept | `bunx x manifest`, then commit |
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
git merge feature-b
|
|
56
|
+
bunx x manifest
|
|
57
|
+
bunx x verify
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**What stays a conflict, on purpose:**
|
|
61
|
+
|
|
62
|
+
| Both branches | Why a person decides |
|
|
63
|
+
|---|---|
|
|
64
|
+
| changed or removed one existing line | `merge=union` would keep both, so a revoked grant in `roles.ts` would come back |
|
|
65
|
+
| declared one key, or one import name, differently | either could be the right one |
|
|
66
|
+
| gave one catalog key two wordings | which text ships is a decision |
|
|
67
|
+
|
|
68
|
+
`X_MERGE_UNRESOLVED` lists what is left: `git diff --name-only --diff-filter=U`. Resolve each, `git add` it, finish the merge.
|
|
69
|
+
|
|
70
|
+
- **Why one entry per line.** Registries are written that way (`x new`, and the `merge-drivers` codemod on `x upgrade`), because a list on one line is one line both sides changed. Keep the comment inside the list: it is what stops Biome joining the list back up.
|
|
71
|
+
- **Where the drivers do not run.** A hosted merge button and a clone that never ran setup use git's plain text merge, so the same files conflict there and nothing is lost. Merge locally. `x doctor` warns `X_MERGE_DRIVER_UNSET` on such a clone.
|
|
72
|
+
- **Migrations: `bunx x db gen --merge-fork`.** Two branches that each ran `x db gen` fork the chain: the newest snapshot lacks the other branch's table. `x db gen`, `x db migrate` and the gate's `drift` step refuse it as `X_MIGRATION_FORKED`, before any `record …` migration is suggested. `--merge-fork` corrects the newest `.snapshot.json` only: no SQL changes and nothing is deleted, so it is safe after either migration was applied. Two creates of one table are the exception: run `bunx x db status --json` on every database first, and remove a migration only if `data.pending` lists it on all of them ([Migrations](Migrations-And-Backfills)).
|
|
73
|
+
- **One `x db gen` at a time per checkout.** A second run waits on the checkout's `db-gen` lock instead of diffing the same sidecar and writing a second `create table`. With several agents in one checkout, one run's migration can still record another agent's new entity: the success line names the migration and its tables, and "no migration needed" names the migration that already records them.
|
|
74
|
+
|
|
75
|
+
## CPU pressure
|
|
76
|
+
|
|
77
|
+
Memory alone does not bound a machine: at 14.3 of 15.9 GB reserved, an 8-core box sat at load 74 with 69 runnable tasks and `cpu some avg10` at 95.8 (`As of 2026-11-18`). So the queue's head also waits while the CPU is saturated **and** another heavy run is admitted:
|
|
78
|
+
|
|
79
|
+
| Signal | Waits at |
|
|
80
|
+
|---|---|
|
|
81
|
+
| PSI `cpu some avg10` (`/proc/pressure/cpu`) | 80% |
|
|
82
|
+
| without PSI: runnable tasks per core | 2 |
|
|
83
|
+
|
|
84
|
+
First come, first served still holds: only the head is judged. With nothing admitted one run always starts, whatever the pressure and wherever it comes from, and a head held back by CPU alone goes anyway after 5 minutes, so a long holder cannot starve the queue. The wait line then reads `waits for CPU … CPU pressure 96% (new runs wait at 80%)`; `x heavy status` prints the reading as `cpu:`, and `--json` carries `data.machine.cpu` and `data.cpuGate`. Off in CI, inside a test run, and with `ULTIMATE_HEAVY_CPU=0`. The figures and the reasoning: `packages/cli/src/heavy-pressure.ts`.
|
|
38
85
|
|
|
39
86
|
## Cores
|
|
40
87
|
|
|
41
|
-
Locally a run takes **at most 4 cores**, fewer when other sessions' runnable tasks already fill the machine, and never below 2. Test workers are capped per batch, so a run narrows and widens as the machine changes; `tsc` and `biome` get the cap as `GOMAXPROCS` and `RAYON_NUM_THREADS`. `--workers N` is taken as written. CI takes every core.
|
|
88
|
+
Locally a run takes **at most 4 cores**, fewer when other sessions' runnable tasks already fill the machine, and never below 2. Test workers are capped per batch, so a run narrows and widens as the machine changes; `tsc` and `biome` get the cap as `GOMAXPROCS` and `RAYON_NUM_THREADS`. `--workers N` is taken as written. CI takes every core. A run held below its plan says `ran 2 at once (peak), planned 4`; `x test --json` carries it as `data.peakWorkers`.
|
|
89
|
+
|
|
90
|
+
## Neighbouring dev servers
|
|
91
|
+
|
|
92
|
+
`x dev` on a taken port refuses with `X_PORT_IN_USE`, naming the holder's pid and directory, and its fix names a pair of ports that is free when asked. `x doctor` reports a port held from **another checkout** as a warning, because nothing is wrong with this environment. A port held from this checkout, or by a process the OS will not name, stays a finding.
|
|
93
|
+
|
|
94
|
+
## Test service stacks
|
|
95
|
+
|
|
96
|
+
The `live` step prints one line on stderr for the stack it got:
|
|
97
|
+
|
|
98
|
+
| Line | Meaning |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `services: started <project>` | this run started containers, and leaves them running for the next |
|
|
101
|
+
| `services: reused <project>` | they were already up, from this checkout |
|
|
102
|
+
| `services: shared <project> with <dir>` | another checkout of this app started them (same first commit, or same `origin`), or `ULTIMATE_TEST_SERVICES_SHARED=1` says the share is intended |
|
|
103
|
+
|
|
104
|
+
The compose project is the `name:` in `docker/docker-compose.test.yml`. An app `x new` wrote before 31.49.0 states `<app>-test`, so two different apps with one name land on the same stack; from 31.49.0 `x new` writes `<app>-test-<hash of the scaffold directory>` and picks the ports from both, so they do not (`As of 2026-11-19`). A shared name is refused: the step reports `X_TEST_SERVICES_UNAVAILABLE` naming the other directory — a stack that is stopped is said to be stopped, its fix `docker compose -p <project> down --volumes` — compose is not run, and the live suites run without the stack (red when the floor holds `live` and nothing ran). Checkouts git cannot tie together count as different apps. For good: give the app its own `name:` and ports, in the compose file and `docker/test-services.env`.
|
|
105
|
+
|
|
106
|
+
`x clean --services` stops this checkout's stack, keeps one another living checkout started, and lists every other test stack on the machine with its stop command, marking those whose checkout is gone. It stops nothing else.
|
|
42
107
|
|
|
43
108
|
## Switches
|
|
44
109
|
|
|
@@ -46,8 +111,10 @@ Locally a run takes **at most 4 cores**, fewer when other sessions' runnable tas
|
|
|
46
111
|
|---|---|
|
|
47
112
|
| `ULTIMATE_HEAVY_MEMORY=8g` | what the ledger admits; `0` turns it off |
|
|
48
113
|
| `ULTIMATE_HEAVY_CORES=6` | the local core ceiling |
|
|
114
|
+
| `ULTIMATE_HEAVY_CPU=0` | no waiting on CPU pressure; memory still applies |
|
|
49
115
|
| `ULTIMATE_HEAVY_DIR=<path>` | another ledger; also opts a test run in |
|
|
50
116
|
| `ULTIMATE_TEST_SLOTS=0` | test workers skip the ledger |
|
|
117
|
+
| `ULTIMATE_TEST_SERVICES_SHARED=1` | another app's test stack under this app's project name is shared on purpose |
|
|
51
118
|
|
|
52
119
|
Admission is off under `CI`, inside `bun test` (a fixture's `x test` must not queue behind real work), and on **Windows**, which has no `flock`: the core cap still applies there and `x heavy status` says why admission is off. A ledger that cannot work is reported as `X_HEAVY_LEDGER_UNAVAILABLE` and the command goes ahead; it never fails a run.
|
|
53
120
|
|
|
@@ -55,6 +55,19 @@ Every migration applies inside its own transaction, recorded into `x_migrations`
|
|
|
55
55
|
|
|
56
56
|
Its two remedies, in the order they are safe to run: `git checkout -- packages/db/migrations/<id>.snapshot.json`, or, when the file was never written, `rm packages/db/migrations/<id>.* && x db gen "<name>"`. The delete comes first because `x db gen` against the migration that is still there raises this same code. Until 2026-08 the `fix:` said "restore … from version control" alone while `x db migrate`'s `unknown-schema` difference answered `x db gen "snapshot <name>"` — each naming the command that raises the other, with nothing to restore in an app whose sidecar was never written.
|
|
57
57
|
|
|
58
|
+
### Two branches, one chain — `X_MIGRATION_FORKED`
|
|
59
|
+
|
|
60
|
+
Two branches that each run `x db gen` from one parent leave valid SQL and a wrong sidecar: the newest `.snapshot.json` has never heard of the other branch's work. `As of 2026-11` every reader refuses that chain before acting on it: `x db gen`, `x db migrate`, `x db reset`, the `drift` step and `x doctor`.
|
|
61
|
+
|
|
62
|
+
| The chain holds | Fix | What it touches |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| an object the newest sidecar omits, or one it still records after another migration dropped it | `x db gen --merge-fork` | the newest `.snapshot.json`, then the `.hash` and the schema dump. No `.sql`, so no checksum moves, and it is safe after either migration was applied |
|
|
65
|
+
| two unguarded creates of one table or column, so a replay stops at `42P07` / `42701` | `x db status --json` on **every** database first | remove a migration only if `data.pending` lists it on all of them, then `x db gen --merge-fork`. A migration any database applied stays |
|
|
66
|
+
|
|
67
|
+
The detector folds the chain: each sidecar adds what it records, each `up` removes what it drops, and what survives is what a replay builds (tables, columns, indexes, foreign keys, checks, views). A migration with no sidecar was written by hand and ends what earlier sidecars can claim. Never answer a fork with a new migration: `create table` for a table the chain already builds is the statement that cannot replay.
|
|
68
|
+
|
|
69
|
+
`x db gen` also runs one at a time per checkout, `As of 2026-11`: two overlapping runs diffed one sidecar and each wrote every new table. The entities are one registry, so the first run's migration carries a second agent's table too: its summary names the tables, and the later run's names the newest migration. The lock is the machine ledger's, so it is off under `CI`, on Windows and with `ULTIMATE_HEAVY_MEMORY=0`; there, a collision is what `X_MIGRATION_FORKED` reports afterwards.
|
|
70
|
+
|
|
58
71
|
### Foreign keys are their own statement
|
|
59
72
|
|
|
60
73
|
Every foreign key is `alter table … add constraint`, emitted **after** every table statement, and
|
|
@@ -294,6 +307,10 @@ A NOT NULL contract is the same story. On an empty table — a fresh or `x db re
|
|
|
294
307
|
| `X_MIGRATION_ROLLING_UNSAFE` | a column leaves the entity without having been retired, with or without `--allow-destructive`. Also a retired name no migration records or `columns` still declares, a NOT NULL column with no default or a key column (the new release's inserts would fail, so relax it first), a committed `drop`/`rename` when the `drift` rail is on, and a retire and its drop both pending on a live production database |
|
|
295
308
|
| `X_MIGRATION_IRREVERSIBLE` | the retired column is removed without `--allow-destructive`. Retiring is not consent to losing the rows |
|
|
296
309
|
|
|
310
|
+
**A plain column made `generated` is a drop**, `As of 2026-11-19`: Postgres has no `set expression` for it, so the migration drops the column and adds it back computed, and the stored values are gone. `x db gen` asks the same two consents: `X_MIGRATION_ROLLING_UNSAFE` unless the column was retired first (or `--rolling-unsafe`), then `X_MIGRATION_IRREVERSIBLE` unless `--allow-destructive`. Before, it wrote the migration unasked.
|
|
311
|
+
|
|
312
|
+
**A drop's `down` restores the column's indexes and foreign keys**, `As of 2026-11-19` — those the previous `.snapshot.json` recorded over it, for every dropped column, retired or not. The rows, NOT NULL and the default are not restored. Only newly generated migrations change.
|
|
313
|
+
|
|
297
314
|
An app that stops before it starts (one instance, `strategy: Recreate`) says so: `x db gen "drop legacy" --allow-destructive --rolling-unsafe` writes `-- rolling-unsafe: true` and needs no retire.
|
|
298
315
|
|
|
299
316
|
**The rail.** `rollingSince: "<migration id>"` in `x.verify.json` turns on the `drift` step's fifth rail for every migration after that id: a `drop column` with no `-- retires` in an earlier file, a `rename column`, a `rename table`. A closed list, on statements and not on prose. `x new` writes `"0"`. Unset, the rail does not run, because an applied migration cannot gain a marker (checksum); `x doctor` prints one line naming the id to set. A retire before the bound still earns the drop after it.
|
|
@@ -568,6 +585,7 @@ Scaffolds a working pair, never a stub: `x g backfill <name> --feature <slice>`
|
|
|
568
585
|
| `X_MIGRATION_CONFLICT` | the ledger disagrees with this build — a foreign app-version row that is not a rollback (rows all newer than the build are accepted), or an applied migration whose checksum moved | deploy the version `cause` names, or `x db gen "fix <migration>"` — never edit an applied migration |
|
|
569
586
|
| `X_MIGRATION_IRREVERSIBLE` | a generated plan drops a column or table and its `down` cannot restore the rows | `x db gen "<name>" --allow-destructive`, or put the column back in `columns` and keep it |
|
|
570
587
|
| `X_MIGRATION_DESTRUCTIVE` | a committed migration's `up` destroys data with no `-- destructive: true` line | add the marker, or regenerate with `--allow-destructive` — before the migration is applied |
|
|
588
|
+
| `X_MIGRATION_FORKED` | two branches generated from one parent and were merged, so the newest sidecar is wrong or two migrations create one object | `x db gen --merge-fork`, which changes no SQL and deletes nothing. A collision: `x db status --json` on every database first, and never delete a migration any of them applied |
|
|
571
589
|
| `X_MIGRATION_SNAPSHOT_MISSING` | the newest migration on disk carries no `.snapshot.json` sidecar to diff against | `git checkout -- packages/db/migrations/<id>.snapshot.json` — or, when it was never written, `rm packages/db/migrations/<id>.* && x db gen "<name>"`, the delete first |
|
|
572
590
|
| `X_MIGRATION_CONCURRENT_IN_TRANSACTION` | a migration without `-- transaction: false` holds a concurrent index statement, which Postgres refuses inside a transaction block (`25001`) | `sed -i '1i -- transaction: false' packages/db/migrations/<id>.sql` before it is applied, or move the statement into a migration of its own. Refused before `BEGIN`, so nothing is applied |
|
|
573
591
|
| `X_MIGRATION_VIEW_DEPENDS` | a view is compiled against a column this migration retypes — Postgres answers `0A000` and rolls the whole migration back | `drop view "<v>";` then `x db migrate`, then re-create it from the `create view` the `fix` line carries verbatim. Caught by a **preflight** inside the migration's own transaction, before its first statement, so nothing partial is applied |
|
package/wiki/Notify.md
CHANGED
|
@@ -167,7 +167,7 @@ What each push-service answer does:
|
|
|
167
167
|
| 404 / 410, or an expired subscription | the subscription is deleted; nothing is retried |
|
|
168
168
|
| 429 / 5xx / no connection | `X_PWA_PUSH_FAILED` — thrown after every other device was tried, so the delivery fails as `X_NOTIFY_DELIVERY_FAILED` and the notifier job retries on its own backoff |
|
|
169
169
|
| 400 / 413 | `X_PWA_PUSH_REJECTED` — logged and counted, never retried |
|
|
170
|
-
| 401 / 403 | `X_PWA_PUSH_REJECTED
|
|
170
|
+
| 401 / 403 | `X_PWA_PUSH_REJECTED` — logged with its code and counted as `refused`; the subscription is **kept** (`As of 2026-11-19`): a push service answers a fault in this server's token (a `pwa.vapid.subject` it refuses, a skewed clock) the same way as a rotated key, and deleting on it unsubscribed every device a send reached. After a real key rotation `subscribeToPush` (or the emitted `subscribePush`) replaces such a browser's subscription the next time it asks |
|
|
171
171
|
|
|
172
172
|
A retry re-sends to the devices that already got it; the `tag` makes that a replacement on the device
|
|
173
173
|
rather than a second notification. `renotify` without a `tag` is dropped with a warning — the spec
|