Skip to content

One non-UTF-8 string or file name fails the whole TypeScript member pass #1959

Done

Description

@KaloyanNaumov

Company

Independent

Component

Code index

Describe what's wrong

Two encoding cases on the member path from #1782 fail the whole TypeScript pass, and the worker keeps the watermark, so every later pass fails the same way. A third, older case in the converter is listed with them.

  1. A document with a string that is not valid UTF-8 fails the merge. scripts/scip_harness/scip_merge_indexes.py:95-97 parses each member's index as one scip.Index, and python-protobuf refuses the whole message when any string in it is not valid UTF-8. scip-typescript writes such a string for a literal type that holds a lone UTF-16 surrogate ("A\uD800B" as const). The merge runs after every member is indexed, so the pass exits 1 at the end: on the repository from The TypeScript tier cannot index a large monorepo through its root tsconfig, and every delta repeats the full cost #1678 (9 such documents), a three-project delta stopped after 1,707 s. Before Index TypeScript monorepos by member project, not the umbrella root #1782 the same input failed one step later, in the converter's per-document parse ('scip.Document'). Skip a SCIP document that fails to decode or convert; its file keeps its rows, marked stale #1704 (open) would make the converter skip such a document and mark its file stale, but the merge parses first, so the pass fails with or without it.
  2. A file name that is not valid UTF-8, anywhere in the window and of any file type, fails the member filter. _read_lines (scripts/scip_harness/scip_ts_projects.py:277-280) reads the window lists with strict UTF-8, while git_paths writes names as raw bytes (core.quotePath=false). filter raises UnicodeDecodeError, filtered=$(…) exits under set -e, and the worker records a harness failure. Before Index TypeScript monorepos by member project, not the umbrella root #1782 the same window passed, because only the TypeScript-glob list was read: a TypeScript edit plus packages/b/caf\xe9.md gave 1 file before and exit 1 on main.
  3. Older than Index TypeScript monorepos by member project, not the umbrella root #1782 and noted here because it is the same class: a TypeScript or JavaScript file whose own name is not valid UTF-8 fails in the converter, whose _path_list (scripts/scip_harness/scip_to_delta.py:1395-1398) reads the window lists strictly. Decoding them with os.fsdecode alone moves the failure: such a name, deleted, reaches the delta's deleted_files as a lone surrogate, and the server's delta parse (pydantic_core.from_json) refuses the whole delta. Carrying these names needs a byte-safe path form in the delta, which is a wire decision for the maintainers.

File content that is not UTF-8 is not affected: an edit to a file holding raw Latin-1 bytes converts on main (1 file, 2 symbols).

Does it reproduce on the latest release or main?

Yes

How to reproduce

From a checkout of main, with the server's virtualenv.

The file name:

printf 'packages/a/src/x.ts\npackages/b/caf\xe9.md\n' > changed.txt
python3 scripts/scip_harness/scip_ts_projects.py filter --changed-file-list changed.txt -- packages/a packages/b
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 34: invalid continuation byte

The merge, with one member whose index holds a document with a string that is not UTF-8:

import importlib.util, subprocess, sys

spec = importlib.util.spec_from_file_location("scip_pb2", "scripts/scip_harness/vendor/scip_pb2.py")
pb = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pb)

index = pb.Index()
for path, text in (("packages/app/src/a.ts", "ok"), ("packages/app/src/bad.ts", "ZZBADUTF8ZZ")):
    doc = index.documents.add()
    doc.relative_path = path
    doc.text = text
raw = index.SerializeToString().replace(b"ZZBADUTF8ZZ", b"\xff\xfeBADUTF8ZZ")
open("app.scip", "wb").write(raw)
subprocess.run([sys.executable, "scripts/scip_harness/scip_merge_indexes.py", "--output", "merged.scip",
                "--project", "packages/app", "--known-project", "packages/app", "app.scip"])

The merge exits 1 and writes nothing, although packages/app/src/a.ts is a valid document. With the real indexer: an umbrella of two members, one holding export const labels = ["A\uD800B", "\uDC00AB"] as const;, run with DELTA_OUT=d.json scripts/scip_harness/run_typescript_delta.sh <tree> --full HEAD, exits 1 with the error below.

Expected behavior

  1. The merge does not decode documents. The ownership rule needs only the top-level records and each document's relative_path, which the converter's _top_level_records and _document_path already read, and the kept records can be copied byte for byte. A document the converter cannot decode then reaches the converter, which skips it with Skip a SCIP document that fails to decode or convert; its file keeps its rows, marked stale #1704. A pull request for this follows; it does not change the file-name case.
  2. _read_lines reads file names the way git writes them: path.read_bytes().decode("utf-8", "surrogateescape") or os.fsdecode, so a name that is not UTF-8 is carried through or ignored rather than failing the window.
  3. For a TypeScript or JavaScript file whose name is not UTF-8, the delta needs a path form the server's JSON parse accepts (an escaped deleted_files entry, for example). That is a wire choice for the maintainers; decoding with os.fsdecode alone moves the failure to the server.

Error message and logs

google.protobuf.message.DecodeError: Error parsing message with type 'scip.Index': String field had bad UTF-8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 34: invalid continuation byte

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, protobuf from the server's virtualenv.
run_typescript_delta.sh in DELTA_OUT mode, the worker's mode; no ClickHouse involved.
The 1,707 s run: #1782's head e8fbb33 before the merge (same whole-index parse), the repository from #1678, a project list of 222 entries, a 24 GiB heap.

Related issues and pull requests

Caused by: #1782
Related: #1704
Related: #1678

How this was found

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

Additional context

Caused by applies to the file-name case. For the merge case #1782 moved the failure from the converter, where #1704 can skip one document, to the merge, after all indexing.

A test that would catch the file-name case: a commit adding caf\xe9.md beside a TypeScript edit; assert exit 0 and the TypeScript file converted. The merge case gets its test with the pull request.

Redaction

  • I removed tokens, keys, passwords and personal or customer data from everything above.
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