Skip to content

A TypeScript or JavaScript file whose name is not valid UTF-8 fails the delta pass #1999

Backlog

Description

@KaloyanNaumov

TL;DR: A TypeScript or JavaScript file whose own name is not valid UTF-8 stops the member delta pass. The converter's window-list read raises UnicodeDecodeError and no delta is written, so the watermark stays and the next pass fails the same way. Decoding the name with os.fsdecode alone moves the failure to the server, so carrying such names needs a byte-safe path form in the delta wire format, which is a maintainer decision.

Company

Independent

Component

Code index

Describe the situation

This is the part of closed #1959 (item 3) that #1963 did not cover. #1963 made the project filter read the window lists byte-safe (scip_ts_projects.py:287-294); the converter still reads them as strict UTF-8.

On upstream/main at 82dc31216fd252db028fa57eca570fe87258e64a:

  1. git_paths writes a name as the tree stores it (core.quotePath=false, scripts/scip_harness/lib.sh:60-69), and window_files puts the TypeScript and JavaScript names into changed.txt and deleted.txt (lib.sh:76-85, called from run_typescript_delta.sh:190).
  2. The converter reads both lists with Path(path).read_text() (scip_to_delta.py:1395-1398, called at :1463 and :1465). A name holding byte 0xff or 0xfe raises UnicodeDecodeError, run_typescript_delta.sh exits 1 and no DELTA_OUT file is written. An added or edited file and a deleted file fail the same way; I ran each.
  3. The worker raises harness_failure from _run_harness (server/code/workers/scip_ts_delta.py:253-254) before it sets the watermark (:154 and :168), so the entry's watermark stays. The next pass uses the same base, and the window fails again for as long as the net diff from the watermark names the file.
  4. With os.fsdecode in _path_list (a local patch I made to test this), the pass succeeds, but a deleted name reaches deleted_files as a lone surrogate. scip_to_delta.py writes it with json.dumps (:1312-1320) as "src/bad\udcff.ts", and the server's delta parse (pydantic_core.from_json, server/code/app/index/delta_file.py:161) refuses it: lone leading surrogate in hex escape at line 3 column 33. The server would refuse the whole delta.
  5. In a --full pass over a tree that holds such a file, scip-typescript 0.4.0 emits no document for it: a fixture with three TypeScript files, one named src/bad\xff.ts, converts to 2 files. So no compiler-tier row exists for such a file, and an added or changed one is absent from files with or without the patch. I did not check what the fast tier does with the name.

Does it reproduce on the latest release or main?

Yes

How to reproduce

From a checkout of main, with the server's virtualenv first on PATH, @sourcegraph/scip-typescript 0.4.0 installed, and SCIP_TYPESCRIPT set to its binary:

L=$PWD; W=$(mktemp -d) && cd "$W" && git init -q fx && cd fx
git config user.email a@b && git config user.name t
printf '{"name":"fx"}' > package.json
printf '{"compilerOptions":{"target":"es2022","module":"nodenext","moduleResolution":"nodenext","strict":true},"include":["src"]}' > tsconfig.json
mkdir src && echo 'export const a = 1;' > src/a.ts
git add -A && git commit -qm base && BASE=$(git rev-parse HEAD)
printf 'export const z = 1;\n' > "$(printf 'src/new\xfe.ts')"
git add -A && git commit -qm head && HEAD=$(git rev-parse HEAD)
cd "$L"
DELTA_OUT=$W/d.json scripts/scip_harness/run_typescript_delta.sh "$W/fx" "$BASE" "$HEAD"
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 7: invalid start byte
# exit 1, no $W/d.json

The same failure with the file deleted: commit src/bad\xff.ts in the base, git rm it in the head, and run the window.

The server side: with os.fsdecode(Path(path).read_bytes()) in place of read_text() in _path_list, the window above passes and writes $W/d.json. For a window that deletes src/bad\xff.ts its deleted_files entry is the lone surrogate:

python3 -c "import pydantic_core,sys; pydantic_core.from_json(open(sys.argv[1],'rb').read())" "$W/d.json"
# ValueError: lone leading surrogate in hex escape at line 3 column 33

Expected behavior

  1. A name that is not valid UTF-8 does not fail the pass. The wire format needs a decision on how the delta carries or omits it; the options I see:
    1. An escaped or base64 path field next to path and in deleted_files and skipped_files, so the name survives the JSON parse. This keeps tombstones for a file that did have rows, but no compiler-tier row exists for such a file today (item 5 above).
    2. Skip the file with a stated warning: the converter drops the name from both lists, names it on stderr as it does for a skipped document, and the pass advances. Nothing is lost that the compiler tier held.
    3. Refuse it at ingest: the converter fails with a message that names the file, instead of a UnicodeDecodeError traceback. The pass still stops, but the log says why.
  2. Whichever is chosen, _path_list reads bytes (os.fsdecode or surrogateescape), as _read_lines in scip_ts_projects.py already does, so the name never reaches read_text.

The choice between these is the maintainers'. Decoding with os.fsdecode alone is not enough (item 4).

Environment

Loom main at 82dc31216fd252db028fa57eca570fe87258e64a.
@sourcegraph/scip-typescript 0.4.0, node 22.23.4, Python 3.12, git 2.43.
run_typescript_delta.sh in DELTA_OUT mode, the worker's mode; no ClickHouse involved.
Linux; a one-package fixture.

Related issues and pull requests

Related: #1959
Related: #1963
Related: #1782

Additional context

How this was found

Found and reproduced with AI assistance.

Redaction

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

Activity

  1. KaloyanNaumov commented on Dec 2, 2026

    @KaloyanNaumov
    ContributorAuthor

    @zlareb1 product decision needed here: how the delta carries a file name that is not valid UTF-8. The options I see:

    1. A byte-safe path field in the delta (escaped or base64), which the server decodes back to bytes. This is a wire-format change.
    2. Skip such a file with a warning in the pass output, and keep the rest of the delta.
    3. Refuse such a file at ingest with a clear error, so the pass reports it instead of failing on decode.

    Today the pass fails on decode and the watermark stays, so the next pass fails the same way. Option 2 or 3 would stop that loop without a wire change.

  2. zlareb1 commented on Dec 6, 2026

    @zlareb1
    Member

    @KaloyanNaumov option 2, and for every compiler tier, not only TypeScript. _path_list (scip_to_delta.py:1495) should read the lists as bytes and drop any name that doesn't decode as strict UTF-8, from both the changed and the deleted list, with one scip_to_delta: warning: line naming its bytes. Everything else converts, the watermark moves, and the delta format stays as it is.

    Dropping these names loses nothing, because no tier can hold a row under one. relative_path is a proto3 string (vendor/scip.proto:91), so python-protobuf refuses a document with a non-UTF-8 path no matter which indexer wrote it. The parser tier doesn't index them either: it decodes git's listings with replace (gitrepo.py:302), and show_file then finds no blob under that spelling. A byte-safe field would add a second path spelling to the store and to every JSON answer, all for files nothing indexes. Refusing would leave the pass stuck. git_paths already drops names it can't carry the same way (lib.sh:60-69).

    It isn't only TypeScript. Every harness goes through _path_list, and the C++ window lists files of any type (run_delta.sh:108), so a .cpp edit next to one such .md fails the C++ pass today.

    Tests, in tests/unit/test_scip_harness_windows.py: for each tier in _TIERS and for C++, a window that adds, edits and deletes a non-UTF-8 name next to a valid edit. It should exit 0, convert the valid file, leave the bad name out of files and deleted_files, warn once per name, and write a delta that delta_file.open_delta accepts. On main the converter raises UnicodeDecodeError. Nothing in delta_file.py, scip_delta.py or delta_version should change.

    This should land on its own. It also changes #1704, which keys such names on their replace spelling, so I'll put the details on that PR.

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