Skip to content

Keep Relayfile discovery and babysitters durable#140

Merged
kjgbot merged 15 commits into
mainfrom
fix/durable-relayfile-mount-supervision
Jul 20, 2026
Merged

Keep Relayfile discovery and babysitters durable#140
kjgbot merged 15 commits into
mainfrom
fix/durable-relayfile-mount-supervision

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jul 20, 2026

Copy link
Copy Markdown
Member

What changed

  • supervise SDK-launched local Relayfile mounts, rotate workspace tokens, refresh stale sessions, and report degraded/recovered mount health durably
  • coalesce same-checkout mount work and cap cross-checkout refreshes at four, preventing the observed 52-mount token-refresh herd
  • consume the published public @relayfile/sdk@0.10.32 supervisor surfaces; Factory does not bypass Relayfile
  • recover babysitters whose Relaycast identity remains agent_not_found: forget the stale tracking entry, best-effort release it, resume/cold-spawn the durable session, retarget ownership and pending wakes, then probe with a cooldown
  • reconcile existing PR receipts when a restart finds a missing implementer
  • treat batchSize as an implementation-work limit: durable PR babysitters continue receiving review events without starving new ready issues
  • use Relayfile's canonical GitHub issue index to select open factory-ready issues before reading metadata, with a complete legacy tree-scan fallback
  • keep the loop heartbeat fresh while scanning very large fallback trees

Root causes

Factory could stay alive after its short-lived local mount session expired, leaving discovery stale while instance heartbeats still looked healthy. All 52 repository mounts also shared the same refresh deadline, causing a simultaneous refresh storm. Separately, restart reconciliation could discover an existing PR but lose its durable receipt, and PR babysitters counted against the implementation batch indefinitely. Together, those restored lifecycles consumed every slot even though implementation work had already reached GitHub.

Operational result

Mount failures now produce durable mount-health state plus factory.anomaly events. NightCTO consumes that health path and pages on degradation. Stale babysitters recover automatically and preserve their queued PR-feedback wake. Babysitter-owned PRs no longer consume implementation capacity, so queued factory-ready issues can advance. Indexed discovery finds eligible issues immediately, with a correctness-preserving fallback for legacy indexes that do not yet contain labels.

Validation

  • npm test -- --reporter=dot — 48 files, 997 tests passed

  • npm run build

  • isolated tarball install: all library exports imported, configured node export imported, CLI help passed

  • tarball resolved published @relayfile/sdk@0.10.32

  • focused fault tests cover mount expiry/restart, same-directory singleflight, bounded multi-repo refresh concurrency, unreachable babysitter recovery/cooldown, restart PR-receipt reconciliation, post-handoff capacity release, indexed discovery, and CPU-heavy fallback heartbeat liveness

  • exact-PR ownership regression: stale weak-match babysitter is released, durable receipt is replaced, and only the exact branch PR keeps ownership

  • live shutdown proof: all 28 lifecycle leases were relinquished immediately while a slow fallback scan was still draining

@cursor

cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 35 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: ce84cd15-d55e-499a-97b7-140aa36c5e78

📥 Commits

Reviewing files that changed from the base of the PR and between 6fd918f and ca67cab.

📒 Files selected for processing (11)
  • src/fleet/internal-fleet-client.test.ts
  • src/fleet/internal-fleet-client.ts
  • src/github/repo-identity.test.ts
  • src/github/repo-identity.ts
  • src/orchestrator/batch-tracker.test.ts
  • src/orchestrator/batch-tracker.ts
  • src/orchestrator/factory.test.ts
  • src/orchestrator/factory.ts
  • src/state/file-state-store.test.ts
  • src/state/file-state-store.ts
  • src/state/in-memory-state-store.ts
📝 Walkthrough

Walkthrough

Changes

Local mount health reporting

Layer / File(s) Summary
Mount supervision and token handling
src/mount/relayfile-cloud-mount-client.ts, src/mount/relayfile-cloud-mount-client.test.ts
Adds local mount staleness supervision, concurrency control, degraded/recovered events, token-provider fallback, cleanup, and observability scopes.
Mount health writeback contract
src/writeback/mount-health.ts, src/writeback/index.ts, src/index.ts, src/__tests__/writefile-callsite-invariant.test.ts
Defines, publishes, and re-exports the factory mount-health record and path.
Fleet CLI cloud event wiring
src/cli/fleet.ts, src/cli/fleet.test.ts
Buffers mount-health events, publishes Relayfile records, and emits cloud anomaly or snapshot events.

Terminal agent lifecycle

Layer / File(s) Summary
Terminal-agent cleanup
src/fleet/relay-fleet-client.ts, src/fleet/relay-fleet-client.test.ts
Adds explicit terminal-agent marking without emitting exit callbacks.

Factory discovery and babysitter recovery

