Repository navigation
Bound replica shutdown, backup leases and recovery errors - #254
Conversation
Leases run on the database clock and backup/drill hold a renewing lease (2 min TTL, 30 s renewal) whose loss or the shutdown's cancel phase ends the run. Shutdown drains /readyz before closing the listener and waits for deposits, drills and the sync worker. Ordinary requests get a 25 s deadline with named long-route exemptions. PostgreSQL replicas record a keyed shared-configuration fingerprint and refuse a mismatch; accept-replica-config rewrites it with an audit row. Pairing reads come from one statement, read errors are no longer reported as unpaired, and a pinned key's topology is write-once. Snapshot scratch is locked and swept at start; local copies are listed read-only. The import refuses a source that fails its checks or changes before commit; restore keeps unexpired device assertion IDs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the shutdown budget and sequence on a real listener, lease renewal, loss and transient errors on the database clock, a dead holder's bound, the request deadline and its pinned exemptions, the replica fingerprint table and accept-replica-config on PostgreSQL, coherent pairing reads under re-pairing, read errors, write-once topology including two servers pinning at once, scratch locking and sweeping, both backup-directory layouts, import source proofs, the identity catalog and kept replay history. Fixes a missing return that let a refused topology change in PairRemote fall through to success. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l replicas A database error during the session lookup used to read as no session (401), sending a signed-in user to sign in; it is now 503. Process tests on PostgreSQL drain a replica on SIGTERM while the other keeps the session, and survive a database frozen behind an in-test relay. migrate-to-postgres and restore are tested with relative, dot-dot and absolute paths and a relative database URL file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scripts/check-postgres-cutover.sh stops a SQLite install with docker stop, migrates it from a read-only volume into a pinned PostgreSQL 17 on an internal network, refuses a repeat and starts the image on PostgreSQL. The docker job runs it; its timeout rises to 20 minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RUNNING.md covers load balancer checks, retries and timeouts (and what nginx and Nginx Proxy Manager passive checks cannot do), the stop sequence and 30 s grace period, an unexecuted Kubernetes sketch, the request deadline, the shared-configuration check and accept-replica-config, renewed leases, both backup-directory layouts and the stricter migration. RESTORE.md, UPGRADES-AND-RECOVERY.md, ASSURANCE-CASE.md, CHANGELOG.md, the manual and both AGENTS.md files follow. Application replicas are documented as not database HA, with no capacity claim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…psule On PostgreSQL under the race detector the backup run itself takes over a second, which the bound is not about. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A renewal is a statement with no deadline of its own: on a connection that stalls without an error (a one-sided partition, a frozen proxy) it blocked keepLease, the hold outlived the lease, and another replica could run the same backup. Each renewal now runs under a deadline one interval before the lease's local expiry estimate, release cancels before it waits, and taking and giving back the lease carry contexts (the give-back is bounded at 5 s). Tests: a blocked renewal ends the hold with ErrLeaseLost before the TTL and a release during it returns at once; a hold over a frozen pgx connection ends at 1.5 s of a 2 s TTL while another replica takes the lease only after it; and a session with a shifted database clock shows the lease follows the database, not the caller (a caller-clock lease fails it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
checkReplicaConfig ignored a lost compare-and-swap when recording a field the record lacked, so of two starts with different values for a newly added field the loser started uncompared. It now re-reads and compares again (bounded). accept-replica-config parses its arguments before any configuration or database work: -h prints usage, a stray flag or argument is refused, and nothing is rewritten. Refusals name no other replicas (a single PostgreSQL server records too) and give the steps in the order that works; a first accept says it recorded. The topology 409 names the pinned k-of-n and the documented way to correct it, and a refused pairing says the code is spent and its token should be revoked. A sweep reports another user's snapshot leftover instead of skipping it silently, a single server no longer logs a 0 s drain, and the backup handler's run tracking is allocated once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shutdown test pins cancellation to the wait phase (in-flight work answers only after the drain and the listener's full shutdown). A real server start is shown to sweep a crash's snapshot and a mismatched replica to exit naming only the field. The restore-with-Replace half of the identity test resets every identity first, so a skipped restart fails it. Shared and per-replica directories are compared through each replica's own backup status page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A relay key renewal can take a send, a 15 s wait for another replica's key, a registration and a second send, longer than the 25 s request deadline. CreatePushChallenge now waits at most 10 s for the sends and lets the rest finish on their own: the challenge already stands and the sign-in page polls it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The backup page defaulted a status it could not read (now a 503) to unpaired and unpinned, and offered to pair or pin again. Until a status is read every fact says Unknown, pairing, pinning and the schedule are withheld, and a failed refresh keeps the last status read. The first session check signed the browser out on any failure, including the new 503 for a session the database could not look up; only a 401 does now, and otherwise a retry screen says the browser is still signed in. A failed capsule export shows the server's error_description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RUNNING.md: exempt routes are not bounded by the write timeout on a frozen database; nginx's proxy_next_upstream error may resend an idempotent request, and Nginx Proxy Manager needs a multi-address name or a custom upstream; the Kubernetes readiness probe allows 3 s for the 2 s database read; single PostgreSQL servers record the configuration too; accept-replica-config runs once with the servers stopped and their full environment, with a checked Compose one-off command and Kubernetes guidance marked unexecuted; turning on KYIDENTITY_REPLICATED after the first PostgreSQL start is an accepted change; per-replica listings and shared-directory KEEP; how to correct a wrongly pinned split; the library's sealing-time cancellation limit. Troubleshooting, upgrade notes, changelog and both AGENTS.md files follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The store's writer lock is one key for the whole test database, which other packages share under -p 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measure the first lease expiry before its bounded acquisition and prove that release cancels a blocked renewal before waiting. Keep confirmed sign-out distinct from an unavailable session check, and disable the schedule until its status is known. Document a single-run Kubernetes Job and a checked stopped-server SQLite pin repair. Correct the test-lock explanation and topology error contract without changing the immutable pin or external key anchor.
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
Advisory only: this comment never gates the pull request. |
Security review - clearedDetail 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-kyidentity-server-254, where it is readable by the operator and expires seven days after the last post.
gpt-6.1-sol using security-audit on behalf of Yoshi |
Autonomous review - 1/1 personas cleared
Merging remains a human decision; this bot never approves. gpt-6.1-sol using security-audit on behalf of Yoshi |
KyIdentity replicas now drain before shutdown, stop backup work when ownership is lost, and report database outages without presenting the server as unpaired or signing users out. SQLite remains the single-host default, with a checked path to PostgreSQL.
accept-replica-configoperator command.kyidentity.dband legacykysignon.db.Review first: lease ownership, configuration acceptance, and operator recovery procedures. Pin topology becomes write-once and PostgreSQL configuration is recorded in the database; reverting code does not undo those records. Migration/restore and manual pin repair require deliberate operator action. The Factory decision is ESCALATE: owner acceptance is required before merge; this PR remains open for hosted verification.
Checked: fresh full Go build/vet/govulncheck and default/FIPS race suites at
54f1ec3; full PostgreSQL-p 2with real failover/drain/frozen-database/lease tests; 273 web tests and byte-identical rebuilt assets; docs/link/static checks; production-image smoke, public-HTTP refusal and SQLite-to-PostgreSQL cutover. Independent round-three code review repeated default/PG runs, killed the relevant mutants, and repeated frozen-lease tests 10 times. At final docs-only251ae2a, rebuilt the image and executed the documented pin repair for both filenames using the real Compose configuration on isolated resources, retaining static addressing and security options. Runtime inputs are unchanged from54f1ec3.Hosted verification: all 12 active checks passed at
251ae2a(publish/promote are skipped on a PR). The autonomous security marker isverdict=clearedfor this exact head, with an explicit truncated-input coverage notice; its private report says no actionable finding in the reviewed changed lines. Independent Factory security review also passed; no full-coverage automated audit is claimed.Limits: no production deployment. Kubernetes and nginx/NPM guidance and browser rendering are unexecuted. A historical PostgreSQL test-setup lock timeout did not recur in later full runs; its cause remains unproven. The shared library still has a documented cancellation window during sealing before local copy/pruning; uploads are cancellation-bound. No capacity, PostgreSQL HA or edge HA claim.
Review and validation detail
Factory round three on
54f1ec3: security PASS 9.5/10, code PASS 9.5/10, UI PASS 9/10 for API/error-state behaviour (no visual score), UX CHANGES 9/10. The remaining UX finding was the legacy SQLite filename in the repair helper;251ae2afixes it and the exact commands pass on modern-only and legacy-only volumes. The original review verdict is retained; no new all-PASS round or human approval is claimed. Factory decision: ESCALATE for owner acceptance of the persistent/key/recovery changes and recorded limits. Named outbound timeout exemptions and applying the configuration check to PostgreSQL installations were already permitted by the spec; those two are not additional scope requests.Full local checks run serially with 6 GiB memory and zero swap, persistent caches, and production push relays explicitly disabled. PostgreSQL tests use isolated pinned PostgreSQL 17 C/UTF8 containers. No job-specific regression was skipped; the existing SQLite-only/container-gated tests retain their documented skips.
The base replica PR Busnes-app/ky-server-base#121 is a reference only and has its own owner gate. This product imports no base internal package and copies no shared recovery library implementation. Existing externally anchored recovery-key replacement, digest-required restore, split capsule members, signing/encryption/VAPID/relay keys, audited mutations, administrator/step-up rules and HR/SCIM/OIDC behaviour are preserved.