Skip to content

feat(scripts): --for-dev starts a shared server for the developer on a copy of their data - #556

Merged
Jacksondr5 merged 5 commits into
j5/mainfrom
j5code/live-test-for-dev
Oct 12, 2026
Merged

Jacksondr5 merged 5 commits into
j5/mainfrom
j5code/live-test-for-dev

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Problem

When the developer wants to look at a branch themselves, an agent has to stand up a server on a copy of their data and share it over the tailnet by hand, and each step has a way to go wrong: the copy, the port, a share that fails silently, a mapping left behind. Part of #546 (stage 3, third of five stacked PRs; based on #555).

What changed

A start or rebuild takes --for-dev:

node scripts/j5/setup-agent-live-test.ts --for-dev
  • A copy, never the live database. The home is built by apps/server/scripts/migrate-dev-db.ts --base-dir <worktree>/.j5code/live-test/home. That script attaches ~/.j5code/userdata read-only and writes only below its base directory.
  • Shared on the tailnet, on a port that was checked. --share replaces whatever is mapped on the web port, and the dev runner moves to the next free port pair when its first choice is taken. So the script pins the runner to this worktree's own ports (both given explicitly, which turns the runner's search off) and, before starting anything, refuses: the live install's tailnet port 8444; a port that already carries a mapping this server did not make; and a port something is already listening on.
  • A failed share stops the server. A failed share only warns in the dev runner, so the script waits for the "shared on tailnet:" log line and, if it sees "could not share on the tailnet" instead, stops the server and refuses with the reason.
  • The pairing URL is the developer's. The script prints the server's startup pairing URL from its log, which is the tailnet one. It mints none (pair would give a localhost URL) and never opens it. restart prints a new one.
  • stop removes only its own mapping. The dev runner removes its mapping on a normal exit. After stopping, the script acts only if this run's log recorded a share, and only on a mapping that proxies to this server's own web port on loopback: it runs tailscale serve --https=<that port> off and checks again. A mapping on that port that proxies anywhere else is reported and left alone, without refusing, so restart and rebuild still work while it is there. A failed read of the mappings is an error, never "nothing is mapped". It never calls serve reset.
  • After a killed runner. If the runner was killed outright, the script will not signal what is left of its group. It still removes its own tailnet mapping before saying so, since that signals nothing.
  • Ports browsers refuse. Pinning the port skips the dev runner's own check for ports browsers will not open (6000, 6665 to 6669 and so on), so the script applies the runner's isBrowserAllowedPort itself and refuses such a port.
  • The output says what this server is. It is for the developer; agents take no turns on it, because its threads point at real checkouts and resume real provider sessions; and reachability from another device was not checked.

The mode rules from #554 apply: one build per worktree, fixed at build, rebuild to switch.

Live testing

On 2026-10-11, on the dev host, from this branch's worktree. I did not open the pairing URL or take a turn on this server.

Exercised:

  • rebuild --for-dev: 16 s. The output shows a https://<host>.ts.net:<web port> pairing URL and "Shared at". Recovery reported no terminalized runs and no stopped sessions, and the log shows no provider turn started.
  • tailscale serve status listed this server's port beside the live install's 8444 while it ran. After stop, only 8444 remained and the web port was free.
  • restart shares again and prints a new URL; a bare start on the for-dev build is refused with the two commands.
  • With the pinned ports: the runner used exactly the ports that were checked (7594 and 15634), and the mapping read back as https://<host>:7594 -> http://localhost:7594.
  • The cleanup fallback: with the server stopped I created this worktree's own mapping by hand, as a killed runner would leave it, and stop removed it and left 8444 in place.

After the port-pinning and cleanup changes, the Captain released the mode for one watched run, in my worktree at the reviewed commit: tailscale serve status showed only the live 8444 mapping before; the runner used exactly the pinned ports and logged "shared on tailnet"; during the run the status showed this server's port proxying to http://localhost:<web port> beside an unchanged 8444; after stop only 8444 remained. A plain rebuild then replaced the copy. The tester repeated it from its own worktree at this PR's head (report: artifact test-reports/setup-agent-live-test-for-dev.md): startup, status, restart, the copy staying inside its worktree, and stop removing only its own port's mapping, with 8444 unchanged at every check.

This PR also carries two small fixes to the merged peer mode: status gives both peer-list reads one deadline, and a failed peering advises restart unless both servers are running (found and rechecked by the tester).

Not exercised:

  • Reachability from another device. A request from this host bypasses the tailnet policy and proves nothing. Only the developer can confirm it.
  • Pairing with the printed URL, for the same reason: it is the developer's and works once.
  • The share-failure path on a real server (covered by tests on the log parser and the refusal).
  • The three refusals before a share (port 8444, a foreign mapping, a listener on the port) on a real host; they are covered by tests. I did not create a foreign mapping to try one.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction (no UI change)
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR (none edited; migrate-dev-db and the dev runner are called, not changed)
  • Upstream product: any change to what upstream's product does has a human decision linked above and a register entry in docs/j5/product/upstream.md (none)
  • Surfaces: entry points, clients, providers, contracts, reverse states, connection modes (see AGENTS.md). stop undoes the share. Tailnet only.
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them (the skill text is in docs(j5): agents live-test with one setup script, the Browser panel and a testing skill #549)

Tests: vp test run scripts/j5/setup-agent-live-test.test.ts (40 pass): the flag and its refused combinations, reading the share line and the share failure from the log, refusing an unshared server only when a share was required, reading each mapping and its target from tailscale serve status, recognising a mapping as this server's own, refusing port 8444 and a foreign mapping, treating a failed status read as an error, and removing only this run's own mapping on stop. Typecheck and lint are clean on the touched files.

Built with Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Oct 12, 2026 5:20am UTC

Request Review

@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-peer branch from 4a6b2e7 to 32130b1 Compare October 12, 2026 04:05
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from c39ae0a to 7c919e0 Compare October 12, 2026 04:05
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-peer branch from 32130b1 to 0055f90 Compare October 12, 2026 04:06
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 7c919e0 to 88d81ed Compare October 12, 2026 04:06
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-peer branch from 0055f90 to d82f7db Compare October 12, 2026 04:09
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 88d81ed to 19da1ed Compare October 12, 2026 04:09
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 19da1ed to 7140218 Compare October 12, 2026 04:16
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 7140218 to 561c2ed Compare October 12, 2026 04:24
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 3cdf4ad to 1b935fd Compare October 12, 2026 04:43
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-peer branch from de18fe9 to c0fa7c0 Compare October 12, 2026 04:46
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 1b935fd to a66e0c1 Compare October 12, 2026 04:46
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from a66e0c1 to 31ae118 Compare October 12, 2026 04:55
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 31ae118 to 9213ae1 Compare October 12, 2026 04:57
@Jacksondr5
Jacksondr5 force-pushed the j5code/live-test-for-dev branch from 9213ae1 to 991ede5 Compare October 12, 2026 04:59
Base automatically changed from j5code/live-test-peer to j5/main October 12, 2026 05:10
Jacksondr5 and others added 4 commits October 12, 2026 01:17
…a copy of their data

A start or rebuild with --for-dev copies a slice of the developer's data into
its own home with migrate-dev-db, starts the dev server shared on the tailnet,
and prints the tailnet pairing URL for the developer. It refuses a server
that could not be shared, never opens the pairing URL, and on stop makes sure
its own tailnet mapping is gone. The output says agents take no turns there.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t make

Sharing replaces whatever is mapped on the web port, and the dev runner moves
to another port pair when its first choice is taken. The script now pins the
runner to this worktree's own ports, and before starting refuses the live
install's tailnet port, a port that carries someone else's mapping, and a port
something is already listening on. On stop it removes a mapping only when
this run's log recorded a share and the mapping proxies to this server's own
web port. A failed read of the mappings is an error.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed runner and refuses blocked ports

Review fixes for #556:
- A foreign tailnet mapping on the port is reported and passed over on stop,
  not refused, so restart and rebuild still work while it is there.
- When the runner was killed outright and the group will not be signalled,
  the tailnet cleanup runs before that refusal. It signals nothing and acts
  only on a mapping this run made.
- A web port that browsers refuse to open is refused, since pinning the port
  skips the dev runner's own check.
- The dry run and the tailscale reads are capped by the start's time budget.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…unning

The advice was always to run the same start again, but a start only joins a
server that is already there, so with one server not serving it waited out
its budget and failed. The same start is advised only when both are running.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jacksondr5
Jacksondr5 marked this pull request as ready for review October 12, 2026 05:31
@Jacksondr5
Jacksondr5 merged commit 64e0ccf into j5/main Oct 12, 2026
33 checks passed
@Jacksondr5
Jacksondr5 deleted the j5code/live-test-for-dev branch October 12, 2026 05:31

This branch was successfully deployed

1 active deployment
Preview — 88c0f32a Deployed Oct 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant