Jump to content

MindAttic.Orchestrator/MESH ARCHITECTURE

From MindAttic Docs
Revision as of 00:47, 3 December 2026 by Docs Sync (talk | contribs) (md2wiki: sync from MindAttic.Docs)

Mesh architecture: every machine a peer

Design record for epic M.ORCH-T2540, written under M.ORCH-T2543 (2026-12-02) and revised the same day with the owner's answers (M.ORCH-T2578, see "Owner decisions (2026-12-02)" at the end). The owner signs it off by approving the code tickets under M.ORCH-T2540. Nothing here is built until then.

Summary: every decision on one screen

  1. Every machine is a full Orchestrator. Each runs its own daemon, CLIs, gateway and dashboard, and can always work on its own. Joining the mesh adds abilities and takes none away. The rig never gives up anything.
  2. One shared database, no authority machine. The ticket database moves off the rig to a SQL Server on a Hetzner box, reached only over Tailscale and read/write from every machine. The mesh tables (claims, membership, published burn) live in it too. That database is the single serialised writer; every machine is a symmetric peer. Everything else stays machine-local. Nothing is shared between machines by copying databases.
  3. Claims are leases. A claim is an atomic conditional UPDATE in the shared database. It grants a ticket to exactly one (machine, CLI) with a lease that the claimant's daemon keeps renewing. If the lease lapses, the ticket comes back only after a grace period. Every close carries the lease's generation number, so a stale holder can never close or re-claim over a newer one.
  4. No failover, because there is no authority to lose. The rig can be off and the laptop still claims. The new single point of failure is the Hetzner box and the internet link to it. When the database is unreachable every peer stops new claims, keeps its running work, and reads tickets from a read-only SQLite mirror. Backups and a tested restore cover the box itself.
  5. Peers trust each other through a peer key, not the owner key. Each peer gets its own revocable key. The gateway seals it and uses it to mint renewing tokens, the same way machine connect handles the owner key today, so the link never lapses. This key covers the machine-to-machine gateway (watch, interact, start CLI). Database access is a separate SQL login per machine.
  6. Joining takes a one-time code. An existing peer shows a short code (orchestrator mesh invite). The new machine runs orchestrator mesh join <peer> <code>. The gateway also checks through Tailscale whois that the caller belongs to the owner's Tailscale user. Being on the tailnet is not enough to join.
  7. Interact works everywhere, and one machine holds the keyboard. Every wall surface (tile, phone card, pop-out) can type. Whoever typed last holds the keyboard. Another machine takes it once the holder has been idle for a short gap, or at once with "Take keyboard". Every viewer sees who is typing. The owner's own machines need no consent prompts. Member consent rules are unchanged.
  8. Pacing is per login across the whole cluster. Each machine publishes each login's burn and running subagents to the shared database. Every peer reads all of it and computes the same pace per login and the same split of the subagent allowance, by a deterministic rule. A machine that cannot reach the database falls back to a stricter local pace. No login passes its 5-hour or weekly cutoff, wherever its CLIs run.
  9. Placement, the end state, scores (machine × signed-in login) pairs. The score weighs login headroom (unused window that would otherwise expire is spent first), the machine's free RAM against one CLI's footprint, and repo readiness. Placement works until every login reaches its cutoffs, and never past them. It runs on every peer and takes its decision through the same atomic claim. Milestone 1 does not build this: each machine's own /allocate claims from the shared database, and pacing caps it.
  10. Git stays the arbiter for code. Each machine has its own checkouts on main and pushes with fetch, merge, push. The commit gate stays per checkout. Exactly-once claims keep two machines off one ticket. The committed data/orchestrator.db holds only the shared tables, and one machine at a time writes it under a lease held in the shared database.
  11. Version skew is guarded. The mesh protocol carries a version number. A peer on another protocol version can still watch and type, but cannot claim or pace until it is updated, and every dashboard says so.
  12. Migration is opt-in and leaves the old roles alone. Standalone acts as a mesh of one. The host and client roles and machine connect keep working for the VM case. Mesh peers appear as gateway remotes, so the Team Wall merges them without new plumbing.
  13. Milestone 1 is rig plus laptop working completely (definition in the Build plan). The placement scorer comes in milestone 2. The Hetzner database must exist first; its provisioning is an owner-assisted ops task.
  14. Every login on every machine, signed in by hand. All Team Premium seats and the Ultra login go on each machine. The owner signs each one in on each machine the first time. Credentials are never copied between machines.

a. Topology and the shared database

