fix(gastown): dispatch refinery to correct rig in multi-rig towns#693
Merged
fix(gastown): dispatch refinery to correct rig in multi-rig towns#693
Conversation
Contributor
Code Review SummaryStatus: No New Issues Found | Recommendation: Address existing comments, then merge OverviewThis PR fixes the refinery rig assignment bug in multi-rig towns. The core changes are well-structured:
All 6 existing inline comments from the previous review round remain relevant. No additional issues were found in this review pass. Other Observations (not in diff)
Files Reviewed (8 files)
|
Four compounding bugs caused the refinery agent to be dispatched into the wrong rig's repository in multi-rig towns: 1. Refinery was a town-wide singleton — getOrCreateAgent reused the same refinery across rigs. Now refinery is per-rig like polecats, with idle agent reuse scoped by rig_id. 2. processReviewQueue hardcoded rigList[0] to resolve the rig. Now reads rig_id from the merge_request bead itself. 3. merge_request beads were created with rig_id = null. Now submitToReviewQueue populates rig_id from the input. 4. ReviewQueueInput/ReviewQueueEntry types lacked rig_id. Added to both.
Three issues with how merge_request beads and the refinery interact: 1. processReviewQueue hooked the refinery to the SOURCE bead instead of the MR bead. This overwrote the source bead's assignee (losing track of which polecat worked on it). Now hooks the MR bead directly. 2. MR bead was created with assignee_agent_bead_id set to the polecat. Now left null — the refinery claims it via hookBead, matching upstream gastown behavior. Source agent stored in metadata.source_agent_id. 3. agentDone (polecat path) did not close the source bead after submitting to the review queue. Now calls closeBead so the source bead is closed with its original polecat assignee preserved, matching upstream gt done. Also updated the refinery's agentDone path: since the refinery now hooks the MR bead directly, completeReviewFromMRBead reads the source_bead_id from the MR's metadata instead of searching by source_bead_id.
Add a Related Beads section to BeadPanel that shows the bead's DAG neighborhood — child beads, source work (for MR beads), and review beads (for source work beads). Each entry is clickable, pushing a new bead drawer onto the stack. The DAG is computed client-side from the existing listBeads data — no new API endpoints needed. The metadata.source_bead_id and metadata.source_agent_id fields (added in the MR lifecycle fix) provide the MR-to-source link. Also adds a bead_dependencies 'tracks' row when creating MR beads in submitToReviewQueue, formally linking the MR to its source bead in the dependency table for future query use.
43773a0 to
b7ade5c
Compare
- Log warning when agent.rig_id is null in agentDone - Fix misleading docstring on completeReviewFromMRBead (no longer closes source bead — polecat's agentDone handles that) - Add null guard for getBead in completeReviewFromMRBead - Remove unused ArrowUpRight import in BeadPanel.tsx - Add no-op early return in updateBeadStatus when status unchanged, preventing redundant status_changed events from double-close
jeanduplessis
approved these changes
Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 4 compounding bugs that caused the refinery agent to be dispatched into the wrong rig's repository in multi-rig towns, fixes 3 additional issues with MR bead assignment and the review lifecycle, and adds a Related Beads DAG section to the bead drawer UI.
Closes #657
Also adds UI to show relationship between related beads (like a task bead to review bead)
The bug chain (before this fix)
submitToReviewQueuerig_id = nulland assignee = polecat (Bugs 3, 5)processReviewQueuepops the entryrigList[0]-> gets rig A (Bug 2)getOrCreateAgent('refinery')returns the existing refinery for rig A (Bug 1)in_progressinstead of closed (Bug 7)Fixes
Bug 1: Refinery was a town-wide singleton
agents.ts: RemovedrefineryfromsingletonRoles(now onlywitnessandmayor)rig_idBug 2:
processReviewQueuehardcodedrigList[0]Town.do.ts: Now readsentry.rig_idfrom the merge_request beadBug 3: merge_request beads created with
rig_id = nullreview-queue.ts:submitToReviewQueuenow writesinput.rig_idto the beadBug 4:
ReviewQueueInputtype lackedrig_idtypes.ts: Addedrig_id: stringto bothReviewQueueInputandReviewQueueEntryBug 5: MR bead assignee set to polecat instead of left for refinery
review-queue.ts: MR beadassignee_agent_bead_idnow null on creation (refinery claims it viahookBead). Source agent stored inmetadata.source_agent_id.Bug 6: Refinery hooked to source bead, not MR bead
Town.do.ts:processReviewQueuenow hooks the refinery toentry.id(MR bead), notentry.bead_id(source bead). This preserves the source bead's polecat assignee.review-queue.ts: RefineryagentDonepath updated —completeReviewFromMRBeadreads the source bead from the MR's metadata instead of the oldcompleteReviewForSourceBeadlookup.Bug 7: Source bead not closed after polecat submits to review
review-queue.ts:agentDone(polecat path) now callscloseBeadon the source bead after submitting to the review queue, matching upstreamgt donebehavior.Feature: Related Beads DAG in bead drawer
BeadPanel.tsx: New "Related Beads" section shows the bead's DAG neighborhood:parent_bead_idmatches the current beadmetadata.source_bead_idmerge_requestbeads that track this beadlistBeadsdata — no new API endpointsbead_dependencies'tracks' row when creating MR beads to formally link the DAGFiles changed
cloudflare-gastown/src/types.tsrig_idtoReviewQueueInputandReviewQueueEntrycloudflare-gastown/src/dos/town/agents.tscloudflare-gastown/src/dos/town/review-queue.tscloudflare-gastown/src/dos/Town.do.tscloudflare-gastown/src/handlers/rig-review-queue.handler.tsparams.rigIdtosubmitToReviewQueuesrc/components/gastown/drawer-panels/BeadPanel.tsxcloudflare-gastown/test/integration/rig-do.test.tsrig_idto test datacloudflare-gastown/test/integration/rig-alarm.test.tsrig_idto test data