Skip to content

fix(reef): stop exposing retired account runtime - #129131

Merged
steipete merged 2 commits into
mainfrom
steipete/elegant-haibt-0097be
Aug 25, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/elegant-haibt-0097be

Conversation

@steipete

@steipete steipete commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #129063

AI-assisted: Claude Code and Codex.

What Problem This Solves

Fixes an issue where stopping or replacing a running Reef account left both the retired account's global runtime and already-borrowed outbound, pairing, friendship, and review capabilities usable while shutdown was draining or after it completed.

Why This Change Was Made

Reef now creates one generation-specific authority before constructing the account-owned flow, friend manager, and review store. Account abort or replacement revokes that authority through the owners themselves, so callers cannot omit or substitute the generation fence. Cleanup clears the global slot only when the retiring generation still owns it.

The same authority reaches final relay I/O, deferred friendship serialization, trust expansion, review decisions, and command reads. Fail-closed friendship tombstones and ambiguous outbound friend-request intent remain durable during cancellation.

User Impact

Stopped Reef accounts no longer handle outbound messages or privileged Reef commands through stale transport, key, guard, trust, or review state. Work that began before abort is stopped before its final relay or privileged state effect, while a replacement account remains usable even when an earlier generation finishes shutting down late.

Evidence

  • Original pre-fix account-boundary regression failed immediately after abort because getActiveReef() still returned the stopped account.
  • The first exact-head review found an additional retained-capability race. New RED tests reproduced four failures before the authority fence: stale relay delivery after paused guard work, stale pairing dispatch after paused reconcile, stale command completion after paused lookup, and missing duplicate-module authority revocation.
  • node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts extensions/reef/src/runtime.test.ts extensions/reef/src/outbound.test.ts extensions/reef/src/config-schema.test.ts extensions/reef/src/friends.test.ts — 69 tests passed on the final owner-bound implementation.
  • node scripts/run-vitest.mjs extensions/reef — 308 tests passed.
  • node scripts/check-changed.mjs -- extensions/reef/runtime-api.ts extensions/reef/src/channel.test.ts extensions/reef/src/channel.ts extensions/reef/src/config-schema.test.ts extensions/reef/src/flow.ts extensions/reef/src/friends.test.ts extensions/reef/src/friends.ts extensions/reef/src/outbound.test.ts extensions/reef/src/runtime.test.ts extensions/reef/src/runtime.ts extensions/reef/src/state.ts extensions/reef/src/transport.ts — passed formatting, production/test typechecking, lint, plugin boundaries, dead-code checks, and import-cycle checks. The only advisory is the existing test temp-directory fixture style.
  • Fresh structured autoreview reported no accepted or actionable findings after the owner-bound refactor.
  • Production delta: +134/-54 (net +80). This is the account-owned authority boundary and cancellation propagation through final relay/trust/review effects; no shared Plugin SDK or config surface was added. Tests: +400/-38.
  • Sibling invariant: Buzz and Nostr already retire an account-owned bus only when the retiring generation still owns the active slot. Reef additionally requires owner-bound cancellation because its encrypted flow and friendship operations cross local guard, relay, and durable-state awaits.
  • Live relay proof was not used: deterministically proving this race requires holding guard/reconcile work and predecessor shutdown open while replacing the account, which would mutate a real Reef identity and relay friendship state. The real reefPlugin.gateway.startAccount, encrypted flow, friend manager, review store, and transport boundaries are exercised with deterministic final-effect assertions instead.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: reef Channel integration: reef size: M maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete steipete self-assigned this Aug 25, 2026
@steipete
steipete marked this pull request as ready for review August 25, 2026 08:01
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 5:32 AM ET / 09:32 UTC.

ClawSweeper review

What this changes

This PR replaces Reef’s mutable active-runtime slot with generation-bound cancellation that retires borrowed outbound, friendship, and review capabilities when an account stops or is replaced.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking patch defect found: the re-review P1 is addressed by an account-owned generation fence that reaches the borrowed owners and their final effects. Keep this active maintainer PR open for normal exact-head merge validation; local current-main comparison was unavailable in this checkout.

Priority: P1
Reviewed head: 5b11b169220bc9a0e831ba543d9f262c9d3f7ee0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The reworked owner-bound patch and focused regressions address the prior blocker; current-main comparison remains unavailable locally.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer PR is exempt from the ordinary contributor-proof gate; the source-reviewed authority regressions remain supplemental exact-head evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer PR is exempt from the ordinary contributor-proof gate; the source-reviewed authority regressions remain supplemental exact-head evidence.
Evidence reviewed 7 items Account-owned authority: Account startup creates one authority before constructing the transport-bound flow, friend manager, and review store; it activates only when ready and releases in the lifecycle finally block.
Final relay fence: The flow checks the generation signal after guard composition and immediately before the relay send, then passes that signal to the transport request.
Borrowed capability fence: Friend operations serialize against the account signal, re-check after awaits, and pass it into relay operations; review reads and decisions also reject after retirement.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts extensions/reef/src/outbound.test.ts extensions/reef/src/friends.test.ts

Result: FAIL (partial) — step 2 expect_output Tests: expected terminal output was not visible within 30 seconds: "Tests"

node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts extensions/reef/src/outbound.test.ts extensions/reef/src/friends.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129131-Na2rtA/target$ node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts extensions/reef/src/outbo
und.test.ts extensions/reef/src/friends.test.ts
node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts extensions/reef/src/outbound.test.ts extensions/reef/src/friends.test.ts
[test] starting test/vitest/vitest.extensions.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129131-Na2rtA/target

