Skip to content

ci: no gate catches an export that no other file imports #2536

Closed

Description

@schlessera

Context

Nothing in bun run lint or the test suite notices an export that no other file imports. The api-report (tests/api-surface.test.ts) only covers names reachable from a package entry point. A module-level export that no entry re-exports and no other file imports passes every gate. The repository review on 2026-10-22 (dcf5341aa) found many:

  • ui-server: 207 exported declarations in packages/ui-server/src (111 types, 96 values) whose name appears in no other file in the repo, CHANGELOGs excluded. Examples: handoffTranscript and checkHandoffReferences (src/ws/handoff.ts), boundFollowUpText (src/ws/turns.ts), inProcessPlanner and validatePlan (src/brain/application.ts), inQuietHours and nine ACTION_* constants (src/inbox/notify.ts).
  • ui-kit: about 15 more, for example clusterLetter (src/blocks/MapView.tsx:385), moveRankItem (src/decisions/AskUserRankCard.tsx:34), diffRows (src/primitives/DiffBlock.tsx), and the TRACKER_* constants in src/blocks/TrackerPillList.tsx.
  • ui-react: five exports used only in their own file: selectBackendForProvider (packages/ui-react/src/stores/provider-state.ts:101), normalizeDirPath (src/stores/file-state.ts:548), isUnconfirmed (src/lib/answer-delivery/types.ts:117), CountBadge (src/components/activity/span-bits.tsx:296), ViewerError (src/components/files/file-viewer-frame.tsx:112). This issue owns dropping their export; ui-react: default-root wrappers left by the export cut have no caller or only test callers #2535 only deletes ui-react's default-root wrappers.

A hand clean-up would regrow, and a naive one would be wrong in places:

  • Some of the 111 ui-server types are the options or result types of an exported function (BackendRegistryOptions, src/agent/backend.ts; SubscriptionMonitorOptions, src/agent/subscription.ts). Dropping their export means a caller can no longer name the type. Keeping or dropping each is a per-case call.
  • A declaration the api-report records, as an entry export or as one reached from a public signature, must stay exported. The export-boundary rule says so (docs/decisions/public-export-boundary.md:75-76: "a type reachable from a public signature is public with it").

How the ui-server count was produced:

for f in $(find packages/ui-server/src -name '*.ts'); do
  grep -oE '^export (async )?(function|const|class|let|type|interface|enum) [A-Za-z0-9_]+' "$f" | awk '{print $NF}' |
  while read sym; do
    [ "$(git grep -lw "$sym" -- . ":!$f" ':!**/CHANGELOG.md' | wc -l)" = 0 ] && echo "$f $sym"
  done
done | wc -l    # 207

Scope

  • Add a check to bun run lint (scripts/lint.ts) that, for the src/ of ui-server, ui-kit and ui-react only, reports an exported declaration that (a) no other file in the repo imports, and (b) is not recorded anywhere in api-report/<package>.txt, whether as an entry export or as a declaration reached from a public signature.
  • Drop the export keyword from what it reports in ui-server, ui-kit and ui-react (including the five ui-react names above), or delete the declaration where it is also unused in its own file. Then make the check required for those three packages.
  • The package list is explicit in the check's source. Other workspace packages are not scanned by this gate; extending it to them is follow-up work, filed as its own issue from the PR.
  • The check runs offline and deterministically, like the other lint gates. Choosing an existing tool or a script under scripts/ is up to the implementer. Verify the tool's current API against its installed version rather than from memory.

Out of scope

Acceptance criteria

  • bun run lint fails on a newly added export function unusedProbe() {} in packages/ui-server/src, naming the file and symbol; mutation recorded in the PR.
  • It does not fail on a declaration recorded in the package's api-report signature section (a fixture or a named existing case proves this).
  • After the clean-up, the check passes for ui-server, ui-kit and ui-react with no allowlist entries, or with each allowlist entry carrying a one-line reason.
  • git grep -nE '^export function (selectBackendForProvider|normalizeDirPath|isUnconfirmed|CountBadge|ViewerError)\b' -- packages/ui-react/src returns nothing.
  • A newly added unused export in a package outside the three (for example packages/core/src) does not fail bun run lint, proving the enforced scope is the stated one.
  • bun run typecheck, bun run test and tests/api-surface.test.ts pass, and no api-report changes except for removed non-entry names.

Verification

bun run lint
bun run typecheck
bun run test

Contract impact

None. Only names outside every entry point change.

Found by a repository review on 2026-10-22.

2026-10-24: took sole ownership of the five ui-react own-file export removals (removed from #2535) and fixed the required gate's initial enforcement to ui-server, ui-kit and ui-react, with other packages unscanned until a follow-up.

Activity

  1. added
    type: chore
    area: ui-server
    area: ui-react
    area: ui-kit
    area: ci
    priority: p3
    agent-ready
    on Oct 21, 2026
  2. self-assigned this
    on Nov 3, 2026
  3. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claiming (token c2536-6bcd). Branch chore/2536-unused-export-gate, based on the epic/2542-dead-code integration branch at 9df9192f3. Citations re-checked at that base: the five ui-react names and public-export-boundary.md:75-76 still hold. collisions.ts --paths reports closure-only overlap with 38 open PRs that touch the ui workspaces, and no path collisions on scripts/lint.ts. The cleanup will touch many ui-server, ui-kit and ui-react files, so I'll re-run it against the PR and record the result there. This stays clear of #3413 and #3412, which only touch the ui-sdk ./internal entries.

  4. added this to the 0.45.0 milestone on Nov 3, 2026
  5. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    PR #3448 (head f54c4b768, against epic/2542-dead-code at b29668b29) adds the gate to bun run lint and clears 478 exports in ui-server, ui-kit and ui-react. 18 allowlist entries remain, each with a reason. Extending the gate to the other packages is #3438. This issue closes when the epic batch lands on main. Hosted proof is pending; local check:pr passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: ciarea: ui-kitarea: ui-reactarea: ui-serverpriority: p3type: chore

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions