Skip to content

refactor(plugin-sdk): isolate core session state from plugin mutations - #107795

Closed
zhangguiping-xydt wants to merge 6 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-pr96230-plugin-session-isolation
Closed

zhangguiping-xydt wants to merge 6 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-pr96230-plugin-session-isolation

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an isolation gap where core-owned restart-recovery coordination could be exposed, overwritten, or lost through Plugin SDK session APIs.

Upstream now persists channel-turn recovery fields under the restartRecovery* namespace. This PR keeps those shipped fields, as well as the later split series' mainRestartRecovery aggregate, out of plugin reads, callback inputs, replacements, ACP resolution, and injected runtime surfaces.

The repair also addresses two earlier review findings: an identity-preserving whole-store key move could silently drop private recovery state, and the ACP SDK declared that it returned the internal AcpSessionManager class even though the runtime object was already a restricted facade.

Why This Change Was Made

Plugin-visible session rows now pass through one projection/reconciliation owner. The public SessionEntry type omits mainRestartRecovery and the complete restartRecovery* namespace, matching runtime behavior.

Private recovery state is retained for same-key updates and for a unique one-to-one sessionId key move. It is not copied when the source or destination mapping is ambiguous, and it is cleared when the effective session identity changes. Future restartRecovery* plugin extension slots are reserved before a new core field can collide with them.

The ACP getter returns an explicit AcpSessionManagerFacade interface. The runtime object remains stable, frozen, null-prototype, and limited to bound public methods, so plugins cannot reach the internal manager constructor or bypass session projection.

Compatibility note: released v2026.7.1-beta.5 / v2026.7.1 and the frozen PR #96230 returned the real manager class. This PR intentionally does not preserve instanceof, prototype, or constructor identity because exposing the internal constructor would reopen the private-session-state escape path. The SDK catalog documents that contract for maintainer review.

User Impact

Plugin authors continue to use the same session and ACP methods, while current and future core restart-recovery coordination remains private and survives valid session-key moves.

Plugins that relied on getAcpSessionManager() being an actual internal class instance must migrate to the structural AcpSessionManagerFacade contract. No session schema, storage format, ACP method behavior, retry budget, or production mainRestartRecovery writer is added by this PR.

Evidence

  • Recovery isolation matrix: 9 files, 82/82 tests passed across direct Plugin SDK APIs, modern and deprecated whole-store mutation, unique and ambiguous key moves, ACP, agent runtime, channel runtime, combined transcript-store reads, injection rejection, and session identity rotation.
  • Plugin SDK surface budget tests: 10/10 passed.
  • Public API contract: generated declarations expose the projected SessionEntry and AcpSessionManagerFacade; no mainRestartRecovery or restartRecovery* declaration remains in the generated SDK baseline.
  • Plugin SDK API baseline, public export budget, formatting, lint, max-lines ratchet, and diff-check passed after syncing to exact base ff1687e04f11df6c35002c4531cdafba6a845f8f.
  • Upstream's current public Plugin SDK export baseline is 7,991; this PR's reviewed AcpSessionManagerFacade is the sole additional export, for a passing budget of 7,992.
  • Source audit found no remaining critical, major, minor, security, performance, persistence, or public-contract issue.
  • Frozen PR comparison at edc24088387a8d573798233979a71f3b40a24ac9 confirms that its whole-store implementation lacked cross-key recovery transfer and its ACP SDK returned the internal class directly.
  • The branch contains zero production mainRestartRecovery producers. Existing upstream restartRecovery* writers remain unchanged and now sit behind the Plugin SDK projection boundary.
  • Range-diff against the prior reviewed PR2 head found the five functional commits patch-equivalent; the resync changed only upstream surface-budget context and the generated API hash.

Protected local TypeScript validation could not be recorded because this machine cannot attest the required cgroup limits; the guard stopped before execution and was not bypassed. GitHub CI remains the authoritative protected typecheck/build lane.

Per maintainer-requested workflow for this split, the final audit is a complete code-diff/source review rather than a separate automated final-review pass.

@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/problem-pr96230-plugin-session-isolation branch from e53c00b to b2beb28 Compare July 15, 2026 13:02
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 15, 2026
@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/problem-pr96230-plugin-session-isolation branch from b2beb28 to 7f3ad02 Compare July 15, 2026 15:27
@clawsweeper

clawsweeper Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 16, 2026, 7:51 PM ET / 23:51 UTC.

Summary
Centralizes plugin-visible session projection and reconciliation, hides core restart-recovery fields across Plugin SDK/runtime surfaces, and changes the ACP manager getter from the internal class to a frozen structural facade.

PR surface: Source +463, Tests +1031, Docs +5, Generated 0, Other +1. Total +1500 across 27 files.

Reproducibility: yes. at source level: current main exposes core session rows through Plugin SDK helpers and directly returns the internal ACP manager. No live current-main exploit transcript was provided, so this is source-reproducible rather than runtime-reproduced.

Review metrics: 1 noteworthy metric.

  • Public SDK contract: 1 getter return contract changed; 1 facade interface added. The new interface is additive, but replacing the getter's shipped concrete-class identity creates an upgrade-sensitive Plugin SDK break.

Stored data model
Persistent data-model change detected: serialized state: src/config/sessions/main-session-recovery.types.ts, serialized state: src/config/sessions/restart-recovery-private-keys.ts, serialized state: src/plugin-sdk/session-store-runtime.current-recovery-isolation.test.ts, serialized state: src/plugin-sdk/session-store-runtime.key-move.test.ts, serialized state: src/plugin-sdk/session-store-runtime.test.ts, serialized state: src/plugin-sdk/session-store-runtime.ts, and 13 more. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Resolve the ACP getter compatibility decision with the SDK/security owner and implement the selected contract.
  • [P1] Add redacted installed-plugin terminal output or logs covering the changed session and ACP behaviors.
  • Resolve the current merge conflicts and refresh validation on the resulting head.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Extensive tests and CI are present, but merge still needs redacted installed-plugin terminal output or logs proving private reads/injection are blocked while mutations, key moves, identity rotation, and ACP calls remain functional; updating the PR body should trigger review, otherwise request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Existing plugins that use instanceof, the manager prototype, or constructor identity will stop working immediately after upgrade.
  • [P1] The broad reconciliation path changes session-state preservation, deletion, key-move, and identity-rotation behavior; tests are strong, but no installed-plugin evidence demonstrates those transitions against a real runtime.
  • [P1] This patch changes a security boundary: an incorrect projection or facade escape could expose or overwrite core restart-recovery state even if unit tests remain green.
  • [P1] The current head conflicts with main, so the reviewed behavior and generated SDK baseline may change during conflict resolution.

Maintainer options:

  1. Preserve the shipped getter contract (recommended)
    Refactor the public manager path so plugin-visible outputs are projected without replacing the concrete getter identity, then add compatibility coverage.
  2. Explicitly accept the break
    An SDK/security owner may approve the immediate identity break with migration guidance and installed-plugin upgrade proof.
  3. Pause until a breaking release
    Keep the isolation work staged but defer the concrete manager replacement if neither secure compatibility nor an immediate break is acceptable.

Next step before merge

  • [P1] An SDK/security owner must first choose the permanent ACP compatibility contract; contributor proof and conflict resolution follow that decision.

