Skip to content

Yield live event drains to protect heartbeat#281

Merged
kjgbot merged 2 commits into
mainfrom
factory-sdk-live-event-drain-sb-impl3
Jun 13, 2026
Merged

Yield live event drains to protect heartbeat#281
kjgbot merged 2 commits into
mainfrom
factory-sdk-live-event-drain-sb-impl3

Conversation

@kjgbot

@kjgbot kjgbot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the live-daemon heartbeat starvation path by pacing live issue event handling.

  • Subscribe callbacks now enqueue live issue events instead of running #handleLiveChange directly on the push callback.
  • Live events drain serially in bounded batches with a macrotask yield between batches so heartbeat timers and writes can run during replay/catch-up bursts.
  • Poll replay pages use the same yielded batch helper.
  • Drain batch boundaries refresh the live heartbeat when it is due, tightening steady-state heartbeat age under sustained live-event work.

Safety

  • Factory SDK only; no new dependencies; no src/main changes.
  • Does not change synthetic/real classification, merge policy, or termination/reaper semantics.
  • Stop clears pending live events before unsubscribing/releasing.

Regression Proof

Added a non-vacuous live subscription burst test that routes through the real #handleLiveChange -> #handleChange -> #readIssue path:

  • A test mount performs synchronous blocking issue reads and advances the factory clock before returning, which forces real event-loop starvation on the unfixed direct-callback path.
  • The test observes stale-while-reading directly from the heartbeat file while the daemon is alive; reverting the queue/yield path makes that observation go true.
  • Post-fix, stale-while-reading remains false, the heartbeat catches up to less than half the stale threshold, live drain yields are recorded, and real dispatch occurs.

Validation

  • npx vitest run packages/factory-sdk/src/orchestrator/factory.test.ts --testNamePattern "keeps the live heartbeat fresh"
  • npx vitest run packages/factory-sdk/src/orchestrator/factory.test.ts
  • npm run typecheck:node
  • npx vitest run packages/factory-sdk
  • Force-fresh bundle cache: rm -rf /Users/khaliqgant/Projects/AgentWorkforce/pear/node_modules/.cache/pear-factory-sdk

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kjgbot, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 54 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d041604a-bc76-41b1-a6bb-c3f09b66a5a8

📥 Commits

Reviewing files that changed from the base of the PR and between 7c4ab03 and c3a4ef4.

📒 Files selected for processing (2)
  • packages/factory-sdk/src/orchestrator/factory.test.ts
  • packages/factory-sdk/src/orchestrator/factory.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch factory-sdk-live-event-drain-sb-impl3

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 and usage tips.

@kjgbot kjgbot added the no-agent-relay-review Disable agent-relay automated PR review/fixes label Jun 13, 2026
@kjgbot kjgbot force-pushed the factory-sdk-live-event-drain-sb-impl3 branch from e40cf41 to c3a4ef4 Compare June 13, 2026 18:51
@kjgbot kjgbot merged commit c652420 into main Jun 13, 2026
4 checks passed
@kjgbot kjgbot deleted the factory-sdk-live-event-drain-sb-impl3 branch June 13, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-agent-relay-review Disable agent-relay automated PR review/fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant