factory design: extract the multi-project factory core — invert the harness-sync topology #571
Labels
No labels
agent-blocked
agent-working
autopilot
bug
deferred
deploy-pending
enhancement
landing-pr
model-haiku
model-opus
model-sonnet
needs-design
needs-info
needs-triage
no-triage
out-of-scope
priority
ready-for-agent
ready-for-human
ready-for-session
rehearsal-183
snapshot-pending
standing-drive
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
Reference
Matou/idss#571
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The harness-sync model ("ourcloud is canonical, push sed-transformed commits into siblings") structurally cannot scale to project #3 (survey:
docs/research/2026-08-15-factory-reengineering-survey.md§sync):check-harness-drift.sh:3claims to be canonical in matou-app while its own header claims it carries no slug)harness-sync.yml:31), and the generated drift workflow hardcodesruns-on: matou-workstationProposal to rule on
Extract the factory core into its own repo, consumed by each project, inverting the topology:
run-swarm.shdecomposed along its already-visible seams (preflight → identity → schedule → provision → execute → verify → land → report; six of eight stages already have a library)swarm-identity.sh(the same 8 copy-pastedFORGEJO_APIdefault lines collapse into it)prompt.mdfrom a shared skeleton, Dockerfile toolchain layer, secretsforgejo-lib.shtracker adapter (the reporter alone speaks Forgejo in three styles across ~15 calls; every script re-learns label-PATCH-ignored the hard way) — also the layer a TUI and any future tracker sits onNeeds Ben: topology ruling (separate repo vs npm-style package vs status quo), repo name/home, and whether matou-app migrates in the same arc or after.
RULED by Ben, 2026-08-19: yes — the factory core moves out of any one product repo. The proposal above is accepted as written, with the topology pinned as follows:
Factory core → its own repo (working name
Matou/swarm-factory): the orchestrators (run-swarm.shdecomposed along its eight seams, healer, rehearsal executor/reporter), all ~1,300 lines of tested libs, workflow skeletons, prompt skeleton,forgejo-lib.sh,swarm-db— and, downstream,factory onboard(#572) and the TUI (#573). The factory repo gets its own CI/self-tests and its own issue tracker, so the swarm can dogfood factory tickets.Product repos keep only a thin declarative layer:
swarm-identity.sh(slug, API URL, label IDs, channel, checkout paths — collapses the 8 copy-pastedFORGEJO_APIdefaults), prompt enrichments + protected-path lists layered on the factory skeleton, the e2e driver conforming to #570's driver contract (the contract is the plug-in interface), and per-repo.sandcastle/.envsecrets (per #578).Distribution flips push → pull. No sed-sync, no push credential into targets: workers consume the factory at a pinned ref; product repos upgrade by bumping the ref. "Drift" becomes "behind a tagged release" instead of "matches whatever was last synced". The ownership-inversion bug class disappears because there is no canonical product repo.
Host state is factory-owned: crontab entries,
/tmp/matou-swarm.lock,swarm.db, and host scheduling belong to the factory, not to any repo — this is what gives #577 (capacity semaphore / per-repo fairness / drive-vs-worker serialization) an arbiter with standing.Consequences: the swarm-atlas splits (factory mechanics move; ourcloud-specific driver/journey docs stay); matou-app's forked 9KB orchestrator copy retires; migration is the work of this ticket. An ADR recording this topology ruling should land with the extraction's first commit (mint from the then-current sequence — do not reserve a number now).
Two-way door from here (ADR 0174): flipping to
ready-for-agent.Ruling recorded; extraction routes to a session
Landed ADR 0180 (
docs/adr/0180-the-factory-core-lives-in-its-own-repo-consumed-by-pull.md, commit3d6b7b0, onorigin/main) recording Ben's topology ruling verbatim — the extraction's first commit, per the ruling ("An ADR recording this topology ruling should land with the extraction's first commit"). STATUS.md updated (header + milestone log).Why the code extraction cannot land from a swarm worker — routing to
ready-for-session: the migration proper is, by construction, protected-path + external-repo work a swarm worker is forbidden from performing:.sandcastle/and.forgejo/machinery (the ~1,300 lines of libs, the three orchestrators, the workflow skeletons) into the new repo. Both dirs are the fingerprinted protected set (protected-paths-lib.sh:50): any create/delete/change a worker makes is rolled back and fails the run (ADR 0174 / #445).swarm-identity.sh,forgejo-lib.sh, prompt enrichments — themselves live under a product repo's protected.sandcastle/.Matou/swarm-factory), outside a swarm worker's sandbox.Per the
ready-for-sessionbar (ADR 0174 /docs/agents/triage-labels.md): this is exactly "protected.sandcastle/paths (#445) … work an interactive agent session can execute but a swarm worker must not pick up." The topology one-way-door is already ruled by Ben above, so there is no human decision left — only session-standing execution.Labels swapped:
ready-for-agent→ready-for-session. #572 (factory onboard) and #577 (host scheduling) carry the rest of the arc.Ruled by agent under ADR 0174 — veto anytime. Executing ADR 0180's topology ruling hit a hard credential wall; rather than land nothing, extracted the achievable two-way-door slice.
What I tried and found
Minting
Matou/swarm-factoryunder the Matou org needs a credential this session does not hold:POST /orgs/Matou/reposwith both ben's token and swarm's token →403:"token does not have at least one of required scope(s): [write:organization]"(both tokens resolve to thebenaccount perGET /user, is_admin true, but scope is checked independently of admin status).git pushto a not-yet-existingMatou/<repo>) →403:"Push to create is not enabled for organizations."Neither route is available to a session. This is a personal/org-credential one-way door (ADR 0174 list item 1), not a judgement call — the topology itself is already ruled.
What landed instead — proven, tested, pushed (
21d7978)Fully inside the existing sync-harness.sh push model, closing the concrete bug this ticket's Problem section named:
.sandcastle/swarm-identity.shcollapses the FORGEJO_API/WORKDIR ourcloud-defaults that were copy-pasted intoclaim-next-task.sh,heal.sh, andschedule-backstop.shinto one file, added toharness-manifestas the legitimate slug-as-value case (the ONE file that should differ per repo under the sed transform).check-harness-drift.sh:3's self-contradicting header ("CANONICAL in Matou/ourcloud" / "carries no repo slug") — the exact bug named in this ticket — is rewritten to name the canonical repo only via the.harness-canonicalmarker'sslug=field, never a literal string a sed-render can invert.schedule-backstop.sh's matching ownership claim (the second of the "2 of 13" offenders) gets the same fix..sandcastle/tests/*.shsuites green before and after;bash -nclean on every touched script.Proof: commit
21d7978onorigin/main,STATUS.mdmilestone log + header updated in the same commit.Why human
Needs one of:
Matou/swarm-factory(empty repo is enough) under the Matou org — the swarm/session token already has push rights once the repo exists, orwrite:organizationscope lands in the host env, orOnce the repo exists, the rest of ADR 0180's migration (moving
.sandcastle//.forgejo/machinery in, retiringsync-harness.sh/check-harness-drift.sh, authoringforgejo-lib.sh, the pull-based drift check) is session-shaped work — no further ruling needed, just re-armready-for-sessiononce the repo exists. #572/#577 still carry the rest of the arc as scoped in ADR 0180.Labels:
ready-for-session→ready-for-human.Unblocked by Ben, 2026-08-19: the factory repo exists —
ben/dev-factory(route 1 from the comment above, with two deltas):dev-factory(Ben's choice), superseding ADR 0180's working nameswarm-factory.push: true, admin: trueon it, and both factory tokens resolve to the ben account — so the migration can proceed againstben/dev-factorynow. An org transfer stays open as a two-way door (repo Settings → Transfer ownership →Matou, orPOST /repos/ben/dev-factory/transfer {"new_owner":"Matou"}with Ben's credential — a session attempt was classifier-blocked as an ownership change). If it transfers later, only the remote URL / pinned-ref references change.State check at re-arm: repo is empty,
has_issues: true, default branchmain.Also noting for the migrating session: #578's secret-move has since landed —
.sandcastle/.envno longer carriesFORGEJO_TOKEN(empty). Tracker credentials now come from~/.git-credentials(bothswarmandbenPATs). The migration'sforgejo-lib.shshould source credentials the post-#578 way, not from.env.Re-arming per the previous comment: the remaining migration (move
.sandcastle//.forgejo/machinery intoben/dev-factory, retiresync-harness.sh/check-harness-drift.sh, authorforgejo-lib.sh, pull-based drift check) is session-shaped, no further ruling needed.Labels:
ready-for-human→ready-for-session.Ownership transferred, 2026-08-19: the factory repo is now
Matou/dev-factory— org-owned per ADR 0180, superseding theben/dev-factoryinterim in the comment above. Verified post-transfer: still empty, and both the ben PAT and the swarm machine PAT hold push+admin on it. Migration target =https://git.matou.nz/Matou/dev-factory.git. No other state changed; stillready-for-session.Close report — the extraction is built, migration lands
Ruled by agent under ADR 0174 — veto anytime. The topology ruling itself was already Ben's (ADR 0180, this ticket's earlier comment thread); this session did the execution the last comment re-armed
ready-for-sessionfor ("no further ruling needed, just execution"), onceMatou/dev-factoryexisted to migrate into.What landed
Matou/dev-factory(new repo, org-owned,has_issues: true) — the factory core, vendored byte-identical:run-swarm.sh,heal.sh,rehearsal-report.sh,session-runner.sh, ...),swarm.config,git-fence/git-hooks/forgejo-lib.sh(new) — the tracker adapter the survey named as the biggest missing seam (the reporter alone made ~15 Forgejo calls in 3 styles); adopted inrehearsal-report.sh.forgejo/workflows/ci.yml, pinned tomatou-workstationafter a first run against the sharedswarmpool landed on elitebook-03 and failed with no log surface reachable from this session — no Forgejo REST log-fetch endpoint found)628234c(initial extraction),70b799f(CI pin fix + why),2a5f79a(check-harness-drift.sh joins the vendored set, stale-comment fixes)Matou/ourcloud— the consumer side:FORGEJO_APIdefaults intoswarm-identity.sh(839e606)forgejo-lib.sh, adopted inrehearsal-report.sh(e67d774)rehearsal-healer-test.shinto a repo with a differentREPO_SLUG(50ebeb5)sync-harness.sh/harness-sync.yml/harness-manifest/their test entirely; rewrotecheck-harness-drift.shfor the pull direction (FACTORY_REFpins the commit,FACTORY_MANIFESTlists the 79 vendored paths, byte-for-byte diff, no transform — the ownership-inversion bug class this ticket named, 2 of 13 old-manifest files arriving ownership-inverted including the drift checker itself, is now structurally impossible) (5312eac)b8c9778)Proof
.sandcastle/tests/*.shsuites green in ourcloud; all 38 green standalone inMatou/dev-factory(independently, no shared PATH)check-harness-drift.shlive-run against the realMatou/dev-factory@2a5f79a— OK, not just an offline fixturebash -nclean on every touched scriptMatou/dev-factory's own CI green on a real push (run 2,matou-workstation)Not done — scoped out, not forgotten
Follow-ups filed rather than rushed into this pass (each named the risk that kept it out):
Matou/dev-factory#1— prompt-skeleton templating/render pipeline (a live prompt reaching every future worker is too high-blast-radius to template blind)Matou/dev-factory#2—run-swarm.sh's 8-stage decomposition (topology move was load-bearing; the internal refactor is separable, lower risk done alone)Matou/dev-factory#3— host-state ownership (crontab/swarm.db/lock) move, ADR 0180 point 4 — coordinates with#577Matou/ourcloud#602— wirecheck-harness-drift.shintoci.yml/seam-smoke.sh(didn't touch the healer-verdict wiring blind in the same pass)#572(already filed, blocked on this)Advancing #571.
rehearsal-report.shdrifted - bdb42ff6’s token-leak fix must land in dev-factory (which still leaks) and ride back on a FACTORY_REF bump #1683