Maintainer decision needed

  • Question: Should the shipped getAcpSessionManager() class-identity contract be preserved while its public outputs are hardened, or may this PR intentionally break that contract immediately to close the isolation escape?
  • Rationale: Repository policy favors staged Plugin SDK compatibility, while the contributor argues that preserving constructor and prototype identity reopens the private-session-state boundary; choosing the permanent public contract requires explicit owner intent.
  • Likely owner: steipete — This choice sets the permanent shipped Plugin SDK compatibility and security-boundary contract.
  • Options:
    • Preserve identity, harden outputs (recommended): Keep the existing getter identity and move projection into its plugin-visible methods or another internal/public split so private recovery state is inaccessible without breaking current callers.
    • Approve immediate security break: Accept the facade replacement now with explicit owner approval, migration guidance, release communication, and compatibility tests documenting the intentionally unsupported identity behavior.
    • Defer removal to breaking release: Introduce the facade API additively now and remove concrete manager identity only in the next approved breaking Plugin SDK release.

Security
Cleared: The patch strengthens a sensitive plugin/core boundary and introduces no dependency, workflow, secret, or supply-chain changes; no concrete new vulnerability was identified in the reviewed diff.

Review findings

  • [P1] Stage the shipped ACP getter contract before replacing it — src/plugin-sdk/acp-runtime.ts:143
Review details

Best possible solution:

Keep one canonical projection/reconciliation owner, preserve the shipped ACP getter identity by hardening its public method outputs or stage the facade through an explicitly approved compatibility path, then rebase and provide redacted installed-plugin proof.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main exposes core session rows through Plugin SDK helpers and directly returns the internal ACP manager. No live current-main exploit transcript was provided, so this is source-reproducible rather than runtime-reproduced.

Is this the best way to solve the issue?

Not yet. Centralizing projection is the right architectural direction, but immediately replacing a shipped class-identity contract is not the safest upgrade path without explicit owner approval or a design that preserves identity while hardening outputs.

Full review comments:

  • [P1] Stage the shipped ACP getter contract before replacing it — src/plugin-sdk/acp-runtime.ts:143
    The current head still changes getAcpSessionManager() from the released concrete AcpSessionManager instance to a structural facade, breaking plugins that use prototype, constructor, or instanceof identity. Preserve the shipped identity while hardening plugin-visible method outputs, or obtain explicit owner approval for a documented breaking-release path before landing this replacement.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7a589567681b.

Label changes

Label justifications:

  • P2: This is important Plugin SDK isolation hardening, but the current issue is bounded and no active core outage or proven data loss is shown.
  • merge-risk: 🚨 compatibility: The PR intentionally removes the shipped ACP manager's prototype, constructor, and instanceof identity for existing plugins.
  • merge-risk: 🚨 session-state: The new reconciliation owner governs preservation, clearing, deletion, and key moves for private recovery state across plugin mutations.
  • merge-risk: 🚨 security-boundary: The patch defines whether plugins can observe, inject, or bypass access controls around core-owned restart-recovery coordination.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Extensive tests and CI are present, but merge still needs redacted installed-plugin terminal output or logs proving private reads/injection are blocked while mutations, key moves, identity rotation, and ACP calls remain functional; updating the PR body should trigger review, otherwise request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +463, Tests +1031, Docs +5, Generated 0, Other +1. Total +1500 across 27 files.

View PR surface stats
Area Files Added Removed Net
Source 14 624 161 +463
Tests 10 1032 1 +1031
Docs 1 7 2 +5
Config 0 0 0 0
Generated 1 2 2 0
Other 1 2 1 +1
Total 27 1667 167 +1500

What I checked:

  • Current ACP SDK contract: Current main directly re-exports getAcpSessionManager from the internal control-plane manager, so callers receive the concrete manager identity that the PR replaces. (src/plugin-sdk/acp-runtime.ts:3, 7a589567681b)
  • Isolation gap on current main: Current SessionEntry contains the shipped restartRecovery* coordination fields, while Plugin SDK session helpers expose the core session type directly; the reported boundary problem is therefore source-reproducible. (src/config/sessions/types.ts:16, 7a589567681b)
  • Proposed compatibility break: The PR introduces AcpSessionManagerFacade and returns a frozen structural object instead of the internal class, intentionally removing prototype, constructor, and instanceof identity. (src/plugin-sdk/acp-runtime.ts:143, 9462fa3d07ad)
  • Shipped API policy: The Plugin SDK migration policy says documented public behavior should not be removed or changed incompatibly during ordinary minor releases and requires a staged deprecation or explicit breaking-release path. Public docs: docs/plugins/sdk-migration.md. (docs/plugins/sdk-migration.md:22, 7a589567681b)
  • Prior finding remains: The previous ClawSweeper P1 finding asked the PR to stage or preserve the shipped ACP getter contract; the latest body instead explicitly accepts the immediate identity break, so that finding remains unresolved rather than fixed. (src/plugin-sdk/acp-runtime.ts:143, 9462fa3d07ad)
  • Proof remains test-only: The PR body reports extensive unit, API-surface, lint, and CI results but no redacted installed-plugin transcript or runtime logs demonstrating reads, rejected injection, mutations, key moves, identity rotation, and ACP behavior after the change. (9462fa3d07ad)

Likely related people:

  • steipete: Repository governance assigns final project decisions here, and the unresolved question is whether a shipped Plugin SDK identity contract may break immediately for isolation hardening. (role: official repository and Plugin SDK decision owner; confidence: high; files: src/plugin-sdk/acp-runtime.ts, docs/plugins/sdk-migration.md)
  • vincentkoc: Recent merged ACP implementation work makes this a useful secondary routing candidate for the manager API and runtime contract. (role: recent ACP feature contributor; confidence: medium; files: src/acp/control-plane/manager.ts, src/plugin-sdk/acp-runtime.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (7 earlier review cycles)
  • reviewed 2026-07-16T06:31:28.008Z sha 89d8b6e5a2f36e237b3a27954f9fcb86959bfdb0 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-16T07:13:26.531Z sha 89d8b6e5a2f36e237b3a27954f9fcb86959bfdb0 :: needs real behavior proof before merge. :: [P1] Version or preserve the shipped manager identity contract
  • reviewed 2026-07-16T07:55:33.844Z sha 89d8b6e5a2f36e237b3a27954f9fcb86959bfdb0 :: needs real behavior proof before merge. :: [P1] Rebase the projection onto current recovery fields | [P1] Preserve or explicitly deprecate the shipped ACP getter contract
  • reviewed 2026-07-16T14:01:16.754Z sha 0e96f8b7ec850a1eef481405ce357559881ad7c5 :: needs real behavior proof before merge. :: [P1] Preserve or version the shipped ACP manager identity
  • reviewed 2026-07-16T14:47:20.861Z sha 0e96f8b7ec850a1eef481405ce357559881ad7c5 :: needs real behavior proof before merge. :: [P1] Stage the shipped ACP getter contract before replacing it
  • reviewed 2026-07-16T17:42:19.340Z sha add683257e028da5a428675c8702481fd2afcd19 :: needs real behavior proof before merge. :: [P1] Stage the shipped ACP getter contract before replacing it
  • reviewed 2026-07-16T20:05:08.132Z sha add683257e028da5a428675c8702481fd2afcd19 :: needs real behavior proof before merge. :: [P1] Stage the shipped ACP getter contract before replacing it

@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/problem-pr96230-plugin-session-isolation branch 3 times, most recently from 2c22c8d to 89d8b6e Compare July 16, 2026 06:22
@zhangguiping-xydt
zhangguiping-xydt marked this pull request as draft July 16, 2026 07:19
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 16, 2026
@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/problem-pr96230-plugin-session-isolation branch from 89d8b6e to 0e96f8b Compare July 16, 2026 13:09
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Jul 16, 2026
@zhangguiping-xydt
zhangguiping-xydt marked this pull request as ready for review July 16, 2026 14:02
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 16, 2026
@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/problem-pr96230-plugin-session-isolation branch from 0e96f8b to add6832 Compare July 16, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant