Skip to content

TypeScript member indexing drops cross-package edges and files compiled from outside a member #1958

Backlog

Description

@KaloyanNaumov

Company

Independent

Component

Code index

Describe what's wrong

Since #1782 by @ZYZ666-RGB, the TypeScript tier indexes an umbrella root one member project at a time. On a references repository without workspaces it names member symbols that the root pass left unnamed (RyanCavanaugh/project-references-demo: 0 symbols before, 10 after), and a one-member delta runs one indexer process. On a pnpm workspace with an umbrella root, two parts of it change what the index holds, measured with the real scip-typescript on a 4-package fixture:

run indexer processes files / symbols / edges in the delta
harness before #1782, --full 1 5 / 7 / 7
harness before #1782, --full, SCIP_TS_PATHS=0 1 5 / 7 / 2
main, --full 4 4 / 6 / 2
  1. Cross-package edges are lost when discovery finds an umbrella. run_typescript_delta.sh:52-55 sets WORKSPACES="" and SCIP_TS_PATHS=0 for a discovered umbrella. In an unbuilt pnpm or yarn workspace, scip_ts_paths.py's dist/ rewrite is what resolves import … from "@x/a" to source; scip-typescript 0.4.0 does not redirect a project reference to source either. The fixture's calls edges b → a go from 3 to 0 and d → a from 1 to 0. The comment on those lines explains the setting for an operator's SCIP_TS_PROJECTS list; a discovered umbrella over an unbuilt workspace still needs the rewrite.
  2. Files a member compiles from outside its directory are dropped. The merge keeps a document only for the member whose directory contains its path (scip_merge_indexes.py:107-118, project_owns at scip_ts_projects.py:211-218), not for the member whose tsconfig compiled it. With packages/c/tsconfig.json including ../../shared/**/*.ts, the harness before Index TypeScript monorepos by member project, not the umbrella root #1782 emits shared/util.ts; main does not, on a full pass or on a delta that changes that file, and the edge gamma → sharedUtil points at a symbol with no rows. The same rule applies to an operator's scip_ts_projects list, so lists that worked before lose these files too. On the next full backfill the worker's gone_documents (server/code/workers/scip_ts_delta.py:158-163) retires the rows the earlier pass wrote. Reverting Index TypeScript monorepos by member project, not the umbrella root #1782 does not bring them back until a full rerun.

Case 2 also feeds a cost problem: a change to such a file selects every member and converts nothing (tracked with the other cost findings in #1961).

Does it reproduce on the latest release or main?

Yes

How to reproduce

The fixture, a pnpm workspace with nothing built:

  • Root: package.json, pnpm-workspace.yaml with packages: ["packages/*"], tsconfig.base.json with composite, declaration, strict and module/moduleResolution nodenext, and tsconfig.json {"files": [], "references": [{"path": "./packages/a"}, {"path": "./packages/b"}, {"path": "./packages/c"}, {"path": "./packages/d"}]}.
  • Each packages/<p>/package.json has "exports": {".": {"types": "./dist/index.d.ts", "default": "./dist/index.js"}}; b, c and d depend on "@x/a": "workspace:*". Each tsconfig.json extends the base with include: ["src"], and b, c and d add "references": [{"path": "../a"}].
  • packages/a/src/index.ts exports alpha() and a class Alpha with run(); b calls alpha and new Alpha().run(); d calls alpha.
  • packages/c/tsconfig.json also has "rootDir": "../.." and "include": ["src", "../../shared/**/*.ts"]; packages/c/src/index.ts calls alpha and sharedUtil from ../../../shared/util.js; shared/util.ts at the root exports sharedUtil.
pnpm install --ignore-scripts
DELTA_OUT=main.json scripts/scip_harness/run_typescript_delta.sh /path/to/fixture --full HEAD
# the harness before #1782, from a second Loom checkout at 1bc5be8b1^1:
DELTA_OUT=pre.json scripts/scip_harness/run_typescript_delta.sh /path/to/fixture --full HEAD

Count the documents, symbols and edges in each delta: pre.json has shared/util.ts and the calls edges from b and d into a; main.json has neither. A commit that changes only shared/util.ts, run as a delta on main, runs the indexer 4 times and writes 0 files; the harness before #1782 writes 1.

Expected behavior

  1. A discovered umbrella over a workspace keeps the workspace's SCIP_TS_PATHS (the rewrite already runs once before the member loop when the flag is on), so a full pass has the edges it had before Index TypeScript monorepos by member project, not the umbrella root #1782.
  2. A file a member's tsconfig compiles keeps its rows. Either ownership follows the files each member's program resolves, or a document that no member owns by directory is kept from the first part that emitted it. Until then, a revert of Index TypeScript monorepos by member project, not the umbrella root #1782 needs a full rerun to restore the retired rows.

Environment

Loom main at 3058a5816 (contains #1782); "before #1782" is scripts/scip_harness/ at 1bc5be8b1^1.
@sourcegraph/scip-typescript 0.4.0, node 22.23.4, pnpm 12.15.0, Python 3.12.
run_typescript_delta.sh in DELTA_OUT mode, the worker's mode; counts are read from the delta JSON, so no ClickHouse was involved.

Related issues and pull requests

Caused by: #1782
Related: #1678
Related: #1961

How this was found

An AI tool found it, and I have not reproduced it myself

Additional context

Smaller gaps in what the index holds, from the same audit:

  1. A one-member delta loses calls edges into arrow-function constants of members it did not index: the converter's kind prepass (scip_to_delta.py:389, _ts_prepass) reads definition kinds from the merged index only. On a synthetic repository the full pass emits a → f and a → g, the delta only a → g.
  2. A member taken out of the root's references keeps its rows. The config rebuild converts only the remaining members and emits no deletion (fixture: packages/d dropped, 3 members reindexed, deleted_files: 0), and the worker runs a full pass only without a watermark.
  3. The merge concatenates external_symbols from every part without removing duplicates.
  4. docs/architecture/code-index-architecture.md:354 says the converter bounds the output to the TypeScript window, which does not hold on a config rebuild; the harness README's TypeScript section and the scip_ts_delta.py docstring ("every pass re-indexes the workspace") describe the tier before Index TypeScript monorepos by member project, not the umbrella root #1782.

The harness tests run a stub indexer that writes empty indexes, so these cases need the real one. Tests that would catch them:

  1. A pnpm workspace with an umbrella root and @x/b importing @x/a through an unbuilt dist/ export: assert a calls edge b → a in the delta.
  2. A member whose tsconfig includes ../../shared/**/*.ts: assert shared/util.ts is in the full delta and in the delta for a change to it.
  3. A member removed from references: assert its rows are retired, or document that they are not.
  4. Two parts with the same external_symbols: assert one copy of each in the merge.
  5. One end-to-end run with the real scip-typescript on a small references repository, asserting per-member file, symbol and edge counts, so the ownership rule is checked against the relative_path values the indexer writes.

Redaction

  • I removed tokens, keys, passwords and personal or customer data from everything above.

Activity

  1. KaloyanNaumov commented on Dec 1, 2026

    @KaloyanNaumov
    ContributorAuthor

    One more case under item 1, found while testing the fix for it: a member that a workspace lists through a standalone named config (packages/d/tsconfig.build.json that does not extend the package's tsconfig.json) still loses its imports of sibling packages. The paths rewrite edits only tsconfig.json, and since #1782 the member is indexed through the named config. The whole-root run indexed that package through its tsconfig.json, so the edge existed before. A named config that extends tsconfig.json inherits the paths and keeps its edges. On a fixture with one of each, the run before #1782 has d → alpha, and main and the directory-member fix do not.

  2. KaloyanNaumov commented on Dec 2, 2026

    @KaloyanNaumov
    ContributorAuthor

    @zlareb1 product decision needed here, on case 2: which member owns a file that a member's tsconfig compiles from outside its directory. I see two shapes:

    1. Ownership follows the files each member's program resolves. It is exact, but the harness needs each member's file list from the indexer, and the delta filter has to use the same list, or a change to such a file still selects every member (TypeScript member passes index more members than a change needs, and one failing member fails all #1961, item 1).
    2. A document that no member owns by directory is kept from the first part that emitted it. It is small and deterministic, but "first" depends on member order, and the filter still selects every member for a change to such a file.

    Case 1 is in #1964. On a large pnpm monorepo, case 2 drops 13 declaration files; on the fixture it drops a source file and its edges.

  3. zlareb1 commented on Dec 6, 2026

    @zlareb1
    Member

    @KaloyanNaumov on case 2, ownership should follow what each member's tsconfig compiles, and you don't need a file list from the indexer for that. scip-typescript 0.4.0 only emits documents for config.fileNames: the loop in ProjectIndexer.index() skips every program file that isn't in it. So what a member emits is exactly its files/include minus exclude, through extends. A file it only imports never becomes a document.

    That means the merge already has the exact answer. A document inside some member's directory still goes to the most specific member. A document outside every member's directory is kept from the member that emitted it. If more than one member emits it, take the first by member path rather than discovery order, so a delta and a full pass keep the same copy.

    The filter doesn't need to be exact. For a member whose files/include leaves its directory (_files_stay_in already walks this), select it when a changed path falls under the fixed prefix of one of those outside entries. ../../shared/**/*.ts gives shared/, so a change to shared/util.ts selects packages/c and nothing else. Selecting too many costs time, not rows, so if an extends can't be read, just select the member. Today that change selects nothing (#1976), so the file is never re-indexed.

    Files that gone_documents has already retired come back on the next window that touches them or on a full reindex. Say so in the PR body.

    The rest, checked on main:

    • Case 1 is fixed by TypeScript umbrella members resolve imports between unbuilt workspace packages #1964, including your named-config follow-up: the paths rewrite now goes into the config each member is indexed through.
    • Smaller gap 1 is fixed by A one-member TypeScript delta keeps the calls into other members' arrow constants #2003.
    • Smaller gap 2 is still open. A root tsconfig.json change already reindexes and converts every member, so treat that pass as a full one and retire gone documents the way the worker does without a watermark. Leave out the files of a member that failed (A failing TypeScript member keeps the other members' rows #1973), or a failing member would wipe its own rows. A nested umbrella is worse: a change to packages/tsconfig.json selects no member at all, so a member added or removed there isn't noticed. Count a change to any config that discover walked as shared.
    • Smaller gap 3 is still open: merge_indexes appends every part's external_symbols. Dedupe them on the raw payload, the way documents are keyed.
    • Smaller gap 4 is still open: the architecture row still says the converter bounds the output to the TypeScript window, and the scip_ts_delta.py docstring still says every pass re-indexes the workspace.

    Gaps 2–4 can go in one PR. Case 2 should be its own.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions