Skip to content

fix(formula): resolve refinery agent bead ID dynamically#3301

Merged
steveyegge merged 1 commit intogastownhall:mainfrom
JustinThirkell:fix/refinery-agent-bead-id
Mar 27, 2026
Merged

fix(formula): resolve refinery agent bead ID dynamically#3301
steveyegge merged 1 commit intogastownhall:mainfrom
JustinThirkell:fix/refinery-agent-bead-id

Conversation

@JustinThirkell
Copy link
Copy Markdown
Contributor

@JustinThirkell JustinThirkell commented Mar 26, 2026

Summary

The refinery patrol formula hardcodes the wrong agent bead ID, causing it to loop with "no issue found" errors after any DB reset/recovery.

This PR updates the refinery patrol formula with dynamic resolution matching the witness pattern for finding the agent bead.

Note: I'm fairly new to Gas Town - the Claude-based reasoning on why the correct fix is to update the formula seems plausible to me but I'm happy to be corrected on this.

Details

After a Gas Town restart I noticed the Refinery looping with:

Could not read agent bead (starting at idle=0): Error fetching gt-foo-refinery: no issue found matching "gt-foo-refinery"

The root cause according to Claude is that the burn-or-loop step in mol-refinery-patrol.formula.toml hardcodes gt-<rig>-refinery as the agent bead ID.

Two bugs compound:

  1. The formula uses gt as the prefix, but non-gastown rigs use their own prefix (e.g. foo for Foobar)
  2. AgentBeadIDWithPrefix() in agent_ids.go collapses the ID when prefix == rig — so for rig foo with prefix foo, the actual bead ID is foo-refinery, not gt-foo-refinery

The witness formula already handles this correctly by resolving its agent bead ID dynamically at runtime via bd list --type=agent.

The fix was to replace the hardcoded ID with the same bd list dynamic resolution pattern used by the witness. Also added a regression test (TestPatrolFormulasUseDynamicBeadResolution) to prevent re-hardcoding.

Verification

After restarting Gas Town with this fix the Refinery was able to find its agent bead and enter normal patrol on non-gt-prefixed rigs.

The refinery patrol formula hardcoded `gt-<rig>-refinery` as the agent
bead ID in the burn-or-loop step. This breaks when prefix == rig because
AgentBeadIDWithPrefix collapses the ID (e.g. `cp-refinery` not
`gt-cp-refinery`), causing the refinery to loop with "no issue found".

Replace with dynamic resolution via `bd list --type=agent`, matching
the pattern already used by the witness formula.

Add regression test to prevent re-hardcoding.

Fixes: hq-9xs

Co-Authored-By: Claude
@github-actions github-actions bot added the status/needs-triage Inbox — we haven't looked at it yet label Mar 26, 2026
@steveyegge steveyegge merged commit 802ef84 into gastownhall:main Mar 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/needs-triage Inbox — we haven't looked at it yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants