Skip to content

fix(patchy): dev no longer serves a manifest that disagrees with its generated client - #366

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/331-double-config
Sep 24, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/331-double-config

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #365 (branch fix/318-fixture-retry).

patchy dev evaluated patchy.config.ts twice and kept the second result. Saving a file the config imports between the two runs gave a prepared manifest that differed from the generated client. Closes #331.

Preparation now evaluates config once. The second run was also where the generated index checks happened (release, manifest version, stamps, declarations), so those move into resolveStamps, shared with executeConfig. prepare stamps its single evaluation with resolveStamps, using the index from the generation response, and that one manifest is checked against the generation metadata, written to manifest.json and returned. The old second walk that stamped from the response's uses array is gone; the metadata consistency check stays.

Behaviour changes:

  • The index is checked before the generated files are activated, so a stale index is refused without touching the repo. Before, the files were written and then rolled back.
  • A generation response with no index is refused with "Generation returned no declaration index."
  • Stamps come from the index, not the response's uses array. The server builds both from one array, so a mismatch between them is a server defect; it now surfaces as stale_generated instead of "Generation returned no stamp for …" / "an inconsistent declaration set".

Tests: devPreparation.test.ts calls prepare against an in-memory instance.

  • The reproduction (change fields.ts from title to body mid-generation) failed before the fix and passes now.
  • A stale-release index is still refused with stale_generated.
  • A declared shared table is stamped from the index, and metadata with a different revision is refused.

The existing executeConfig refusal tests pass unchanged. pnpm typecheck and pnpm lint pass, and all 310 tests in packages/patchy pass.

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

@github-actions github-actions Bot added area:cli Touches the cli area size:m 100-500 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed origin/fix/318-fixture-retry...HEAD, base 104be71 through PR head 2718d91, against #331. One pass, no subagents. One merge blocker.

Standards

Method: keep one stamped-manifest assembly

At devPreparation.ts:148–151, resolveStamps(unresolved, index.contents) returns a complete validated manifest, but the caller discards it. prepare already assembled another manifest at lines 98–113. Both paths build an alias map, check declaration membership, apply IDs/revisions and decode Manifest.

I would block on finishing this simplification. Keep the shared resolveStamps implementation and use its returned manifest for activation and the prepared result. Remove the earlier independent stamp assembly; validate metadata against that manifest's uses. Preserve necessary response-consistency checks as checks, not as another manifest construction. Do not simply delete the new call: its release/version/stamp/declaration refusals are required by #331.

This is a possible Duplicated Code finding and a design judgment, not a demonstrated runtime regression. It follows the root AGENTS.md guidance: "Do not preserve complexity just because it already exists." The overlap is in assembly; the index and metadata checks have distinct responsibilities and should remain.

No separate YAGNI blocker. The helper has two current consumers, and moving index validation before activation is part of removing the second config execution.

Spec

No merge-blocking findings. #331 says: "Return the first validated manifest without executing config again" and "Retain the generated index release, version, stamp and declaration checks against that snapshot." The diff does both. The main-config source guard remains in the activation transaction; imported files are not overwritten.

Verification

Ran pnpm exec vitest run --config packages/patchy/vitest.config.ts packages/patchy/src/devPreparation.test.ts packages/patchy/src/executeConfig.test.ts: 33 tests passed across 2 files. These tests use temporary directories. Did not run pnpm dev, the patchy CLI, or use existing local dev state.

Summary: Standards 1 blocker, overlapping stamp assembly; Spec 0 blockers, none.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed 104be71...2718d91 against issue 331. Separate passes covered the spec, repo standards, the implementation method, YAGNI, and regressions.

Standards

The diff conforms to the documented standards. It leaves commands, flags, exit codes, and the --json shape alone. ADR-0004 and the patchy README still match publish. executeConfig reads patchy/_generated/index.json and refuses a mismatch with stale_generated.

Effect service conventions do not apply. resolveStamps is a plain function shared by executeConfig and prepare.

No Fowler smell needs a change. The extraction is the existing index walk, called from dev on the response body and from publish on the file. Two callers is the point where this repo shares a function.

Spec

Issue 331 is met.

The problem is a save of an imported file between two config executions, so the prepared manifest can disagree with the manifest generation already ran. prepare returns the manifest decoded from the first evaluation. devPreparation.test.ts writes fields.ts as title, changes it to body during the generate request, and asserts the request and the prepared manifest both still have title.

The issue says to return that first validated manifest, skip the second execution, and still refuse a generated index whose release, manifest version, stamps, or declarations do not match the snapshot. prepare calls executeConfig once, with resolve: false. resolveStamps(unresolved, index.contents) runs those four refusals on the index in the generation response. The publish path is unchanged. A stale release still fails with stale_generated, and the executeConfig refusal tests are untouched.

The issue says to leave the author's concurrent edit in place. activate still throws ProjectChanged when patchy.config.ts differs from the source read before generation. An imported file stays as saved, and this preparation does not adopt it.

The PR also checks the index before activate, and a response with no patchy/_generated/index.json fails with "Generation returned no declaration index." That follows from running the check on the response instead of on a file the second execution used to read back. The old failure was stale_generated after a write and a rollback, which tells the user to refresh. ADR-0004 allows a local error with no code. The message matches the existing "Generation returned no stamp" errors.

Method

The method is sound. Dev keeps one config evaluation. The manifest written to manifest.json is the manifest prepare returns. The index refusal runs on the same bytes activate will write, and it runs before the write.

generated.uses is alias, id, and revision. The loop from line 98 through 113 copies those onto the first evaluation, decodes manifest, and checks generated.metadata against that object. Local dev opens tables from prepared.manifest and connection state from prepared.metadata, so those ids are the ones that have to match. resolveStamps copies ids from the index and never reads metadata. prepare ignores its return value because the manifest to run is the one just checked against metadata. The call is there to throw.

Keep both walks. A uses array that omits an alias is "Generation returned no stamp", with no refresh code. An index from another release is stale_generated. Replacing the first walk with the resolveStamps result would report one of those failures as the other, or would leave a second check beside it.

Generation.generate builds one uses array, writes it into index.json, and returns alias, id, and revision from that same array. The index and generated.uses in a current server response are slices of that array. The wire type does not link the fields. Leave that alone. An equality check would only reject a response this server does not send.

Description still arrives on the returned manifest. prepare copies repo.description onto the first evaluation before generation, and decodeManifest keeps it. defineConfig has no description field, so the removed second execution was not where description came from.

A save of patchy.config.ts after activate returns used to be read by the second executeConfig. This run now keeps the first snapshot, and the save waits for the next run. The guard inside activate is the same.

YAGNI

The diff is as small as the constraint. Keep resolveStamps. Publish needs the manifest it returns. Dev needs the throw. A second helper that only throws would repeat the walk, or drop the value publish uses.

The comment above the call states why dev must not evaluate config again. The doc comment on resolveStamps states what a bad index refuses. Both match the code.

The new test is the one this bug needs. prepare forks the config child and calls /api/me and /api/sdk/generate, so the temp repo and the in-memory client are the seam. The column assertion is the imported-file regression. The stale-release assertion fails if the resolveStamps call is deleted. The rest of the stamp matrix stays in executeConfig.test.ts.

Summary

Standards, 0 findings. Spec, 0 findings. I would merge this.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review follow-up, in 6065647.

Fixed

  • Astra's blocker, the duplicate stamped-manifest assembly. prepare now uses the resolveStamps result as the manifest it activates, checks against generated.metadata and returns. The earlier walk that stamped aliases from generated.uses is deleted.
  • devLifecycle.ts lost its SchemaError handler ("The instance returned invalid declaration metadata."). prepare no longer decodes a manifest itself, so that error can no longer occur and the handler failed typecheck.
  • Added a test: a declared shared table is stamped from the index, and metadata with a different revision is refused with "Generation returned inconsistent metadata for contacts."

Kept as is

  • The metadata consistency checks (count and per-alias kind/id/revision/handle/table). They validate what local dev opens connections from, a separate job from the index checks, and they now compare against the one manifest.
  • The release, manifest version, stamp and declaration refusals in resolveStamps. patchy dev: double config execution can disagree with the generated manifest #331 requires them.
  • grok's case for keeping both walks. As the foreman decided, a uses array that disagrees with the index is a server defect, since Generation.generate builds both from one array. It now surfaces as stale_generated instead of "Generation returned no stamp for …" or "Generation returned an inconsistent declaration set." No test asserted those messages, so no expectations changed. The PR description lists this as a behaviour change.

Base automatically changed from fix/318-fixture-retry to main September 24, 2026 14:53
allisonmahmood and others added 2 commits September 24, 2026 16:54
patchy dev evaluated patchy.config.ts twice: once for generation and again
after activation, returning the second result. Saving an imported config file
in between produced a prepared manifest that differed from the generated
client.

Preparation now returns its first validated manifest and runs the generated
index checks (release, manifest version, stamps, declarations) against that
same evaluation through resolveStamps, shared with executeConfig. The index is
checked before activation, so a stale one is refused without touching the repo.

Closes #331

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

prepare assembled a stamped manifest from the response's uses and then built
the same manifest again in resolveStamps only to discard it. It now uses the
resolveStamps result as the manifest it activates, checks against the
generation metadata and returns. The metadata consistency check stays.

prepare no longer decodes a manifest itself, so the dev lifecycle's
SchemaError handler for it is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit a53b31b into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/331-double-config branch September 24, 2026 15:02
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
Stacked on #366 (branch fix/331-double-config).

Closes #324.

A tier 1 patch that routed to `/café` saw `/café` after `route.set`, then `/caf%C3%A9` after pressing Back to the same history entry, so a router matching the path showed "not found" while the URL hadn't changed (#324). The client kept its own raw request after a set. Back reported the browser's percent-encoded address. The initial load already decoded it.

Now the shell decodes the patch-relative path once, the same way hosted parsing does, and reports that form for the initial load and Back/Forward. `route.set` still acknowledges with `null`, as wire 1 promises. Right after the acknowledgement the shell sends its ordinary `route` event with the decoded path, so `set("/caf%C3%A9")` also settles on `/café`. The client still takes the requested path on acknowledgement, and it no longer notifies subscribers when a route update leaves the path unchanged, so a plain set reports once. Already-built bundles keep their `null` result and their cached request path is corrected by the same event; there is no wire-version bump, so no stored version is sent to the needs-rebuild door.

Tests:
- New tier 1 browser test (set, Back, reload, encoded set) failed on the old code with `Received: "/caf%C3%A9"` after Back and passes now. The full Chromium tier 1 suite passes 5/5. Firefox wasn't run because its Playwright build isn't installed locally.
- `clientTransport.test.ts` has the shell's route event repeat an unchanged path after a set and checks that subscribers aren't notified twice. That assertion fails without the change.
- `pnpm typecheck` and `pnpm lint` are clean. `pnpm test`: 953/958 under load from parallel runs. The 5 failures were in `devLifecycle.test.ts` and the two Postgres integration files, none of which this PR touches, and all 17 tests in those files pass when run alone.

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:cli Touches the cli area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

patchy dev: double config execution can disagree with the generated manifest

1 participant