Skip to content

fix(reef): avoid shutdown delays during friend reconciliation - #129016

Merged
steipete merged 1 commit into
mainfrom
steipete/stoic-jackson-9f12ea
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/stoic-jackson-9f12ea

Conversation

@steipete

@steipete steipete commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where stopping or replacing a Reef channel while friend reconciliation was waiting on the relay could leave the old account task running until the full relay deadline. That can exceed the Gateway's bounded channel-stop window even though the lifecycle has already been aborted.

The observed startup timeout itself remained retryable and Reef recovered to connected/ready; the defect was cancellation ownership during shutdown, not the timeout duration, retry policy, log severity, or peer-trust policy.

Why This Change Was Made

The Reef account lifecycle now passes its abort signal through both friend-list requests and the existing transport deadline, and it stops before dispatching local overdue-delivery notices after cancellation. The existing 15-second request deadline, 30-second reconciliation cadence, error reporting, serialization, and fail-closed trust checks are unchanged.

This PR is AI-assisted. I reviewed the source, live evidence, regression behavior, and final diff.

User Impact

Gateway shutdowns, reloads, and account replacements no longer wait for a stalled Reef friend-reconciliation request after the account lifecycle has ended. Transient relay failures during normal startup continue to recover as before, and unrefreshed or changed peer keys remain fail-closed.

Evidence

  • Sanitized live canary evidence showed transient TimeoutError entries followed by Reef returning to running, connected, lifecycle: ready, with a later promotion producing zero Reef timeout entries.
  • Pre-fix real-HTTP reproduction: after abort, a stalled /v1/friends request remained pending after 100 ms and settled after 804 ms only when its artificial 800 ms deadline fired.
  • Post-fix reproduction: the same lifecycle settled 3 ms after abort.
  • Regression coverage exercises both the initial friend reconciliation and the second pairing-candidate friend-list request against a real stalled local HTTP server.
  • node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts — 17 passed.
  • node scripts/run-vitest.mjs extensions/reef/src/friends.test.ts — 21 passed.
  • node scripts/run-vitest.mjs extensions/reef/src/transport.test.ts — 39 passed.
  • node scripts/run-vitest.mjs extensions/reef/src/transport.timeout.test.ts — 3 passed.
  • node scripts/check-changed.mjs -- extensions/reef/src/channel-lifecycle.ts extensions/reef/src/channel.ts extensions/reef/src/friends.ts extensions/reef/src/transport.ts extensions/reef/src/channel.test.ts — passed, including extension typechecks, lint, import-cycle, dead-code, and repository guards.
  • Fresh uncommitted autoreview: no accepted/actionable findings.
  • Live patched-head proof was not run because deploying an unmerged branch would mutate the operator canary; the patched owner boundary is instead exercised with real local HTTP, exact-head CI, and the repository Testbox landing gate.
  • Production LOC: +15/-14 (net +1). Tests: +68/-0.

@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: S maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete
steipete marked this pull request as ready for review August 25, 2026 05:03
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification

Prepared head: 3c1c502908067bc19bd85d7fe846197a2234feba

Focused local proof:

  • node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts — 17 passed.
  • node scripts/run-vitest.mjs extensions/reef/src/friends.test.ts — 21 passed.
  • node scripts/run-vitest.mjs extensions/reef/src/transport.test.ts — 39 passed.
  • node scripts/run-vitest.mjs extensions/reef/src/transport.timeout.test.ts — 3 passed.
  • node scripts/check-changed.mjs -- extensions/reef/src/channel-lifecycle.ts extensions/reef/src/channel.ts extensions/reef/src/friends.ts extensions/reef/src/transport.ts extensions/reef/src/channel.test.ts — passed.
  • Real-HTTP A/B: pre-fix lifecycle settled 804 ms after abort on an 800 ms request deadline; patched lifecycle settled in 3 ms.
  • Fresh autoreview: no accepted/actionable findings.

Exact-head hosted CI is green: run 32811365956. scripts/pr prepare-run 129016 passed at 2026-08-25T05:25:14Z with gate mode hosted_exact_or_recent_parent; the Testbox-specific lanes were not applicable because the exact-head hosted gate supplied the required proof.

Proof gap: the patched head was not deployed to the operator canary because running an unmerged branch there would mutate production. The changed owner boundary is covered by real local HTTP, exact-head hosted CI, and the native prepare gate.

ClawSweeper's exact-head review publisher is still running and has published no rank-up moves. The latest comment was read immediately before merge; there are therefore no moves to skip or apply, and repository policy treats a queued/late publisher update as non-blocking.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 1:13 AM ET / 05:13 UTC.

ClawSweeper review

What this changes

The PR passes the Reef channel lifecycle abort signal through friend reconciliation and pairing-candidate relay requests, preventing shutdown from waiting for their request deadline.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer landing: no blocking correctness or security finding was identified, and the protected maintainer-authored PR repairs the cancellation path at its lifecycle owner.

Priority: P2
Reviewed head: 3c1c502908067bc19bd85d7fe846197a2234feba

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with credible real-HTTP regression coverage and no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: this is a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless documents a real local HTTP after-fix scenario.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: this is a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless documents a real local HTTP after-fix scenario.
Evidence reviewed 5 items Current-main failure path: At the recorded main revision, reconciliation invokes its callback without the lifecycle signal, while the Reef channel’s callback calls friend reconciliation and pairing-candidate listing without cancellation; a stalled request can therefore outlive shutdown until its transport deadline.
Abort contract: The existing shared timeout helper combines its caller signal with the deadline signal, so threading the lifecycle signal to the existing transport request cancels the real fetch without changing the 15-second timeout policy.
Owner-boundary regression coverage: The new table-driven test uses a real local HTTP server, stalls both the initial and second friend-list request, aborts the lifecycle, and asserts completion before the artificial request deadline.
Findings None None.
Security None None.

