fix: resolve bugs surfaced by the personas QA workflow - #79
Merged
Conversation
Walked the app as distinct user personas (widget end-user, admin operator, ops/self-hoster) and fixed concrete, verified defects: ops / self-hoster - serve.ts: guard PORT parsing against non-numeric values (e.g. "8787/tcp") that produced NaN and bound an arbitrary port. - serve.ts: close the shared Redis connection on SIGTERM/SIGINT. Its open socket + reconnect timers kept the event loop alive past server.close(), forcing the hard-deadline exit(1) on every rolling deploy. Adds closeRedis() to lib/redis.ts. - serve.ts: detect the entrypoint via argv basename instead of import.meta.url, matching the hardened guard in migrate.ts (robust to bundler inlining; handles both compiled .js and tsx .ts). - index.ts: guard ADMIN_SESSION_TTL_DAYS against NaN, which made every minted cookie expire at NaN so logins "succeeded" but the next request 401'd. - rotate-secrets.ts: stop counting retired-kid rows skipped without --reencrypt-all as "skipped-active"; report them under a new skipped-other counter so the summary no longer implies rotation is complete while rows still need re-encryption. admin operator - adminAuth.ts: remove the obsolete TOFU branch. Login now persists sessions via recordAdminSession, so re-admitting a never-recorded cookie let a replayed cookie survive logout until HMAC expiry — defeating server-side revocation. A missing session row now 401s. - dashboard client: correct the listTickets doc — `recent` sorts by created_at desc (tie-broken by id), not updated_at. widget end-user - locales.ts: use `||` instead of `??` when reading navigator.language so an empty-string value (some browsers) falls through to navigator.languages[0] instead of rendering the default locale. https://claude.ai/code/session_01UgPHbsFRraBXDg5BXDyQRQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Ran a personas QA workflow — walked the app as three distinct user personas (widget end-user, admin operator, ops/self-hoster) to surface real bugs, then fixed the concrete, verified ones. Speculative findings, intentional design choices, and large feature gaps were deliberately left out to keep this focused and low-risk.
Fixes
Ops / self-hoster
serve.ts— PORT NaN guard.Number(process.env.PORT ?? 8787)returnsNaNfor a stray value like8787/tcp, which then binds an arbitrary port. Now validated with a loud fallback to the default.serve.ts— close Redis on shutdown. The sharedioredissocket and its reconnect timers kept the event loop alive pastserver.close(), so the process never exited cleanly and always hit the 10s hard-deadlineexit(1)on every rolling deploy. AddedcloseRedis()(lib/redis.ts) and called it in the drain path.serve.ts— entrypoint guard. Switched fromimport.meta.url === file://${argv[1]}to the argv-basename check already used (and documented) inmigrate.ts, which is robust to bundler inlining. Handles both the compiled.jsimage andtsxdev (.ts).index.ts—ADMIN_SESSION_TTL_DAYSNaN guard. A non-numeric value madeexpiresAt = Date.now() + NaN→NaN, so logins "succeeded" (200) but the next request 401'd with no obvious cause. Now falls back to the 7-day default.rotate-secrets.ts— counter mislabel. Retired-kid rows skipped without--reencrypt-allwere counted asskipped-active, making the summary imply rotation was complete while rows still needed re-encryption. They now report under a newskipped-othercounter.Admin operator
adminAuth.ts— remove obsolete TOFU branch (logout bypass). Login now persists sessions viarecordAdminSession, so the trust-on-first-use branch re-admitted a never-recorded cookie — letting a replayed cookie survive logout until HMAC expiry and defeating server-side revocation. A missingadmin_sessionsrow now correctly 401s. The in-code comment had already flagged this branch for removal once login persisted.listTicketscomment:recentsorts bycreated_atdesc (tie-broken by id), notupdated_at(verified against the server query).Widget end-user
locales.ts— locale auto-detection. Used||instead of??when readingnavigator.language; some browsers expose it as an empty string (not nullish), which short-circuited??and discarded a validnavigator.languages[0], rendering the default locale to a non-English user.Verification
pnpm --filter @koe/api test→ 89/89 passtypecheckgreen across@koe/api,@koe/shared,@koe/dashboard,@wifsimster/koeNot included (intentionally)
batchIdrevert correlation — the code has an explicit design comment choosing per-event undo, and it'd need a schema migration.X-Forwarded-Forleft-most-hop trust — deployment-topology-specific; a blind change could break legitimate setups.https://claude.ai/code/session_01UgPHbsFRraBXDg5BXDyQRQ
Generated by Claude Code