Skip to content

Allow conflict-safe private storage from plugin panels - #36273

Merged
AmethystLiang merged 5 commits into
mainfrom
AmethystLiang/panel-storage
Oct 30, 2026
Merged

AmethystLiang merged 5 commits into
mainfrom
AmethystLiang/panel-storage

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37

Sidebar plugins currently cannot persist notes through the supported host API. Allow private storage reads from frames and add storage.compareAndSet (host API 1.1) on all surfaces so panels can save without silently overwriting concurrent edits.

The compare and write run synchronously together after capability checks and mutation audit admission. Storage remains scoped to the authenticated plugin and uses the existing quotas and durable store. No filesystem or worker access is exposed.

Validation: 34 targeted tests pass across panel storage, worker API, frame facade, and renderer handshake. A separate integration check uses the actual host handler and disk store to verify saving, reopening a new store instance, and rejecting a stale write. Generated the API reference and formatted changed TypeScript. Full CI is running; the previous production commit passed lint and typecheck, and the follow-up updates the renderer handshake test for API 1.1 and the newly available methods.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e9bb5ec5-dd70-419a-ae6f-b99e6fffcb2c
Commits

Reviewing files that changed from the base of the PR and between 9d7971c and 94de3df.

Files selected for processing: 5
  • docs/reference/plugin-host-api.md
  • src/main/plugins/plugin-storage-store.test.ts
  • src/main/plugins/plugin-storage-store.ts
  • src/main/plugins/workers/plugin-panel-storage.test.ts
  • src/shared/plugins/workers/plugin-host-api.ts
Files skipped from review as they are similar to previous changes: 1
  • src/shared/plugins/workers/plugin-host-api.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

The plugin Host API is now version 1.1. The storage.get method is available to workers, panels, and editors. The new storage.compareAndSet method conditionally writes a private JSON value and returns whether the value was swapped. The handler includes the key in audit summaries. Tests cover capability denial, concurrent compare-and-set calls, retrieval of the stored value, and the updated API version. Plugin storage reads now ignore inherited properties.

Priority: Normal

Severity of issue fixed: Low

Merge Risk: Minimal · up to 94de3

No actionable merge-blocking risk remains; the null comparison behavior matches the intended Host API 1.1 contract.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the main change, rationale, implementation, and testing, but it omits most required template sections, including ELI5, Linked Issue, Visual Proof, structured Testing, Review, … Rewrite the description using the repository template. Add an actual linked issue under “Linked Issue,” provide visual proof or state N/A with a reason, complete the Testing section with platforms and test status, and complete the Review,…
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: conflict-safe private storage for plugin panels.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the main change, rationale, implementation, and testing, but it omits most required template sections, including ELI5, Linked Issue, Visual Proof, structured Testing, Review, Notes, and Checklist.

Resolution

Rewrite the description using the repository template. Add an actual linked issue under “Linked Issue,” provide visual proof or state N/A with a reason, complete the Testing section with platforms and test status, and complete the Review, Notes, Agent skill upstream boundary, AI Disclosure when applicable, and Checklist sections.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 9 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 29d2510f-98cc-40de-a3ca-bafacfe68ecc
Commits

Reviewing files that changed from the base of the PR and between 7358da2 and b4af2b1.

Files selected for processing: 7
  • docs/reference/plugin-host-api.md
  • src/main/plugins/workers/plugin-host-method-bindings.ts
  • src/main/plugins/workers/plugin-host-methods.ts
  • src/main/plugins/workers/plugin-host-runtime.test.ts
  • src/main/plugins/workers/plugin-panel-storage.test.ts
  • src/shared/plugins/frames/plugin-frame-api.test.ts
  • src/shared/plugins/workers/plugin-host-api.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

'storage.compareAndSet': bind(
api['storage.compareAndSet'],
async ({ key, expected, value }, { pluginId, services }) => {
if (!isDeepStrictEqual(services.storage.get(pluginId, key) ?? null, expected)) {

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.

Major · Data Integrity & Integration · Heavy lift

Supported by static analysis

Script executed:

sed -n '1,200p' src/main/plugins/plugin-storage-store.ts
sed -n '140,160p' src/main/plugins/workers/plugin-host-method-bindings.ts
sed -n '55,70p' docs/reference/plugin-host-api.md

Repository: stablyai/orca

Length of output: 5236


Script executed:

rg -n -F -A 12 -e 'new PluginKvStore(' -- src/main || test "$?" -eq 1
rg -n -F -A 3 -e 'export type PluginJsonValue' -- src/shared || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 4983


Stored null matches an absent key in storage.compareAndSet.

PluginKvStore.set keeps a JSON null as a present key. The services.storage wrapper passes get straight through, and get returns null for both a stored null and an absent key. The binding's ?? null therefore makes the two compare equal. The documented contract says null expects an absent key, so a caller that expects absence can overwrite a value that another caller stored as null.

For example, caller A runs compareAndSet(key, expected: null, value: null) on an absent key and gets swapped: true. Caller B then runs compareAndSet(key, expected: null, value: "b"). The stored null matches expected: null, so B also gets swapped: true, and A's write is lost.

Fixing this requires a contract decision, so no patch is proposed. Either:

  • expected: null must mean the key is absent. The binding would then check services.storage.get(...) === undefined. A plugin could no longer compare-and-swap a stored null, so the API needs a way to express a present null expectation, or the limitation must be documented.
  • set with null must remove the key, as delete does. Then null is never stored as present. This changes keys() and getAll() output, so the storage tests and the API reference need updates.

Choose one direction and update the API reference to match.


Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '1,200p' src/main/plugins/plugin-storage-store.ts
rg -n 'storageKeySchema' src/shared/plugins/workers/plugin-host-api.ts

Repository: stablyai/orca

Length of output: 4537


Script executed:

sed -n '55,80p' src/shared/plugins/workers/plugin-host-api.ts
echo '---bindings---'
rg -n -F -e 'compareAndSet' -e 'storage.get' -e 'PluginKvStore' -e 'isDeepStrictEqual' -- src/main/plugins/workers/plugin-host-method-bindings.ts || test "$?" -eq 1
echo '---bindings lines---'
sed -n '120,170p' src/main/plugins/workers/plugin-host-method-bindings.ts

Repository: stablyai/orca

Length of output: 4131


Read only own properties in PluginKvStore.get.

Keys such as toString pass storageKeySchema, but an absent toString reads the inherited Object.prototype.toString function. storage.compareAndSet then compares that function with expected: null, returns { swapped: false }, and the panel cannot create the key. storage.get returns the same non-JSON function value for that key.

Suggested fix
 // src/main/plugins/plugin-storage-store.ts
   get(key: string): PluginJsonValue | undefined {
-    return this.read()?.[key]
+    const settings = this.read()
+    return settings && Object.hasOwn(settings, key) ? settings[key] : undefined
   }

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant