Skip to content

feat(patchy): initialize tier 2 repos and switch tiers with refresh - #435

Merged
allisonmahmood merged 2 commits into
mainfrom
tier2/402-init-tier2
Oct 1, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
tier2/402-init-tier2

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Tier 2 patches can publish, but agents still need a working starter and a reliable way to move existing repos between tiers.

Adds patchy init --tier 2 with a Preact page and typed server handlers. Init takes the exact workerd pin from the installed release. Refresh manages both tier transitions, including pins, generated server types and the tier-specific skill, while preserving authored files. Updates the global and project skills, skill-lock hash and CLI/product documentation.

Stacked on tier2/401-publish-tier2 / #434. This PR targets that branch and contains only the #402 changes. Implements #402 from spec #384.

Verification

  • Typecheck and lint passed.
  • Full suite passed: 1,394 tests across 124 files. After the final init pin-source correction, package typecheck, targeted lint and both init tests passed.
  • Isolated smoke covered init, two-artifact publish, both tier transitions, stale module-list and pin refusals, context cleanup and public-sharing recovery.
  • The hosted starter saved a note and retained it after reload. A separate release-drift smoke selected the installed release's engine and typechecked in 0.83 seconds.

Tier 2 query subscriptions and the patch-repo dev engine remain #403 and #404; the starter uses one-shot server calls on this stack.

Implemented with OpenAI GPT-6 Astra through omp.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:xl Over 1,000 changed lines; review in multiple passes labels Sep 29, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed b952a135 against origin/tier2/401-publish-tier2 at 246580f9, using git diff origin/tier2/401-publish-tier2...HEAD. One pass, no subagents. Scope: merge-blocking intent, method and YAGNI findings against #402 and #384 §13.

Standards

No merge-blocking method or YAGNI findings. The change extends the existing generation and managed-file transaction paths rather than adding a separate tier-change mechanism.

Spec

No merge-blocking intent findings. The implementation covers tier 2 initialization, both tier transitions, managed pins/files/skills, stale module-list refusal and the requested skill fixes. It keeps query subscriptions and the production-engine dev loop explicitly assigned to #403 and #404.

Verification used a temporary repo, loopback-only metadata and package-registry fixtures, the real SDK generator, packed CLI and installed tools:

  • init --tier 2 installed exact workerd 1.20260924.1, generated server helpers and installed patchy-server. The unchanged tree typechecked in 1.27 seconds; its Vite page build passed.
  • Adding a server module without refresh made publish return stale_generated.
  • Refresh in both directions added/removed the engine pin, server helpers and server skill, removed stale context, and preserved authored source. Typechecking passed after returning to tier 2; an unchanged refresh reported no pin change.
  • The global skill's SHA-256 matches skills-lock.json.

Reviewed the affected CLI/JSON, generation/dev preparation, starter, skills, ADR, product and glossary changes. No new wire schemas, migrations, company-resource locking or package-layout changes. Hosted publication, browser behavior and the full test suite were not rerun.

Blocking findings: Standards 0; Spec 0. No merge blocker identified on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Opus review

Reviewed b952a13 against origin/tier2/401-publish-tier2 (git diff origin/tier2/401-publish-tier2...HEAD), checking it against #402 and #384 §13/§19. I verified the tier flip and the starter on a scratch copy of the worktree; the details are under each finding.

Blocking, most severe first

1. Internal tracker numbers ship to customer agents. This PR adds #403/#404 to content that leaves the repo:

  • the project skills: packages/sdk/skills/patchy-loop/SKILL.md:20, :156; patchy-server/SKILL.md:16-17; patchy-postgres/SKILL.md:16; patchy-shared-tables/SKILL.md:16
  • the global skill: skills/patchy/SKILL.md:145
  • the package README: packages/patchy/README.md:160-162, :412

The patchy tarball ships README.md and skills (files in packages/patchy/package.json), and the global skill installs from GitHub. A company's agent can't open these issues, and the text won't change when the tickets close. None of these files had tracker refs on the base branch. Say what is true in this release instead, for example "patchy dev does not run tier 2 handlers in this release; exercise them on a development instance with invented data". The refs can stay in ADR-0004 and docs/product.md, which are internal.

2. Write-once AGENTS.md now contains a temporary workaround (packages/patchy/src/initProject.ts:200). Every repo initialized from now on, on any tier, gets "For tier 2, typecheck and publish to a development instance with invented data". This PR's own docs say refresh never rewrites AGENTS.md, so the line stays wrong in those repos after the tier 2 dev loop lands. §13 asks for AGENTS.md wording that "holds on either tier". Keep the durable pointer ("the loop skill says how to exercise each tier") and leave the temporary boundary to the release-bound skills, which already state it.

3. The Done-when behaviour has no test. #402's Done-when says: "flipping tier and running refresh both ways leaves the right pins, generated files and skills". The new reconciliation in packages/patchy/src/Project.ts:596-608 (workerd setPin, a second prepareInstall/install when the patchy pin is unchanged, pinChanged = true) is not exercised anywhere. Existing coverage is ManagedProject rollback, SdkApi skill selection and a tier 2 refresh that starts with workerd already pinned. On a scratch copy I extended the offline init case: init tier 1, set tier: 2, refresh, typecheck, set tier: 1, refresh, refresh again. It passes: the workerd pin, server.ts and patchy-server are added and then removed, typecheck names the three patchy.tables calls, and the last refresh reports pin: false. So the behaviour works. Commit a test like that, extending the existing it.each([1, 2]) init case, so it stays working.

4. A tier round trip rewrites builder-owned package.json bytes (packages/patchy/src/packagePin.ts:50-55). The insert goes directly after {. From the scratch run:

  • tier 1 → 2 produced "devDependencies": {"workerd": "1.20260924.1",\n "patchy": …
  • tier 2 → 1 left "devDependencies": {"patchy": …

The newline and indent that belonged to patchy are lost for good. That contradicts ADR-0004 ("preserving builder-owned keys and the surrounding package.json bytes") and leaves a noisy diff in a committed file. Insert "workerd": "…", plus the first property's leading whitespace at that property's getStart. The existing removal path (property start to the next property's start) then restores the original bytes exactly.

5. The pin removal relies on an incorrect type (packages/patchy/src/ManagedProject.ts:150). JSON.stringify(pin) with pin: string | undefined is typed string. The removal path only works because JSON.stringify(undefined) returns undefined at runtime. Write pin === undefined ? undefined : JSON.stringify(pin) so the "remove" meaning shows in the types.

Checked and fine

  • Starter tree. init --tier 2 typechecks in about 1.2 s and lints clean. Its generated server.ts binds notes, and Inspection.inspect on the starter's server bundle returns notes.list (query) and notes.create (mutation).
  • Publish in the cli.test harness. It stops at inspection only because the harness CLI (packages/patchy/dist) cannot resolve workerd. That is a harness limit: the repo-installed CLI resolves it.
  • Surfaces and contracts. Init --json shape and exit codes are unchanged. The skills-lock.json hash matches sha256sum skills/patchy/SKILL.md. Dev no longer rewrites server.ts. patchy-server removal below tier 2 works through removedSkills. The reference-CRM skill fixes (bigint aggregate, named ref index, both concurrency limits) are present and their numbers match packages/limits/src/registry.ts.

Reviewed by Claude Opus 5.5 via Claude Code.

@allisonmahmood

allisonmahmood commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner Author

Addressed the review in 7c3ffa9.

I read the conversation comments, review bodies and inline review comments. Astra reported no blockers. Opus's five findings were valid; all five are fixed. No Grok review or inline findings were present.

  1. Shipped tracker references: replaced feat(runtime): tier 2 query subscriptions: traced dependencies, recoverable refusals, the re-run caps #403/feat(patchy): patchy dev on the production engine: live server rebinding, the colleague mount on both tiers, dev.log #404 in the global skill, project skills and package README with explicit current-release limits. Customer agents no longer need internal issues to understand supported behavior. Refreshed the global skill's lock hash.
  2. Write-once agent guidance: generated AGENTS.md now points to the release-bound patchy-loop skill for exercising the configured tier. It no longer freezes the temporary tier-2 workaround into newly initialized repos.
  3. Tier-transition coverage: extended the real offline CLI init case through tier 1 → 2 → 1 and an unchanged refresh. It checks the exact installed engine, generated server helpers, server skill, expected TypeScript diagnostics, restored typechecking, unchanged authored files and changed.pin: false on the final refresh.
  4. Package formatting: insertion now starts at the first property's token and repeats its leading whitespace after the inserted comma. Removing the engine pin restores the original bytes. Added successful-transaction coverage for compact, spaced, LF and CRLF/tab formatting; the CLI round trip also asserts original package.json bytes.
  5. Removal type: setPin now passes an explicit undefined for removal instead of relying on JSON.stringify(undefined) returning a value its declared type hides.

Kept as is:

  • Internal issue references in ADR-0004 and docs/product.md, because those documents track implementation work inside this repository rather than instruct customer agents.
  • The current tier-2 runtime boundary and one-shot starter calls. Query subscriptions and the patch-repo dev engine remain separate work; this PR does not claim they are available.
  • Astra's no-blocker assessment required no additional change.

Verification on the pushed changes:

Latest-commit verification is complete for 7c3ffa950bcca2fe33767b68c40f4bf2b5232fbe. All eight reported checks passed: test (22), test (24), lint including formatting and workspace typecheck, cli-smoke, postgres-concurrency, clerk-live, dependency-review and label. CI run. The stacked base has no configured required status checks.

Rechecked conversation comments, review bodies and inline comments after CI: no new findings. GitHub reports MERGEABLE and CLEAN against tier2/401-publish-tier2. No unresolved blockers; ready to merge into the specified stacked base. I have not merged the PR.

@allisonmahmood
allisonmahmood force-pushed the tier2/401-publish-tier2 branch from 246580f to 9d2f17e Compare October 1, 2026 03:31
Base automatically changed from tier2/401-publish-tier2 to main October 1, 2026 03:43
@allisonmahmood
allisonmahmood merged commit b2a50ca into main Oct 1, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the tier2/402-init-tier2 branch October 1, 2026 03:56
allisonmahmood added a commit that referenced this pull request Oct 1, 2026
Tier 2 pages can call server queries, but their results do not stay in
sync when a colleague changes the data.

Enable generated query `.subscribe` and `useQuery` through the existing
document stream and scheduler. The host tracks resources read by each
query, preserves the last value through refusals, and recovers on
reshare. Permanent failures end only the affected subscription; loss of
document authority stops the document. The installed SDK uses one Preact
runtime in optimized development and production builds.

Stacked on #435, `tier2/402-init-tier2`. This PR targets that branch and
adds only the query-subscription work for #403.

Closes #403.

## Verification

- Typecheck and lint passed.
- 39 focused runtime tests and 27 Postgres concurrency tests passed.
- Three published-browser scenarios passed, covering two-viewer updates,
reconnect and hidden-tab recovery, unshare/reshare, handler removal, and
argument limits.
- Packed Preact checks passed in optimized development and production
builds. Manual browser smoke used real published workerd patches.
- Standards and spec reviews have no remaining findings.

The full offline suite is not green: 123/125 files passed, with four
timeout failures. Postgres mapping passed in isolation, and refresh
passed with a longer diagnostic deadline. Both unchanged CLI-init cases
still timed out. No diagnostic edits or timeout changes are included.

Implemented with OpenAI GPT-6 Astra using the omp harness.
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:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(patchy): patchy init --tier 2, the server module list and changing tier in refresh

1 participant