The decision. The mesh is N symmetric peers around one shared database. There is no authority machine. Every machine is a worker (runs CLIs) and a viewer (a dashboard showing every machine's CLIs). The shared database is the single serialised writer of:

  • the ticket database (MindAttic.Tickets). It moves off the rig to a SQL Server on a Hetzner box and every machine's tickets CLI reads and writes it there. This is "back on" a remote server: the Tickets server store already ran against a remote Azure SQL database (M.TIX-T342 skips CREATE DATABASE and honours the configured auth and timeouts, M.TIX-T344 made the SQLite mirror refresh incremental, M.TIX-T374 added the connect timeout and retry). That code path is reused as it is. Azure itself is decommissioned (MAT-T297) and is never used;
  • claims: today NamedClaim.Claim does its check and write as one step under the local assignments lock (src/MindAttic.Orchestrator.Core/Scheduling/NamedClaim.cs:24-28). In the mesh the same step is one atomic conditional UPDATE (or one short transaction) on a claims table in the shared database (f gives the statements);
  • membership: who is in the mesh, their pins and key fingerprints, and each machine's last-seen time;
  • published burn: each machine's per-login meter reading, tokens per minute and running subagents, which every peer reads to pace (d).

What moves and what stays. Only what must be shared goes to the Hetzner server:

  • Shared: the ticket database; the three new mesh tables (mesh_claims, mesh_members, mesh_burn); and the organization tables members, organizations and org_members, which are small and must read the same on every machine (M.ORCH-T670, M.ORCH-T655; defined at OrchestratorDb.cs:456, :476, :482). The mesh tables sit in their own database on the same instance as the tickets, so a ticket close and its claim check can share one transaction (one SQL Server instance supports a transaction across its databases; a test proves it, T2565).
  • Local, unchanged: everything else in the Orchestrator's store of record: accounts, usage_samples, pace_ledger, usage_history, ticket_costs, settings, assignments (this machine's own dispatch queue), state, leases (process locks, one row naming the holding pid; OrchestratorDb.cs:369, which "mean nothing on another machine"), gate_events, the subagent tables, session and grant tables, plus the CLIs, TermHost sessions, rl-status.json per Claude home (src/MindAttic.Orchestrator.Core/Sessions/AccountDirs.cs:25) and machine.json. The mesh mesh_claims table is new and is not the local assignments or leases table.

The Orchestrator's store already runs against any SQL Server by connection string (M.ORCH-T716 handles a bad one; the store ran on Azure SQL under M.ORCH-T1748), but it is all-or-nothing per database today. Splitting it, so the shared tables use the Hetzner connection and the rest use the local store, is new work (T2563).

Every peer is symmetric. Any machine can be off, asleep or lost and the others claim, pace and place as before. The first mesh invite no longer founds an authority. It only starts the membership list.

The new single point of failure is the Hetzner box and the internet link to it. If either is down, no machine can claim a ticket or write the ticket database. f says what each machine still does then, and how the box is backed up.

Recommended host (the owner confirms). A Hetzner Cloud Linux server in a US location (Ashburn or Hillsboro, to keep latency down from the owner's machines), running SQL Server Express for Linux: free, no Windows licence, about $5 to $15 a month at the sizes that fit. The owner rejected a Windows server at about $257 a month as too costly, so Windows is not proposed. Express caps each database at 10 GB of data (the log is not counted). On 2026-12-02 on the rig's localhost the data in MindAttic.Tickets is 262 MB used and in MindAttic.Orchestrator 33 MB (read-only query), so the cap is not a near-term limit; the shared set is smaller than the Tickets figure plus a few small tables. Two other Express limits are fine here: about 1.4 GB of buffer memory and one socket's worth of cores. The localhost transaction logs are 3.0 GB and 1.8 GB on disk. The new instance gets a deliberate recovery model and log backups so its log does not grow like that.

Reaching it. SQL Server listens only on the box's Tailscale 100.x address (mssql-conf network.ipaddress), the host firewall allows the port only on the tailscale0 interface, and the Hetzner cloud firewall has no public rule for it. A Tailscale ACL limits it to the owner's machines. Connections use TLS (a tailscale cert certificate for the box's tailnet name) and SQL authentication with one login per machine, each with rights on the shared databases only. mesh remove drops that machine's login. Each machine keeps its connection string sealed for its Windows user, as the gateway keys are today (GatewayRemote.cs:34). The box never has a public SQL port.

Why. The owner wants the ticket database read/write from every computer, and the rig is not always on. A shared database gives that without a second protocol: atomicity lives in the database, which already does it correctly, and the claim check-and-write is already one step. Exactly-once claims follow from one serialised writer, which is the simplest thing that can be proven correct, and the writer is a database instead of a machine, so no peer has to be elected. It also reuses a store mode that already ran remotely.

Rejected alternatives.

  • Fully peer-to-peer with distributed locks. Each claim would need consensus across machines that sleep and roam. Two-node lock protocols cannot tell "peer asleep" from "network split", so they either block or double-claim. Raft or Paxos inside the Orchestrator is a large, permanent cost for a mesh of two to four machines.
  • Each machine claims locally and syncs databases. Two machines would claim one ticket during the sync gap, and merging two SQL stores is a problem class of its own. This is the bug the epic exists to prevent.
  • One machine as the authority (the rig), with peers asking it through the gateway. This was the first draft. It makes the rig a single point of failure that is often off, forces a failover design for two machines (which cannot vote), and makes every tickets call from a peer a gateway round trip. The owner's choice of a shared database replaces it.
  • The whole Orchestrator store on the Hetzner server. It would put per-machine state (usage samples, process leases, this machine's dispatch queue) on the wire for no gain, and make every daemon tick depend on the internet link.
  • A Windows server on Hetzner. About $257 a month. Rejected by the owner as too costly.
  • Keep host/client. It turns the second machine into a viewer and stops its daemon (src/MindAttic.Orchestrator.Core/Setup/MachineSetup.cs:56-63, :453), which is the opposite of the goal.

Moved out of Rejected (2026-12-02): SQL Server opened to the tailnet so peers write it directly. The first draft rejected this for three reasons, and the owner's choice answers each:

  • "Peers could claim without the one lock." The lock is now the database. A claim is one conditional UPDATE, so atomicity lives in the DB and no peer can bypass it. There is no second path.
  • "A database port would be exposed." It is exposed only on the tailnet: bound to the 100.x address, refused on the public interface by two firewalls, TLS on, a SQL login per machine, a Tailscale ACL on top. It is never on the public internet.
  • "It ties every peer to SQL Server, which blocks a Linux peer (M.ORCH-T2538)." SQL Server client libraries run on Linux (Microsoft.Data.SqlClient is cross-platform, and the Tickets and Orchestrator stores already use it), so a future Linux peer connects the same way.

b. Identity, trust and auth over Tailscale

The decision.

  • A peer key of its own. At admission each side mints a random peer key for the other. The receiving machine stores it sealed for its Windows user, as GatewayRemote.SealedOwnerKey is today (src/MindAttic.Orchestrator.Core/Settings/GatewayRemote.cs:34). GatewayClient.MintIfDueAsync gains a third key kind next to the owner and member keys (src/MindAttic.Orchestrator.Core/Sessions/GatewayClient.cs:140-160). It mints a 60-minute interact token whenever fewer than 10 minutes remain, so the link renews itself and never lapses. A peer token's subject is the owner, with scope peer. That grants list, watch, interact and start-CLI on that machine. Claims, pacing, membership and tickets no longer go through the gateway, because they live in the shared database (a). It does not grant /branches (the host model's work-branch queue, GatewayApp.cs:240) or the owner-key-only administration.
  • Admission by one-time code plus Tailscale identity. orchestrator mesh invite on any current peer prints a code: single use, 128 bits written as words, lasting 10 minutes (a Vault setting). orchestrator mesh join <peer> <code> on the new machine connects over Tailscale. The inviting gateway asks the local Tailscale daemon's whois API who the caller is, and accepts only a node owned by the same Tailscale user as itself. Then both sides exchange certificate pins and peer keys over that channel. The code authenticates the pins, so neither side trusts on first use. The new peer is recorded in mesh_members in the shared database, and every peer reads it from there. The new machine's SQL login for the shared database is made by the owner with the admin connection (kept only on the owner's own machine), because a peer must not be able to create logins.
  • Gateway exposure. On a mesh peer the gateway binds to the machine's Tailscale 100.x address (plus loopback), never to every network. The default for non-mesh machines stays 127.0.0.1 (src/MindAttic.Orchestrator.Core/Settings/GatewaySettings.cs:14).
  • Revocation. orchestrator mesh remove <peer> on any peer: the peer's mesh_members row is deleted, every peer forgets its key, and the owner drops its SQL login. A lost laptop is cut off without rotating the rig's owner key.
  • Claude logins stay per machine. They remain DPAPI-sealed per Windows user per machine and signed in with orchestrator login (docs/REMOTE_HOST.md:165). The mesh never moves credentials. M.ORCH-T2562 confirms this. Every Team Premium seat and the Ultra login are signed in on every machine, each by the owner by hand the first time on that machine (see the owner decisions at the end).

Why. A 60-minute --token remote (src/MindAttic.Orchestrator.Gateway/GatewayOptions.cs:31) would drop every link within an hour. The self-renewing pattern already exists and is proven for the owner and member keys. A key per peer makes revocation local and leaves the owner key's power where it is.

Rejected alternatives.

  • Share the owner key with peers. Copies of the owner key would live on every laptop. It unlocks /tickets, /branches and admin on every machine, and revoking one lost machine would mean rotating it everywhere.
  • Tailnet membership alone. Anything ever added to the tailnet (a phone, a shared node, a compromised device) could drive CLIs that hold commit rights. That would be an open door.
  • An invite link or file. A link has to be carried between machines, usually over channels less private than the screen. A code read off one screen and typed into the other covers the same need.
  • Tailscale whois as the only check. Whois tells who owns a node, not that the owner meant to admit it. Used as a second factor it costs nothing.

c. Interact semantics

The decision.

  • Every surface can type. The inline tile stream and the phone card stop being watch-only (src/MindAttic.Orchestrator.Wpf/TeamWallWindow.cs:191 connects with watch: true, :427 pops out with interact: false). Each opens with interact when the gateway lists the session with access=interact, which every session does for a peer token.
  • One keyboard per CLI. TermHost tracks a keyboard holder per session. A viewer's keystrokes are delivered when that viewer holds the keyboard, or when the holder has been idle for InputHandoffSeconds (a Vault setting, default 2). The keyboard then passes to the new typist. Keystrokes from a non-holder inside that window are dropped. Every viewer's frame shows "Typing: RIG" (the holder's machine name). "Take keyboard" takes it at once, and the previous holder sees "Keyboard taken by LAPTOP". Resize follows the keyboard holder.
  • No consent between the owner's own peers. HubPolicy and TermHubPolicy govern org members' CLIs and Windows accounts on a host (src/MindAttic.Orchestrator.Core/Setup/HubPolicy.cs:8, src/MindAttic.Orchestrator.Term/TermHubPolicy.cs:5). A peer token's subject is the owner, so those rules never fire for it. Member grants and consents work unchanged on every peer.

Why. It is one person on several screens, so the hazard is interleaved keystrokes, not someone else typing. Last-typist-wins with an idle gap matches how the owner moves between machines, and nobody has to remember a "take control" step.

Rejected alternatives.

  • Free-for-all (every viewer's input delivered). Two half-typed lines interleave into one prompt sent to an agent with commit rights.
  • A strict lock released by hand. The owner walks away from the rig and finds the laptop locked out.
  • Watch-only tiles plus pop-out to type. This is today's behaviour, and the owner asked for the opposite.

d. Cluster-wide pacing

What is per machine today. The level of a window is already account-wide. ClaudeMeterProbe asks Claude's own usage endpoint, the one /usage shows (src/MindAttic.Orchestrator.Core/Budget/ClaudeMeterProbe.cs, class summary), so spending on another machine shows up there. Three things are only local:

  • the burn rate estimated from this machine's transcripts;
  • the subagent allowance computed from this machine's subagent marks (src/MindAttic.Orchestrator.Core/Budget/AccountPacer.cs:18-22);
  • the time between meter readings.

With one login on two machines, each machine grants the full allowance and predicts from half the burn. Their combined spend can run past the cutoff between readings.

The decision.

  • Every peer's daemon publishes, for each login it runs, one row in mesh_burn: the newest meter reading with its timestamp, its tokens per minute and its running subagents. It does this on its existing pace tick, and it is M.ORCH-T2570.
  • Every peer computes the same pace (M.ORCH-T2571). Each tick it reads all mesh_burn rows in one query and runs the existing math: Pacer and, for the Ultra login that has no 5-hour window, Pacer.WeeklyPace (src/MindAttic.Orchestrator.Core/Budget/Pacer.cs:518, called at AccountPacer.cs:275). The inputs are the newest meter reading from any machine and the sum of burn and subagents across machines. A row older than MeshPaceStaleSeconds (a Vault setting) is ignored, so a machine that went quiet stops counting.
  • The split is deterministic, so peers agree without talking. It is a pure function of the rows read: machines are ordered by machine id, each gets a share of the subagent allowance proportional to its demand using whole numbers, and the leftover units go one at a time to the largest remainders, ties broken by machine id. No clock, no random value and no peer-specific input enters it. The same rows always give the same shares, on any machine. Peers read at slightly different instants, so for one tick two peers may see different rows. They then apply their own share only, and the margin below absorbs that skew.
  • Each peer writes its own share into that login's rl-status.json, so the pace gates and hooks are unchanged.
  • Cutoffs stay exactly as configured: 98% of the 5-hour window and 90% of the week by default, per member through /org limit. They are enforced on the cluster sum.
  • If the shared database is unreachable, a peer paces each login locally with the allowance divided by the number of machines last seen running that login, and stops new work at the cutoff minus MeshOfflinePaceMarginPercent (a Vault setting, default 3 points). It does this until it has read the database again within MeshPaceStaleSeconds.
  • The dashboard's usage shows each login's cluster total and every machine's share of it (M.ORCH-T2572).

Why. It reuses the pacer whole and changes only its inputs. Because the meter is already account-wide, the only new data is burn and subagent counts, which are small and summable. Computing on every peer removes the machine that would have had to answer. The offline fallback errs toward stopping early, never toward passing a cutoff.

Rejected alternatives.

  • Each machine paces alone with a fixed split (for example 50/50). That wastes the window whenever one machine is idle.
  • Pin each login to one machine. That defeats "any CLI on any login on any machine".
  • One peer computes the pace and the others ask it. That is the authority again, with the failover problem.
  • Each machine reads the meter more often. It narrows the overshoot but cannot close it. Burn between readings is still invisible to the other machine, and the endpoint is not built for hammering.

e. Placement and scheduling

The decision (end state). Placement runs on every peer and picks the best (machine, login) pair for each approved, unclaimed ticket. Because the claim is atomic, two peers choosing the same ticket cannot both win, and the loser picks the next. (A pair is chosen from the shared mesh_burn and mesh_members rows, so peers see the same machines.) Candidate pairs are the logins signed in on that machine. A pair is eligible only when:

  • the login's cluster pace (d) allows new work,
  • the machine's free RAM, after the MemoryGuard's own floor (src/MindAttic.Orchestrator.Core/Activity/MemoryGuard.cs:69), covers one more CLI tree at CliFootprintGb (a Vault setting, default 1.3; measured at about 1.24 GB on 2026-11-17),
  • the machine is on the current protocol version, and
  • the machine has the repo's checkout, or can clone it.

Eligible pairs are scored, most important first:

  1. login headroom that expires soonest. Unused 5-hour or weekly headroom that resets sooner is spent first ("use it or lose it");
  2. machine RAM and CPU headroom;
  3. repo readiness, which prefers a machine already working in that repo's checkout.

The placing peer then tells the chosen machine, through that machine's gateway, to start the CLI on that login and claim the ticket (M.ORCH-T2573 to M.ORCH-T2575). Placement keeps going until every login sits at its cutoffs or no machine has room (M.ORCH-T2576). Logins and limits disappear from the owner's view. He approves tickets and the cluster spends what it has, never more.

Milestone 1 builds none of the scorer. Each machine runs /allocate as today. Every claim is an atomic update in the shared database, so it is exactly-once, and cluster pacing caps every login. That already makes the rig and the laptop "code tickets until thresholds".

Why. Placement needs claims, leases, cluster pacing and machine headroom to be right first. Building the scorer on milestone 1's foundations keeps every rule in one place: the shared database's claim.

Rejected alternatives.

  • Work-stealing, where each machine grabs when free. That is milestone 1's behaviour and it is correct, but it cannot prefer an expiring window or keep RAM-poor machines (the 16 GB laptop holds about 6 CLIs) from overcommitting.
  • A login pinned per machine. See d.

f. Failure modes

The decision.

  • Claim leases. A claim is a row in mesh_claims with machine, CLI, session, login, expiry and a lease generation. All times are the database's own clock (SYSUTCDATETIME()), so machine clocks never matter.
    • Grant: UPDATE mesh_claims SET holder = @m, generation = generation + 1, expires = now + lease WHERE ticket = @t AND (holder IS NULL OR expires + grace < now). One row affected means granted. Zero means someone else holds it.
    • Renew: the same UPDATE with WHERE ticket = @t AND holder = @m AND generation = @g. Zero rows means the lease was lost.
    • Close: the ticket status update and a check of holder = @m AND generation = @g run in one transaction, so a stale generation cannot close. The claimant's daemon renews every ClaimLeaseMinutes / 3 (ClaimLeaseMinutes is a Vault setting, default 10). When renewals stop, the claim becomes orphaned, and every dashboard shows it as "LAPTOP unreachable since 14:02". The ticket returns to the queue only after a further ClaimOrphanGraceMinutes (a Vault setting, default 30). A sleeping laptop often still holds uncommitted work in its own checkout, and a short grace would double the work.
  • The sleeper returns. If its lease is still the newest generation, it renews and carries on. If the ticket was re-granted meanwhile, its daemon tells that CLI "this ticket moved to RIG; commit or drop your work". Its close is refused, because a stale generation is fenced, and it can still push commits. Git sorts out any overlap at merge.
  • A CLI dies mid-ticket. Same as today (NamedClaim.cs, class summary): the claim is released when the CLI is gone. The difference is that the claimant's daemon releases the row in the shared database.
  • Lost peer on every dashboard (M.ORCH-T2567). Its tiles grey out, they are labelled with the last time it was seen, and they come back without a manual refresh.
  • The rig goes down. Nothing special happens. The rig held no authority, so the other machines keep claiming, pacing and placing. Its claims orphan and requeue by the lease rules above, like any lost peer.
  • The Hetzner database is unreachable (the box is down or the internet link is). This is the one outage that stops the mesh, and it is the single point of failure this design accepts. Every peer then:
    After the outage. A peer that finds the database back renews its own claims first, then sets a recovered_at value in the database. No claim is requeued until ClaimOrphanGraceMinutes after recovered_at, because during the outage no holder could renew and silence then does not mean the holder is dead. This is one rule for T2565 and it has its own test.
    • grants no new claims and files or closes no tickets (the writes wait or fail clearly; nothing is queued as if it had happened);
    • keeps every running CLI, keeps interact among the reachable machines, and keeps committing and pushing code, which is git and does not need the database;
    • reads tickets from the local read-only SQLite mirror that the Tickets server mode already keeps (M.TIX-T344's incremental mirror; tickets db server shows each table's rows in both);
    • paces on the offline fallback (d).
  • Backups and restore (M.ORCH-T2566). The Hetzner instance gets a nightly full backup and frequent log backups to its own disk, and a copy pulled to the rig over Tailscale, so the box's disk is never the only copy. Hetzner's paid server backups are an optional second layer. The existing tickets db sync dump (data/Tickets.sql in the Tickets repo, committed to git) remains a third copy. A restore is tested once before the cutover and written in a runbook: provision a fresh Linux box, install SQL Server Express, restore the latest backup (SQL Server backups restore across Windows and Linux), start Tailscale, bind the 100.x address, and update each machine's connection string. Automatic failover of the database is not built; with one small box the recovery is a restore, in minutes to hours.
  • Version skew (M.ORCH-T2568). /health already returns the build version (GatewayApp.cs:156). The mesh adds an integer protocol version. A peer on a different protocol keeps watch and interact but is refused claims, pacing and placement, and every dashboard shows "LAPTOP needs update".
  • Many machines on main (M.ORCH-T2569). Each machine works in its own checkouts on main, with no branches and no worktrees. The commit gate stays per checkout (mindattic-agent-standard/shared/hooks/commit-gate.py, header): it guards agents sharing one checkout, and no checkout is shared across machines. Across machines, exactly-once claims keep two agents off one ticket, and the existing landing rule (fetch, merge, push, retry when rejected) handles different tickets in one repo. The gate's "close only from the claim's holder" check asks mesh_claims in the shared database instead of the local store. data/orchestrator.db commit rule (revised). Git carries it between machines (docs/REMOTE_HOST.md:8-9), and the old rule "only the authority commits it" has no authority to name. Two machines committing a binary file would conflict, and most of its tables are per machine (usage, leases) and mean nothing on another machine (OrchestratorDb.cs:364-367). The new rule: the committed file and its dump hold the shared tables only (organization tables and mesh membership). The per-machine tables are no longer committed. One machine at a time writes it, by taking a short dump_commit lease row in the shared database first (the same conditional UPDATE as a claim), then fetch, merge, push as usual. A peer that does not hold the lease never stages the file. tickets db sync (the Tickets dump) takes the same lease. Dropping the per-machine tables from the commit is a change to the dump, so it is a task of its own (T2569).

Why. Every failure falls back to doing less, never to doing something twice. The one serialised writer is a database that is backed up and restorable, instead of a machine that has to be elected.

Rejected alternatives.

  • A short lease with immediate requeue. Every laptop lid-close would start the ticket again on the rig.
  • Automatic or manual failover between machines. There is no authority machine to fail over, so the problem is gone. Failover of the database itself (a second box with replication) is more than one small box's worth of cost and complexity for one owner. A tested restore covers it.
  • Peers claim locally while the database is unreachable and reconcile later. Reconciliation discovers the double claim only after both machines have done the work.

g. Migration

The decision.

  • Standalone is a mesh of one. Nothing changes on a machine until mesh invite or mesh join runs there. The rig keeps its daemon, CLIs and dashboard throughout, so it never loses local capability. The ticket database is the exception, and it moves first (next bullet).
  • The ticket database migrates once, from the rig. After the Hetzner instance exists (the provisioning task), tickets db server migrate --server <the box's tailnet address> --database MindAttic.Tickets (or --connection) on the rig copies the rig's current database across, checks every table's row count, and switches the rig to it. Its flags are the ones tickets db server migrate --help lists today. tickets db server back undoes it. Use --replace only on that first copy.
  • Every other machine points at it without copying. migrate copies data and would overwrite, so a second machine does not run it. The tickets CLI picks its server from MINDATTIC_TICKETS_SQLSERVER or database.json in %APPDATA%\MindAttic\MindAttic.Tickets (TicketsServer.cs:21, :29, :57-58), so mesh join writes the per-machine connection string there (the machine's own SQL login, sealed). Each CLI keeps its local SQLite mirror for reads.
  • The host and client roles stay as they are (src/MindAttic.Orchestrator.Core/Setup/MachineRole.cs:7-18, MachineTopology.cs:39) for the remote-VM case in docs/REMOTE_HOST.md. A machine in the client role cannot join a mesh, because the client role stops its daemon. It must first go back to standalone. MachineRole.HostRemoteName (MachineRole.cs:32, one host) is untouched. Mesh peers are a separate list.
  • Mesh peers are gateway remotes with kind peer. They are stored in GatewaySettings.Remotes with a sealed peer key. TeamWallWindow.RefreshAsync (TeamWallWindow.cs:209), which merges LocalSource (:239) with every remote, shows them with no new plumbing. Existing gateway remote add remotes keep working (M.ORCH-T936's Team Wall).
  • Membership has two parts. The shared list (machine names, last seen, protocol version, key fingerprints) is mesh_members in the shared database. What is private to one machine, its sealed peer keys, certificate pins and SQL connection string, lives next to machine.json in a per-machine mesh.json under %LOCALAPPDATA%. Neither is in orchestrator.db (M.ORCH-T2563).
  • The tickets CLI on every machine talks to the shared server directly (M.ORCH-T2564 changes: no gateway forwarding), so agents keep typing tickets ... unchanged. The gateway /tickets route and the machine connect shim stay for the remote-VM case.
  • Once milestone 1 is accepted, docs/REMOTE_HOST.md gains a pointer here. The host and client roles are retired only by a later ticket, and only if the owner wants it.

Why. Nothing existing breaks: every new path is opt-in and additive, and reusing gateway remotes means the wall, TermViewer and RemoteViewer work unchanged.

Rejected alternatives.

  • Build the mesh on machine connect. It forces the client role and hands off the daemon (MachineSetup.cs:88-114).
  • Convert the rig to the host role. The host role is meant for a remote VM, and it would make the laptop a client.

h. Verification

Agents never run test suites unasked. The owner runs /test on the repo after each feature lands. Each feature adds NUnit tests:

Feature NUnit tests it adds
Type into a peer's CLI peer-key minting renews before expiry; inline tile and phone card open with interact when access=interact; keyboard holder handoff after InputHandoffSeconds, drop of a non-holder's keys, "Take keyboard"
Join with one command invite code single use and expiry; whois owner mismatch refused; pin and key exchange both ways; remove revokes on every peer
One shared database claim on two peers at once (a race test against SQL Server) grants exactly one; lease renewal, orphaning, grace requeue; stale generation close refused; no requeue until the grace after recovered_at; ticket close and claim check in one cross-database transaction; protocol skew refuses claims but allows interact; shared tables only in the committed dump, one dump_commit holder at a time
Cluster-wide pacing sum of two machines' burn gates at 98% / 90%; the same rows give the same split on any machine, with remainder ties broken by machine id; stale rows ignored; offline fallback margin when the database is unreachable; Ultra weekly-only path
Placement eligibility (RAM floor, pace, version, checkout); score order, with an expiring window first; stop at thresholds

Two-machine acceptance (M.ORCH-T2577), run by the owner on the rig and the laptop:

  1. Fresh laptop with Tailscale: mesh invite on the rig, mesh join on the laptop. Both walls show both machines' CLIs.
  2. Type into a laptop CLI from the rig, and a rig CLI from the laptop. Typing on both at once shows a single holder.
  3. Start /allocate on both machines in one repo. Every ticket is claimed once, and both machines land commits on main.
  4. Run one login on both machines near its 5-hour cutoff. The combined spend stops at 98% (Ultra: the weekly line).
  5. Close the laptop lid mid-ticket. The rig shows it as orphaned, and the ticket is not re-granted before the grace period ends. Reopen the lid: the laptop renews and finishes.
  6. Stop the rig's Orchestrator. The laptop keeps claiming and working. Restart the rig and it rejoins.
  7. Cut the laptop's route to the Hetzner box (Tailscale down). The laptop keeps its CLIs, refuses new claims, and reads tickets from its mirror. Restore the route: it renews its claims and resumes, and nothing was requeued meanwhile.
  8. The rig alone (laptop off) works as before, with tickets read and written on the Hetzner database.
  9. Restore drill: restore the latest backup to a scratch instance and compare row counts with the live database.

Build plan

Milestone 1, "rig and laptop work completely": both machines remain standalone-capable, each types into the other's CLIs, claims are exactly-once with leases, pacing is correct across both, a lost peer shows on every dashboard, skew is guarded and both commit to main safely. Tickets and claims live in the shared Hetzner database, so the provisioning and migration come first. There is no authority machine and no failover to build, and no scorer.

Decision Feature / story Tasks Milestone
c, b (link) Type into a peer's CLI M.ORCH-T2544 (under M.ORCH-T2539) T2556 self-renewing peer link, T2557 interact from every wall surface, T2558 input ownership 1
b Plug a machine into the mesh M.ORCH-T2546 (under M.ORCH-T2545) T2559 serve this machine, T2560 join both ways, T2561 find peers, T2562 confirm per-machine logins 1
a Provision the shared database (owner-assisted ops, new ticket, see below) Hetzner Cloud Linux in Ashburn or Hillsboro, SQL Server Express, Tailscale-only bind and firewalls, per-machine SQL logins, backups 1, first
a Exactly-once claims M.ORCH-T2548 (under M.ORCH-T2547) T2563 membership record and split store (shared tables on the Hetzner server, rest local), T2564 tickets CLI on every machine points at the shared server, T2565 claim leases as atomic conditional UPDATEs, with the post-outage rule 1
f The mesh survives a lost machine M.ORCH-T2549 T2567 lost peer, T2568 version skew, T2569 many machines on main (and the revised data/orchestrator.db rule) 1
f (same story) T2566 database unreachable and backup/restore 1 (reduced)
d No login over its limits M.ORCH-T2551 (under M.ORCH-T2550) T2570 publish login burn, T2571 pace on cluster burn, T2572 show cluster usage 1
e Tickets go to the best machine and login M.ORCH-T2553 (under M.ORCH-T2552) T2573 machine headroom, T2574 scorer, T2575 dispatch, T2576 work until thresholds 2
h Rig and laptop work as one M.ORCH-T2555 (under M.ORCH-T2554) T2577 acceptance checklist 1 (checklist steps 1-9), extended in 2

Tickets this design changes.

  • New: provision the shared ticket database. Owner-assisted ops item: Hetzner Cloud Linux server in a US location, SQL Server Express for Linux, Tailscale, mssql-conf bound to the 100.x address, firewalls, TLS, a SQL login per machine, nightly and log backups with a copy pulled to the rig, a documented restore. The owner confirms the host size and location and pays; an agent cannot do it alone. Everything else in milestone 1 waits on it.
  • M.ORCH-T2563. Gains the split store (which tables use the shared connection) next to the membership record.
  • M.ORCH-T2564. Was "tickets CLI forwards to the coordinator through the gateway". Now: the tickets CLI on every machine points at the shared server (MINDATTIC_TICKETS_SQLSERVER or database.json), plus the one-time tickets db server migrate on the rig. No gateway forwarding.
  • M.ORCH-T2565. Claims are atomic conditional UPDATEs on the database clock, plus the recovered_at rule.
  • M.ORCH-T2566 Authority failover. Shrinks to: behaviour when the Hetzner database is unreachable (no new claims, running work continues, read-only SQLite mirror) and database backups and restore. No mesh take-authority, no epochs. It stays in milestone 1 in reduced form.
  • M.ORCH-T2569. Also carries the revised data/orchestrator.db commit rule (shared tables only, one holder).
  • M.ORCH-T2570 and M.ORCH-T2571. Publish to and read from mesh_burn; every peer computes the same deterministic pace and split.
  • M.ORCH-T2573 to M.ORCH-T2576. Milestone 2. Milestone 1 relies on per-machine /allocate claiming from the shared database.
  • MAT-T530 "Add the laptop as a gateway remote" (Agency). Superseded by M.ORCH-T2560, which does the same with a renewing peer key. Its status is unchanged by this revision.

Built so far

  • Membership record (M.ORCH-T2563, part). Mesh/MeshConfig.cs reads this machine's mesh connection and name from %APPDATA%\MindAttic\Mesh\database.json (SqlServer, Machine; MINDATTIC_MESH_SQLSERVER overrides the connection). No file means a mesh of one: every claim path behaves exactly as before. mesh_members gets one row per machine (protocol, build, last seen) from the daemon's lease tick. Not yet done: moving the organization tables (members, organizations, org_members) to the shared connection, which needs the Orchestrator store to open those three tables on a second connection.
  • Claim leases (M.ORCH-T2565). Mesh/MeshClaims.cs creates mesh_claims, mesh_members and mesh_state in the MindAttic.Mesh database and grants, renews, releases and fences claims with the statements in f, on the database clock. orchestrator next --claim and orchestrator claim record the local claim first (under the assignments lock, which settles CLIs on one machine), then ask the mesh; refused there, or with the database unreachable, the local claim is undone and the ticket isn't handed out. The daemon (MeshLeases.Keeper) renews every ClaimLeaseMinutes / 3, releases rows no local claim stands behind, claims local claims made on paths that don't ask the mesh, and sets recovered_at after an outage once its own claims are renewed. MeshClaims.MayClose is the fenced close check. Not yet done: the close itself in the Tickets CLI running in one cross-database transaction with that check, and the commit gate (mindattic-agent-standard commit-gate.py, which reads ticket_work) asking mesh_claims.
  • Off the tick, and the moved-ticket message (M.ORCH-T2581, part). The daemon's lease pass runs on a background task: the tick only starts a pass when one is due and none is running, and logs what finished passes left, so an unreachable shared database never stalls the tick. Every mesh connection waits at most MeshConnectTimeoutSeconds (a Vault setting, default 5) to connect. When a local claim's ticket is held by another machine, the claiming CLI is told in its session, once per grant, through the same nudge file the other daemon messages use (nudge-<pid>-mesh-moved.txt): "this ticket moved to LAPTOP; commit or drop your work".
  • Pull before work (M.ORCH-T2569, part). Every ticket handed out by next --claim or claim has its checkout brought up to date first (MeshLeases.SyncCheckout): fetch, fast-forward, or on a clean tree with local commits a merge (aborted on conflict). Uncommitted work is never touched. The dump_commit lease is not built yet.

Owner decisions (2026-12-02)

  1. The ticket database goes back on Hetzner, read/write from every computer. In the owner's words: "Will need to put Tickets db back on Hetzner so it's read/write from every computer." Recorded as a shared SQL Server on a Hetzner box, reached only over Tailscale (the 100.x address, never the public internet). Consequences are worked through in a, d, f and g: the shared database, not the rig, is the single serialised writer for tickets and the mesh tables; there is no authority machine; pacing is computed identically on every peer; the Hetzner box and the link to it are the new single point of failure, covered by "database unreachable" behaviour and by backups with a tested restore. The owner rejected a Windows server at about $257 a month, so the recommended host is a Linux Cloud server with SQL Server Express (a, "Recommended host"). That host is a recommendation the owner confirms, not yet a decision.
  2. Logins: every login on every machine. All Team Premium seats and the Ultra login go on each machine. The owner signs each one in by hand on each machine the first time (orchestrator login). Credentials are never copied between machines, because copying Claude OAuth files risks refresh-token rotation signing the other machine out. The org member list comes along by itself once the organization tables are in the shared set. It is stored in the Orchestrator database, not in a file: the members table (M.ORCH-T670: email, name, role, tier, status), plus organizations and org_members (M.ORCH-T655), at OrchestratorDb.cs:456, :476 and :482. They are in the shared set (a), so a member added on any machine shows on every machine. A member whose login is not signed in on a machine still gets a Sign in tab there, as M.ORCH-T670 already does. The sign-in itself is per machine (the accounts table is local).
  3. Defaults kept as starting values, tuned once it runs. Claim lease 10 minutes (ClaimLeaseMinutes), orphan grace 30 minutes (ClaimOrphanGraceMinutes), keyboard handoff 2 seconds (InputHandoffSeconds), offline pace margin 3 points (MeshOfflinePaceMarginPercent). All are Vault settings.

New open questions

  1. Confirm the Hetzner host. Cloud Linux in Ashburn or Hillsboro, SQL Server Express, about $5 to $15 a month: which location, and which server size? Check the current price list when ordering.
  2. Backup destination. Is a nightly copy pulled to the rig over Tailscale enough, or should a second off-site copy (for example an owner-held cloud drive) be added? Hetzner's paid server backups are optional on top.
  3. Outage tolerance. The design stops new claims everywhere when the box is unreachable. Is that acceptable for an outage of an hour or more, or does the owner want a warm second box? Not planned, because it costs a second server and replication.
From MindAttic.Orchestrator/docs/MESH_ARCHITECTURE.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.