Fix stale GitHub dispatch recovery and diagnostics#119
Conversation
The observed dispatch failure sequence — issue admitted, implementer
worker_ready, reviewer agent_spawned but never ready, Factory tears down
the workers, the broker retries an orphan, and the dashboard only shows
dispatch_failed — has a concrete cause in defaultRestartPolicy.
Factory owns durable resume/respawn for its dispatch agents and neutralizes
the broker's default restart policy with { maxRestarts: 0 } so a broker-level
retry can't re-register a name before Factory resumes it (relay#1116-family).
That opt-out was applied to implementer and babysitter but NOT reviewer, even
though routeReviewerSpec sets no restartPolicy and the reviewer shares the
implementer's dispatch lifecycle (spawned in the same batch, torn down by the
same dispatch-failure/#releaseAndTerminateAgents paths, resumed via the same
#resumeDurableDispatch flow). So a torn-down reviewer fell through to the
broker default, which re-registered its name as an orphan while the dashboard
only reported dispatch_failed.
Extend the maxRestarts:0 opt-out to the reviewer role. Add a regression test
asserting both the implementer and reviewer dispatch spawns carry
{ maxRestarts: 0 } (the reviewer's restartPolicy was previously undefined).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthroughChangesFactory lifecycle and observability
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant FactoryLoop
participant GithubIssueSource
participant FleetClient
participant LifecycleStore
participant FactoryEventReporter
FactoryLoop->>GithubIssueSource: reload issue state
GithubIssueSource-->>FactoryLoop: current GitHub issue
FactoryLoop->>FleetClient: spawn or release agents
FactoryLoop->>LifecycleStore: persist lifecycle outcome
FactoryLoop->>FactoryEventReporter: emit cancellation telemetry
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces support for configuring and validating explicit reporting instance names, adds structured telemetry for run cancellations, and prevents orphan reviewer agents by disabling broker-level restarts. It also ensures that durable dispatches are not resumed or dispatched if the live GitHub issue is closed or no longer ready. The review feedback highlights two key areas for improvement: first, a potential performance bottleneck where the entire directory tree is scanned to resolve preferred issue paths, and second, a state-handling bug in #abandonDurableResume where failure handoffs are not cleared from the state store after a successful worktree teardown.
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.
Root cause
A persisted GitHub dispatch could be resumed without re-reading the live issue. HoopSheet issue #41 was already closed, but its stale durable lifecycle and by-id alias still allowed Factory to spawn the reviewer. Reviewer spawns also inherited the broker restart default, so teardown could re-register the name as an unowned orphan. Cancellation telemetry then collapsed the result into a generic
dispatch_failed/abandoned event.Changes
restartPolicy.maxRestartsto0source_state_changed, without provider error textreporting.instanceNameor a sole configured repo nameValidation
npm test -- --silent --reporter=dot: 44 files, 943 tests passednpm run build: passedgit diff origin/main...HEAD --check: passedSummary by cubic
Fixes stale GitHub dispatch recovery and telemetry. We now refuse to dispatch or resume closed issues, stop the broker from re-registering torn-down reviewers, and report clear, privacy-safe cancellation reasons and instance identity.
Bug Fixes
restartPolicy.maxRestarts: 0to prevent broker orphan re-registration.Observability
source_state_changed,agent_spawn_failed,agent_delivery_failed,dispatch_failed) viaFACTORY_CLOUD_CANCELLATION_REASONS_V1.worker_exited->exited,live dispatch state changed->source_state_changed) without leaking provider error text.reporting.instanceNameor the sole configured repo; trimmed, validated, and sent asinstance.metadata.name.Written for commit 02897ff. Summary will update on new commits.