Skip to content

feat(loop): the dispatcher, dark (4/4) - #69

Merged
Ardnived merged 6 commits into
mainfrom
claude/loop-dispatcher
Sep 8, 2026
Merged

Ardnived merged 6 commits into
mainfrom
claude/loop-dispatcher

Conversation

@Ardnived

@Ardnived Ardnived commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Fourth of four, stacked on #68. The GitHub Actions dispatcher and this repo's caller. Dark: the org variable BOT_DISPATCH is off, so the caller still runs state-machine.yml and the dispatcher never executes. Setting it to dry runs the dispatcher logging its plan and writing nothing; on runs it for real.

Design: ~/.claude/plans/let-s-consider-and-create-starry-church.md (rev. 3), Part A.

Shape

dispatcher.yml (reusable) → job resolve (event → items) → job act (one matrix leg per item, concurrency: dispatch-<repo>-<number>, re-derives the decision from live GitHub state) → job journal (journal repo's schedule only). Code in dispatcher/, a sibling of workflow/ so the plugin validator ignores it and "nothing under workflow/ fetches" stays true.

Module Role
resolve.mjs event → targets; CI events resolve the SHA to open PRs and drop stale ones
gather.mjs Octokit → snapshot; imports merge-gate.mjs unchanged
decide.mjs pure: evaluatePr and every event row; 24 tests
apply.mjs executes a plan; every write reads first
fire.mjs the /fire client and the dispatch record (a pointer; lock included)
record.mjs the per-item status comment (handler, attempt, session link, fixCi, recheck, pending)
projects.mjs Projects v2 by name; ids resolved once per run
journal.mjs day issue, anomaly comments, title tally
sweep.mjs the 30-minute residue sweep
verbs.mjs, markers.mjs grammar and body-line parsers

Rules worth checking against the plan

  • Mark-ready is unreachable before the critic exists (evaluatePr step 5) unless the PR is under review.skipWhen.
  • Approved + conflicting → resolve-conflicts first, merge on the next green (step 3 precedes step 6).
  • A failed fire always releases the lock and marks stuck; the sweeper retries; after maxAttempts → awaiting + comment.
  • Copilot counts for PR reviews and inline comments but cannot issue verbs; humans need write access.
  • ci.ignoreCheckNames excludes the dispatcher's own check run (L11) — the act.test proves an in_progress "dispatch / act" run does not block a draft.

Verification

  • node --test dispatcher/test/*.test.mjs — 34 pass (verbs 5, markers 3, decide 21, end-to-end over a fake Octokit 5: resolve, dry-run, live implement, 429, critic/threshold).
  • claude plugin validate ./workflow --strict — passed (dispatcher is outside the plugin).
  • YAML parses; no run: step interpolates github.event.*.

Not in this PR

The four product-repo callers (one PR each, to open after this merges — they reference dispatcher.yml@main), the five routine tokens (ROUTINE_TOKEN_<REPO> org secrets), the board setup (UI), SENTRY_CLAUDE_WORKFLOW_TOKEN as an org secret.

2026-09-08 revision. fire.mjs keys the token and routine id by repo only (ROUTINE_TOKEN_<REPO>, ROUTINE_ID_<REPO>, fallback dispatch.routines[repo]); dispatcher.yml declares five secrets and five ids instead of twelve. 34 tests pass.

2026-09-08, later. No WIP cap: the implement verb fires at once; the drain path and the queued comment are gone. The sweeper keeps a <!-- tally --> block in the day issue's body (per handler, per repo, busiest items) for reflect's usage report. The token secret is SYDEVS_BOT_PAT; PUT …/merge needs its Contents:write. 35 tests pass.

Ardnived and others added 6 commits September 8, 2026 11:35
… the mechanical work

A reusable GitHub Actions workflow plus the `dispatcher/` modules it runs
from a checkout of this repo's main. Every event in the five repos reaches
it through a thin caller. It does, with no tokens, everything an event
determines:

- classify: verbs (`@sydevs-bot implement|revise|split|answer` on issues,
  `address|review` on PRs, case-insensitive), the respondTo allowlist plus
  write access for humans, the bot-actor filter with its one exception
  (the adversarial review), stale-SHA CI events;
- lock and fire: apply `bot:working`, write the status comment, POST the
  dispatch record (a pointer only) to the handler's routine; on 429/400/5xx
  release the lock, mark `stuck`, record the retry window;
- mechanical writes: board Status (Proposed/Revising/Approved/Done),
  `awaiting` as the single writer, `blocked` from native relationships and
  `Blocked by:`/`Re-check:` markers, mark-ready after the critic (or under
  the size threshold), reviewer request at ready, squash-merge on the
  merge gate, Sentry resolve on merge, dependents on close, the conflict
  scan, fix-ci counting, WIP-capped implement queued at Approved and
  drained oldest-verb-first;
- the sweeper: per-repo every 30 minutes — retries whose window passed,
  locks past their deadline (re-fire, then hand over to awaiting after
  maxAttempts), missed rechecks, orphaned drafts, awaiting drift; and the
  journal day and title in the journal repo.

`decide.mjs` is pure and tested; `act.test.mjs` runs the whole path over a
fake Octokit, dry-run and live, including a 429. `merge-gate.mjs` is
imported unchanged as the one definition of green and mergeable; the
dispatcher's own check runs are excluded from it (`ci.ignoreCheckNames`),
which would otherwise deadlock a draft.

Nothing runs until a caller selects it: BOT_DISPATCH is `off`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… BOT_DISPATCH

`off` runs the state machine as before; `dry` runs the dispatcher logging
what it would do and writing nothing; `on` runs it for real; `migrating`
runs neither. The gate is in the caller because a repo can always read
its own variables. Events widened to what the dispatcher needs: edited and
unlabeled issues, review comments and threads, workflow_run for our CI,
check_suite for app checks, status for Railway, a 30-minute sweep, and
this repo's two journal-day crons at 00:05 America/Vancouver.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
fire.mjs keys ROUTINE_TOKEN_<REPO> and ROUTINE_ID_<REPO> (fallback
dispatch.routines[repo]); dispatcher.yml carries five secrets and five
ids instead of twelve. The record's handler field selects the skill.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…SYDEVS_BOT_PAT

The implement verb fires at once — the human who types it is the throttle
(why: docs/why.md#there-is-no-wip-cap). The drain path and the queued comment
are gone. The sweeper now keeps a tally block in the day issue's body
(per handler, per repo, busiest items) for the weekly reflect to report usage.
The dispatcher's token secret is renamed from ADD_TO_PROJECT_PAT.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Ardnived
Ardnived force-pushed the claude/loop-dispatcher branch from 996eca9 to 6cec14b Compare September 8, 2026 18:35
@Ardnived
Ardnived merged commit 990206b into main Sep 8, 2026
1 check passed
@Ardnived
Ardnived deleted the claude/loop-dispatcher branch September 8, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant