Skip to content

Twelve-factor design, with explicit storage boundaries ​

Replace the API process in the middle of a conversation. Which records should still be there and who owns the disk that holds them?

A red spike rises on a paper strip beneath two analog monitoring gauges.

LinkedIn opens a draft you can review before posting.

Suppose the hosted API is replaced during a deployment. A reader should still be able to recover their conversation and its citations. That expectation leads to a more useful question than whether the project uses containers. Which process may disappear, and which component owns a record that must survive?

The matrix applies the published twelve-factor model to the proposed API and workers. The portable local research library needs an explicit storage exception. Each row is an acceptance test for a future implementation. The Twelve-Factor App

Two profiles, one codebase ​

Hosted profile. Replace an API or compute worker while the private Rust store continues to own SQLite and durable artifacts. Verify that sessions, runs, leases, review decisions, and replay cursors survive. The browser connects through one public origin. The store remains private.

Local appliance. On a workstation, an explicitly selected library directory can hold the same domain and storage modules together. This stateful profile trades horizontal scaling and process disposability for portability. Recovery, configuration, backup, and provenance still need direct tests.

A volume is not a magic statelessness switch. The hosted store remains stateful and single-writer per writable library; it needs its own backup/restore contract. We do not mount a live SQLite WAL database over a network filesystem. SQLite documents that WAL processes must operate on the same host. SQLite WAL.

Follow the proposed API replacement through one deployment. Collect all three records for the same run.

  1. TF-05, artifact. Before rollout, compare the digest selected for deployment with the digest that passed QA. Record both identifiers and the deployment configuration revision.
  2. TF-06, recovered session. Record the run ID and last committed cursor, then replace the API process. Reopen the session through the replacement and verify that the private store supplies the same run, citations and checkpoint. Keep the responses from both processes.
  3. TF-09, shutdown. Send the old API a termination signal. Record when it stopped admitting work, the disposition of the active request and whether it exited within the configured grace period. Compare the terminal state with what the replacement serves.

These are acceptance records to collect when a hosted implementation is available.

Verification matrix ​

GateFactor and project decisionFalsifiable acceptance evidence
TF-01Codebase: one application workspace, many deployments; donor history recorded, not separate environment forksQA and production identify the same source revision and selected artifact; no production-only source patches
TF-02Dependencies: commit lockfiles; pin toolchains, base images, OS tools and model/tokenizer manifestsClean checkout builds using declared inputs; removing an undeclared tool causes an explicit readiness failure, not hidden fallback
TF-03Configuration: deployment values supplied independently of code; strict typed parsing; secrets server-onlySame built artifact accepts different endpoint/limits configuration; malformed supplied values fail startup; secret scan/log tests show no disclosure
TF-04Backing services: hosted API attaches to a private state service and model endpoints through contractsReplace the store endpoint or inference provider configuration without recompiling the API; incompatible contracts are rejected
TF-05Build, release, run: immutable artifacts, configuration-bound release manifest, no build at startupPromote the tested digest without rebuilding; startup runs with no compiler or package registry access; retain schema/library compatibility evidence
TF-06Processes: hosted API/workers keep no sole durable truth in memory or writable process filesReplace an API with an empty ephemeral filesystem; history, ownership and committed replay remain correct; local embedded-store exception is declared
TF-07Port binding: the server binds a configured address and port; proxy is externalRun behind a different approved proxy without changing application source; health/readiness and actual HTTPS streams pass
TF-08Concurrency: scale explicit process roles and bounded worker slots, not uncontrolled threadsTwo workers race for one task; one acceptance succeeds; stale epoch fails; queue/memory limits hold; no claim of horizontally replicated SQLite writers
TF-09Disposability: fast readiness, graceful shutdown and crash recoverySIGTERM stops admission and drains within a configured grace; SIGKILL does not duplicate accepted work; interrupted runs and lease recovery remain visible
TF-10Development/production parity: same storage engine, protocol and release path; platform capabilities vary explicitlyLinux QA runs the production image and schema; Mac/Swift workers pass common contract fixtures; mock inference is not presented as model-quality validation
TF-11Logs: structured event output to stdout/stderr, aggregated by the environmentNo application-managed production log rotation; logs carry request/run IDs but omit credentials, raw sensitive inputs and provider payloads
TF-12Admin processes: one-off migration, import, verification and export use the same release and policyRun a scoped admin operation with target guard and least privilege; retain an audit receipt; reject incompatible schema or production target in destructive tests

Configuration contract ​

Proposed runtime variables are granular, validated settings, not a single opaque production switch:

VariableMeaning and boundary
LAB_BIND_ADDR, LAB_PORTHTTP bind location; local defaults may be loopback, container deployment explicitly binds an approved interface
LAB_STORE_URLPrivate store endpoint for hosted API/workers
LAB_LIBRARY_PATHStore/local-authoring process only; never a browser-selected filesystem path
LAB_MODEL_MODEExplicit mock, local or remote; absence is not silent permission to call a provider
LAB_MODEL_ENDPOINTOperator-controlled, allowlisted model service
LAB_MAX_CONCURRENT_RUNS, LAB_MAX_OUTPUT_BYTESPositive bounded limits; parsed on startup
LAB_SHUTDOWN_GRACE_SECONDSGrace budget coordinated with the process supervisor

Secrets use the deployment's credential injection mechanism and are never committed, returned in public configuration or printed. A variable carrying a secret-file reference is a deliberate injection choice, not permission to put its contents into a release manifest.

The Svelte frontend should use relative /api paths and a sanitized runtime configuration endpoint when needed. Environment-specific URLs baked into JavaScript at build time would prevent promoting exactly the same frontend artifact. Public runtime configuration is an allowlist, not a dump of the process environment.

State and release rules ​

The canonical store transaction owns graph changes and their events. The hosted conversation store is operational state, separate from the immutable published research snapshot. No cross-database atomic transaction is assumed: each answer pins an already published library revision and records that reference durably in its own run transaction.

A release manifest records source revision, application artifact digest, schema compatibility range, selected library revision, embedding-space identities and enabled worker/model versions. Configuration fingerprints exclude secret values. A schema-changing release may require a forward repair or a restore; switching an image tag alone is not a safe rollback plan.

Operational logs and the evidence audit ledger are different. Stdout logs support diagnosis; the audit ledger is durable, access-controlled application data and must participate in the relevant transaction and retention policy.

Explicit exceptions and nonclaims ​

The local embedded store does not meet strict stateless-process scaling. The hosted private store is a stateful backing resource, not an API replica. CUDA and Apple implementations need compatible contracts but need not produce bit-identical floating-point output. Multi-architecture images require separately built and tested artifacts; an OCI index alone does not prove parity.

Do not claim twelve-factor compliance because the project uses Docker, Rust or environment variables. Claim each tested property separately. The clean-build plan, examples and roadmap turn these gates into work.

IS373 · Documentation and contract labs available · Research runtime planned