Live Verification

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

Result: FAIL (partial) — step 2 expect_output promptly aborts a stalled friend reconciliation request: expected terminal output was not visible within 30 seconds: "promptly aborts a stalled friend reconciliation request"

node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129016-8t7GZz/target$ node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts
node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts
[test] starting test/vitest/vitest.extensions.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129016-8t7GZz/target

 ✓  extensions  extensions/reef/src/channel.test.ts (17 tests) 751ms
     ✓ exposes locally trusted peers as routable directory entries  529ms

 Test Files  1 passed (1)
      Tests  17 passed (17)
   Start at  05:14:26
   Duration  21.59s (transform 17.32s, setup 759ms, import 19.77s, tests 751ms, environment 0ms)

[test] passed 1 Vitest shard in 26.08s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129016-8t7GZz/target$ node scripts/run-vitest.mjs extensions/reef/src/channel.test.ts
[test] starting test/vitest/vitest.extensions.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129016-8t7GZz/target































Assertions:

  • FAIL expect_output: promptly aborts a stalled friend reconciliation request

How this fits together

Reef is a bundled channel plugin whose account lifecycle refreshes relay friendship state before and during inbox operation. Those relay calls affect trust and pairing updates, while lifecycle shutdown must stop both the inbox and reconciliation work promptly.

flowchart LR
  A[Gateway stop or replacement] --> B[Reef account lifecycle]
  B --> C[Friend reconciliation]
  C --> D[Reef transport request]
  D --> E[Relay friends endpoint]
  B --> F[Lifecycle abort signal]
  F --> D
  C --> G[Trust and pairing updates]
Loading

Before merge

  • Resolve merge risk (P1) - Production code is net +1 line: the added abort check is necessary to prevent local overdue-delivery notices after the lifecycle has ended; the cancellation propagation itself replaces existing call shapes rather than adding a parallel path.
  • Complete next step (P2) - No repair-lane action is needed: the patch has no supported actionable defect, while the protected maintainer item remains open for normal exact-head validation and landing.
Agent review details

Security

None.

PR surface

Source +1, Tests +68. Total +69 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 15 14 +1
Tests 1 68 0 +68
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 83 14 +69

Review metrics

Metric Value Why it matters
Production versus regression-test LOC production +1, tests +68 The single production line prevents post-abort local notices; the test growth covers both sequential friend-list calls against a stalled real HTTP server.

Stored data model

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain one lifecycle-owned abort signal through both friend-list calls and the existing transport deadline, then land after exact-head required checks complete.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain one lifecycle-owned abort signal through both friend-list calls and the existing transport deadline, then land after exact-head required checks complete.

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

Yes, from source: current main starts reconciliation without its lifecycle signal, while the transport already supports combining a caller signal with its request deadline. The PR’s supplied real-local-HTTP scenario directly exercises that path, though this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Propagating the existing lifecycle signal through the lifecycle callback, friend manager, and existing transport timeout is the narrow owner-boundary repair; downstream shutdown guards would leave the stalled request alive.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded Reef channel shutdown reliability repair with limited plugin-local blast radius.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded Reef channel shutdown reliability repair with limited plugin-local blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

  • Current-main failure path: At the recorded main revision, reconciliation invokes its callback without the lifecycle signal, while the Reef channel’s callback calls friend reconciliation and pairing-candidate listing without cancellation; a stalled request can therefore outlive shutdown until its transport deadline. (extensions/reef/src/channel-lifecycle.ts:14, ebc70fa1b3f6)
  • Abort contract: The existing shared timeout helper combines its caller signal with the deadline signal, so threading the lifecycle signal to the existing transport request cancels the real fetch without changing the 15-second timeout policy. (src/utils/fetch-timeout.ts:126, ebc70fa1b3f6)
  • Owner-boundary regression coverage: The new table-driven test uses a real local HTTP server, stalls both the initial and second friend-list request, aborts the lifecycle, and asserts completion before the artificial request deadline. (extensions/reef/src/channel.test.ts:358, 3c1c50290806)
  • History and likely ownership: Blame on the recorded main revision attributes the affected Reef lifecycle, channel, friend-manager, and transport lines to the recent Reef-area history carried by Peter Steinberger; the PR head is the direct follow-up cancellation repair. (extensions/reef/src/channel.ts:429, 5775cd3dfaf4)
  • Release and main comparison: The PR commit is not contained by a local release tag or branch; direct comparison against the supplied current-main tree shows the cancellation plumbing is not already present. (extensions/reef/src/transport.ts:222, 3c1c50290806)

Likely related people:

  • steipete: Current-main blame on the lifecycle, channel, friend-manager, and transport boundary attributes the affected lines to Peter Steinberger’s recent work; this PR continues that same boundary. (role: recent Reef-area contributor; confidence: medium; commits: 5775cd3dfaf4, 3c1c50290806; files: extensions/reef/src/channel-lifecycle.ts, extensions/reef/src/channel.ts, extensions/reef/src/friends.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the remaining exact-head required checks complete before landing.

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.

@steipete
steipete merged commit 8b147db into main Aug 25, 2026
176 checks passed
@steipete
steipete deleted the steipete/stoic-jackson-9f12ea branch August 25, 2026 05:38
@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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant