Repository navigation
Conversation
- Sign a node in to Coder at its own agent address when it cannot reach this machine's Coder address, and remove the token of a failed sign-in. - On the node, run the setup steps that need only sudo when sudo there asks no password, and list the steps left for the person once, at the end, each with its command. - Keep the node's engine when it runs this machine's engine commit, and apply the profile with it instead of running get.sh again. - Say the hub reaches the node when T3 Code on the hub lists it, read T3 Code here when the command runs on the hub, and skip hedge peers link then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Send no Coder token over plain HTTP. The node's agent address is used only over HTTPS. When the node answers only at an HTTP agent address, devbox add makes no token and prints the one sign-in the person runs. - Take an address only when /api/v2/buildinfo answers 200 with Coder's JSON, without following redirects. - When the token removal fails too, name the token and the command that removes it. - After the node applies the profile, ask the node's own hedge doctor --to-do which steps are left, even when apply exits 0. Run the sudo steps, apply and ask again, and keep the profile step open while steps are left. hedge doctor --to-do is new and prints them as JSON. - Keep the node's engine only when its hedge command runs and it sits at this machine's commit. The install step always runs get.sh until done. - Use the status from T3's list: an expired or unreachable link gets hedge peers link again, or a hint that names its state. - Printed commands set the PATH that Hedge's own SSH calls set. - Share one environment id check and one T3 link type, and drop the new doc comments. - The node in the tests runs the real hedge apply and doctor with the files adapter, and the tests check node state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Send a Coder token to the node's agent address only when that address reports the same deployment_id as this machine's Coder, and over HTTPS. Parse the agent address as a bare http or https origin, quote it in the printed sign-in, and install the Coder CLI on the node before that hint. Read build info with curl -q, so no curl config follows a redirect. Run no step left for the person on the node. List each one with its command. A node engine without --to-do finishes the profile step and points to hedge doctor there. The unreachable-link hint names only the command that links it. The fake keeps the hub's T3 links, and the tests check node state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the guards pack on, devbox add stopped at the profile step until the person ran the Git allowlist and earlyoom commands, before the Claude, ChatGPT, T3 Connect and link steps. When the node's apply passed and hedge doctor --to-do lists only steps for the person, the profile step now finishes, setup goes on, and devbox add ends with the list of those steps, each with its command, and exits 0 as hedge apply does with To do lines. An apply that fails for any other reason still stops setup. Hedge runs none of the steps. The test for another engine commit now moves the node's engine after the install step, so it fails when the profile step skips get.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign the node in to Coder only at the hub's own Coder address, over HTTPS. Write the token into the node's Coder CLI session and url files over SSH, so it travels in no HTTP request during setup, and install a missing Coder CLI only from that address over HTTPS. Drop the agent address fallback, its deployment ID check, the HTTP download and coder login. hedge doctor --to-do now exits 1 and prints the other findings when the node finds more than steps for the person, so hedge devbox add stops at the profile step then. The final list tells the person to run hedge apply on the node after the steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…om this machine The local shell now has its own HOME and a sudo that refuses, so a step whose outer quoting breaks runs here and fails, instead of passing on the node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hedge no longer checks the new Coder token from the node. This machine makes the token, so it is valid as made. The node keeps any Coder sign-in it already has another way, and its sign-in becomes a step for the person. The token goes through new owner-only staging files. The Coder CLI installs only from an HTTP 200 answer with no redirect, after it runs. hedge doctor --to-do counts a step that Hedge repairs as a finding, and a failed apply on the node names what hedge doctor there finds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Coder url or session path that is not a regular file counts as another sign-in, and the write fails when a destination is not a regular file after its move. When Hedge leaves another sign-in alone, it still installs a missing Coder CLI from the hub's HTTPS address, names CODER_URL and CODER_SESSION_TOKEN when the node sets them, and prints no sign-in command when the hub's Coder address is plain HTTP. hedge doctor --to-do matches one finding to one step with one predicate. The tests cover each CLI download check alone, give the whole fake SSH session the node's environment, and run the printed repair through a fake ssh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What the first run hit
The first headless run of the cloud-only setup (#284) added a node with
hedge devbox addfrom the hub. It hit these problems in that command. The numbers are the run's findings.dial tcp ...: i/o timeout), only its own agent address,CODER_AGENT_URL, such ashttp://coder.internal/. The Coder sign-in failed, and the token thatcoder tokens createmade stayed behind, unused.T3 Code cannot run as a service.devbox addended with "The hub has not linked the node ... run hedge peers link". But T3 Code on the hub already listed the node through T3 Connect, andhedge peers linkthen failed withT3 RPC request failed.devbox add, the node's doctor listed the Git allowlist, earlyoom and a team pack's review key asTo do, steps the person already did on the hub.devbox addran none of them.get.shagain, which fetches the engine, installs its packages and applies the whole profile, for several minutes.What this PR does
ssh coder.<hub>, whichcoder config-sshroutes through the Coder CLI. The Git key needs none, sincescripts/coder-git-key.shuses the workspace agent. Sodevbox addstill makes a token, but sends it only to the hub's own Coder address, the URL this machine's Coder CLI is signed in to, never to an address the workspace names. Before it makes a token, it checks that the node reaches that address over HTTPS:curl -q --proto =httpson/api/v2/buildinfomust answer 200, with no redirect followed. When the address is plain HTTP, or the node does not reach it,devbox addmakes no token, sends none, installs nothing, and stops with the sign-in the person does on the node: install the Coder CLI from their deployment, andcoder loginwith an HTTPS address the node reaches. A rerun keeps the session the person made, whatever address it uses. When the node is already signed in to Coder another way,devbox addleaves that sign-in alone: when itsurlfile names another address, when it has asessionfile and nourl, when itsurlorsessionpath is not a regular file (a directory, a link, or anything else), or whenCODER_URLnames another address orCODER_SESSION_TOKENis set in its SSH environment. It makes no token and writes no sign-in file. When the hub's Coder address is HTTPS, it installs a missing Coder CLI the same way as below, and listscoder login <address> && coder config-ssh --yesamong the steps for the person at the end. WhenCODER_URLorCODER_SESSION_TOKENis set, that step first says to remove them from the node's environment, by name and with no value, because the Coder CLI reads them before its files. When the hub's Coder address is plain HTTP, the step says so and that the person signs the node in over HTTPS, and it prints no command. It writes only when the node has no Coder sign-in, or itsurlalready names this exact address. When the node has no Coder CLI,devbox addinstalls it only from that address, withcurl -q --proto =https --max-redirs 0, into a newmktempfile. It moves the file in place only when the answer was HTTP 200, the file is not empty, and the downloaded CLI'sversionruns. Nocoder loginruns. The token goes over the SSH channel on standard input, and a shell on the node writes it withprintf(a built-in, so it is in noargv) tosession, and the address tourl, in${CODER_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/coderv2}. Each goes first into a staging file thatmktempcreates there, new and owner-only, thenmvputs it in place. The write runs the sign-in check again right before it, and fails when a destination is not a regular file after itsmv. These are the files the Coder CLI reads on Linux:coder login --helpin v2.37.4 says Linux keeps the session token in a plain text file,--global-configdefaults to$CODER_CONFIG_DIRor<user config dir>/coderv2, which followsXDG_CONFIG_HOME, andcoder login tokenprints the raw file. Hedge makes no authenticated request from the node during setup. This machine makes the token, so it is valid as made, and the HTTPS check already shows that the node reaches the same address. The node's next Coder use,coder config-ssh --yes, is the same use as after anycoder loginby the person. When Hedge cannot write the files, it removes the token, which never reached the node, or names it and the command that removes it. The agent address fallback, itsdeployment_idcheck, the plain HTTP download, the node-sidecoder whoamicheck of the new token, andcoder login --use-token-as-sessionare gone. A cross-region node like the first run's, which reaches Coder only athttp://coder.internal/, still needs that one manual sign-in.fix/cloud-setup-run) turns on lingering insidehedge applywhen the user manager does not answer.devbox addruns that apply on the node, so this PR reuses it and adds no linger step of its own. It only setsXDG_RUNTIME_DIRto/run/user/<uid>for the node's apply when the SSH session has none, sosystemctl --userfinds the user manager once it runs.hedge peers link,devbox addreads the node's T3 environment id and the hub'st3 environment list. When the hub lists the node with the statusreachable, it prints✓ The hub, <hub>, reaches <node> in T3 Code.and does not runhedge peers link. A link listed asexpiredorunreachablegetshedge peers linkas before, and when that cannot run, the hint names the link's state and the command that links it. It no longer says the hub's daily renewal links it: that renewal skips an unreachable link with more than seven days left. Run on the hub, it reads T3 Code on this machine instead of over SSH. The hint names where to runhedge peers link:hereon the hub, orssh <hub> '<PATH>; hedge peers link <node>'elsewhere.devbox addasks the node which steps are left: the newhedge doctor --to-doprints them as JSON on its last line, from the node's own profile and pack revisions. (hedge applyexits 0 while a human step with a command is open, so the exit code cannot tell.) Before that line it prints every other finding that fails the doctor, such as the guards pack's systemd version check, and then it exits 1; with only steps for the person, it exits 0. A step is for the person only when its finding's repair type ishuman: a pack step that Hedge repairs itself (repair: "apply") is another finding, never a step for the person. It runs none of those steps itself, with or without a password forsudo. When the apply passed and the node reports nothing but steps for the person, the profile step counts as done: it prints how many are left, anddevbox addgoes on with the Claude, ChatGPT, T3 Connect and link steps. At the very end it lists those steps once, each with itsssh -t <node> '<PATH>; <command>', thenDo each one, then run hedge apply on <node>., so the jobs, steps and settings that wait on those steps get installed. It exits 0, ashedge applydoes when it ends withTo do:lines. When the apply failed, or the node reports anything else,devbox addstops at the profile step, with the other findings and the steps left in its error. A failed apply prints what the node's doctor found too, which the apply may not have printed. A node engine older than--to-doanswershedge: unknown option --to-do; then the step finishes when the apply passed, with one line that points tohedge doctoron the node.<PATH>is the samePATH="$HOME/.local/bin:$HOME/.bun/bin:$PATH"that Hedge's own SSH calls set, so the command works in a plain SSH session.get.sh --install-onlyuntil it is done, as before. When the node's engine is at the commit this machine's engine runs and the node's~/.local/bin/hedge helpruns, the profile step runs the node'shedge apply --profiledirectly instead ofget.sh. With another commit, or a launcher that does not run, such as after a failedbun install, it runsget.shas before.SETUP.md(item 3 of adding nodes) andCHANGELOG.mdsay what changed.Tests
The tests are in
src/setup/devbox-node.test.tsandsrc/setup/devbox-node-apply.test.ts, and runhedge devbox addthroughmain. The fake machine insrc/setup/testing.tshas a node whose shell runs for real in a temporary home. Its engine runs the realhedge applyandhedge doctorwith the files adapter (src/setup/fixtures/node-engine.ts). WithstepsFail, every pack command there fails, so the real apply fails on a pack step: the "another reason" case. WitholdSystemd, the guards pack's systemd version check fails. Its system boundaries are stand-ins:sudo(with or without a password),gh(clones the local profile repo),curl,ssh, and the root state of the Git allowlist and earlyoom. The node's Coder CLI signs in with thesessionandurlfiles in~/.config/coderv2only when they hold a token this machine made and has not removed, at an address the node reaches, or a session the person made, at any address. The node'scurlrefuses any protocol but HTTPS when told--proto =https. WithcoderRedirects, its build info or its CLI download answers with a redirect, which it follows when-Lor a~/.curlrcwithlocationsays so, unless-qcomes first or--max-redirsis 0. WithcoderCli, the CLI download answers with another status than 200 and a CLI that runs, with an empty 200, or with a 200 CLI whoseversionfails. Every shell command on the node runs withboxEnv, and the node's Coder CLI readsCODER_URLandCODER_SESSION_TOKENbefore its files. The Coder CLI it downloads runscoder login, and itscoder config-sshwrites~/.ssh/configforCODER_URL, or else for itsurlfile. The tests check outcomes: the root state, the installed engine's commit, its packages and whether its launcher runs, the node's applied profile, the T3 links this machine made, the fake Coder's token list, the content and mode of the node'surlandsessionfiles, the SSH config its Coder CLI writes, the Coder CLI on the node, a file that a staging path links to, and the rawt3 environment list --jsonof the hub. Each printed step runs whole through a fakessh, so the local shell parses its quoting, with its ownHOMEand asudothat refuses, apart from the node's.at this machine's Coder address, with the session file its Coder CLI reads, which only its owner can readcoder loginback in placeinstalls the Coder CLI there from this machine's Coder address over HTTPSbut makes no token, sends none and installs nothing when the workspace does not reach that address, and leaves the sign-in to the personand makes no token and installs nothing when this machine's Coder address is plain HTTP, though the workspace reaches itand never writes the token through a file that already waits in its Coder foldersession.hedgepathurlandsessionfiles, mode 600, and its SSH confighedge devbox add signs a Coder workspace in to Coder and writes its SSH config, so it reaches the hub and the other nodes by their coder. names(devbox-add.test.ts)urlmove~/.curlrcfollows redirectsand makes no token and installs nothing when the workspace's Coder build info answers with a redirect, though its curl follows redirects-qand installs no Coder CLI and makes no token when the CLI download answers with a redirect, though its curl follows redirectsversionchecksversionfailsand installs no Coder CLI and makes no token when the CLI download %s(3 cases)url, asessionwithouturl,CODER_URL,CODER_SESSION_TOKEN; the CLI gets installed, the step names the variables to remove, and the printed repair, run through a fakesshonce the variables are gone, points the SSH config at the hub's Coder addressbut leaves the workspace's own Coder sign-in %s as it is, makes no token, installs the Coder CLI, and lists a sign-in that points its SSH config at this machine's Coder address(4 cases)urland theCODER_URLchecks, the CLI install, or the variable namessessiondirectory is another sign-inbut leaves a session path that is a directory as it is, makes no token, and lists the sign-in for the personsessiondirectory appears after the first checkand fails the write, and removes the token it made, when a session directory appears after the first checkand lists no plain HTTP sign-in, and installs nothing, when it leaves another sign-in alone and this machine's Coder address is plain HTTPand removes the token it made when it cannot write it on the workspaceand names the token and the command that removes it when its removal fails too--to-doexits 1--to-do exits nonzero and lists no step for the person when a step that only Hedge repairs fails(cli.test.ts)names what hedge doctor on the node finds when the apply fails, though the apply printed none of itruns none of the steps left for the person, though sudo there asks no passwordhedge applygoes on to the link step when only steps for the person are left, and lists each one once at the end, as a command that runs over plain SSH(runs each printed command through a fakessh)still lists the steps left for the person when a later step failsstops at the profile step, links nothing, when the apply fails for another reason, and a rerun after the fix applies the profile and links the nodestops at the profile step, and names what else the node finds, when a check that is no step for the person fails beside one that is--to-dofinishes the profile step, and points to hedge doctor on the node, when the node runs an older Hedge without --to-dotakes the steps left from the node's own profile, not from this machine'skeeps the installed engine and its packages when the engine sits at this machine's commit, and applies the profile with itinstalls again with get.sh when the engine has moved to another commit since the install stepfinishes on the next run an install that stopped before the engine's packagesinstalls again with get.sh when the engine sits at this machine's commit but its launcher does not runsays the hub reaches the node, and keeps its link as it is, when T3 Code on the hub reaches it(compares the hub's raw list)links the node again when T3 Code on the hub lists its link as expired, so the hub lists it as reachable(reads the hub's raw list)names the link's state and a repair that runs over plain SSH when the hub cannot link an unreachable noderun on the hub, reads T3 Code here, and says the hub reaches the node when the hub's own update failsI broke each fix once in round 3, and the named test failed each time: the HTTPS reach check (the no-reach test), the
https://and--proto =httpschecks (the plain HTTP test), the session file write put back ascoder login(the session file test),--to-doexiting 0 with other findings (the systemd test), thehedge applyline (the link-step test), the list moved out offinally(the later-failure test), the outer quoting of a printed step (the link-step test, through the fakessh), the hub's reachable and expired branches (the two hub tests, on the raw list), and the link from this machine (the failed-apply rerun, the link-step and the older-engine tests). Earlier rounds broke the engine and hub fixes the same way. Round 4: I broke each fix once again, and the named test failed each time: theurlcheck of another sign-in, theCODER_URLcheck, themktempstaging files (put back assession.hedge), the 200, non-empty andversionchecks of the CLI download,-qon the build info check, theurlmove, the repair-type check in--to-do, and the doctor findings of a failed apply. Round 5: I broke each fix once again, and the named test failed each time: the regular-file check (thesessiondirectory and the late directory tests), the plain HTTP step (the plain HTTP test), the CLI install beside another sign-in (the 4 sign-in cases), the variable names (theCODER_URLandCODER_SESSION_TOKENcases), and the 200, non-empty andversionchecks one at a time (one CLI download case each). The check after eachmvhas no test of its own: only a race inside the write's one shell line reaches it, since the write's own check catches a directory first. The--to-dopredicate is a refactor, and itscli.test.tstests pass before and after.bun run typecheckpasses.bun run testfails the 16 tests that fail on this devbox on the base too: 12 privacy scan (no gitleaks), 3 tracker and frontier origin, and 1 page code parser.Overlap with the setup-fixes PR
Both PRs start from
feat/cloud-only. This PR changes no file that the setup-fixes branch changes (src/adapters/t3/service.ts,packs/guards/system/earlyoom.sh,src/setup/setup.ts,src/setup/human.ts). It depends on that PR for two things on the node. Itshedge applyturns on lingering (35). Itsearlyoom.shsetsNEEDRESTART_MODE=aandDEBIAN_FRONTEND=noninteractiveitself, so the earlyoom command the person runs on the node does not wait on a hidden prompt (finding 25). Until that PR merges, a node still needssudo loginctl enable-linger <user>once.Not in this PR
hedge setup --devbox <host>runs the same node steps, so it now also checks the node's left steps after apply (37). It still stops at the node's profile step while steps for the person are left: its final check runshedge doctoron the node, which fails while aTo dois open, so going on there needs a change to that check too. It does not pass the engine root, so it keeps runningget.sh(38). Passing it means changingsrc/setup/setup.ts, which the setup-fixes PR changes too. It is a one-line follow-up once that PR merges.devbox adddoes not list them again;hedge doctoron the node does. When a later step fails in the same run, the list still prints, above that error.hedge doctor --to-dodoes not run the doctor's live drift probes of hub services, since the node's forward to the hub may not be up yet right after its first apply.hedge doctorin step 8 still runs them.SETUP.mdsigns the hub itself in to Coder withcoder login, run by the person and their agent. This PR does not change it.hedge doctor --to-dolist.Merge risk
Warning
🟡 Merge risk: medium · two-way door
hedge devbox addon the hub, in the unreleasedfeat/cloud-onlybranch. It mints a Coder session token with the owner's permissions and writes it into the node's Coder CLI session file over SSH, on standard input. It does so only for the hub's own Coder address, over HTTPS, when the node reaches it there without a redirect. No other address gets a token, and nocoder loginruns. A node that does not reach that address over HTTPS gets no token, no Coder CLI, and a manual sign-in step. The Coder CLI comes only from that address over HTTPS. A node signed in to Coder another way, or with aurlorsessionpath that is not a regular file, keeps that sign-in and gets no token. Its step for the person names the environment variables to remove, and prints no command over plain HTTP. Hedge checks the token on the node with no request: this machine made it. A token that Hedge cannot write is removed, or named for removal.devbox addreads the steps left from the node's own plan. It runs none of them. When the apply passed and the node's doctor finds nothing but those steps, it goes on to the sign-ins and the link, and lists each step with its command at the end, then tells the person to runhedge applyon the node. Any other failure stops at the profile step. A node engine without--to-dofinishes the step and points tohedge doctor.maincover each path, with the node's realhedge applyandhedge doctor.coderv2/sessionwould not sign in;coder config-sshon the node then fails anddevbox addstops. The token stays in that file on the node, which only its owner reads.Decisions
feat/cloud-onlyand merge before Make Hedge cloud only: the Mac and phone only coordinate #284 goes to main. (the PR owner, merge, the setup run's conductor thread)deployment_idproves nothing, so the agent address fallback is gone. (agent, review round 3)sessionandurlfiles over SSH, from standard input, through new owner-onlymktempstaging files. Nocoder loginruns. (agent, review rounds 3 and 4)CODER_URLor a redirect could send elsewhere. The node's latercoder config-sshis the same use as after the person's owncoder login. (agent, review round 4)sessionand nourl, or throughCODER_URLorCODER_SESSION_TOKEN, keeps that sign-in. Hedge makes no token and lists the sign-in for the person. It writes only when the node has no sign-in, or itsurlnames this exact address. (agent, review round 4)urlorsessionpath that is not a regular file another sign-in? Yes: Hedge leaves it alone, makes no token, and lists the sign-in. The write checks again right before itsmv, and fails when a destination is not a regular file after it. (agent, review round 5)coder loginthat runs on the node at the same moment? No:devbox addruns on a node that the same person is setting up, and nothing else on a fresh node runscoder login. Only that person could race the twomvcalls, and the result is their own token beside their own login. No write order closes the window: writingsessionfirst leaves another interleaving that pairs the hub's token with another URL. (agent, review round 5)CODER_URLandCODER_SESSION_TOKEN, with no values, to remove from the node's environment first. Over plain HTTP it says to sign in over HTTPS and prints no command. (agent, review round 5)ssh coder.<hub>throughcoder config-ssh, which needs a user session. The Git key does not, so it stays on the workspace agent. (agent, review round 3)devbox addrun a pack's human step on the node? No: it lists every step with its command for the person, also whensudoasks no password. (agent, review round 2)devbox add? No: when the apply passed andhedge doctor --to-doexits 0, with nothing but those steps, setup goes on to the link and lists them once at the end, then says to runhedge applyon the node, exit 0. Any other failure, such as a failing pack check, still stops it at the profile step. (conductor after review round 2; agent, review round 3)🤖 Generated with Claude Code