Repository navigation
Description
Parent: #793
What problem should this solve?
Durable startup, health, CLI, logs, and tests expose related facts but do not give an adopter one non-mutating diagnosis containing the problem, likely cause, safe fix, and canonical documentation link. The first doctor should diagnose the connected store and runtime configuration only. Definition discovery, host telemetry configuration, and physical target equivalence require evidence the CLI does not possess.
Proposed shape
Extend the existing appsurface durable command family with:
appsurface durable doctor \
--connection-env APPSURFACE_DURABLE_CONNECTION \
--runtime-epoch-env APPSURFACE_DURABLE_RUNTIME_EPOCH \
[--worker-id <privacy-safe-id> --stale-after <duration>] \
[--timeout <duration>] \
[--format text|json]--connection-env reuses the existing schema-command behavior and defaults to APPSURFACE_DURABLE_CONNECTION; no connection-string argument is accepted. For doctor, it must resolve to the restricted runtime-role credential, not migration owner. --runtime-epoch-env defaults to APPSURFACE_DURABLE_RUNTIME_EPOCH and must resolve to a nonempty GUID. --worker-id and --stale-after must appear together; the latter is the host's actual configured stale threshold, not a CLI guess. --timeout defaults to ten seconds and accepts one second through two minutes. --format defaults to text.
The command may read:
- schema compatibility and migration status;
- configured and active runtime epoch;
- provider StoreId or equivalent authoritative connected-store identity;
- the selected worker's heartbeat age and state, when a worker ID is supplied;
- whether migration 0010's heartbeat-retention capability is installed.
Retention capability is not inferred from migration number alone. One bounded catalog query resolves exact regprocedure appsurface_durable.prune_runtime_heartbeats(interval,integer,text,uuid) and verifies:
- the function owner equals the
appsurface_durableschema owner; prosecdefis true;proconfigcontains exactly the required fixed search path;- the current runtime credential has
EXECUTE; - the function ACL has no
PUBLICgrantee and grants no grant option to the current credential; ix_runtime_heartbeat_retentionexists on the exact table andpg_get_indexdefmatches(last_heartbeat_at, worker_id).
The command reports capability unavailable if any invariant fails; it never calls the pruning function. Existing role checks reject a current credential that owns Durable objects, has BYPASSRLS, or holds grant options, with guidance to supply the runtime role.
Heartbeat observation uses one SQL statement that captures clock_timestamp() once as observed_at_utc and computes nonnegative age from that same value. Rendering receives an immutable observation and never calls the process clock. Unit snapshots use a fixed observation; PostgreSQL integration tests assert the database timestamp within a bounded wall-clock range rather than snapshotting a live timestamp.
The command does not accept or compare a second connection string, infer host OpenTelemetry listener/exporter state, or inspect Work definitions. A later manifest case may be designed only if case 2 can produce a deterministic compile-time artifact from the same source facts without loading or executing a consumer assembly. That future case is not part of this rail's success.
Use one stable diagnostic descriptor model across health guidance, CLI output, logs, testing assertions, and troubleshooting/durable-diagnostics.md:
code
problem
likely cause
safe fix
canonical docs link
Every text finding ends with the exact next applicable command, such as rerunning durable schema preflight, supplying the
paired worker arguments, or invoking the generated application's end-to-end verifier. JSON output carries the same next
action and documentation URL as stable fields. A clean doctor result says “store/runtime checks passed” rather than “worker
ready,” and links to the application-composition verifier because the doctor deliberately cannot prove registration,
authorization, activation routing, or exporter delivery.
Acceptance criteria
- The default command is non-mutating and never applies migrations, rotates epochs, drains workers, retries Work, or changes retention.
- Human and JSON output are deterministic, bounded, secret-free, and covered by snapshots.
- With worker inputs, diagnostics distinguish not-started/worker-not-found, current, stale, draining, schema incompatible, epoch incompatible, retention capability absent, and unavailable database. Without worker inputs, the command makes no heartbeat/readiness claim.
- Exit code 0 means no finding in the requested checks, 2 means an actionable compatibility or worker finding, 3 means invalid input, and 4 means the dependency was unavailable. Unexpected CLI failure retains the CLI's existing general failure code.
- Raw connection strings, credentials, payloads, scope/aggregate IDs, arbitrary exceptions, and trace context never appear.
- Tests prove the exact connection/epoch/optional-worker inputs from command line and environment, precedence rules, bounded timeouts, cancellation, unavailable dependencies, and no interactive prompts.
- Catalog mutation tests independently break function signature, owner, security-definer flag, search path, runtime execute privilege,
PUBLICACL, grant option, index presence, and index shape; each produces one bounded diagnostic without invoking maintenance. - Text and JSON snapshot tests inject one fixed database observation so heartbeat age and timestamps are byte-deterministic.
- Documentation states what the doctor cannot prove, including registered Work definitions, physical target equivalence, provider-effect truth, application authorization, and Activity listener/exporter delivery.
Dependencies and coordination
Depends on cases 1 and 4. It does not depend on definitions, target comparison, the reference host, or the experimental adapter.
Activity