Durable cloud command jobs and manual sessions
The local receiver is documented separately in durable local jobs. Cloud acceptance, TLS identity and an active lease do not supply its local operating permission or physical evidence.
This is the implemented simulation-only cloud boundary for #28, under ADR-0005. Job handlers are mounted in the selected Next.js app. PostgreSQL persists manual leases, immutable command intent, protocol receipts, terminal results and existing audit/outbox admission. No transport receipt, browser request or cloud lifecycle result establishes a physical effect.
Authority and composition
createJobsServer requires the accepted Gredice identity adapter, current site/resource resolver, allowed browser origins, migrated PostgreSQL, and a trusted current-authority resolver. currentAuthority(previous, signal) must read current Gredice session, membership, account and site permission for the persisted actor/session/capability, return a current AuthorizedContext, and honor cancellation. It must never just return the persisted context, deserialize a browser principal or install a fixture authority in a deployment. This separate resolver permits delivery after cloud restart without persisting bearer tokens or verification secrets. The service bounds it to one second and checks its binding, human actor, session, capability, account, realm, site/resource and expiry. Trusted adapters remain responsible for validating their directory source and freshness using the accepted authorization contract. Only human operators use this slice; service capture scheduling is separate work.
Call configureJobs only from protected server composition. There is no environment shortcut or default site, issuer, identity, provider credential or fixture catalog. Production realms and hardware resource scopes are denied. An unconfigured build returns only an uncached, redacted 503, including on signed-device routes. Engineering presentation never supplies permission.
Migrate 0001-enrollment.sql, 0002-media.sql, 0003-audit.sql, then additive 0004-jobs.sql. Run pnpm --filter @arbi/dashboard db:migrate:jobs with privately supplied ARBI_JOBS_DATABASE_URL; never use migration ownership as the runtime role. No build/start migration or deployment resources are created. Use a bounded pool acquisition timeout. Runtime permissions need registry SELECT/row-lock, job projections SELECT/INSERT/UPDATE, immutable reports/lease requests SELECT/INSERT, and the existing audit staging grants described in audit durability. Historical audit/report/lease-request mutation is trigger-protected; immutable job intent/authority/command/terminal fields have a database guard. Privileged schema-owner tampering remains outside this accidental/application mutation protection.
HTTP contract
All actions use /api/sites/:siteId/jobs/:action. Browser calls use dedicated ARBI bearer authentication; mutations also require an approved Origin and x-arbi-request: 1. JSON bodies reject extra fields, are bounded to 16 KiB and a five-second read deadline. IDs follow arbi/1.0. Successful reads and writes are private/no-store. Fixed errors redact storage and provider exceptions.
| Action | Method and exact input | Result and permission |
|---|---|---|
acquire |
POST: key, deviceId, ttlMs |
Exclusive site lease; manipulation.request |
renew |
POST: key, leaseId, fence, ttlMs |
Current human/session holder only; same fence |
release |
POST: key, leaseId, fence |
Current holder ends its cloud session |
revoke |
POST: key, leaseId, fence |
Current configuration.write authority; separately attributable revoker intent and holder lifecycle |
submit |
POST: key, deviceId, leaseId, fence, timeoutMs, body |
202 cloud admission; never completion |
status |
GET: exactly one jobId query |
Current state.read; site-bound persisted status |
cancel |
POST: jobId |
Original human/session with current manipulation permission; disables further cloud delivery |
device |
POST: signed envelope below | Enrolled current edge credential and identity; no browser Origin or Authorization header |
Lease TTL is 500–15000 ms and command timeout is 500–10000 ms, both capped by the current authorization freshness/expiry bound. Durations must also fit the conservative receiver uncertainty bound and manual lease lifetime. Renewing a lease cannot revive or extend an admitted command's deadline. A shortened lease invalidates work whose deadline no longer fits.
Supported bodies are accepted arbi/1.0 motion.move, camera.gimbal, camera.capture, and control.stop. Capture in this slice is also a manually leased human request. Local calibration, envelope/interlock validation, job orchestration and actuator state transitions remain the edge owner's responsibility. control.stop uses leaseId=null and fence=null: remote authorized stop intent does not require the motion holder's lease. Cancellation records a cloud delivery cancellation only. An explicit stop request is a separate job, and its device outcome is separate from both cancellation and lease end. Independent local stops never consult these cloud tables or audit availability.
Browser fields cannot supply actor, role, account/site ownership, source/target boot, configuration revision, correlation ID or receiver deadline. The server derives them from current authorization, the locked enrolled-device registry and authenticated receiver snapshot. Each command retains the original cloud source boot/session, command ID, correlation ID, actor, target, lease fence, configuration and source-clock semantics across retries and process replacement. Its envelope is immutable.
Persistence, fences and evidence
The inventory row is locked before site/job/lease/report/audit work on the same native PostgreSQL connection, following PostgreSQL row-lock semantics and the node-postgres transaction boundary. Enrollment revocation/replacement and command admission therefore serialize. A unique active site lease plus a persistent uint64 fence prevent competing processes from admitting two holders. New acquisition advances the fence after timeout, release, revocation or receiver/configuration replacement. Renewal checks exact lease, fence, actor and human session. Current session/member revocation cannot become takeover authorization; unavailable directory reads fail closed. Lease state and request-key deduplication survive restart.
Keys are scoped by realm/site/human actor, with the original session and entire intent in the fingerprint. Repeated exact submissions return the same job; different payload/session with the same key conflicts, including reordered/concurrent requests. Audit intent, attributable allow decision, the existing arbi_audit_outbox, and job or lease mutation share one transaction via PostgresAuditStore.stageAdmission. A report, outcome projection or audit failure also rolls back together. synchronous_commit=on and audit's fsync requirement precede admission; receipts are returned only after COMMIT.
The status projection deliberately separates cloudDisposition, nullable deviceStatus, and nullable immutable terminal. Admission is cloudDisposition=admitted with no device status. A signed accepted receipt establishes edge acceptance; running establishes device-reported execution. Only a signed, bound completed/rejected/failed/cancelled protocol result establishes a terminal device-reported result. The first terminal stays immutable. An exact report retry is idempotent; a distinct same-outcome report is terminal-repeat; a contradictory terminal is retained as append-only evidence with decision=contradiction, while the original terminal stays unchanged. Reordered accepted/running reports cannot regress terminal state. Terminal reports may arrive without intermediate receipts, because those receipts can be lost.
The accepted audit vocabulary is unchanged. Lease lifecycle uses correlated cloud service outcomes with effect=none. Nonterminal acknowledgements are authenticated immutable protocol receipts because audit 1.0 defines only terminal device outcomes. Terminal reports use auditFromProtocolOutcome, preserving original actor/intent/command/configuration context and authentic device source time; receiver UTC/uncertainty is added separately. Cloud suppression is a service failure with effect=none, reason=execution-failed and the appropriate protocol error (DEADLINE_EXPIRED, NOT_AUTHORIZED, TARGET_RESTARTED, CLOCK_INVALID, CANCELLED); this means failure of cloud delivery permission, never a physical execution failure. The job projection retains the more specific disposition.
Device, clock and recovery boundary
The exact signed envelope is version, realm, siteId, deviceId, credentialId, identity, issuedAtMs, expiresAtMs, action, payload, signature, with version=arbi.jobs-device/1.0. Use the accepted Ed25519 enrollment proof digest over the complete envelope excluding signature. Lifetime is at most 10 seconds. Credential revocation, expiry and current enrolled edge identity are checked under the inventory lock. Module credentials cannot consume cloud jobs. Repeated polls are intentionally safe reads; they cannot advance execution status. Snapshot/outcome protocol message IDs and stream/sequence pairs are persistently deduplicated with conflict detection.
snapshotpayload is an authentic simulation arbi/1.0state.snapshot, bound to current edge boot/session and registry-applied config. It supplies only the job receiver's supported commands and deadline clock anchor, not general telemetry history. Reordered/regressing snapshots are retained as stale evidence without refreshing the anchor. An admitted unsynchronized or disjoint clock anchor permanently suppresses pending work; a later synchronized snapshot cannot revive it.pollpayload is{}. It returns at most eight immutable envelopes. Every eligible job rechecks current original authorization, enrolled device, configuration, receiver clock/deadline and active lease fence. The transaction has a four-second processing bound as well as database statement/lock/idle timeouts. Receiving the HTTP response does not mark a job accepted or complete. Once an authentic accepted/running receipt is durable, it is omitted from future delivery pages.outcomepayload is an authentic arbi/1.0command.outcomebound to the stored command, correlation, cloud request source and exact target. Current enrolled credentials may replay a result for a protected retired boot of that same device; this records historical evidence only. Configuration changes and human revocation cannot rewrite a historical result. A revoked/replaced device cannot upload as the active device.
Receiver anchors must be fresh within five seconds, have synchronized source UTC with declared uncertainty at most 250 ms, and match the current enrolled boot and applied config. Server UTC uncertainty is explicitly configured (default conservative host assumption 100 ms, restricted to 1–250 ms). Mapping reserves both clock uncertainties plus a 50 ms drift/processing allowance in both directions. The command deadline is expressed in receiver boot/session monotonic time, while source monotonic time remains the cloud emitter's own clock. UTC rollback below the persisted database clock floor or within a transaction denies work. Null clocks, stale anchors and disjoint/future clocks cannot grant manual delivery.
These uncertainty limits are a host-simulation policy, not measured production synchronization. Live deployment must establish/monitor bounds and fail closed when they are unavailable; it cannot treat the defaults as clock measurements. Cloud process restart keeps committed jobs/fences; a changed receiver boot or ambiguous time suppresses old motion. Expired manual work is never a reconnect backlog. A lost delivery can return the identical command until its original bounded deadline; receiver-local durable deduplication/fence/deadline enforcement is required under #30. This cloud slice proves one logical durable command, not exactly-once physical execution or cancellation of already accepted work. #29 owns broker routing/resynchronization and must preserve these admission and delivery checks.
Committed host evidence and remaining gates
The native PostgreSQL suite runs via pnpm --filter @arbi/dashboard test:postgres in a fresh socket-only temporary cluster. It uses independent pools/connections, signed ephemeral devices and current isolated Gredice authorization. It exercises competing humans, key conflicts, exact retry/reordered report delivery, immutable/contradictory terminal results, wrong site/session/service/origin and forged claims, session/device revocation, config/reboot fences, renewed/expired leases, expired commands, cancellation versus stop receipt, unsynchronized/future/regressing clocks, audit/outbox/job/report rollback, killed processes before COMMIT and after admission COMMIT before delivery, and restart/replay of the original envelope. PostgreSQL 15.19 host evidence is distinct from Neon integration.
The HTTP suite verifies default denial and truthful empty receipt/result state. The native suite also invokes configured Fetch handlers against real PostgreSQL and signed identity. pnpm --filter @arbi/dashboard build plus test:http exercises mounted production Next.js routes on loopback and verifies every unconfigured job/lease action returns the redacted 503.
Run owning lint/typecheck/test/test:postgres/build/test:http, pnpm docs:check, pnpm protocol:check, and git diff --check. No protocol/scenario contracts or generated bindings change in this slice. This is source and isolated host evidence. Live Gredice/Neon/Vercel setup, clock-bound instrumentation, provider restore/role/connection behavior, broker integration (#29), edge durable execution (#30), dashboard presentation (#39/#50), bench/HIL, installed operation and qualified physical safety acceptance remain unverified. Recording (#68), live media (#38), and physical actuation remain disabled/deferred. No lease or journal clears any gate in ADR-0006.