Files
Strata/docs/MANAGEMENT_PROTOCOL.md
T
Niko1221 b9eff8d348 runtime: the restart plan reports the stop phase's limit and, apart from it, the last stop's time; protocol notes (#5956 #5958 #5954)
One lifecycle contract for the three management PRs (all by l473n79c618e),
reimplemented after review:

#5956: the PR's min_wait_s (last observed drain + 5 s) is not a safe floor:
a fast stop says nothing about the next one, and the kill/reap wait after the
drain deadline was left out. The restart plan now carries two additive
fields: teardown_limit_s, the stop phase's worst case (shutdown_timeout +
the host's 8 s kill grace + the 10 s reap wait, Host._stop_child; named
STOP_KILL_GRACE / STOP_REAP_WAIT), and last_teardown_s, what the last stop of
a running server took here (null before the first; informational, never a
bound). Nothing else in the plan or the status changes.

#5958: no new action. runtime.status of a ready instance already carries
state, instance_id, profile_revision, model_state and api_url (the readiness
probe's result), and the owner re-checks owner and instance at the restart
itself; fixtures only.

#5954: docs/MANAGEMENT_PROTOCOL.md "Semantic notes" (approved by the
coordinator 11-16). Corrected against the code: for runtime.restart, wait_s
is the caller's wait for the owner's answer, not a server-side budget
(runtime.restart -> _rpc timeout); a failed new instance gets its own stop
before the rollback start, so the whole restart is bounded by
2 x (teardown_limit_s + startup_wait_s). The PR's point that
`connect --write --output json` does not write is dropped (fixed by #5955).

Tests: tests/terminal/test_restart_teardown_budget.py (fake clock, no
processes): fast then slow stop, a stop that times out and is reaped, a
failed load with rollback inside the documented bound, the status fields a
swap gate reads, a ready file of an earlier instance gives no address, a
restart planned on one instance refused after a swap (nothing stopped), and
the two plan readers (bench managed match, recipes plan) with the new fields.
On 756242554 they fail; with test_runtime, test_recipes and test_bench
106 passed on p2003.
2026-11-16 14:25:46 +01:00

20 KiB

Owner-local management bridge, version 1

The Strata CLI and a local Desktop host use the same saved-profile store and strata_control.management.runtime_action() for runtime operations. A trusted Desktop host can invoke the one-shot python -m strata_control.management process for runtime actions, component/model inspection, reviewed benchmark runs and saved evidence, reviewed calibration and profile edits. Send one UTF-8 JSON object on stdin, close stdin, and read one JSON object on stdout. The command exits with the response's exit_code on failure; ordinary success exits 0. Diagnostics go to stderr. The input limit is 64 KiB.

This is owner-local process IPC. It has no HTTP listener and does not accept an inference or monitor API key. The imported Node host has limited, opt-in loopback HTTP seams for one host-configured saved profile: /api/native/runtime for Serving, /api/native/telemetry for Monitor, /api/native/components for component inspection, /api/native/models for installed run configs, /api/native/models/inspect?id=MODEL_ID for details, /api/native/models/import-plan for an explicit read-only GGUF preflight, /api/native/profile for saved settings, /api/native/bench/review, /execute and /job?id=JOB_ID for reviewed benchmark launch, /api/native/bench/report and /compare for saved evidence, plus /api/native/calibration/review, /execute, /job?id=JOB_ID and /cancel for reviewed calibration, bounded progress and exact active-measurement stop requests. Serving, Profile, Benchmarks and Calibration use short-lived, single-use server-side reviews before mutations. The Node routes check local Host/Origin and a custom JSON action header for action POSTs; Python rechecks reviewed preconditions. This local preview is not audited Desktop authentication or a general browser management API. The other UI screens still use prototype data; native mode refuses prototype mutations and /v1 inference. The shared Desktop journal and full operation API remain integration work.

Request and response

{"schema_version":1,"action":"runtime.start.plan","profile":"four-gpu","params":{"shutdown_timeout_s":30}}

schema_version must be the integer 1. action and params must match one row below exactly. profile is a saved lowercase profile ID. Unknown fields, duplicate JSON keys, nonfinite numbers, booleans in numeric fields and unexpected actions are rejected before an operation starts. Runtime errors return {"schema_version":1,"ok":false,"error":"...","exit_code":N}. Successful results include schema_version:1 and the owner runtime's result. Journaled actions also return an operation_id that both UI and CLI can inspect with strata ops result.

Action Exact params keys Effect
bench.run.plan path, suite, concurrency, repeat, request_timeout, condition Check a new absolute output directory, bounded workload, loaded model and matching managed profile/owner/telemetry instance. Return the planned request count, phase list and pinned identities. No inference request or output directory is created.
bench.job.create job_id plus all bench.run review and identity keys Create an owner-only journal receipt for a reviewed Desktop job before launching its worker. The 32-character job ID is generated by the host. A receipt without an active lease or final report does not prove that the worker started.
bench.job job_id Read the durable receipt, exact-run lease, private progress and matching report. A saved final report can finish a receipt left running by a crash after report write. An unfinished receipt without an active lease becomes completion_unknown after a short launch window.
bench.run all bench.run.plan keys plus if_profile_revision, if_source_sha256, if_owner_id, if_instance_id; Desktop also sends job_id Recheck the reviewed source, owner and instance, then use the CLI benchmark runner with managed matching before and after. Create a private results.json when measured phases fail. With a job ID, the worker verifies the receipt matches the reviewed request and finishes it with a bounded outcome.
bench.progress path Read the owner-only progress.json in an absolute output directory (or next to its results.json). It reports completed phases and the current phase without prompts, answers or credentials. For saved-profile runs, the response also checks the exact output path against the owner-local lease: active, ended, other_active or untracked. A running record alone does not prove process liveness.
bench.cancel path Request a stop for the exact active saved-profile run. The owner-local lease and private output directory are checked before writing an owner-only cancel.request marker. Returns cancel_requested until the runner writes final evidence; it does not claim that the engine has already stopped. CLI: strata bench cancel --profile NAME --path /absolute/run/results.json.
bench.report path Read an absolute local bench run output directory or results.json, summarize its phases and produce a privacy-safe Markdown export. No workload, mutation or journal entry.
bench.compare baseline, candidate Read two absolute local saved reports, apply the CLI's workload and available-environment match checks, and produce a provisional comparison and privacy-safe Markdown export. No workload, mutation or journal entry.
calibration.plan none Read-only decode-sweep preflight, including saved-profile revision, source digest, selected devices and component status. No engine launch or journal entry.
calibration.job.create job_id, action, path, exclusive_ack, if_profile_revision, if_source_sha256, if_report_sha256 Create an owner-only receipt for a reviewed Desktop measure/apply/rollback action before launching its worker. if_report_sha256 is null for measure. The receipt alone does not prove the worker started.
calibration.job job_id Read a bounded receipt after a Desktop host restart. A measurement report bearing the exact job ID and reviewed profile/source identity can finish a receipt left running after report write. An exact worker lease proves active work; without it or a final journal result or matching report, the receipt becomes completion_unknown after a short launch window. The response also carries bounded stage progress and stop-request state.
calibration.cancel job_id Request a stop only for the exact active measurement worker. The owner-only marker is polled by that worker and passed into engine generation; the request acknowledges intent, while the final receipt says whether cancellation occurred. Apply and rollback cannot be cancelled in flight.
calibration.measure path, exclusive_ack, if_profile_revision, if_source_sha256; Desktop also sends job_id Require explicit exclusive-access acknowledgement, reject a stale saved profile or source, then measure into a new absolute local report path and journal the result. Recheck source under the calibration lock. With a job ID, every preflight and execution failure finishes the matching receipt.
calibration.apply.plan path Review one saved report for freshness and applicability, pin report body digest, profile revision and source digest. No write or journal entry.
calibration.apply path, exclusive_ack, if_profile_revision, if_source_sha256, if_report_sha256; Desktop also sends job_id Recheck reviewed profile, source and report, then smoke-test and apply the candidate with private rollback evidence; journal the outcome.
calibration.rollback.plan path Review the exact applied state and saved backups for rollback; pin report, profile and current source. No write or journal entry.
calibration.rollback path, exclusive_ack, if_profile_revision, if_source_sha256, if_report_sha256; Desktop also sends job_id Recheck the reviewed state, smoke-test the previous config and restore config/settings; journal the outcome.
components.inspect live Read the saved profile's installed component report. live: true also runs the bounded host GPU probe. An inspection can succeed (ok: true) while report.ok is false because required files or selected cards are missing. No operation journal entry is created.
models.installed none List at most 128 setup-written local run configs for model selection; presence and execution compatibility remain separate. Requires the configured saved profile to exist.
models.inspect model_id Inspect one installed run config and its component report. Model-file integrity and engine compatibility remain unverified. No journal entry.
models.import.plan path Check an absolute local GGUF file or shard folder using the CLI's bounded preflight. It never copies, adopts or loads a model. No journal entry.
profile.inspect none Read the saved profile, revision, source digest and effective serving values. No mutation or journal entry.
profile.change.plan overrides, source_config, if_revision Validate typed overrides and an absolute run config against the revision loaded in the editor; show before/after, effective values, current profile revision and proposed source digest. No file write or restart.
profile.change overrides, source_config, if_revision, if_source_sha256 Save the reviewed candidate through the same versioned profile store as CLI. Reject changed profile revision or source digest. The running instance is unchanged; the operator reviews Restart separately. Profile history records the old revision, but this save is not a runtime journal operation.
runtime.status none Read the owner's current instance state.
runtime.start.plan shutdown_timeout_s Validate the saved profile and show effective launch arguments, launch.profile_revision and source_sha256; no launch or journal entry.
runtime.start wait_s, shutdown_timeout_s, if_profile_revision, if_source_sha256 Start through the owner host with both reviewed preconditions and journal the outcome. Both preconditions are required by the Desktop bridge.
runtime.restart.plan allow_source_switch, allow_source_migration Compare the current owned launch with the saved profile and report source, owner and instance preconditions.
runtime.restart wait_s, startup_wait_s, if_profile_revision, if_owner_id, if_instance_id, allow_source_switch, allow_source_migration, if_source_sha256 Drain and restart through the owner host, with reviewed profile, source, owner and instance preconditions and a journal record. All four preconditions are required by the Desktop bridge.
runtime.verify.plan load Read the ready owner and instance IDs, model load state and whether this check would load the model. It performs no probe and creates no journal entry.
runtime.verify wait_s, load, if_owner_id, if_instance_id Recheck the reviewed owner and instance inside the owner host before checking API identity, launch attestation and generation when loaded. It may explicitly load a model and is journaled. Both IDs are required by the Desktop bridge; direct CLI verification may omit them.
runtime.stop.plan none Read the current owner ID and, when available, engine instance ID; no drain or journal entry.
runtime.stop wait_s, if_owner_id, if_instance_id Drain and stop only the reviewed owner and instance; journal the outcome. if_owner_id is required by the Desktop bridge.

Desktop benchmark review bounds the total phase count and per-request timeout against its 1,900-second bridge deadline; longer workloads remain available through strata bench run. Saved-profile CLI runs and Desktop runs share a local per-profile benchmark lease that refuses overlapping launches; a raw --url run has no saved-profile lease. STRATA_API_KEY and optional STRATA_TELEMETRY_KEY are read only by the host process. Desktop now creates a private journal receipt before launch and recovers a job by ID after a host restart. The phase progress file and final report persist in the private output directory. Reports retain the planned and completed phase counts; success requires every planned phase to pass. A caught phase exception saves partial evidence and is labelled incomplete in the Desktop and Markdown export; an abrupt process kill can leave only the last progress record. Operator cancellation closes active benchmark-owned response streams and saves cancelled: true, successful: false, and a cancelled final progress state. It can take up to the configured request timeout if a connection has not received response headers yet. The request marker is an acknowledgement, not the final outcome. A malformed postflight telemetry response is saved as failed evidence with unavailable after-state. The exact-run lease check distinguishes a process still holding that path from one that released it. other_active and untracked do not prove that the saved run is alive. A held lease does not prove that inference is making progress. A crash before the benchmark creates an output directory can leave only the receipt; after the launch window it is labelled completion_unknown. Windows lease and receipt recovery still need target qualification.

Times are seconds. if_profile_revision is a 16-character lowercase profile revision; if_source_sha256 is a 64-character lowercase digest. For start, take them from runtime.start.plan as plan.launch.profile_revision and plan.source_sha256. For restart, take candidate_profile_revision, candidate_source_sha256, current_owner_id and current_instance_id from runtime.restart.plan. For stop, take plan.owner_id and plan.instance_id from runtime.stop.plan; the instance ID may be null while the engine is starting or has failed. Owner and instance IDs are 32-character lowercase values when present. Restart plans require a ready instance, so both identities are present. The bridge rejects stale restart and stop reviews before journaling; the owner host checks again before draining. A stale start plan is rejected before the journal begins when possible; the owner host checks the same preconditions again immediately before launching the engine. A plan does not reserve the profile, source file or instance. An interrupted or timed-out mutating call may have an uncertain outcome. Inspect the operation journal and runtime status before retrying; never assume the process exit reversed a side effect.

Semantic notes

  • runtime.restart: wait_s is how long the caller waits for the owner's answer; it does not limit the owner. startup_wait_s is the owner's wait for the new instance to be ready, and the same wait again for the previous launch when the new one fails and is rolled back. If wait_s runs out first, the restart goes on; ask runtime.status for the outcome. To wait for the whole restart, give wait_s at least teardown_limit_s + startup_wait_s, and twice that to cover a rollback.
  • runtime.restart.plan reports teardown_limit_s, the longest the stop phase can take (the shutdown timeout, then the kill and the reap), and last_teardown_s, what the last stop on this owner took (null before the first one). last_teardown_s is information only, never a bound: the next stop can take longer.
  • The change booleans of a plan predict a change of the saved configuration or the model files, not of the process: a restart starts a new instance even when all of them are false.
  • runtime.status is per account: it reads the owner's private runtime folder, so called by another account it reports that account's own runtime, not the owner's.
  • After a successful runtime.restart, the response's instance_id names the new instance; the plan's current_instance_id named the old one. Use the response's value from then on.
  • A status answer is a snapshot and authorises nothing. A restart or stop meant for the instance the caller looked at passes if_instance_id (and if_owner_id); the owner refuses with instance_changed_after_restart_plan when another instance runs by then.

Desktop adapter requirements

The Desktop host now maps one configured profile's Start, Stop, Restart and Verify controls to these typed actions and displays the returned operation ID and owner state. A changed source config causes the first Restart review to refuse the action and show an explicit source-change review; the second plan sets only the operator-selected source-switch/migration allowances and displays the candidate path, digest and rollback requirement before drain. Its Components screen reads the same doctor.inspect report as the CLI; the optional live card probe runs only after the operator requests it. Profile presents typed override fields and installed model config choices, stores a reviewed candidate server-side for 90 seconds and saves through the shared profile store. Models lists the same setup-written run configs as CLI, inspects one config and its component report on request, and offers an explicit read-only GGUF file or folder preflight. Benchmarks reads saved local results through the shared CLI parser, shows selected bounded phase fields and compares only workload-compatible runs; its Markdown download omits addresses, credentials, prompts and answers. It launches reviewed managed workloads and can request cancellation for the exact active run. Calibration reviews a decode sweep and saved apply/rollback candidates through the same Python calibration module as CLI. The browser receives only bounded selected settings and findings; argv and raw measurement reports stay on the host. One host job can run at a time. The browser polls an owner-journal job ID for launching, running, succeeded, failed, cancelled or uncertain status, while the Python action writes bounded progress and the final shared operation record. Benchmark jobs are queryable by the same ID after a Desktop host restart through the owner journal and saved evidence. Calibration jobs have owner-only journal receipts recoverable by ID after a Desktop host restart. An exact saved measurement report can reconcile a receipt left running after report write. Measurement writes bounded stage/sample progress; a live exact worker lease distinguishes active work from an orphaned receipt. An operator can request cancellation for an active measurement, and its engine generation receives the stop event. The final receipt records cancelled only after the worker exits; inspect strata ops runs and the report path before retrying an uncertain operation. The browser receives only selected, bounded inspection fields; a plausible model file set still needs engine, model-pack, integrity and hardware checks. The host filters and bounds every report before sending it to the browser. Verify uses a single-use 90-second review and pins owner and instance IDs; an explicit Load + Verify choice is shown when the model is unloaded. A successful one-token probe does not establish answer quality or sustained throughput. It must preserve the plan/execute review step, keep only one lifecycle authority for a profile, and never build shell command strings from browser content. The harness screen still needs its shared typed mapping. Calibration progress, exact-worker liveness and measurement cancellation are implemented locally; long-run GPU behavior, cleanup after abrupt worker death, and unmanaged/Windows engine exclusion need target qualification. The current one-shot bridge does not provide a general write lease, streaming progress or recovery for an ambiguous start/stop/restart result.

Before production use, qualify this bridge and its owner transport on Windows/Linux, test an actual engine launch, and run UI/CLI parity scenarios against the same profile and journal. The source-run macOS fake-engine test checks that a bridge-started instance is visible and stoppable from CLI, that stale start, stop and restart reviews do not affect a different launch, and that malformed requests create no journal entry.