Skip to content

engine: export node-control provider-disconnect + fix dropped-provider aggregate leak#244

Merged
willwashburn merged 4 commits into
mainfrom
export-provider-disconnect
Jul 8, 2026
Merged

engine: export node-control provider-disconnect + fix dropped-provider aggregate leak#244
willwashburn merged 4 commits into
mainfrom
export-provider-disconnect

Conversation

@willwashburn

@willwashburn willwashburn commented Jul 8, 2026

Copy link
Copy Markdown
Member

Two changes on the node-control provider-disconnect path: expose it to
out-of-process socket owners, and fix an aggregate-count leak in it.

1. Export the provider-disconnect lifecycle

@relaycast/engine/node-control re-exports handleProviderDisconnect and
markNodeOffline alongside handleNodeControlMessage.

An out-of-process node-control socket owner — the relaycast-cloud NodeDO, which
holds the /v1/node/ws sockets in a Durable Object — owns its sockets but drives
the engine for everything else. On socket close it must flip the correct
liveness:

  • one provider's socket drops while others stay connected → only that provider
    (and its agents) goes offline, the node stays online;
  • the node's last connection drops (or a liveness-alarm lapse / operator
    disconnect) → the whole node, its providers, and its agents go offline.

That logic already lives in engine/node.ts (handleProviderDisconnect,
markNodeOffline) — what the in-process adapter calls on its own socket close —
but it was not exported from node-control, so the DO had to hand-roll a SQL
mirror of it. Multi-provider nodes turned that one mirror into several. Both
functions encapsulate the full effect (provider row, hosted agents, node
aggregate, invocation reschedule), so a host never reassembles them.

2. Fix the dropped-provider aggregate leak

markProviderOffline and markNodeOffline left node_providers.active_agents
at its last value, but recomputeNodeAggregate sums active_agents across ALL
providers (online and offline). So after a provider's socket dropped with others
still connected, nodes.active_agents kept counting the dropped provider's now-
offline agents until it reconnected. Both markers now zero active_agents on
offline; a reconnect / heartbeat repopulates it from the provider's own report.
This is in the exact function the export above exposes, so it ships here rather
than as a separate follow-up.

Test

nodeControlExports.test.ts drives the public exports against the in-memory
engine: provider-scoped offline (node stays online), last-connection offline, and
node-wide offline; plus the aggregate correction — the node total drops a dropped
provider's agents and restores them on the next heartbeat, and markNodeOffline
zeros every provider's count.

Full engine suite green (414).

Ships with

The consumer is relaycast-cloud#27 (NodeDO multi-provider sockets), which deletes
its hand-rolled node/registration.ts mirror and delegates to these exports.
Both ride the same next @relaycast/engine release.

🤖 Generated with Claude Code

…ontrol

Out-of-process node-control socket owners (the relaycast-cloud NodeDO) own their
sockets but not the DB. On socket close they must flip the right liveness — one
provider offline while the node stays online, or the whole node offline when the
last connection drops — and that logic already lives in `engine/node.js`
(`handleProviderDisconnect`, `markNodeOffline`) but was unreachable from the
`@relaycast/engine/node-control` entrypoint, forcing the host to hand-roll a SQL
mirror. Re-export both so the host delegates instead.

Both encapsulate the full effect (provider row + agents + node aggregate +
invocation reschedule); a conformance test asserts the public exports produce the
provider-scoped, last-connection, and node-wide offline states.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request exports handleProviderDisconnect and markNodeOffline from the node-control module to support out-of-process socket owners driving the node-offline lifecycle, and adds a conformance test suite to verify their behavior. The feedback suggests using optional chaining (stack?.close()) in the test teardown to prevent masking setup errors if initialization fails.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/engine/src/__tests__/conformance/nodeControlExports.test.ts Outdated
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@willwashburn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9b8cb83f-e32a-4b90-ad00-44432891e560

📥 Commits

Reviewing files that changed from the base of the PR and between d89b8a0 and ee5c2c3.

📒 Files selected for processing (3)
  • packages/engine/src/__tests__/conformance/nodeControlExports.test.ts
  • packages/engine/src/engine/node.ts
  • packages/engine/src/engine/nodeProvider.ts
📝 Walkthrough

Walkthrough

Adds a new Vitest conformance test suite verifying node-control's provider-disconnect behaviors (partial disconnect, full disconnect, and markNodeOffline), including helpers to enroll nodes, attach simulated provider sockets, and query provider/node status. Adds an explanatory comment in node-control.ts documenting these lifecycle semantics.

Changes

Node-control disconnect behavior verification

Layer / File(s) Summary
Lifecycle documentation comment
packages/engine/src/node-control.ts
Adds a comment describing how handleProviderDisconnect and markNodeOffline handle provider-row, agent, aggregate, and rescheduling side effects.
Test suite setup and helpers
packages/engine/src/__tests__/conformance/nodeControlExports.test.ts
Declares the test suite with setup/teardown, an enrollNode helper, an attachProvider socket simulation helper, and DB query helpers for provider/node status.
Disconnect and offline assertions
packages/engine/src/__tests__/conformance/nodeControlExports.test.ts
Tests verify partial disconnect keeps the node online, full disconnect marks the node offline, and markNodeOffline marks the node and all providers offline.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant EngineAPI
  participant ProviderSocket
  participant DB

  Test->>EngineAPI: enrollNode()
  EngineAPI->>DB: create node record
  Test->>ProviderSocket: attachProvider() registration + heartbeat
  ProviderSocket->>DB: write provider status
  Test->>EngineAPI: handleProviderDisconnect(remaining)
  EngineAPI->>DB: update provider/node status
  Test->>DB: query nodeProviders.status / nodes.status
  DB-->>Test: status results
Loading

Poem

A provider hops offline, one paw at a time,
The node stays cozy, still online, still fine.
Pull the last plug, and darkness descends,
markNodeOffline sweeps up all its friends.
Tests confirm it — hip hop, hooray! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title accurately summarizes the export of provider-disconnect logic and the aggregate leak fix.
Description check ✅ Passed The description is directly related to the node-control export change and the offline aggregate fix.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch export-provider-disconnect

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Re-trigger cubic

willwashburn and others added 2 commits July 8, 2026 13:18
…n error

Addresses review feedback on #244.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… correct

`markProviderOffline` and `markNodeOffline` left `node_providers.active_agents`
at its last value, but `recomputeNodeAggregate` sums active_agents across ALL
providers (online and offline). So after a provider's socket dropped with others
still connected, `nodes.active_agents` kept counting the dropped provider's now-
offline agents until it reconnected. Reset it to 0 on offline; a reconnect /
heartbeat repopulates it from the provider's own report.

Regression test in nodeControlExports asserts the node aggregate drops the
dropped provider's count and restores it on the next heartbeat, and that
markNodeOffline zeros every provider's count.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@willwashburn willwashburn changed the title engine: export handleProviderDisconnect + markNodeOffline from node-control engine: export node-control provider-disconnect + fix dropped-provider aggregate leak Jul 8, 2026

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/engine/src/__tests__/conformance/nodeControlExports.test.ts">

<violation number="1" location="packages/engine/src/__tests__/conformance/nodeControlExports.test.ts:152">
P3: The aggregate reconnect test reuses the disconnected socket's handle to send the reconnect heartbeat. In production a new socket creates a new handle via `attachNodeSocket`; reusing the old handle tests only the DB write path, not the full lifecycle. Consider calling `attachNodeSocket` + heartbeat through the fresh handle to match the reconnect path more closely.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/engine/src/__tests__/conformance/nodeControlExports.test.ts Outdated
…tion

Close the dropped provider's socket (driving the disconnect through the adapter's
own close path) and register a fresh socket with a new instance for the restore,
instead of re-heartbeating the stale handle — matches how a provider actually
reconnects. Addresses review feedback on #244.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@willwashburn willwashburn merged commit 8b3ec71 into main Jul 8, 2026
5 checks passed
@willwashburn willwashburn deleted the export-provider-disconnect branch July 8, 2026 21:11
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