Skip to content

Support replica health checks and PostgreSQL recovery - #121

Merged
Yoshiofthewire merged 16 commits into
masterfrom
feat/base-multiserver
Nov 18, 2026
Merged

Yoshiofthewire merged 16 commits into
masterfrom
feat/base-multiserver

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

In one line: PostgreSQL deployments gain health-checked application replicas and sealed KyBackup recovery, while SQLite stays the single-server default. Factory requires an owner merge decision for this change. Its newly found relative-source migration defect is fixed at e3a3862; all current-head CI and local checks pass, and Council is unanimously satisfied. Current-head qualified security clearance is complete; owner merge acceptance remains pending. Suite rollout has not started.

What changed

  • Replicas expose liveness/readiness, drain before shutdown, and reject mismatched shared configuration.
  • A Compose profile runs replicas behind HAProxy, with bounded database-outage responses and durable shared local backups.
  • PostgreSQL produces verified, point-in-time portable capsules; restore clears sessions and disables scheduling before migration into an empty target.
  • Recovery keys and custodian topology remain write-once across replicas, including ownership-connection loss.
  • Recovery pairing commits the URL and sealed token together; each operation reads a coherent pair during refresh or unpair. Existing credentials retain their format.
  • Compose respects a configurable, wire-valid service label; generated products keep their own overridable label and refuse an unknown initializer template. Migration guidance preserves SCIM secrets and requires product sequence advancement.
  • Failure tests exercise server/worker death, database disruption, shared security, backup retention and the documented restore commands.

Review this: snapshot completeness, atomic pairing and its coherent reader, and restore/cutover. Preserve the deployed encryption key and original database; no production migration is performed by this PR. Generated frontend assets are safe to skim.

Checked: the new relative-source regression fails at 00494a7 and passes after the fix. At e3a3862, PostgreSQL migration passes check-only and copy with no source override, leaves the original SQLite bytes unchanged, and materializes the same recovery pin on a fresh replica. Local CI, four fresh CLI race/FIPS runs, shellcheck and clean-export REUSE pass. All current-head hosted CI jobs also pass, including PostgreSQL, FIPS, Docker and replica failover. The complete 00494a7 hosted suite and earlier full runtime proof remain historical, not current-head passes.
Pending: owner merge acceptance. The security reviewer now clears current head e3a3862, with its truncated-input coverage notice retained. All three Council round-4 reviewers pass: Opus 9.5/10, Sol 9/10 and Gemini 10/10. Opus and Sol independently tested actual binaries across default, relative and absolute sources, source/pin preservation and missing-pin refusal; the old helper makes the new regressions fail. Factory escalated the merge under its key/auth/restore-policy gate; it has not authorized merging. The new relative-path defect it identified has been reproduced and fixed rather than left for a follow-up.
Decided for you: PostgreSQL coordinates replicas without Kubernetes; HAProxy supplies active readiness checks. KyDNS peer enrollment remains separate because its nodes replicate independent data stores.
You need to: review the schema, key-handling and restore contracts before production use. No deployment has occurred.

Detail

The base keeps SQLite local and supports explicit maintenance-window migration. PostgreSQL snapshot export reuses the verified table copier in one repeatable-read read-only transaction, refuses unknown tables/columns/history, verifies counts and content, and seals the same portable database member used by SQLite. Capsule limits and the blind KyRecovery deposit contract stay unchanged. This is scaffold recovery: derived applications need their own schema and file/queue adapters.

The restore path writes a separate directory, removes restored sessions and the configuration fingerprint, disables scheduled deposits, then migrates into an empty PostgreSQL database. The old database is retained; changing back after new writes requires a data migration rather than a blind DSN rollback.

The replica overlay retains separate disposable app data directories and one durable sealed-backup archive. PostgreSQL has its own private volume. Key pin rows use conditional inserts, so an expired advisory-lock owner cannot replace another key or custodian topology. Normal requests have a 14-second context limit before the 15-second listener deadline. HAProxy uses an 8-second upstream limit without timeout retries; only capsule deposit, drill and export use the long budget. Backup status reports failed settings reads as 503 rather than inventing unpaired state.

Historical c8d2256 local proof: make ci; four fresh go test -race -count=1 ./... executions across SQLite/PostgreSQL and FIPS; vulnerability, REUSE, shell and Compose checks; a fresh image and all eight Compose tests passed. The end-to-end run took 226.75 seconds and includes real binary restore/migration, backup retention, database disruption and fresh-database readiness. Hosted checks passed at the same head. Council corrections are implemented at b4b8920. Fresh local verification completed with ALL REQUIRED CHECKS PASSED: make ci, four uncached race/FIPS suites, four CI-budget fuzz runs, govulncheck, REUSE, shell/Compose checks, a clean current-head image and all eight replica failure/restore stages (223.04 s). Pairing writes and removals use one transaction over the existing URL/token rows, while the recoveryclient adapter reads one coherent snapshot per operation. The wire format and encrypted credential label stay unchanged. Shared-key read errors remain failures on every backup endpoint, including a new replica without its local key file. Existing service identities and SCIM secrets are preserved by the runbooks; products must reset all their sequences and prove subsequent inserts after restore.

Application replicas do not make PostgreSQL or the edge proxy highly available. Separate-host deployments and capacity at 10,000 users still require product-specific qualification. KyDNS is excluded from the rollout; products with unresolved shared-file or queue ownership will be documented before any replica-readiness claim.

The final initializer correction (e1094c1, completed by 00494a7) rewrites the default within Compose interpolation, validates service-label input and refuses an unrecognized template before creating files. A standard-library regression exercises the actual script with the shipped Compose template, checks a derived product can scaffold again, and runs in local/hosted smoke. A full source scaffold and its own generated-product regression were also exercised, with no server or production service started. No Go, dependency, runtime Compose, proxy or frontend inputs changed after the passing b4 matrix.

All round-4 reviewers accepted the final CLI correction (e3a3862), which normalizes a relative source with filepath.Abs before constructing its read-only SQLite URI, matching the copier. Its tests cover the actual unset-data-dir default, check and copy, source preservation, and pin synchronization. Current-head hosted CI and local checks pass; previous-head results remain historical. The optional suggestion to export a shared URI helper is deferred because the behavior is now guarded by regressions.

Council review

Rounds: 4 completed; unanimous satisfaction at e3a3862.

Delegate Round 1 (c8d2256) Round 2 (b4b8920) Round 3 (00494a7) Round 4 (e3a3862) Current verdict
Claude Opus 5.5 8.5/10 — Changes 9/10 — Changes 9.5/10 — Pass 9.5/10 — Pass Satisfied
GPT Sol 7.5/10 — Changes 9/10 — Pass 9/10 — Pass 9/10 — Pass Satisfied
Gemini Argon 9.5/10 — Pass 10/10 — Pass 10/10 — Pass 10/10 — Pass Satisfied

All first-round recovery, pairing, service-label and cutover findings are fixed. Round 2 confirmed the Go implementation and rollout contract; Opus identified a counterpart initializer rewrite that no longer matched the Compose default. The initializer now preserves a product-specific overridable identity and fails clearly on a changed template. Fresh focused verification passes, and all three delegates are satisfied at the reviewed 00494a7 head. Opus notes two nonblocking initializer limits: locale-sensitive non-ASCII input can fail later during Go module validation after creating a partial target, and second-generation container/image coordinates retain the parent (the service label itself is correct). Neither can produce a successful scaffold with an invalid recovery label. These are retained as advisories rather than reopening the accepted server work.


gpt-6.1-sol using Factory, Council and pull-request on behalf of Yoshi

Yoshiofthewire and others added 11 commits November 17, 2026 22:27
/readyz pings the store at most once a second behind a mutex, times the
ping out at 1s and answers only the status word. StartDraining turns it
to 503 while every other route keeps serving.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shutdown marks the server draining, cancels backup work and keeps
serving for readinessDrainDelay (5s) before closing the listener; the
budget is now 20s. On PostgreSQL the bootstrap lock now records an
HMAC fingerprint of the shared settings, keyed by the encryption key,
and refuses a replica that differs, naming only the fields.
accept-replica-config rewrites the record after a deliberate rotation
and audits the changed field names. The record never leaves the
settings API or the logs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
store.SnapshotToSQLite copies every scaffold table from one REPEATABLE
READ READ ONLY transaction into a fresh SQLite file, verifying counts
and row digests, integrity and foreign keys; an unknown table, column
or migration history is ErrSnapshotSchema and nothing is copied.
backup.Collect seals it as the same data/ky_server.db member, so the
capsule, drill, restore and limits are unchanged. The PostgreSQL pool
floor is now 4 connections, proven by a pool-floor test.

A pin or pairing also stores the public key in settings; a replica
writes its missing recovery.pub from it through the lib's write-once
StoreRecoveryKey before every run, export and at startup, and refuses
to start with a recovery.pub that differs from the pin.

restore now deletes every session and the replica fingerprint in the
restored database, beside turning the schedule off, and says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docker-compose.replicas.yml runs KY_REPLICAS app containers on one
PostgreSQL (digest-pinned, private internal network, password
required) behind HAProxy, which finds replicas through Docker's DNS
and checks each /readyz every second; only GET/HEAD get L7 retries.
Replicas share no files: each keeps its own anonymous data and backup
volumes, KY_ENCRYPTION_KEY is supplied explicitly and recovery.pub is
rewritten from the database. The base service gets a /readyz
healthcheck. scripts/check-replicas-compose.py renders the merges.

The Backup page drops the PostgreSQL notice; web/dist rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…CI job

docs/REPLICAS.md: health and drain, the Compose replica overlay and
HAProxy, separate hosts and nginx/NPM limits, Kubernetes probes, the
shared-configuration check and rotation, and the product rollout
contract; application replicas never make PostgreSQL highly available.
docs/RESTORE.md: PostgreSQL restore and rollback; the manual session
delete is gone. DISASTER-RECOVERY, INTERFACES, ASSURANCE-CASE,
STRONG-CRYPTO, README, CHANGELOG and AGENTS.md follow.

KY_EDGE_TRUSTED_PROXIES lets the replicas trust the TLS proxy in front
of HAProxy, so sign-in limits stay per client. make test-replicas and
the new replicas CI job (in publish.needs) run the Compose failure
tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e2e/compose_test.go (KY_E2E_COMPOSE=1) drives docker-compose.replicas.yml
with the local image through HAProxy: SIGKILL and graceful stop of a
replica under 10 rps, shared lockout and logout, elected-worker death
and failover, CLI drill and export on PostgreSQL, PostgreSQL paused and
stopped, and a real-binary restore into a second empty database. It
uses throwaway kits and secrets, empty relay variables and loopback
ports, and removes its own project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pins, pairings and the recovery.pub/record sync run under one database-wide
recovery-pin lock, write on the lock's context and read the pin back, so two
replicas pinning different keys give one success and one 409, and a lost
lock connection pins nothing. A pin no replica can load is reported (status,
startup log, scheduled-run audit, 412) instead of skipped as "not paired".
migrate-postgres records a source's pinned recovery.pub and refuses a pin
without it before copying.

Also: startup removes snapshot scratch a killed process left (flock-owned,
no symlinks followed), prepareStart makes the startup refusal testable,
accept-replica-config refuses a different encryption key, requests outside
/api/backup/ end at the write deadline, and every Config field must be
fingerprinted or classified per host. Includes the backup handler and test
comment corrections from review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…verlay

