Repository navigation
feat(ios): Encrypted Vaults VaultStore orchestration + leak-closure suite (#304) - #326
libravault-xyz wants to merge 2 commits into
Conversation
…-closure suite (#304) Swift port of Android's VaultStore.kt + VaultSessionManager.kt, plus the leak-closure guarantee that makes the whole Encrypted Vaults feature trustworthy end-to-end. Ties together #301 (VaultRegistry/ UnlockAttemptThrottle), #302 (VaultManifest), #303 (SecureEnclaveHardwareKeyWrap) - the last piece of #201's split. What's here: - Sources/VaultStore/VaultConfig.swift: vault.json persistence (Secure Enclave-wrapped KEK-wrapped VMK + independent recovery-key wrap). Deliberately does not store the inner KEK-wrapped blob a second time in the clear - same reasoning Android's VaultConfigDto documents for an early draft's mistake. - Sources/VaultStore/VaultStore.swift: create/unlockWithPin/ unlockWithRecoveryKey/lock, import (streaming, crash-safe rename-then-manifest ordering), cover art, highlights, bookmarks, openReader. Not thread-safe by design, same as VaultFileReader - single-writer boundary is VaultSessionManager's job. - Sources/VaultStore/VaultSessionManager.swift: an actor (first in this codebase) owning the VaultRegistry + one VaultStore per touched vault, giving the same single-writer guarantee Android gets from a shared Mutex, enforced by the compiler instead of by convention. - Sources/VaultStore/VaultForegroundLockObserver.swift: locks every open vault on UIApplication.willResignActiveNotification, per the design scoped in #201's split. Deliberately a separate type from the actor, so VaultSessionManager's own tests never need to simulate app lifecycle notifications. - Leak-closure suite, per #201's scoping comment (#201 (comment)): VaultStoreHasNoLeakSurfaceDependencyTests.swift (static grep guard over Sources/VaultStore/ for ReadingDataPersistence/CoverArtCache, located via #filePath since there's no per-module compilation boundary to enforce this structurally) + VaultLeakClosureTests.swift (behavioral: title/author/highlights/bookmarks/cover-art bytes scanned for on disk, mirrors VaultLeakClosureTest.kt case-by-case). - VaultStoreTests.swift/VaultConfigTests.swift/ VaultSessionManagerTests.swift/VaultForegroundLockObserverTests.swift, FakeHardwareKeyWrap.swift (test double, mirrors Android's testing/ FakeHardwareKeyWrap.kt). Elevated risk vs #302/#303, flagged plainly: this is the first actor and the first async test methods in this codebase, and VaultForegroundLockObserverTests exercises a real NotificationCenter/ UIApplication.willResignActiveNotification path rather than pure logic. No local Xcode to compile-check against, same caveat every prior PR in this series carried. Closes #304, #201, progresses #190. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… 3 test gaps Principal-dev test-coverage review of the VaultStore orchestration work (#304) found one real bug and three missing regression tests: - VaultStore.create()'s failure-path cleanup zeroed a COW-forked copy of the VMK (`var vmkCopy = newVault.vmk; vmkCopy.secureZero()`), not newVault.vmk itself, silently defeating the scrub. NewVault.vmk was a `let`, which made the copy-then-zero mistake the only thing that would even compile. Android's port (`newVault.vmk.fill(0)`) doesn't have this bug because ByteArray has reference semantics, not Data's copy-on-write value semantics. Fixed by making NewVault.vmk `var` and zeroing it directly. - VaultConfig.read had zero negative-path coverage despite its own doc comment documenting the missing-file and malformed-base64 throw paths. - setCoverArt's finalize-rename failure had no regression test, unlike its sibling importFile (which has one specifically because "Android's own review caught" that exact ordering bug once already). Confirmed Android has the same gap and filed #322 to port the equivalent test there. - VaultSessionManager's wrong-PIN/throttled outcomes were only ever exercised via VaultStore directly, never through the actor itself (the actual entry point the app calls). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Principal review: request-changes (risk:high → human-merge regardless, but this needs real rework, not just a human rubber-stamp)Headline finding: this PR is stale/duplicate and its head commit is proven-broken by CI logs
Worse: comparing #319's already-merged version against #326's head, #319 shipped the correct, working version of I didn't just infer this — I verified it against real CI logs:
Net effect: the PR's current, actual head commit will fail its own leak-closure test suite, and nothing in this PR's history has ever caught that, because CI never ran against the real final state. What I'd actually recommendClose/don't merge #326 as-is. The one thing in it that's genuinely missing from Other findings
Outcome: human-merge. |
|
Superseded — this branch predates #319 (already merged to dev, closing the same #304/#201). Re-opening the still-needed fix (VaultStore.create()'s VMK-scrub bug) + 3 test additions as a fresh PR rebased on current dev. Thanks to the review agent for catching this before merge: #326 (comment) |
…very 4h (#335) * feat(ci): add every-4h human-merge sweep for the needs-human-merge backlog docs/agent-team-pipeline.md's state machine ends most risk:high PRs at status:needs-human-merge — correct by design, but until now that backlog only got cleared when a human noticed it and manually asked Claude Code to review + merge each one (as happened this session for PRs #327 and #324, plus closing #292 and #326 as stale/superseded along the way). This adds a new, separate workflow that automates the noticing, not the judgment: - human-merge-sweep.yml: schedule-triggered (every 4 hours) + workflow_dispatch for manual testing. Plain GITHUB_TOKEN — merging/ closing PRs isn't blocked by this repo's "Actions can't create/approve PRs" setting the way *opening* one is (principal-review.yml's own auto-merge step already proves this), so no App-token minting needed. - human-merge-sweep-agent.md: the actual review persona. Re-verifies each status:needs-human-merge PR is still current (stale/conflicting PRs get closed with an explanation if genuinely superseded, left alone if ambiguous), does a real second review (reads the whole diff, cross- checks claims against ground truth, checks for vacuous tests) before merging, and separately sweeps ALL open PRs for the same staleness pattern regardless of label. Hard rule, not a judgment call: never merges anything touching .github/workflows/**, .github/agent-policy.yml, or .claude/agents/** — that class of change always needs a human directly, however clean it looks. - human-merge-sweep-log.md: audit trail, same spirit as auto-merge-log.md but for this human-merge-routed path instead of the risk:low auto-merge path. This PR itself is exactly the kind of change its own new agent is hard-coded to never touch (.github/workflows/**, .claude/agents/**) — by design, flagging it plainly rather than leaving that as an implicit assumption: needs a human's own read, this session will not self-merge it even if CI is green. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * feat(ci): extend human-merge sweep to cover status:needs-info too status:needs-human-merge isn't the only place the pipeline parks work on a human — status:needs-info (issue triage that's underspecified, or a PR whose QA/review run crashed or hit workflow-file drift) blocks on a human just as silently, and was out of scope for the sweep as first built. Adds Part 3 to human-merge-sweep-agent.md, deliberately more conservative than Parts 1-2 given how different the task is — "is this safe to merge/close" is a mechanical check, "does this actually need a human" is not: - Detects when status:needs-info was applied because the *pipeline* crashed (turn budget exhausted, workflow-file drift) rather than because there's a real open question, and retries the stage that crashed — at most once per item, logged to human-merge-sweep-log.md same as a merge. - For everything else — the default assumption, not an edge case — never answers, never changes a label, never invents scope. Only ever ensures a clear comment exists naming the actual open question, so a human can answer faster. - Hard-excludes anything labeled security/release-blocker (agent-policy.yml's sensitive_issue_labels) from all autonomous action, including investigation. Bumped --max-turns 120→160 (three backlogs to work per run now, not two) and broadened human-merge-sweep-log.md's scope/column naming (PR → Item) to cover issues and retries alongside merges/closes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(ci): missing id-token permission + retry using the wrong token Two CONFIRMED findings from principal review of PR #335's own diff: - permissions: was missing id-token: write. Every sibling workflow invoking claude-code-action carries this with an identical comment citing issue #158 ("Could not fetch an OIDC token" after 3 retries) — missed here, and continue-on-error: true on the agent step would have swallowed the failure silently, forever, every 4 hours. - Part 3's retry action re-applies status:ready-for-dev/needs-qa/ needs-review to restart a crashed pipeline stage — that label change must trigger the corresponding workflow, which a plain GITHUB_TOKEN cannot do (see docs/agent-team-pipeline.md's "Cross-workflow triggering"; pr-intake.yml already mints an App token for exactly this reason). Fixed by minting the same pipeline App token and passing it to the agent step as a distinctly-named PIPELINE_APP_TOKEN, with explicit instructions (both in the workflow prompt and the persona file) that it's used for that one action only — everything else stays on the default GH_TOKEN, unchanged. Also tightened the retry-dedup check flagged as a plausible weak point: "grep the comment history for retry text" is now "grep for an exact <!-- human-merge-sweep-retry --> marker, always the first line of the retry comment" — an exact string match instead of a fuzzy read. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…344) Previously a manually-opened PR with no resolvable "Closes #N" line exited pr-intake.yml's guard early with no risk:*/status:* label applied at all, requiring a human to notice and hand-label it (as happened for PRs #326, #335, #342). Now it still runs classify_pr_risk.py and routes into the pipeline — status:needs-qa when an issue is linked (unchanged), status:needs-review when it isn't, since qa-agent.yml hard-stops on a missing linked issue (no acceptance criteria to check) while principal-review.yml already tolerates one gracefully. Closes #343 Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
What
Swift port of Android's
VaultStore.kt+VaultSessionManager.kt— the orchestration layer tying #301 (VaultRegistry/UnlockAttemptThrottle), #302 (VaultManifest), and #303 (SecureEnclaveHardwareKeyWrap) into the actual vault lifecycle API, plus the leak-closure guarantee (static + behavioral) that makes the feature trustworthy end-to-end. The last piece of #201's split.VaultConfig.swift—vault.jsonpersistence (Secure Enclave-wrapped KEK-wrapped VMK + independent recovery-key wrap)VaultStore.swift— create / unlockWithPin / unlockWithRecoveryKey / lock, streaming crash-safe import, cover art, highlights, bookmarksVaultSessionManager.swift— an actor (first in this codebase) owning the registry + oneVaultStoreper touched vault, giving the same single-writer guarantee Android gets from a sharedMutex, enforced by the compilerVaultForegroundLockObserver.swift— locks every open vault onwillResignActive, kept separate so the actor's own tests never simulate app-lifecycle notificationsSources/VaultStore/for plaintext-persistence identifiers, plus a behavioral scan of every byte on disk for plaintext title/author/highlight/bookmark/cover-art contentIncluded in this PR: a principal-dev test-coverage review pass
Reviewed the above against
VaultStoreTests.swift/VaultConfigTests.swift/VaultSessionManagerTests.swift/VaultLeakClosureTests.swiftand found + fixed:VaultStore.create()'s failure-path VMK scrub was a no-op —var vmkCopy = newVault.vmk; vmkCopy.secureZero()zeroed a copy-on-write-forked copy, notnewVault.vmkitself, becauseDatahas value semantics (Android'snewVault.vmk.fill(0)doesn't have this bug —ByteArrayhas reference semantics).NewVault.vmkis nowvarand gets zeroed in place.VaultConfig.readhad no negative-path coverage (missing file / malformed base64 →.malformedHeader) despite its own doc comment documenting both. Added both.setCoverArt's finalize-rename failure path had no regression test, unlike its siblingimportFile(which has one specifically because "Android's own review caught" that exact ordering bug once already). Added the equivalent test; confirmed Android has the same gap and filed [test] Android VaultStoreTest has no regression test for setCoverArt's finalize-rename failure path #322 to port it there too.VaultSessionManager's wrong-PIN/throttled outcomes were only ever exercised viaVaultStoredirectly, never through the actor itself. Added coverage.Risk
ios/.../Sources/VaultStore/**is asensitive_pathsentry in.github/agent-policy.yml— flagged plainly, reviewed by the user directly (not auto-merge eligible by policy regardless of QA/principal-review outcome). No local Xcode/Swift toolchain available to compile-check — CI is the first real build signal, same caveat every prior PR in this series has carried.Closes #304, #201. Progresses #190.
🤖 Generated with Claude Code