A C++ full run claims ctor_calls although its constructor scan skipped a document

Open
#2,001 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
40/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
clickhouse, cpp, python
Domain
backend, databases

Research direction

Read scripts/scip_harness/scip_to_delta.py, especially _prepare and DeltaStream.tail, then follow how features are applied in server/code/app/index/scip_delta.py and read constructor coverage in server/code/app/symbol/coverage.py. Start by running the reproduction against #1704's head and compare its output with the case where the skipped document is listed in changed.txt. The reported claim-withholding fix has tests in a follow-up pull request; the separate question of clearing previously recorded state still needs a maintainer decision.

Written by the indexing model from the issue text.

Description

TL;DR: On #1704's head, DeltaStream.tail claims the ctor_calls feature whenever the window's skipped_files is empty, and ignores _run.ctors_complete. A C++ --full run passes --changed-files, so a document the constructor scan skipped outside that list never reaches skipped_files, and the apply records the namespace as carrying constructor calls. I found no input where this makes an answer wrong; the claim is wider than the scan behind it, and the recorded bit is never withdrawn.

Company

Independent

Component

Code index

Describe the situation

This is a follow-up to #1704, which adds the code it concerns. Cursor Bugbot raised the first part on that pull request (thread r4765529741). All line numbers are on #1704's head 226a92c4a638f6f0a985950d33bdeafd6e5163b1; upstream/main at 82dc31216fd252db028fa57eca570fe87258e64a has neither _Skips nor ctors_complete.

  1. _prepare runs the constructor scan _ctor_overloads over every document in the index and sets ctors_complete to false when that scan skipped one (scip_to_delta.py:1054-1058).
  2. DeltaStream.tail lists as skipped_files only the skipped documents inside the window (:1339-1343), then claims ctor_calls when self._claims_ctor_calls and not skipped (:1354). It never reads self._run.ctors_complete.
  3. The C++ --full harness runs --full together with --changed-files set to every tracked src/*, base/* and programs/* file (run_delta.sh:100-105, :178-183), so changed is not None and _Skips is not in whole mode (:1302). A document outside those paths that fails to decode, a header under contrib/ for example, is counted in skipped_failed and warned on stderr, but is not in skipped_files, and delta_version stays 1.
  4. apply_delta records scip_ctor_calls whenever the feature is present (server/code/app/index/scip_delta.py:293-302). _ctor_edge_coverage then reads the compiler tier as carrying constructor calls unless a compiler-tier file is marked stale (server/code/app/symbol/coverage.py:183-199), and _ctor_edges_absent is false for a compiler-covered seed (:231-243), so an empty code.callers answer for a constructor has no ctor_edges_absent cause.

What I could not show is a wrong answer. A factory call in a window file whose type's constructors the scan missed is itself skipped and listed (_OverloadsIncomplete, :732 and :1194-1197; test_a_factory_caller_keeps_its_rows_when_the_overload_scan_misses_a_document), and in a C++ --full run every tracked source file is in the window. So the constructor answer rests on a scan that is known to be incomplete, but I have no input where an edge is missing from a converted file because of it.

A second part is open: scip_ctor_calls has one write site on the server (scip_delta.py:298) and nothing clears it. A later run that withholds the claim, with this change or because a window file was skipped and marked, leaves the bit an earlier clean run set. Only a stale mark in the window lowers the answer again (coverage.py:195-199); a scan that misses a document outside the window does not.

Does it reproduce on the latest release or main?

Yes, on #1704's head. The code does not exist on main yet.

How to reproduce

From a checkout of #1704's head, with the server's virtualenv. An index of two C++ documents, one inside the window and one outside it whose text field is not valid UTF-8:

mkdir -p root/src && echo 'int x;' > root/src/a.cpp
python3 - "$PWD/root" t.scip <<'PY'
import importlib.util, 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()
index.metadata.project_root = "file://" + sys.argv[1]
for path, text in (("src/a.cpp", "ok"), ("contrib/bad.h", "ZZBADUTF8ZZ")):
    doc = index.documents.add()
    doc.relative_path, doc.text = path, text
    doc.symbols.add().symbol = "cxx . . $ DB/A#"
raw = index.SerializeToString().replace(b"ZZBADUTF8ZZ", b"\xff\xfeBADUTF8ZZ")
open(sys.argv[2], "wb").write(raw)
PY
printf 'src/a.cpp\n' > changed.txt && : > deleted.txt
python3 scripts/scip_harness/scip_to_delta.py --index t.scip --commit abc --full \
  --changed-files changed.txt --deleted-files deleted.txt --source-root root --dry-run out.json
python3 -c "import json; d = json.load(open('out.json')); print({k: d.get(k) for k in ('delta_version', 'skipped_files', 'features', 'stats')})"
{'delta_version': 1, 'skipped_files': [], 'features': ['ctor_calls'], 'stats': {'factory_ctor_edges': 0, 'skipped_generated': 0, 'skipped_failed': 1}}

With contrib/bad.h added to changed.txt, the delta has skipped_files ['contrib/bad.h'], delta_version 2 and no features.

Expected behavior
  1. tail claims ctor_calls only when self._claims_ctor_calls and self._run.ctors_complete and not skipped, so a scan that missed any document withholds the claim. With the feature absent apply_delta writes no scip_ctor_calls, and code.callers reads a constructor's empty answer as lower_bound with ctor_edges_absent; no server change is needed. I have this as a follow-up pull request for after #1704 merges, with two tests: the converter withholds the claim when the scan skipped a document outside its files, and the converter-to-apply-to-code.callers path ends in lower_bound.
  2. Open: whether a run that withholds the claim should clear scip_ctor_calls, for example by the apply writing the state 0 when a full run's delta lacks the feature. Today the bit stays set after a clean full run until a mark lowers it. This needs a maintainer decision, since it makes the apply write state for a delta that does not name a feature.
Environment
#1704 head 226a92c4a638f6f0a985950d33bdeafd6e5163b1; Loom main at 82dc31216fd252db028fa57eca570fe87258e64a for the comparison.
Python 3.12, python-protobuf, the vendored scip_pb2; scip_to_delta.py in --dry-run mode, no ClickHouse and no scip-clang.
Related issues and pull requests

Related: https://github.com/ClickHouse/loom/pull/1704

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.
Dominant language
Python
Stars
221
Forks
35
Avg merge
14h 21m
Merged PRs (30d)
873

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ClickHouse/loom

All issues in ClickHouse/loom

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.