Jump to content

MindAttic.Orchestrator/MESH OPERATIONS

From MindAttic Docs

Mesh operations: operator runbook

This is the runbook for the person who owns the mesh. The user guide is The Orchestrator mesh; the design record is Mesh architecture. This repo is public: this page names no address, password, key or connection string. The shared server is mindattic-01, found by its tailnet name.

The shared server

mindattic-01 is the Hetzner Cloud Linux box in Falkenstein that Gadfly already runs on. The owner chose to share it rather than rent a second one (2026-12-02: "pick the same location that gadfly is running off; share a server").

  • It runs SQL Server with two databases for the mesh: MindAttic.Tickets (every ticket) and MindAttic.Mesh (claims, members, published burn, logins).
  • SQL Server answers on the tailnet only, on port 1433. The Hetzner cloud firewall has no public rule for it, and connections use TLS. There is no route to it from the public internet.
  • The Orchestrator's own store on each PC stays local SQLite. Only the ticket tables and the mesh tables are shared.
  • The server is the one thing the mesh cannot do without. While it is down, no PC can claim a ticket. See "Outage behaviour".

Per-machine SQL logins

Each PC connects as its own login, mesh_<machine>, where <machine> is the PC's computer name in lower case with every character other than a to z and 0 to 9 turned into an underscore.

  • setup-node.ps1 makes the login through tailscale ssh to the server. Tailscale's browser check is the owner's approval. The login gets data rights only (M.ORCH-T2604): db_datareader, db_datawriter and EXECUTE in MindAttic.Mesh (and no writes to mesh_schema), the same in MindAttic.Tickets plus VIEW DEFINITION and VIEW CHANGE TRACKING on dbo. Never db_owner: no node can change the schema or drop the row-ownership triggers.
  • The schema is the owner's step, for both shared databases. After the apps are installed, setup runs orchestrator mesh schema --check and tickets db schema --check with this PC's own login (exit 0 current, 2 when the step is due, 3 when the database doesn't answer). For each database whose schema is behind this build, or whose login is still db_owner (made before M.ORCH-T2604), setup takes orchestrator mesh schema --print or tickets db schema --print (M.TIX-T739: the whole Tickets schema, its guard triggers, system-versioned tables and change tracking included, as idempotent T-SQL), and sends it with the login's rights to the server through tailscale ssh (the same browser check, temp file and sqlcmd -i as the login itself), where they run as the server's administrator; that also drops db_owner from the login. Run setup-node.ps1 again on each PC to take its old login down, and after an Orchestrator or Tickets update whose schema changed: until then that PC's mesh features, and every tickets command (the schema check runs when the database opens), stop with a message naming setup-node.ps1 rather than trying DDL.
  • tickets repos rename, tickets repos recode, tickets ticket reassign and tickets ticket correct lift the Tickets guard triggers or foreign-key checks, which is DDL. On the shared database a node login refuses them with the same message naming setup-node.ps1; run them as a login that owns the database (the server's administrator).
  • The rig's login keeps dbcreator (given by hand, never by setup) for the throwaway MindAttic.Mesh.Test.<guid> and MindAttic.Tickets.Test-* databases its tests make: the maker owns each, so tests keep full rights there.
  • The password is random and is made on the PC. It is stored only in %APPDATA%\MindAttic\Mesh\database.json and %APPDATA%\MindAttic\MindAttic.Tickets\database.json on that PC, in plain text. Nothing encrypts these files: the Windows user account's profile is what protects them, and the login they hold reaches only the two shared databases, and only over the tailnet. MINDATTIC_MESH_SQLSERVER overrides the mesh connection.
  • The password goes to the server on tailscale ssh's standard input and into an owner-only temp file there that sqlcmd -i reads and that is then deleted, so it is on no command line on either machine and never in the setup log.
  • The connection strings say Trust Server Certificate=True. They connect by tailnet address, which the server's certificate does not name, and the traffic already runs inside Tailscale's WireGuard tunnel, which authenticates both ends and encrypts it. TLS is still on (Encrypt=True).
  • Setup never overwrites a database.json that already holds a connection. If both hold one it changes nothing. If only one does, it writes the missing one, reusing the password the other holds. If the Tickets file points at a different SQL Server, setup stops rather than repoint this PC's tickets: move them first (tickets db server migrate, never with --replace against the shared database), or delete that file if they are in the shared database already.
  • An existing login's password is reset only when no file on the PC holds it: it is stored nowhere else, so a new one is the only way back in. Setup says so when it does.
  • One login per PC means one can be dropped without touching the others. orchestrator mesh remove <machine> drops it.

Nightly backups

The PC that holds the backups (the rig) pulls a fresh native backup of each database every night.

Item Value
Scheduler job MindAttic.Orchestrator.Mesh.Backup
Time 03:15 daily
Script tools\mesh-backup-pull.ps1
Destination R:\Backup\MindAttic\mesh
Files tickets-<yyyyMMdd-HHmmss>.bak and mesh-<yyyyMMdd-HHmmss>.bak
Log mesh-backup.log in the destination folder
Retention MeshBackupKeepDays (Vault setting, default 14 days)

The job is registered in MindAttic.Scheduler, not in this repo. The script is what it runs.

How the pull works

The server runs a second sshd that listens only on its tailnet address, on port 2222, with key authentication only. The backup key's authorised entry carries a forced command. That command takes one word, tickets or mesh, backs that database up and streams the .bak to standard output. The key can do nothing else. Because no Tailscale SSH browser check is involved, the Scheduler can run the pull unattended.

On the pulling PC:

  • The private key is %USERPROFILE%\.ssh\mesh-backup. Without it the script logs FAIL no backup key and exits 1.
  • The script writes each stream to a file with cmd redirection, so the bytes stay binary.
  • A file under 1 MB or a non-zero exit counts as a failure; the partial file is deleted.
  • When a local SQL Server (MSSQLSERVER) is installed, each file is checked with RESTORE VERIFYONLY ... WITH CHECKSUM. Without one the log says "not verified".
  • After the pulls, .bak files older than the retention are deleted and logged as pruned.
  • The exit code is the number of failures, so the Scheduler shows a failed night.

Run it by hand:

powershell -NoProfile -ExecutionPolicy Bypass -File tools\mesh-backup-pull.ps1

Parameters, all optional: -Server (default mindattic-01), -Port (2222), -Key, -Dest, -KeepDays (default from the Vault setting MeshBackupKeepDays, else 14).

The repo's own tickets db sync dump (data/Tickets.sql in the Tickets repo, committed to git) is a further copy of the tickets.

Restore

A restore was tested on 2026-12-02: a pulled .bak was restored with RESTORE on a SQL Server and the data read back. SQL Server backups restore across Windows and Linux, so the target can be either.

  1. Pick the newest good file in R:\Backup\MindAttic\mesh (the log says which were verified).
  2. On the target SQL Server run, for each database, a RESTORE DATABASE from that file. To replace an existing database add WITH REPLACE. If the target's file paths differ from the source's, add MOVE clauses for the data and log files (RESTORE FILELISTONLY lists the logical names).
    RESTORE DATABASE [MindAttic.Tickets] FROM DISK = N'<path-to>\tickets-<stamp>.bak' WITH REPLACE, STATS = 10; RESTORE DATABASE [MindAttic.Mesh]    FROM DISK = N'<path-to>\mesh-<stamp>.bak'    WITH REPLACE, STATS = 10;
  3. Recreate the per-machine logins if the server is new. A restored database keeps its users, but a login that is missing from the new server leaves each user orphaned. Re-run setup-node.ps1 on each PC that lacks a database.json: it makes a missing login with the password the PC already holds and writes only the missing file. A PC whose files are complete is left alone, so on a new server make its login by hand with the password from its database.json, or move its two files aside and run setup (that resets the login's password).
  4. If the new server has a different tailnet name, pass it to setup (-Server <name>) on every PC.
  5. When the server is back, each PC renews its own claims and records the recovery. See "Outage behaviour".

Automatic failover of the database is not built. With one server the recovery is a restore.

Outage behaviour

When a PC cannot reach the shared server (waits MeshConnectTimeoutSeconds, 5 s by default):

  • New claims are refused on every PC. Nothing is queued as if it had happened.
  • Running CLIs keep going. git commits and pushes still work.
  • Each PC paces alone: the login's allowance divided by the PCs last seen running it, with new work stopping MeshOfflinePaceMarginPercent points below each cutoff.
  • The daemon logs the outage once. The dashboard's menu bar shows "Shared database unreachable since HH:MM - no new tickets".
  • On recovery each PC renews its own claims first and then sets recovered_at. A lapsed claim is not requeued until ClaimOrphanGraceMinutes after recovered_at.

Not built yet: the Tickets CLI serving reads from its local data/Tickets.db copy while the server is down.

Revoke a lost laptop

Do this as soon as a PC is lost or stolen.

  1. On any other PC of the mesh run orchestrator mesh remove <machine>. It deletes the PC's member row, makes every reachable peer revoke its peer key and drop its remote, and drops its mesh_<machine> SQL login. The laptop's token stops working on its next request to any peer that revoked it, and any open stream is checked against the key.
  2. If the command says a step failed, run it again. If it could not drop the login it prints the T-SQL; run that on the server. The statement kills the login's open sessions, drops its users in both databases and drops the login.
  3. A peer that was off when you ran the command still holds the laptop's key. Run the command again when it is back .
  4. In the Tailscale admin console remove or expire the laptop's device. This is the step that closes its route to the server.
  5. Claude logins on the laptop are not in the mesh. Sign out of or revoke them on the Claude side if needed.

Version skew and updating a node

Each PC reports a build and a mesh protocol (TermGateway.MeshProtocol, currently 1) on its member row. The mesh's protocol is the newest one spoken by a PC seen within MeshPeerStaleSeconds. A PC behind it:

  • is refused claims ("LAPTOP needs update"), is left out of pacing sums, and is not admitted by /mesh/join;
  • can still be watched and typed into.

To update a node, pull the repos on it and run setup again with -Redeploy:

.\Setup-Node.cmd -Redeploy

-Redeploy runs run.ps1 of MindAttic.Tickets, MindAttic.Orchestrator and MindAttic.Launcher again. Without it, setup skips apps that are installed.

Vault settings

Every number is a Vault setting (Scheduler group, except where noted). Change one in the Vault app or the dashboard's settings.

Setting (Vault property) Default Meaning
Mesh claim lease, minutes (ClaimLeaseMinutes) 10 How long a claim lasts. The claiming PC's daemon renews it every third of this. Range 1 to 1440.
Mesh orphan grace, minutes (ClaimOrphanGraceMinutes) 30 Minutes past a lapsed lease, or past recovery from an outage, before the ticket can be claimed again. Range 0 to 10080.
Mesh connect timeout, seconds (MeshConnectTimeoutSeconds) 5 How long any mesh connection waits to reach the shared server before calling it unreachable. Range 1 to 120.
Mesh serve wait, seconds (MeshServeWaitSeconds) 60 How long orchestrator mesh serve waits for the daemon to start the gateway. Range 5 to 600.
Mesh join nonce, minutes (MeshJoinNonceMinutes) 10 How long the join nonce a PC writes on its member row stays good. Range 1 to 1440.
Mesh join timeout, seconds (MeshJoinTimeoutSeconds) 30 How long a joining PC waits for each peer to admit it. Range 5 to 300.
Mesh peer stale, seconds (MeshPeerStaleSeconds) 600 Silence after which a PC counts as lost, and after which its protocol stops counting. Range 60 to 86400.
Mesh pair check, seconds (MeshPairCheckSeconds) 300 How often the daemon looks for a new member to pair with. Range 30 to 86400.
Mesh pair yield, seconds (MeshPairYieldSeconds) 900 Of two unpaired PCs the lower name pairs; the other waits this long for it, then pairs itself. Range 60 to 86400.
Mesh re-pair, minutes (MeshRepairMinutes) 30 When a peer refuses this PC's peer key, the daemon pairs with it again on its own, at most once this often per peer. Range 1 to 1440.
Mesh pace stale, seconds (MeshPaceStaleSeconds) 120 A PC's published burn older than this stops counting toward cluster pace; a PC whose own read is older paces alone. Range 10 to 3600.
Mesh offline pace margin, % (MeshOfflinePaceMarginPercent) 3 Points below each cutoff at which a PC that cannot read the cluster stops new work. Range 0 to 50.
Mesh backups kept, days (MeshBackupKeepDays) 14 Days of pulled .bak files tools\mesh-backup-pull.ps1 keeps. Range 1 to 365.
Mesh dashboard read, seconds (MeshDashboardReadSeconds) 30 How often the dashboard reads the shared server for the logins grid and the outage banner. Range 5 to 3600.
Keyboard handoff, seconds (InputHandoffSeconds, Gateway group) 2 How long a keyboard holder must be idle before another viewer's keys take it. Applies to CLIs started after the change. Range 0 to 3600.

The mesh's connection itself is not a Vault setting. It is in %APPDATA%\MindAttic\Mesh\database.json on each PC (SqlServer, Machine, Server, ServerAddress), written by setup in plain text (see "Per-machine SQL logins"). With no such file the PC is a mesh of one. MINDATTIC_MESH_CHECK_SECS (default 15) bounds how long the commit gate waits for orchestrator may-close before it allows the close with a warning in mesh-close.log.

Troubleshooting

Symptom Check
Setup stops at Tailscale Install Tailscale and sign it in on the owner's account, then run setup again.
"mindattic-01 isn't on this tailnet" The PC is on another tailnet, or the server is offline in the Tailscale admin console. tailscale ip -4 mindattic-01 must answer.
"Couldn't make the SQL login" tailscale ssh root@mindattic-01 must work from the PC and the browser check must be approved. Run setup again.
mesh serve exits 2: gateway isn't serving The dashboard or daemon is not running. Start it and run the command again.
mesh serve or mesh join exits 1 No mesh config on this PC, or Tailscale is down, or the gateway is not on the Tailscale address. Run orchestrator mesh serve first.
mesh join exits 3 or "shared database didn't answer" The server or the link is down, or this PC's login is wrong. Check "Outage behaviour".
mesh join exits 2: a peer refused The peer checks that you are on its own Tailscale user, that your join nonce is fresh (MeshJoinNonceMinutes) and that the protocols match. Run orchestrator mesh join --again.
A PC is greyed out No heartbeat for MeshPeerStaleSeconds. Is it asleep, offline or off? The daemon logs "unreachable since" and its return.
"needs update" on a PC Protocol skew. Re-run setup there with -Redeploy.
A ticket stays claimed by a PC that is gone It requeues ClaimOrphanGraceMinutes after its lease lapsed (and after any recovery). To free it now, remove the PC with orchestrator mesh remove.
Commit gate says another PC holds the ticket Another PC or CLI claimed it. Work another ticket, or wait for its lease to lapse.
Backup log shows FAIL no backup key The key %USERPROFILE%\.ssh\mesh-backup is missing on the pulling PC.
Backup log shows FAIL with a size The forced command or the server's sshd on port 2222 did not answer. Check the server is up and the backup sshd is running.
Backup log shows VERIFY FAILED The file is damaged. Do not use it; the next night's pull replaces it. Keep an older verified file.
Setup log R:\MindAttic\Setup\setup-node.log (first run: C:\MindAttic-Setup\setup-node.log until D: and R: exist).
From MindAttic.Orchestrator/docs/MESH_OPERATIONS.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.