Skip to content

Typecheck slowdown: durable packages/ai regression from 888da0e1 (core task/Workflow generics) #556

Description

@sroussey

Summary

tsc typecheck of the monorepo has grown from ~11s (mid-Feb 2026) to ~40s today (~3.6×). A bisection isolated two regressions; one is fixed, one is still in main and is tracked here.

Full investigation + method + timeline: docs/technical/typecheck-performance-investigation.md (added in #555). A CI guard to prevent recurrences also lands in #555 (scripts/typecheck-budget.ts).

Bisected culprits

  1. 16a94b54 — MCP task schemas spread …properties + allOf, exploding packages/tasks instantiations 289k → 6.77M (23×). Already fixed (tasks back to ~207k).
  2. 888da0e1 ("image generation pipeline with ImageValue boundary") — a task-runner refactor that doubled packages/ai isolated check time (0.9s → 3.4s), persisting to today. This is the open item.

Root cause (888da0e)

The cost is diffuse in the core task / Workflow generics, not in any single construct. Each Workflow.prototype.<name> = CreateWorkflow(<Task>) assignment relates two distinct Workflow<I,O> instantiations (inferred I ≠ written I in the declare module augmentation), forcing a full structural relation over the heavily augmented Workflow interface (~124 builder methods). Cost scales super-linearly with augmentation count; 888da0e1 added imageGenerate/imageEdit, tipping ai over.

Fixes prototyped and measured — all ineffective/net-negative

Measured on the real metric (deps pre-built, isolated tsc -p ai, 0 errors), baseline ai = 3.4s:

Attempt Result
FromSchema<…> input type → hand-written interface in ToolCallingTask no effect (3.4s)
WithImageValuePorts<…> image-task types → explicit interfaces no effect (image tasks ~13ms each)
Restore tsBuildInfoFile line deleted from root tsconfig.json no real effect; only changes tsc -b orchestration and breaks solution builds (TS6377)
Declare correct variance Workflow<in out Input, out Output> no effect (3.4s → 3.58s); removes getVariancesWorker but the structural relation still runs

There is no surgical fix.

Remaining options

  • Architectural: rethink how Workflow is augmented (124 CreateWorkflow<…> members in one mega-interface) and/or how AI task input types are derived. Multi-day effort; validate under both tsc and tsgo before investing.
  • Operational: confirm whether user-felt slowness is tsserver (still tsc) vs build-types (already tsgo, which sidesteps most of this). Note the biggest absolute cost, packages/test (~12s), is mostly legitimate file-count growth exercising the same machinery ×N.

Mitigation already in flight (#555)

  • CI typecheck-budget guard gating per-package instantiation counts. Both culprits above would have failed it.

Suggested next steps

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions