Skip to content

fix(dev): pnpm dev stop works while the broker source doesn't compile - #363

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/330-dev-stop
Sep 24, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/330-dev-stop

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #362 (branch fix/339-stale-confirmation).

Closes #330.

The root dev script bundled the shell broker before handing off to the runner, so every subcommand depended on it. If you were halfway through a broker edit and it had a syntax error, pnpm dev stop exited 1 and left the instance running. status, logs and --dry-run had the same problem.

Now package.json runs the runner directly. pnpm dev (when it actually starts) and pnpm dev reset build the broker first, before they record, stop or wipe anything. A failed build prints esbuild's errors to stderr, then one BrokerBuildFailed line, and exits 1 with the instance and .local/dev untouched. Management commands and confirming a healthy instance never compile it. docs/DEVELOPMENT.md (under the subcommand table) and the patchy-dev-loop skill say so.

Tests. scripts/dev/src/main.test.ts runs the root dev script, as pnpm does, in a throwaway worktree whose broker doesn't compile:

  • stop with a recorded idle process as the supervisor: on the old code it exited 1 and the process stayed alive; now it exits 0 and stops the process.
  • reset with the same recorded process: exits 1, the process stays alive, and plan.json is still there. On the first version of this PR it stopped the process and wiped the state.
  • A plain start: exits 1, stderr names broker.ts, and no plan.json is written.

pnpm typecheck and pnpm lint are clean, and the scripts/dev tests pass (15/15). On the first commit, pnpm test passed 952 of 953. The one failure was packages/integrations/src/postgres/Runtime.test.ts timing out at 5s under machine load; on its own it passes.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).

@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed 03a38b6 against origin/fix/339-stale-confirmation at eafeeb4, using git diff origin/fix/339-stale-confirmation...HEAD. Spec: #330. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The change moves compilation into the existing startup path and follows the runner's subprocess and structured-error patterns. No future-facing machinery was added.

Spec

No merge-blocking intent findings. Issue #330 asks to move broker generation into startup and keep stop, status, logs, and dry-run independent of compilation. The diff does that. A failed broker build still blocks a fresh start before it records a plan.

Verification

  • pnpm exec vitest run --config test/vitest.development.config.ts scripts/dev/src/main.test.ts scripts/dev/src/plan.test.ts: 10 tests passed. The new regressions cover stopping an owned process despite broken broker source and rejecting startup before writing a plan.
  • Additional checks ran the real root dev script in a fresh temporary worktree with invalid broker source. Dry-run returned valid JSON without creating state; status returned its expected unhealthy-instance result rather than a compiler error; logs returned the recorded log.
  • No existing .local/dev state was touched. No full server or database instance was started.

The affected contract is the dev runner and its development documentation. No API, seed, migration, rendered-page, package-layout, or product-model change requires a corresponding update.

Summary: Standards 0 blockers, no method or YAGNI blocker; Spec 0 blockers, no intent blocker.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Standards

No hard violations. BrokerBuildFailed matches the tagged errors already in scripts/dev/src/main.ts, and PackageBuildFailed in scripts/dev/src/supervisor.ts. The message is derived from exitCode. esbuild's text stays on the inherited stderr, so there is no Effect failure to store as cause.

Judgement, dev-loop surface. AGENTS.md says a scripts/dev change follows through to docs/DEVELOPMENT.md, the patchy-dev-loop skill, and the vitest template when seed rows change. docs/DEVELOPMENT.md now says a broker that does not compile fails the start, and names stop, status, and logs. The skill's start and stop steps are still true, and they never mention the broker build, so this is a missed mirror. Seed rows are unchanged. test/postgres.ts still builds the broker in global setup, so the template stays as it is.

The new sentence is glued to the Playwright paragraph. The subcommand table, and the file header in scripts/dev/src/main.ts, still describe start as writing plan.json and spawning. The operational fact belongs next to the table.

Judgement, failure order. buildBroker runs only from start, before writePlan, with stderr inherited so --json stdout stays the plan. stop, status, logs, --dry-run, and a healthy confirm return before that. reset reaches the build only after stopInstance and fs.remove of .local/dev. With the old package.json prefix, a failed broker build never entered main.ts. pnpm dev reset with a broken broker now wipes the dev database and exits 1 with no plan.json. The new tests cover stop, and a start on an empty worktree. They do not cover this path.

No baseline smell that the local pattern overrides. The error class is the house style for this file.

Spec

Issue #330 asked for the smallest change. Move broker generation off the left-hand side of package.json's dev script and into the startup path that needs fresh bytes. Keep stop, status, logs, and dry-run independent of compilation. Only stop had to be tested directly, because the shared wrapper was the gate.

That change is in place. The root dev script runs the runner only. buildBroker is the first step of start, before writePlan or spawn. stop, status, and logs read the recorded plan. --dry-run returns before start. A healthy pnpm dev returns before start, so a confirm does not compile. The server is not watched, and the next real start rebuilds.

reset is outside the keep-independent list. On this axis the wipe is reset's existing contract. A failed build inside start leaves no half-started supervisor and no new plan.json.

Findings against the written requirements: none. The diff is that move. BrokerBuildFailed, stderr inherit, and the stop/start test are how the move is done.

Standards has 2 judgement calls and 0 hard violations. The worst is that pnpm dev reset wipes .local/dev before the broker build can fail. Spec has 0 findings.

The spec axis treats that wipe as reset's existing contract. The method review treats the new failure order as a change from the old && gate. Those stay separate.

Method

Building inside start, before writePlan, is the right seam for the bug. A real pnpm dev and pnpm dev reset both reach start. stop, status, logs, --dry-run, and --help return without buildBroker.

Skipping the rebuild on a healthy confirm is correct. isRunning requires a live supervisor and /healthz. brokerScript is an imported constant, loaded when the server process starts, and the server is not watched. prepare, typecheck, and the serving build still run scripts/build-serving-broker.mjs on their own.

reset's prelude sits in front of that seam. The handler stops the supervisor, deletes .local/dev, then calls start, which builds. A syntax error in packages/serving/src/broker.ts used to fail in package.json before main.ts ran, so the instance and its state stayed. The same error on pnpm dev reset now stops the instance, drops the database and published files, and exits 1 with nothing recorded.

Call buildBroker at the top of reset, before stopInstance, and leave the call in start. A successful reset builds twice. That is smaller than a skip flag. A failed build then exits while the instance and .local/dev are still there.

stderr inherit and stdout ignore are right. esbuild writes the diagnostic to stderr. userFacing turns BrokerBuildFailed into the one line on stderr, and --json stdout stays the plan.

The build script's root is the directory above the script file, from import.meta.url. The runner passes plan.worktree as the script path, so a normal checkout builds that worktree. The test copies the script into the temp worktree. A symlink would follow import.meta.url back to this repo, compile the real broker.ts, and write packages/serving/src/generated/.

YAGNI

Keep the package.json change, BrokerBuildFailed, buildBroker, both tests, and the fake worktree.

buildBroker is worth the name. The invariant is the order: bundle, then record a plan. Once reset calls it too, it has two call sites. Inlining it into start would hide that order and force the reset fix to duplicate the spawn.

The fake worktree is the minimum that proves the bug. .git makes findWorktree stop in the temp dir. The node_modules symlink is how tsx, esbuild, and prettier resolve. The scripts/dev symlink is the root script's relative path. The copied build script plus export const = ; is what makes a restored && fail stop. A valid broker would build, then stop, and the test would pass for the wrong reason.

Keep the stop test's plan.json assertion. Exit 0 can also mean "Nothing recorded to stop." The dead pid shows the runner signaled that process. The file still being there is the "state stays" half of stop, in one line.

status, logs, and dry-run can stay untested. The issue asked for a direct stop test, and those commands share the early return.

Move the new docs/DEVELOPMENT.md clause off the Playwright paragraph. One line on the subcommand table is enough. A real start builds the broker and fails before writing a plan. stop, status, logs, --dry-run, and a healthy confirm do not build. After the reset fix, the table's existing "stop, wipe, and start" line stays the success path, and a broken broker fails before the wipe.

Tests

Both tests prove what they claim, read against the runner.

pnpmDev runs package.json's dev script through sh -c, with cwd set to the broken worktree. That is the string pnpm runs. Putting the build back on the left of && hits export const = ; in the copied script and never reaches stop.

The alive assertion runs inside the same scope as spawn, before the spawner's release finalizer. On the success path the runner's SIGTERM is what kills the idle process. The finalizer kills it if the assertion fails, so a normal failure does not leak the process.

The start test fails in esbuild on that syntax error, before Prettier, and stderr contains broker.ts. buildBroker runs before writePlan, so no plan.json. This path does call real isPortFree. It binds and closes ports. It does not start Postgres or the server when the build fails.

I did not re-run the file. The root Vitest setup starts embedded Postgres and rebuilds the real broker.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review follow-up in 758edc8.

Fixed

  • Reset failure order (grok). reset used to stop the instance and remove .local/dev before the build ran, so a broken broker cost the dev database. buildBroker now runs at the top of reset, before stopInstance and the wipe, and in the dev handler just before start. It is no longer called inside start, so a successful reset builds once, not twice. New test: reset with a broken broker exits 1, the recorded process stays alive, and plan.json is still there. This test failed before the change.
  • Doc placement (grok). I took the operational sentence off the Playwright paragraph and put it under the subcommand table in docs/DEVELOPMENT.md. It says start and reset build first, a failed build touches nothing, and stop, status, logs, dry-run and a healthy confirm never build. I also updated the file header in scripts/dev/src/main.ts to match.
  • Skill mirror (grok). The patchy-dev-loop skill does describe what start does: it lists the components and says where package-build failures show up. So it now has one line saying a broker that doesn't compile fails pnpm dev or reset on stderr before anything is stopped or wiped, and that stop, status and logs still work. It isn't the global patchy skill, so no skills-lock.json hash changes.

Kept as is

  • No tests for status, logs or --dry-run. They take the same early return as stop, which the issue asked to test directly. Astra also checked them by hand.
  • The vitest template. test/postgres.ts still builds the broker in global setup, and the seed rows didn't change.

Astra's review found no blockers.

@allisonmahmood
allisonmahmood force-pushed the fix/339-stale-confirmation branch from 699574a to 379c813 Compare September 24, 2026 14:02
Base automatically changed from fix/339-stale-confirmation to main September 24, 2026 14:09
allisonmahmood and others added 2 commits September 24, 2026 16:09
The root dev script bundled the shell broker before dispatching any
subcommand, so a syntax error in the broker source made `pnpm dev stop`
(and status, logs, --dry-run) exit 1 without stopping anything. The runner's
start path now builds the broker before recording a plan; every other
command dispatches without it.

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

reset stopped the instance and removed .local/dev before start built the
broker, so a syntax error cost the dev database. Start and reset now build
the broker before they record, stop or wipe anything. The operational note
moves next to the subcommand table and the patchy-dev-loop skill mirrors it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit d4404ff into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/330-dev-stop branch September 24, 2026 14:17
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
…patch's own rows (#364)

Stacked on #363 (branch fix/330-dev-stop).

Before a patch's first publish, editing a shared fixture (even a single row or a comment) wiped the patch's own local rows on the next `patchy dev` start. Only owned schema changes are supposed to reset local data.

The full-reset check compared the whole local stamp, and that stamp includes the hashes of the shared fixtures. It now compares only the owned-schema part. A fixture edit goes through the existing per-source refresh, which reseeds only the changed shared source. Identity changes, missing storage and real owned-schema changes still reset everything.

Closes #322

Test evidence:
- New case in `packages/patchy/src/devResources.test.ts`, built from the issue's reproduction with real PGlite state in a temp dir. It failed before the fix (`notes: []`) and passes after it. The same case checks that an owned column retype still recreates local data.
- `pnpm typecheck` and `pnpm lint` pass.
- `pnpm test`: 953/954 passed. The one failure was a 5s timeout in `packages/integrations/src/postgres/Runtime.test.ts` while the full suite ran under load. That file passes on its own.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dev: broker compilation failure prevents pnpm dev stop from stopping an instance

1 participant