Skip to content

[PM-37190] Clean up ephemeral states that go via state bridge - #20976

Draft
quexten wants to merge 3 commits into
mainfrom
km/ephemeral-state-cleanup
Draft

[PM-37190] Clean up ephemeral states that go via state bridge#20976
quexten wants to merge 3 commits into
mainfrom
km/ephemeral-state-cleanup

Conversation

@quexten

@quexten quexten commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-37190
Waiting for SDK changes to move off of state access.
bitwarden/sdk-internal#1155

Please note: This PR will only be merged once the above SDK PR is merged, and the client sdk version is updated.

📔 Objective

Cleans up the ephemeral states that were shaped into a map to go via the repostiory state access. These are now accessed via the state bridge and no longer need these hacks.

📸 Screenshots

@quexten quexten changed the title Clean up ephemeral states that go via state bridge [PM-37190] Clean up ephemeral states that go via state bridge Jun 2, 2026
@quexten quexten added the ai-review Request a Claude code review label Jun 2, 2026
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR cleans up the ephemeral state shapes for USER_KEY and PIN_PROTECTED_USER_KEY_ENVELOPE_EPHEMERAL, removing the Record<string, T> workaround keyed by the empty string in favor of storing the value directly. The two deleted SdkRecordMapper implementations (UserKeyRecordMapper, EphemeralPinEnvelopeMapper) and the user_key_state / ephemeral_pin_envelope_state repository registrations are coordinated with the dependent SDK change (sdk-internal#1155) and the JsWasmStateBridge now writes the raw values directly. All in-tree consumers (key.service.ts, pin-state.service.implementation.ts, state-bridge.ts, and their specs) were updated consistently; no remaining call sites still expect the ["":...] shape.

Code Review Details

No actionable findings.

Notes considered and dismissed:

  • Both USER_KEY (CRYPTO_MEMORY) and PIN_PROTECTED_USER_KEY_ENVELOPE_EPHEMERAL (PIN_MEMORY) are memory-scoped, so the shape change does not require a disk-state migration.
  • The PR description already notes the merge ordering dependency on the SDK PR and version bump, which addresses the cross-repo coordination risk.
  • state-bridge.ts lacks unit tests, but this is pre-existing (the file was introduced without tests in [Shared Unlock] [PM-35083] Add shared unlock typescript drivers and services #20589) and not regressed by this change.

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.34%. Comparing base (1ad0d90) to head (5125ab5).
⚠️ Report is 13 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/common/src/key-management/state-bridge.ts 0.00% 4 Missing ⚠️
libs/key-management/src/key.service.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20976      +/-   ##
==========================================
+ Coverage   48.07%   48.34%   +0.26%     
==========================================
  Files        4032     4025       -7     
  Lines      124881   124101     -780     
  Branches    19112    18982     -130     
==========================================
- Hits        60034    59991      -43     
+ Misses      60352    59624     -728     
+ Partials     4495     4486       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@quexten

quexten commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Looks like the lint failure is unrelated to this PR

@quexten
quexten requested review from djsmith85 and mzieniukbw June 2, 2026 10:46
@quexten
quexten marked this pull request as ready for review June 2, 2026 10:46
@quexten
quexten requested review from a team as code owners June 2, 2026 10:46
@quexten
quexten marked this pull request as draft June 2, 2026 10:47
@quexten
quexten marked this pull request as ready for review June 2, 2026 10:49
@sonarqubecloud

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown

@@ -17,17 +15,13 @@ export async function initializeClientManagedState(
stateClient.register_client_managed_repositories({
cipher: new RepositoryRecord(userId, stateProvider, new CipherRecordMapper(), true),
folder: null,
user_key_state: new RepositoryRecord(userId, stateProvider, new UserKeyRecordMapper()),
user_key_state: null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't exist anymore and needs to be removed, instead of nulled.

stateProvider,
new EphemeralPinEnvelopeMapper(),
),
ephemeral_pin_envelope_state: null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't exist anymore and needs to be removed, instead of nulled.

@djsmith85 djsmith85 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please re-request review after conflicts are resolved and @mzieniukbw comments are addressed

@quexten
quexten marked this pull request as draft June 11, 2026 07:37
@quexten

quexten commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@djsmith85 I've moved this to draft, since the corresponding SDK change is blocked by mobile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants