Repository navigation
fix(check): a failed package leaves no shared TypeScript state behind - #32
Merged
Merged
Conversation
On main, @types/react checked after @types/node's stack overflow in the same process got a signature beginning with Node's assert types: TypeScript's printer clears its writer only when a print finishes, so the overflowing print left its partial text in front of every later print. - serialize.ts: a print that throws replaces the printer before rethrowing, and the transformation result is always disposed. - shared-state.ts: modules register how to discard what they share across packages (the printer, the consumer repository's program and checker, the detailed surfaces, the zod pack's parsed files); check calls resetSharedState() after any per-package failure, before the next package. Tests: a print that fails halfway leaves the next print clean; with widget failing mid-print before logkit (concurrency 1, as the CLI's workers run), logkit's report is byte-identical to checking logkit alone (on main it began with 'Partial<'); a reset gives the next package a fresh program. Cost: nothing without a failure (zod 3 -> 4 declaration diff, four runs each: 54.6-60.3 s on this branch, 56.0-66.6 s on main, identical results). After a failure, one reload of the consumer project: about 4 s on documenso's packages/lib (1,251 files), 0.1 s on storefront. A fresh worker per package would pay a full load (5.6 s there) for every package. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lucas Braum <[email protected]>
…against unregistered caches fix takes one package per run (there is no fix --group), but a process can still run several: the Action fixes each detected upgrade in turn, then checks the next. fix() now discards shared TypeScript state when it fails, before its caller goes on, and so does a failed assisted attempt (which fix catches and retries) before the next attempt or site. Tests, which fail without the wiring (no reset happens): a fix that fails inside TypeScript's printer, followed in the same process by a check of logkit that is byte-identical to logkit checked alone; an agent attempt that fails inside the printer, after which the state is reset and the retry migrates the site. shared-state.test.ts scans packages/core/src: a module-level new Map, new WeakMap, ts-morph new Project or createPrinter( fails the test unless its file registers with onReset or the line is marked '// shared-state: not TS-dependent'. compile.ts's three program/diagnostic WeakMaps and usages.ts's file index now register (they were keyed by a repository a reset discards, now dropped explicitly); the workspace-glob and package.json caches are marked. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lucas Braum <[email protected]>
7 tasks done
lucasbraum
added a commit
that referenced
this pull request
Oct 7, 2026
…t a default's ` = ` (#44) ## What and why **Fixes:** `check` (and `diffPackage`) died with `Manipulation error: A syntax error was inserted.` on `i18next` 23 → 26 and `type-fest` 4 → 5, so those upgrades could not be analyzed at all. It was found while ranking `packs/queue.json` (#43). No issue was filed. **Root cause.** Both packages contain the same construct: a type alias that changed between versions and whose type parameters have defaults. The compat program in `packages/core/src/adapters/typescript/compat.ts` declares each changed alias's old and new body as `type __a_N<params> = body` and adds it with `addStatements`. `bodyFor` (case `'type'`) took the body from the first `' = '` in the signature. With a default, that `' = '` sits inside the type-parameter list, so the generated alias repeated the tail of its own parameter list: - type-fest: `type __a_1<Array_ extends readonly unknown[], Start extends number = never, End extends number = never> = never, End extends number = never> = ...` - i18next: `type __a_0<TOptions = object> = object> = i18nextMod.BackendModule<TOptions>;` ts-morph throws only when the broken alias's body contains a template literal type: type-fest's `CamelCase<Type, Options extends CamelCaseOptions = {}>`, i18next's `TFunctionReturn<…, ActualNS extends Namespace = NsByTOptions<Ns, TOpt>, ActualKey = KeyWithContext<Key, TOpt>>`. Without one, the broken alias didn't crash. It compiled to an error type and its comparison was silently lost. That second effect is fixed too. The recursion cut from #31 and the shared-state reset from #32 are not involved; the mis-split predates both. **Fix** (`compat.ts` only, no try/catch around it): a new `aliasBody()` finds the `>` that closes the type-parameter list and takes the alias's own `' = '` after it. The bracket-depth scan is shared with `headerTypeParams` and `countParams`, and it now ignores the `>` of `=>` and text inside string and template literals. The old scanners miscounted a `=>` inside a parameter's constraint or default. ## How it was verified - Reproduced with `diffPackage` before the fix: `type-fest ERROR Manipulation error: A syntax error was inserted.` (at `index.d.ts:233`) and `i18next ERROR …` (at `index.d.mts:64`). After: type-fest 4.41.0 → 5.10.0 gives 194 changes, and i18next 23.16.8 → 26.4.2 gives 115. - Two regression fixtures, no network, following the `recursion.test.ts` / `fixtures/deps/*-vN` convention. Both fail on main's `compat.ts` with the manipulation error and pass now: - `fixtures/deps/slice-v1`/`-v2` model type-fest: a re-exporting entry, `CamelCase<Type, Options extends CamelCaseOptions = {}>` over a template literal, and `Slice<Array_, Start extends number = never, End extends number = never>`. Result: `type breaking CamelCase` and `widened additive Slice`. - `fixtures/deps/backend-v1`/`-v2` model i18next: aliases over a namespace import, `BackendModule<TOptions = object>` → `<Options = object>`, and a `Lookup<…>` with defaulted parameters over a template literal. Result: `type breaking Lookup`. The checker finds `BackendModule`'s parameter rename equivalent. - `pnpm lint` (601 files, no fixes), `pnpm typecheck` (3/3), `pnpm test` (uptide 345/345; core 876 passed, 15 skipped, the existing env-gated ones). - Pack tests are unchanged. Each line is predicted/expected/false positives/false negatives, identical to main: | Pack | Repository | Result | | --- | --- | --- | | zod (`PASS zod: verified`) | storefront | 38/38/0/0 | | | AwesomeIntune | 12/15/0/3 | | | PATH | 39/51/0/12 | | | band-sdk | 29/37/0/8 | | stripe (`PASS stripe: verified`) | storefront | 4/4/0/0 | | | unkey | 13/15/0/2 | | | saas-starter | 1/1/0/0 | | ai (`PASS ai: verified`) | chatbot | 27/27/0/0 | | | morphic | 20/34/0/14 | ## Checklist - [x] Tests for the change (a bug fix starts with a failing test): `alias-defaults.test.ts`, both cases failing before the fix - [x] `pnpm lint && pnpm typecheck && pnpm test` pass - [x] README and docs updated if behavior changed: no doc describes this internal step - [x] Changeset added (`.changeset/alias-default-params.md`, patch) - [x] No new dependency - [x] No private code, names or paths in fixtures, tests or docs: the fixtures are minimal models, not copies of the packages - [x] The rules in CONTRIBUTING.md ("Rules that do not bend") still hold 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01B2T8GmEVnZwfNrugajEMqi --- _Generated by [Claude Code](https://claude.ai/code/session_01B2T8GmEVnZwfNrugajEMqi)_ Signed-off-by: Claude <[email protected]> Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #31.
Problem
In the regression run for #31,
mainchecked@types/reactright after@types/nodeoverflowed the stack in the same process. One@types/reactchange came out with a signature that began with Node'sasserttypes (AssertOptions & { strict?: …). Run alone,@types/reactwas correct.TypeScript's printer clears its writer only when a print finishes. A print that throws, a stack overflow included, leaves its partial text in front of every later print. Uptide shares one printer across all packages. Reproduced in isolation: after a print of
Partial<X>fails onX, printingLoggerreturns"Partial<Logger".Fix
serialize.ts: a print that throws replaces the shared printer before rethrowing, and the transformation result is always disposed. This fixes the exact corruption seen, wherever a print fails.shared-state.ts: a small registry. Each module registers how to discard what it shares across packages:repo.ts; the per-repository WeakMaps incompile.tsandusages.tsgo with it);usages.ts);checkcallsresetSharedState()after any per-package failure, before the next package. A stack overflow can leave a checker mid-resolution too, not just the printer, so everything is discarded.I chose the reset over a fresh worker per package because of cost (below).
fixtoofixtakes one package per run; there is nofix --group(--groupexists oncheckonly). But one process can still run several packages: the Action fixes each detected upgrade in turn, then checks the next. Two boundaries now reset:fix()itself discards shared state when it fails, before its caller goes on.fixcatches it and retries; the state is discarded before the next attempt or site.Guard against new caches
shared-state.test.tsscanspackages/core/srcand fails on any module-levelnew Map,new WeakMap, ts-morphnew ProjectorcreatePrinter(, unless the file registers withonResetor the line is marked// shared-state: not TS-dependent. A planted cache (const programs = new Map<string, ts.Program>()) is reported by file and line. Current state:compile.ts's three WeakMaps of programs and diagnostics, andusages.ts's file index. They were keyed by the repository a reset discards; they're now dropped explicitly.package.jsoncache, which hold no TypeScript state.Tests
serialize.test.ts: a print that fails halfway leaves the next print clean. Onmainit returnsPartial<Logger.check.test.ts:widgetfails mid-print beforelogkit, with concurrency 1 as the CLI's workers run.logkit's report must be byte-identical tocheckonlogkitalone, ignoring timings and temp paths. Onmainit differs:logkit'sbeforesignature starts withPartial<.shared-state.test.ts: after a reset, the consumer repository gets a fresh program and checker, with the same files.fix, two tests that fail without the wiring (no reset happens):fixthat fails inside the printer, followed in the same process by acheckoflogkitthat is byte-identical tologkitchecked alone;Time cost
main, identical resultspackages/lib(1,251 source files; first load 5.6 s), ~0.1 s on storefrontTests: core 840 passed, cli 322 passed;
typecheckandbiomeclean. Changeset: patch.🤖 Generated with Claude Code