Layer / File(s) Summary
Capacity and slot accounting
src/orchestrator/batch-tracker.ts, src/state/*, src/orchestrator/factory.ts
Capacity checks now account for babysitter handoff and durable capacity waits.
Indexed issue discovery
src/orchestrator/factory.ts, src/orchestrator/factory.test.ts
Uses validated GitHub issue indexes with fallback root discovery.
Startup and authoritative reconciliation
src/orchestrator/factory.ts, src/types.ts, src/orchestrator/factory.test.ts
Restores lifecycle receipts, preserves authoritative pull requests, and bounds startup exit draining.
Unreachable babysitter recovery
src/orchestrator/factory.ts, src/orchestrator/factory.test.ts
Adds cooldown-based recovery, session resumption, retargeting, and superseded-session cleanup.

Estimated code review effort: 5 (Critical) | ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RelayfileCloudMountClient
  participant FleetCLI
  participant CloudReporter
  participant Relayfile
  RelayfileCloudMountClient->>FleetCLI: emit local mount health event
  FleetCLI->>CloudReporter: send factory anomaly or snapshot
  FleetCLI->>Relayfile: write current mount-health record
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: kjgbot

Poem

A rabbit watched the mount grow stale,
Then cheered when fresh health filled the trail.
Cloud events hopped, babysitters returned,
Old agent tracks quietly burned.
“Recovered!” sang the factory bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main theme of durable Relayfile discovery and babysitter lifecycle handling.
Description check ✅ Passed The description clearly describes the mount supervision, babysitter recovery, and discovery updates in the diff.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/durable-relayfile-mount-supervision

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 310a7e9658

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mount/relayfile-cloud-mount-client.ts

@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 introduces local mount health monitoring and supervision to the RelayfileCloudMountClient. It adds support for token rotation, schedules periodic health checks, and reports degraded or recovered mount states via a new LocalMountHealthEvent interface. Corresponding tests and CLI integrations have also been updated. The feedback suggests a minor improvement to remove redundant async and await keywords from the launch function inside src/mount/relayfile-cloud-mount-client.ts to simplify the code.

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 src/mount/relayfile-cloud-mount-client.ts Outdated

@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 found 1 potential issue.

Open in Devin Review

Comment thread src/mount/relayfile-cloud-mount-client.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mount/relayfile-cloud-mount-client.ts`:
- Around line 534-556: Update `#superviseLocalMount` so `#markLocalMountRecovered`
is called only after the successful `#replaceLocalMount` refresh path. In the else
branch, let ensureLocalMount own the health transition and do not emit an
additional recovered state; preserve the existing catch handling and
health-check scheduling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84aa0e8a-fbf0-4556-b5cd-fbb1b16ceb1c

📥 Commits

Reviewing files that changed from the base of the PR and between fc8040b and 310a7e9.

📒 Files selected for processing (5)
  • src/cli/fleet.test.ts
  • src/cli/fleet.ts
  • src/index.ts
  • src/mount/relayfile-cloud-mount-client.test.ts
  • src/mount/relayfile-cloud-mount-client.ts

Comment thread src/mount/relayfile-cloud-mount-client.ts
@kjgbot
kjgbot force-pushed the fix/durable-relayfile-mount-supervision branch from 22b6d7c to 5bb9ae6 Compare July 20, 2026 18:11
@kjgbot kjgbot changed the title Keep Relayfile mounts alive and observable Keep Relayfile discovery and babysitters durable Jul 20, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/orchestrator/batch-tracker.ts`:
- Around line 208-216: Normalize repository identifiers to the same
owner/repository shape before comparing implementer repos with babysitter-owned
pull requests. Update dispatchOccupiesImplementationSlot and the corresponding
handoff checks in src/state/file-state-store.ts lines 800-808 and
src/state/in-memory-state-store.ts lines 527-535; ensure both bare names and
owner/name values compare consistently after normalization.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ba10eec-06eb-4b75-9a10-bef1a373991f

📥 Commits

Reviewing files that changed from the base of the PR and between b6f989b and 6fd918f.

📒 Files selected for processing (8)
  • src/mount/relayfile-cloud-mount-client.test.ts
  • src/mount/relayfile-cloud-mount-client.ts
  • src/orchestrator/batch-tracker.ts
  • src/orchestrator/factory.test.ts
  • src/orchestrator/factory.ts
  • src/state/file-state-store.ts
  • src/state/in-memory-state-store.ts
  • src/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/mount/relayfile-cloud-mount-client.ts

Comment thread src/orchestrator/batch-tracker.ts
@kjgbot
kjgbot merged commit 726d66b into main Jul 20, 2026
2 of 3 checks passed
@kjgbot
kjgbot deleted the fix/durable-relayfile-mount-supervision branch July 20, 2026 21:29
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.

2 participants