Repository source: docs/plans/browser_keychain/browser_keychain_step4_implementation_summary.md
Debug mode: enabled
Effort study: railspike-effort / v3/browser_keychain; cycle ledger. Standing P2 enrollment; parent v3/local_pull_simple.
Extended estimates: enabled
Cycle estimate: 0.80
Branch feature/browser-keychain from origin/main at 1d98d94b. Planning commit 5390712. Feedback: PF-20261104-F19.
Step 4 entry projection (2026-11-28T19:05Z, Claude, single exposed rater): 0.80, reaffirmed from Step 3. Stage estimates below are copied from Step 3, not new ratings.
Stage 1 - Every active key joins the keychain
Original estimate: 0.12
Changes:
public/assets/browser_signing.js:forum_pki_keychainwithkeychainEntries,writeKeychain(checks the write reads back),addToKeychain,keepActiveKeyBeforeReplacing,rememberActiveKeyandkeychainSummary.The three places that write the active key now keep the current key before replacing it and add the new one after:
generateBrowserKey,saveImportedBrowserIdentityandrestoreClearedKeypairBackup. Key bootstrap and Connect reach these throughwindow.__forumBrowserIdentity.A key that was active before the keychain existed joins it when
browser_signing.jsloads.A failed
importAccountPrivateKeyputs the keychain back as it was.window.__forumBrowserIdentity.keychain()lists entries without private keys.
Verification:
Passed:
node tests/browser/browser_keychain.mjs(new). It covers the on-load add, replacement keeping the old key, and no duplicates.Passed:
./v3 test --smoke AccountKeyPageHooksTest(504 passed).Passed:
node tests/browser/key_backup_ui.mjs,key_handoff.mjs,key_bootstrap.mjs.key_backup_ui.mjsfirst failed only because this workspace had no Playwright Firefox. Installing it withnpx playwright-core install firefoxfixed that; it was not a test defect.Not run: the full suite.
Notes:
Deviation from the plan, same scope: if the current key can't be saved before a replacement, the change is refused with a short message and Details. The plan said the change would still happen. Refusing keeps "nothing is lost" true.
The keychain is JSON in
localStorage, like compose drafts.
Estimate details: original scope as planned; uncertainty low; no revision.
Retrospective stage work: 0.12
— Claude · 2026-11-28 UTC · Model: claude-opus-5-5
Stage 2 - Retire forum_pki_previous_*
Original estimate: 0.08
Changes:
public/assets/browser_signing.js:migratePreviousKey()runs on load. It moves aforum_pki_previous_*key into the keychain, and deletes the slot only once the keychain holds that exact private key.public/assets/local_message_pull.js:setAsideCurrentKeybecomesreplacesCurrentKey. It no longer writes the slot, becausesaveImportedBrowserIdentitynow keeps the old key. The final status says the old key "is still in this browser; switch back on Account."docs/concepts/local_development_import.md: names the keychain instead of the slot. The link tobrowser_keychain.mdresolves once Stage 6 adds that entry.tests/browser/key_handoff.mjs: case 7 checks the old and new keys in the keychain and no slot.
Verification:
Passed:
node tests/browser/browser_keychain.mjs, now with the migration case.Passed:
node tests/browser/key_handoff.mjs.Unverified: the new status note. Case 7 stops before Connect's whole pass ends, so the final status never shows; the old test didn't check it either. Stage 6 checks it with the full replay or reports it unverified.
Notes:
Stage 1's commit carries a
Feedback: PF-20261104-F19trailer, but the item file wasn't updated in that commit asAGENTS.mdasks. Stages 2–5 leave the trailer off. Stage 6 carries it and updates the item.
Estimate details: original scope as planned; uncertainty low; no revision.
Retrospective stage work: 0.08
— Claude · 2026-11-28 UTC · Model: claude-opus-5-5
Stage 3 - Restore a different key
Original estimate: 0.10
Changes:
importAccountPrivateKeyno longer refuses a backup of a different key, and no longer refuses when the session names another key. It still refuses a backup whose key doesn't match its own fingerprint, with a plainer message.When the new key differs from the active key or the session's key, it calls
clearAuthenticatedIdentitybefore saving. It then signs in withPrivateSiteAuth.authenticateInPlace({ force: true }), so the member stays on Account. A failure restores the old key and keychain, then signs the old key back in, best effort.The clipboard restore and Connect take the same path. Key bootstrap only installs a key into a browser that has none, so it never switches.
docs/reference/key_backups.md: the "separate browser profile" sentence now describes the switch.
Verification:
Passed:
node tests/browser/key_backup_ui.mjson a public site and withMEMBERS_ONLY=true. New cases: a different backup whose publish fails leaves alice active with no new keychain entry; a successful one makes the other key active, keeps alice in the keychain, and/api/auth_statusno longer names alice.Passed:
browser_keychain.mjs,key_handoff.mjs,key_bootstrap.mjs.
Notes:
Found while testing, same scope: a new session made the default
authenticate()reload the page. A switch now signs in in place, so the Account status stays visible.
Estimate details: original scope as planned; uncertainty medium, as planned; no revision.
Retrospective stage work: 0.12
— Claude · 2026-11-28 UTC · Model: claude-opus-5-5
Stage 4 - Keychain list and Use this key
Original estimate: 0.15
Changes:
templates/pages/account_key.php: adata-role="keychain"account-groupholds a<template>row: name, short fingerprint, "In use" or Use this key.syncKeychainin the page script draws it fromforum_pki_keychainbefore paint, hidden with fewer than two keys. It redraws onstorageandforum:identity-changed, whichsyncSimpleUIalready listens for.public/assets/browser_signing.js:useKeychainKey(root, fingerprint)runsimportAccountPrivateKeywith the entry's key and fingerprint, so a switch takes the Stage 3 path. A delegated click handler on Account shows "Switching keys…", then "Now using <name>’s key." or the error with Details.tests/AccountKeyPageHooksTest.php: three new hooks.
Verification:
Passed:
node tests/browser/browser_keychain.mjs. It checks the rows and active mark, then a switch from bob to alice. The server session is read from Account's HTML (data-authenticated-identity-id), and a second open tab marks alice without a reload.Passed:
./v3 test AccountKeyPageHooksTest(7 passed).Passed:
node tests/browser/key_backup_ui.mjs. Its Stage 3 session check was wrong, because/api/auth_statusonly saysstatus=authenticated. It now reads Account's HTML and names the restored key.Passed by eye: the rows in Word97, Gloss and Ochre (
SCREENSHOTS=<dir> node tests/browser/browser_keychain.mjs).Inapplicable: navigation icons, since there is no new navigation destination.
Notes:
Only the Account page draws the keychain. The header label follows the switch through its existing listeners; the test checks it when the toolbar is present.
Estimate details: original scope as planned; uncertainty medium; no revision.
Retrospective stage work: 0.15
— Claude · 2026-11-28 UTC · Model: claude-opus-5-5
Stage 5 - Remove one key, with a stored Undo
Original estimate: 0.15
Revised estimate: 0.25 (2026-11-28T20:10Z; same scope; new understanding: one test that was already failing to fix, and the unit test stubs behind BrowserSigningNormalizationTest)
Changes:
public/assets/browser_signing.js:forum_pki_removedreplaces the in-memoryclearedKeypairBackup. It holds the removed keychain entry and its removal time, and expires after five minutes; each load purges an expired record.clearBrowserIdentityremoves the key named by the remove dialog (data-remove-fingerprint), or the key in use. It keeps the key for Undo first, so nothing is removed unkept. It signs the session out only when the key in use goes, and deletes only that key's saved copies; the whole cache goes once no key is left. An empty keychain is deleted, not stored as[].Undo puts the key back in the keychain. It becomes active only if no key is active now; otherwise Use this key switches to it. Making or importing a key no longer cancels Undo. After a reload inside the window, Account says what was removed, so Undo isn't shown alone. Undo hides itself when the window ends. After that, Undo says the key is gone and points to Use a key from another device.
public/assets/private_message_cache.js:clearOwner(fingerprint)deletes one key's entries (<owner>:*).src/ForumRewrite/Http/ComposeAndAccountKeyController.php: Account also loadsprivate_message_cache.js, so Remove can useclearOwner. This reuses the cache instead of duplicating its IndexedDB code.templates/pages/account_key.php: keychain rows for keys not in use get Remove, through the same#key-removedialog ("Posts stay under <name>.").
Verification:
Passed:
node tests/browser/browser_keychain.mjs. Removing bob deletes only bob's saved copy and leaves the session on alice. A reload still offers Undo, and Undo brings bob back without making him active. Removing the key in use empties the active slot and its copies. With the record six minutes old, Undo is hidden, the record is purged and nolocalStoragevalue holds the key.Passed:
CHROMIUM_PATH=/opt/google/chrome/chrome node tests/browser/private_message_cache_browser.mjs, with a newclearOwnercase.Passed:
./v3 test --smoke AccountKeyPageHooksTest BrowserSigningNormalizationTest KeyBootstrapTest LocalAppSmokeTest(608 passed).Passed:
key_backup_ui.mjs(public site andMEMBERS_ONLY=true),key_handoff.mjs,key_bootstrap.mjs,account_states.mjs,testing_self_approval.mjs.Not run: the full suite.
Notes:
Commits for Stages 1–4 failed
BrowserSigningNormalizationTest(8 tests). I didn't run that class until this stage. Its Node stubs have noroot.addEventListenerand noroot.dataset, and two tests pin the order of storage writes and requests. The code now checks for both before use. The tests now skip the keychain write and expect the sign-out on a switch. The Clear test expects only the Undo record to remain. Main passes 95/95; this branch now does too.Test already failing on main, fixed as our rule requires:
tests/browser/account_states.mjsfailed on1d98d94too. Its "a local key is replaced" case predates125a58c0("Continue names an existing key rather than replacing it"). It now expects naming, waits for the saved name instead of racing it, and accepts registration throughfinalize_profile_name. The rename control is found bydata-action, because a key named guest shows "Choose a name". The updated test passes on1d98d94and on this branch.The undo-expiry and copy-deletion timers use
window.setTimeoutwhen it exists, so Node test stubs don't wait on them.The Step 3 Completion Contract said "static assets and one template only". Stage 5 also adds one script to Account's asset list in a PHP controller. There is no route, schema or config change.
Estimate details: original 0.15; revised 0.25 for new understanding, scope unchanged.
Retrospective stage work: 0.25
— Claude · 2026-11-28 UTC · Model: claude-opus-5-5
Stage 6 - Docs, feedback item and the whole flow
Original estimate: 0.08
Changes:
New
docs/concepts/browser_keychain.md.docs/concepts/key_handoff.mdsays the old key stays in the keychain. (docs/reference/key_backups.mdanddocs/concepts/local_development_import.mdchanged in Stages 3 and 2.)docs/feedback/items/PF-20261104-F19.txt:Workflow: blockeduntil production acceptance,Evidenceand a dated note. "Log out but keep key" is not built and is still pending.docs/plans/README.md: the cycle is listed under "Awaiting review before merge".public/assets/site.css:.account-group[hidden]joins the existing[hidden]rule.account.csssets.account-group { display: flex }, which beat thehiddenattribute. Since Stage 4, a browser with fewer than two keys showed an empty bordered box on Account. The Stage 4 checks never looked at a one-key browser; the replay below caught it.tests/browser/browser_keychain.mjs: a replay of the Step 2 user flow in a fresh browser, through Account's own controls. Alice restores a backup file of bob; both are listed and the session names bob. Use this key goes back to alice. Remove on bob, and the list hides with one key. A reload still offers Undo; with the record six minutes old, Undo is gone and no value holds bob's key. The copy-ID check now sorts its expected list, because random fingerprints made its order flaky.
Verification:
Passed:
node tests/browser/browser_keychain.mjs, including the replay.Passed before this commit:
./v3 test --smoke AccountKeyPageHooksTest BrowserSigningNormalizationTest KeyBootstrapTest LocalAppSmokeTest(608 passed). Also passed:browser_keychain,key_backup_ui(public and members-only),key_handoff,key_bootstrap,account_states,testing_self_approvalandprivate_message_cache_browser.Passed:
git diff --check, and every link in the new concept entry resolves.Unverified: the Connect status note ("…is still in this browser; switch back on Account.").
key_handoff.mjscase 7 ends before Connect's whole pass finishes, so the note never shows in any check.
Notes:
Final diff review against
1d98d94: no duplicated helpers. The keychain, switch and Undo live inbrowser_signing.js; per-key deletion is in the cache script; Account reusesaccount-groupandaccount-row.options.replacefrom Connect is now ignored byimportAccountPrivateKey. It is harmless and left in place to keeplocal_message_pull.jssmall.
Estimate details: original scope plus the CSS fix found by the replay; uncertainty low; no revision.
Retrospective stage work: 0.10
— Claude · 2026-11-28 UTC · Model: claude-opus-5-5
Closeout
Retrospective cycle scope: 0.95 (Claude, single exposed rater; projected 0.80 at Steps 2–4)
Delivered: Option A as approved in Steps 1–3. Every key that becomes active joins the keychain. A backup of a different key restores and switches. Account lists keys with Use this key and Remove. Undo is stored for five minutes.
forum_pki_previous_*and the in-memory Undo are retired.Not delivered: "log out but keep key" (pending, Step 2 Enhancement Requests) and labels of the member's own (out of scope).
Above the projection, without changing scope:
BrowserSigningNormalizationTeststubs that Stages 1–4 broke, the staleaccount_states.mjsthat already failed on main, and the hidden-group CSS.Checks: listed per stage. The full suite was not run. Firefox for Playwright was installed in this workspace for
key_backup_ui.mjs.Maintainer comfortable-fit judgment: pending.
— Claude · 2026-11-28 UTC · Model: claude-opus-5-5