Replicas keep their own /app/data and share ./backups, whose writes and
pruning run under backup-run; PostgreSQL gets its own pgdata-replicas
volume. HAProxy waits 8s for a reply and never retries a timeout, has one
slot per KY_REPLICAS, and the overlay refuses KY_EDGE_TRUSTED_PROXIES with
a non-default KY_PROXY_BIND. The e2e fires authenticated requests from the
moment PostgreSQL is paused (each answered within 10s, no retries), checks
retention and listing across down/up and scaling, and restores with the
runbook's own docker compose run commands. CI runs it on the image the
docker job tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
REPLICAS: shared backups, upgrade command, SQLite base install to replicas,
edge trust rule, recovery key on replicas, other-proxy timeouts. RESTORE:
createdb in the bundled database, writable restore mount, key import
without echo. INTERFACES, ASSURANCE-CASE, DISASTER-RECOVERY, CHANGELOG and
the touched AGENTS.md files follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Enforce recovery key and topology write-once semantics with conditional database inserts, including after ownership loss. Bound backup management requests before the listener write deadline and reserve the long proxy timeout for capsule operations. Check PostgreSQL TCP readiness and correct restore and rotation commands, with regression coverage.
Keep the first settings read error so status helpers cannot turn an unavailable store into a successful unpaired response. Cover both a settings timeout after successful authentication and an immediate backend failure. Return 409 when a caller changes the pinned custodian topology.
@Yoshiofthewire

Yoshiofthewire commented Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-ky-server-base-121, where it is readable by the operator and expires seven days after the last post.

Review input was truncated; omitted changes were not reviewed.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵

🧪 PR contains tests

🔒 No security concerns identified

⚡ No major issues detected


⚠️ Review coverage: The following files were not included in this review because of the token budget:

  • docker-compose.replicas.yml
  • web/dist/assets/index-D5wKdYWj.js
  • scripts/check-replicas-compose.py
  • scripts/ky-init.sh
  • web/dist/index.html
  • Makefile
  • deploy/replicas/haproxy.cfg

Advisory only: this comment never gates the pull request.
claude-sonnet-5-5 using pr-agent on behalf of Yoshi

Report shared-key synchronization failures instead of missing pairing state. Keep configured app identities with a wire-valid Compose default, verify claim and deposit labels, and retain service identity through restore. Document safe SCIM credential retention, partial pin recovery, the Compose version floor and per-product sequence advancement.
Keep the existing URL and sealed-token rows together on refresh and unpair, and read them from one snapshot per backup operation. Reuse recoveryclient validation and sealing while preserving deployed ciphertext and immutable recovery pins. Cover failed writes, concurrent refresh and unpair, and coherent reads on both database drivers.
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 gpt-6.1-sol responding on behalf of Yoshi

Council corrections are pushed in 8298654 and b4b8920: backup endpoints retain shared-key read failures, pairing updates/removals commit together with coherent credential reads, Compose preserves valid configured service labels, and cutover guidance preserves existing secrets and covers product sequence advancement. Targeted SQLite/PostgreSQL race regressions pass; reverting the atomic writes makes the new tests fail. Fresh full checks and Council re-review remain pending.

Rewrite the product default inside Compose interpolation and refuse an unknown template before creating files. Validate service-label input and cover generated identity, overrides and fail-closed behavior with a scaffold regression in local and hosted smoke checks.

Fixes: 8298654 (preserve recovery state and valid service identities)
Match a valid existing default inside Compose interpolation so generated products keep their initializer checks working. Exercise a second-generation scaffold as well as the base template.
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 gpt-6.1-sol responding on behalf of Yoshi

The remaining Council initializer finding is fixed in e1094c1 and 00494a7. Generated products receive their own overridable recovery service label, including when scaffolding from a previously generated product; a changed Compose template fails before creating files. The new regression failed against the prior script and now passes in local and hosted smoke. Full scaffold/render checks, shellcheck and REUSE pass. Server code, dependencies and runtime configuration are unchanged from the full passing b4b8920 matrix; current-head CI and Council delta recheck are pending.

Normalize the SQLite source before constructing its read-only file URI, matching the migration copier. Exercise the bare-binary default in check and copy modes against PostgreSQL, verify the original source is unchanged, and confirm a fresh replica recovers the same pin.
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 gpt-6.1-sol responding on behalf of Yoshi

The relative-source migration finding is fixed in e3a3862. The regression reproduced SQLite’s invalid-URI-authority error before the fix; check-only and copy now pass against PostgreSQL with the default relative source, preserving the original SQLite bytes and recovery pin. Current-head CI and focused review are rerunning. Factory’s owner merge gate remains in place.

@Yoshiofthewire
Yoshiofthewire merged commit 2340ac8 into master Nov 18, 2026
16 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the feat/base-multiserver branch November 18, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant