Skip to content

fix(patchy): reverting a failed shared fixture edit brings its rows back - #365

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/318-fixture-retry
Sep 24, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/318-fixture-retry

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Stacked on #364 (branch fix/322-fixture-owned-data).

If you broke a shared-table fixture in patchy dev and then put the original back, that source's local rows stayed empty across every restart. Dev had already recreated the source when the fixture failed, but its stamp still recorded the last good fixture, so restoring those bytes looked like "nothing changed" and the INSERT never ran again.

Now dev removes the changed sources' entries from the stamp before it recreates them. A fixture that fails to seed counts as changed on the next start and gets another try. Other sources' entries and the patch's own rows stay as they are.

Test evidence:

  • New devResources.test.ts case follows the ticket's steps against a published consumer with one owned row: seed, typo the column (SharedFixtureInvalid), restore, restart twice. Before the fix: contacts: []. After: the contact is back on both restarts and the owned row is kept. It also passes with the baseline removed (never-published path).
  • pnpm typecheck and pnpm lint are clean. pnpm test: 952 passed, 3 hit 5s timeouts in untouched packages (company-database, integrations/postgres) while other test runs loaded the machine. All 3 pass when re-run alone.

Closes #318

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 104be71f6f265e1378001c9c1b15cb6c895a77fe with git diff origin/fix/322-fixture-owned-data...HEAD against issue #318. One pass, no subagents; merge-blocking findings only.

Standards

No merge-blocking method or YAGNI findings. The change reuses the existing per-source stamp and retry path without adding another state model or abstraction. The regression test exercises real resource preparation and handlers in a scoped temporary directory.

Spec

No merge-blocking intent findings. Issue #318 asks to invalidate the affected source's successful stamp before destructive recreation while preserving unrelated owned data and source stamps. The change removes only changed sources from the saved stamp before database preparation and restores the full stamp only after successful preparation. Reverting a failed fixture therefore triggers reseeding instead of accepting an empty source as initialized.

Verification

pnpm exec vitest run --config packages/patchy/vitest.config.ts packages/patchy/src/devResources.test.ts: 5 passed. The new regression covers the invalid edit, exact revert, and two scoped reopens, with the contact restored and the owned row retained.

No pnpm dev or Patchy CLI invocation. No existing .local/dev or .patchy/dev state used. This was module/handler verification, not CLI or browser end-to-end verification.

Summary: Standards 0 blockers, none; Spec 0 blockers, none.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed 104be71 against issue 318. The base is d89a916 on fix/322-fixture-owned-data.

Standards

The diff follows the documented standards.

Effect service conventions stay out of this change. The new branch in prepare uses the FileSystem already in scope. It does not create, move, or refactor a service.

The stamp rewrite at packages/patchy/src/devResources.ts:307-319 is the small model for this bug. A changed source's hash is dropped before make recreates and seeds. make writes the full stamp only after success, at devResources.ts:198. A failed seed, including a revert to the last good fixture, is a change on the next start. The comment states that invariant. Nothing here changes the wire, the CLI, migrations, vocabulary, or HTML, so those surfaces need no matching edit. The new it.live is the focused behavior test the Effect test rule asks for when behavior changes. It uses the real fixture file.

One smell, as a judgement call. Duplicated code: the new session at devResources.test.ts:316-341 repeats the binding, call, and list shape from the sibling at devResources.test.ts:196-224. Each it.live in this file is self-contained. A shared harness would be an abstraction the Final note in AGENTS.md tells us to skip. The second assert at devResources.test.ts:352 checks that the reseeded rows are still there on the next prepare.

Spec

The diff matches issue 318.

Missing or partial. None. The published-consumer case is covered. The issue says restoring the exact previously-working fixture should restore its contact, and that another restart returned 0 rows. The new test sets a baseline, changes title to titel, expects SharedFixtureInvalid, restores the original bytes, and reads again on a second prepare. prepare drops only changedSources entries from schema.json before make drops and seeds. The reverted bytes no longer match a successful stamp, so the INSERT runs. That prepare then writes the full stamp. The prepare after that reads the rows still in the database.

Owned notes stay. The rewrite keeps companyId, patchId, owned, and every other shared entry. schema.json remains on this path. The issue says deleting all of schema.json would broaden the data loss. Fixture edits still apply on the next prepare, which is the documented stop/start. A valid fixture is seeded on that next prepare. Reset is still there for disposable local data, and this bug no longer needs it.

Scope. None. The diff is the stamp rewrite and the regression test. The issue allows this method in its own words: "Invalidate only the affected source's successful stamp before destructive recreation." The branch does that for every changed source. When the seed later succeeds, line 198 replaces the stripped stamp with the full one. On an unpublished patch, a fixture-only edit already avoids the full wipe, from the parent branch. This same strip covers that edit. The full wipe remains where the parent put it, on unpublished owned-schema changes.

Wrong implementation. None. Failure still happens after the source schema is dropped. make writes the full stamp only when seeding returns, under if (state.changed || state.initialize). A failed seed leaves that source unstamped, so the next start retries it. The bad fixture is never recorded as success. Other sources stay out of changedSources, so their schemas stay.

The new test passed on this commit: vitest reported 1 passed, 4 skipped. Without the strip, the restored bytes match the last good stamp, changedSources stays empty, the INSERT is skipped, and the contact assert fails.

Method

The stamp strip is the right method for this bug.

prepare reads schema.json once. When initialize is false and changedSources is non-empty, it rewrites the file from the decoded stamp with those patch ids removed, before Layer.build and make. make still drops from the in-memory set. SharedFixtureInvalid is thrown before the success write at line 198, so the next process reads the stripped file. A missing shared[patchId] differs from the restored hash, so that source is changed again and the INSERT runs.

On success, changed was computed from the original file bytes, previous !== stamp. A real hash change makes that true, so line 198 replaces the stripped file with the full new stamp.

The new branch runs only when initialize is false. A wipe removes the stamp and the data directory on its own branch. The filter removes only changed patch ids. Two aliases on one source share one stamp entry and one DROP SCHEMA, so both fixtures run again. The rewritten object is the stamp schema: companyId, patchId, owned, and shared. The next decode accepts a missing shared key.

A transaction around the drop and the fixture would roll the empty schema back, so a failed edit would leave the previous shared rows on disk. Drop and provision already commit inside withPatchLock. The fixture runs in a later PGlite transaction. A failed prepare does not serve a session. The next start the user gets is the same either way. That source is seeded from the fixture. Owned rows and other stamps stay. Local rows are disposable. The 13-line stamp edit is the smaller model. Keep it.

YAGNI

This is the small version. There is no new helper, type, parameter, error, or service. Option.isSome narrows the else branch. changedSources.size > 0 skips a rewrite when nothing changed. The comment earns its place. The early write sits next to the success write at line 198, and the comment says why it has to happen first. A failed seed has to leave that source out of the stamp.

The test is the published-consumer repro from the issue. The copied session stays. A stamp service or a transaction type would be a larger model for the same result. The branch, the comment, and this one test are the whole change.

Standards: 0 hard violations. 1 judgement-call smell, the duplicated test session, and the repo's YAGNI note overrides it, so no change. Spec: 0 findings.

Reviewed by Grok 4.7 in Grok Build.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Both reviews are clean on 104be71. Nothing to fix.

Kept as is:

Checks on 104be71 all pass: lint, test (22), test (24), cli-smoke, clerk-live, postgres-concurrency, dependency-review, label. The PR is mergeable. It's stacked on #364, which has to land first.

@allisonmahmood
allisonmahmood force-pushed the fix/322-fixture-owned-data branch from df13176 to 483a491 Compare September 24, 2026 14:17
Base automatically changed from fix/322-fixture-owned-data to main September 24, 2026 14:25
Dev recreated a changed shared source before running its fixture, but a
failed fixture left the last successful stamp in place. Restoring the
original fixture then matched that stamp, so the source stayed empty.
Now the changed sources' stamp entries are dropped before recreation, so a
failed seed is retried on the next start. Other sources' entries and the
patch's own rows are untouched.

Closes #318

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 2ede93a into main Sep 24, 2026
15 of 23 checks passed
@allisonmahmood
allisonmahmood deleted the fix/318-fixture-retry branch September 24, 2026 14:53
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
…generated client (#366)

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).
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: undoing a failed shared fixture edit leaves rows empty across restarts

1 participant