Skip to content

fix(ci): stop the edge-fn type ratchet answering differently on a warm cache (#969) - #973

Merged
thinkclay merged 1 commit into
mainfrom
fix/typecheck-ratchet-determinism
Oct 5, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/typecheck-ratchet-determinism

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #969.

The diagnosis in #969 was wrong, and the real cause is more interesting

I filed that issue claiming CI could not see a real type error. That was incorrect, and worth saying plainly: the zod TS2353 at teams.router.ts:2478 is visible to CI and is what the baseline's allowed 1 for that file accounted for. Nothing was hidden.

The flapping diagnostic is TS2589: Type instantiation is excessively deep and possibly infinite. It is not a property of the code alone — it fires when the checker exhausts its instantiation budget, and how much budget is left depends on what is already in the type cache. So the answer depends on how warm DENO_DIR is.

Measured on 1a735c9cc, same worktree, same minute, trpc only:

cache errors teams.router.ts sites
warm (shared DENO_DIR) 11 824 TS2589 + 2478 TS2353
cold (DENO_DIR=$(mktemp -d)) 10 2478 TS2353 only

Nothing else differed. Warm exceeded the baseline, cold matched it. CI runs on a fresh runner cache; my machine does not. Same commit, two verdicts.

What this changes

TS2589 is split out of the counted diagnostics and reported on its own line. A signal that cannot be reproduced cannot be ratcheted — "may only come down" is meaningless if the number depends on cache state. The cost is stated in the script rather than left implicit: a genuinely new excessively-deep instantiation will no longer fail this gate, it will appear in the advisory line instead.

Doing this immediately exposed a second flapping file nobody knew about: api/routes/user-profiles.ts also carries a TS2589, so api had been oscillating between 333 and 334 independently of trpc. Both are now quarantined.

The real bug underneath

z.date({ message: … }) is zod 4 syntax. Every edge-function import map pins npm:[email protected] (functions/trpc/deno.json, functions/api/deno.json, functions/import_map.json), and a top-level message param only arrived in zod 4. On 3.x the unknown key is ignored, so that custom validation message never reached a caller — invalid_type_error is the 3.x spelling. Quiet, but real, and in a deployed function.

With it fixed, teams.router.ts drops to zero and leaves the baseline entirely.

Baseline tightened, not raised

  • api/routes/user-profiles.ts: 12 → 11
  • trpc/routers/teams.router.ts: removed (was 1)

Total 378, down from 380.

Verification — the acceptance criterion, demonstrated

#969 asked for the same per-file counts locally and in CI. Run twice on this branch, warm and with a fresh DENO_DIR:

warm  ✓ 378 total — api 333, … trpc 9, …
cold  ✓ 378 total — api 333, … trpc 9, …

Every counted number identical, both exit 0. The only difference between the two runs is the advisory line — warm lists 2 TS2589s, cold lists 1 — which is the nondeterminism itself, now somewhere it cannot change the verdict. That is a better demonstration than identical output would have been: the flakiness is still there and is provably quarantined.

I also checked a hazard this could have introduced. background-checks.router.ts:1824 carries a @ts-expect-error for this exact "excessively deep" error; had a cold cache stopped producing the TS2589 there, the directive would have become unused — TS2578, which is stable and counted, and would have pushed that file WORSE. Neither run produces a TS2578, so it still triggers in both states. Worth knowing it is a latent trap: a @ts-expect-error suppressing a nondeterministic diagnostic is itself nondeterministic, and @ts-ignore would be the safer spelling there.

One unrelated line, and why it is here

.github/workflows/api-tests.yml gains packages/supabase/seeds/** in both path filters.

The stack that job builds seeds itself from seeds/*.sql (config.toml [db.seed]), so a broken seed reddens every suite in it — yet a seed-only change could not trigger the workflow at all. #972 is the live example: two skipped checks, a pending combined status, and nothing run, which reads as "nothing to see" rather than "nothing ran". Same class of bug as this PR (a gate that is not checking what people believe it checks), and one line, so it travels with it rather than waiting.

🤖 Generated with Claude Code

…m cache (#969)

The gate was green in CI and red locally on the same commit. My own
diagnosis in #969 was wrong: the zod TS2353 at teams.router.ts:2478 was
always visible to CI and was what that file's baseline of 1 accounted
for. Nothing was hidden.

The flapping diagnostic is TS2589, "type instantiation is excessively
deep". It fires when the checker exhausts its instantiation budget, and
the budget left depends on what is already in the type cache — so the
answer depends on DENO_DIR warmth. Measured on 1a735c9, same worktree,
same minute, trpc only: warm 11 errors (824 TS2589 + 2478 TS2353), cold
10 (2478 only). Nothing else differed.

TS2589 is now excluded from the counted diagnostics and printed on its
own advisory line. A signal that cannot be reproduced cannot be
ratcheted; "may only come down" means nothing if the number depends on
cache state. The cost — a genuinely new deep instantiation no longer
fails this gate — is written into the script.

That exposed a second flapping file: api/routes/user-profiles.ts carries
one too, so api had been oscillating 333/334 independently of trpc.

The real bug underneath is fixed as well. z.date({ message }) is zod 4
syntax; every edge-function import map pins npm:[email protected], where the
unknown key is ignored, so that validation message never reached a
caller. invalid_type_error is the 3.x spelling. teams.router.ts drops to
zero and leaves the baseline.

Baseline tightened, never raised: user-profiles.ts 12 -> 11,
teams.router.ts removed. 378 total, down from 380.

Verified by running warm and with a fresh DENO_DIR on this branch: every
counted number identical, both exit 0, and the only difference between
the runs is the advisory line itself.

Also adds packages/supabase/seeds/** to the api-tests path filters. That
job seeds its stack from seeds/*.sql, so a broken seed reddens every
suite in it, yet a seed-only change could not trigger the workflow at
all — #972 got two skipped checks and a pending status, which reads as
"nothing to see" rather than "nothing ran". Same class of bug, one line.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay

Copy link
Copy Markdown
Contributor Author

CI green: 11 pass, 4 skipping, none red. Including Edge function types, which is the point of the PR — and its log confirms the fix with CI as a third data point rather than two local runs:

run total api trpc advisory TS2589
local, warm cache 378 333 9 2
local, cold DENO_DIR 378 333 9 1
CI (Edge function types) 378 333 9 1

Every gated number identical across all three. The advisory count differs exactly as predicted — CI gets a fresh runner cache, so it sees the same single TS2589 a cold local run does, while a warm local cache sees two. That is the nondeterminism, now somewhere it cannot change the verdict.

Before this PR the same three runs would have disagreed: warm local said api 334 / trpc 11 and failed, CI said api 334 / trpc 10 and passed.

@thinkclay
thinkclay merged commit e8a9696 into main Oct 5, 2026
15 checks passed
@thinkclay
thinkclay deleted the fix/typecheck-ratchet-determinism branch October 5, 2026 16:07
thinkclay added a commit that referenced this pull request Oct 5, 2026
…ng red (#986) (#990)

A pull request from a fork gets a read-only GITHUB_TOKEN regardless of
the `permissions: pull-requests: write` at the top of the workflow, so
`github.rest.issues.createComment` throws "Resource not accessible by
integration". With no guard and no continue-on-error that took the whole
benchmark job down, and with it REST API Tests — every fork PR red for a
step that only posts a comment.

#972 surfaced it: a four-line SQL seed from an outside contributor, its
own Run API Tests green, workflow red. Step outcomes for the same job on
a fork (#972) and a same-repo branch (#973) differ in exactly one place,
the comment step.

Skipped rather than tolerated. continue-on-error would also stop it
failing the build, but silently, and a step that cannot work on forks
should say so. Upload Benchmark Results keeps the figures either way.

Swept the other workflows for the same shape and this was the only one:
dependabot-automerge is pull_request_target (base-repo token),
apple-secret-rotate is workflow_dispatch, codecov already carries
fail_ci_if_error: false and posts through its own app, and the
lighthouse action is label-triggered with no githubToken.

Verified the expression against both context shapes GitHub will supply:
runs for a same-repo PR, skips for a fork. This branch is same-repo, so
its own run exercises only the runs path; the skip path gets its real
test on the next fork contribution, and the step being skipped is the
one that was failing.

Does not touch #987 — the benchmark this posts has never produced any
output, which needs its own decision.

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The edge-fn type ratchet passes in CI and fails locally on the same commit — a gate that disagrees with itself

1 participant