[vitest] still running with no output for 30000ms.










































Assertions:

  • FAIL expect_output: Tests

How this fits together

Reef is a bundled channel plugin whose account startup constructs encrypted messaging, pairing, trust, and review components. Channel sends and Reef commands use that active account runtime, which ultimately performs relay requests or updates channel-owned state.

flowchart LR
  A[Account startup or replacement] --> B[Generation authority]
  B --> C[Active Reef runtime]
  C --> D[Flow friends and reviews]
  D --> E[Relay and state effects]
  A --> F[Abort or cleanup]
  F --> B
  B --> G[Reject retired work]
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by 80 net lines for a bug fix; the growth is justified by the owner-bound signal and post-await checks, but should remain a single Reef-local authority path.
  • Resolve merge risk (P1) - This read-only checkout could not independently compare the branch with current main or its unavailable base object.
  • Complete next step (P2) - No repair lane is needed: the prior concrete blocker is addressed, and this protected active PR remains in normal maintainer validation.
Agent review details

Security

None.

PR surface

Source +80, Tests +362. Total +442 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 7 134 54 +80
Tests 5 400 38 +362
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 534 92 +442

Review metrics

Metric Value Why it matters
Production versus test delta production +134/-54 (net +80); tests +400/-38 (net +362) The production growth is the account-owned authority boundary and its final-effect propagation; the tests cover the retained-capability races it replaces.

Stored data model

Persistent data-model change detected: serialized state: extensions/reef/src/state.ts, unknown-data-model-change: extensions/reef/src/state.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #129063
Summary: This PR is the active candidate fix for the linked stopped-Reef-runtime bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Land with the owner-bound fence (recommended)
    Accept the justified Reef-local authority growth after exact-head checks confirm the paused guard, reconcile, command, and replacement regressions.

Technical review

Best possible solution:

Keep one Reef-local generation authority created before account-owned components and checked immediately before relay or privileged state effects; merge after normal exact-head validation.

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

Yes. The exact-head regression scenarios pause guard, reconcile, and command work, then abort or replace the account before releasing the paused operation; this review did not execute them.

Is this the best way to solve the issue?

Yes. Binding cancellation into the account-owned flow, friend manager, and review store is stronger than relying only on a fresh global-runtime lookup because it also fences already-borrowed capabilities.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 315969f6693e.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer PR is exempt from the ordinary contributor-proof gate; the source-reviewed authority regressions remain supplemental exact-head evidence.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A stopped Reef account could otherwise continue outbound delivery or privileged account operations.
  • merge-risk: 🚨 message-delivery: The patch changes cancellation checks at the final encrypted relay-send boundary.
  • merge-risk: 🚨 security-boundary: The patch changes which account generation may use pairing, trust, and review capabilities.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer PR is exempt from the ordinary contributor-proof gate; the source-reviewed authority regressions remain supplemental exact-head evidence.

Evidence

What I checked:

  • Account-owned authority: Account startup creates one authority before constructing the transport-bound flow, friend manager, and review store; it activates only when ready and releases in the lifecycle finally block. (extensions/reef/src/channel.ts:263, 5b11b169220b)
  • Final relay fence: The flow checks the generation signal after guard composition and immediately before the relay send, then passes that signal to the transport request. (extensions/reef/src/flow.ts:191, 5b11b169220b)
  • Borrowed capability fence: Friend operations serialize against the account signal, re-check after awaits, and pass it into relay operations; review reads and decisions also reject after retirement. (extensions/reef/src/friends.ts:337, 5b11b169220b)
  • Regression coverage: The exact-head tests pause guard, reconcile, and command work across abort or replacement and assert no stale relay call while the replacement remains active. (extensions/reef/src/outbound.test.ts:119, 5b11b169220b)
  • History and ownership: Blame attributes the authority implementation to the exact re-review commit; Reef’s original channel and later trust refactor are also by Peter Steinberger. (extensions/reef/src/runtime.ts:33, 5b11b169220b)
  • Sibling lifecycle invariant: Buzz and Nostr retire only the registration owned by the stopping generation before async close; Reef adds owner-bound cancellation because captured objects retain transport and state references. (extensions/nostr/src/gateway.ts:304, 5b11b169220b)

Likely related people:

  • Peter Steinberger: Introduced the original Reef channel, performed the central trust refactor, and authored the exact authority-fence commit. (role: feature owner and recent area contributor; confidence: high; commits: 882b2fe9004a, f810fb35d554, 5b11b169220b; files: extensions/reef/src/runtime.ts, extensions/reef/src/channel.ts, extensions/reef/src/flow.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-25T07:55:20.175Z sha 42186b1 :: needs real behavior proof before merge. :: [P1] Fence borrowed Reef runtime before relay I/O
  • reviewed 2026-08-25T08:37:53.840Z sha 42186b1 :: needs real behavior proof before merge. :: [P1] Fence borrowed Reef work before final relay I/O

@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The retained-capability P1 is addressed on 5b11b169220bc9a0e831ba543d9f262c9d3f7ee0. Generation authority is now bound into the account-owned flow, friend manager, and review store rather than supplied by callers. New regressions hold guard, reconcile, and command work across abort/replacement and assert the retired generation cannot reach relay I/O or privileged state while the replacement remains authoritative. The PR body has the updated proof and LOC classification.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@steipete
steipete merged commit 0f92753 into main Aug 25, 2026
117 checks passed
@steipete
steipete deleted the steipete/elegant-haibt-0097be branch August 25, 2026 09:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

channel: reef Channel integration: reef maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reef exposes stopped account runtime after shutdown

1 participant