A cached PR overlay is served after the index it was classified against moved

Đang mở
#1,968 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@KaloyanNaumov đang làm issue này rồi.

Từ ngày 1/12/2026.

  • #1969 của @KaloyanNaumov — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start with load_pr_overlay and load_posted_overlay in server/code/app/index/pr_overlay.py, then read the unit-test fakes in tests/unit/test_pr_post_image.py. Trace how the cache keys represent the indexed commit, branch tip, path scope, diff cut and posted overlay SHAs; add cases that change each input between reads. Done means those changes cause cache misses and the tests confirm the refreshed classifications and diff.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Company

Independent

Component

Code index

Describe what's wrong

A reindex within 60 s of a PR read leaves the PR overlay's classification at the old index.

load_pr_overlay (server/code/app/index/pr_overlay.py) keeps its result for code_pr_overlay_cache_ttl_s (60 s) under (mirror, namespace, PR number) and accepts a hit when the PR head sha matches. The overlay classifies each function added, modified or unchanged, and binds each call site, against the name table at the namespace's indexed commit, and the key does not hold that commit. A PR read once, then reindexed to a commit that defines a function the PR adds, still reports that function as added for the rest of the TTL, with its call sites bound against the old names. code.callers, code.callees, code.impact and code.review_brief (through its impact read) all answer from it.

The diff is the PR head against merge-base(head, refs/heads/<branch>), and the key does not hold the branch tip either. When the branch gains commits the PR head already contains (a base merged by merge commit or fast-forward, or by a rebase that reuses shas), the merge-base moves and the diff shrinks, and a hit still serves the old diff.

Three more inputs of the overlay are missing from the key: the target branch, the path scope (path_prefixes) and the diff cut (diff_max_bytes). No caller varies them for one namespace today, since overlay_for_namespace passes the namespace's own git_branch, its path_prefixes and the default cut, so they are a gap in the key's completeness: they bite a direct caller, a repository-entry edit inside the TTL, or any namespace that holds several branches.

load_posted_overlay has the same shape for a post-image sent with the request: the key holds the PR number and the content digest only, so a re-send of the same files after an index move is served the old classification, and a re-send with another pr_head_sha or pr_base_sha keeps the first one's overlay_head_sha label.

The other caches in the module are keyed correctly. _FILE_FACTS is keyed on path and content digest, _FILE_EDGES on path, content digest and the digest of the name-table rows the file's names bind to, and _NAMES on namespace, indexed commit and name. _RUNNING holds an in-flight parse, not a result.

Does it reproduce on the latest release or main?

Yes

How to reproduce

On main at 3058a5816, with the unit-test fakes of tests/unit/test_pr_post_image.py (no server, no ClickHouse):

  1. A namespace whose indexed commit does not define loadDataParts; read a PR that adds it with load_pr_overlay. Move the namespace's git_head state to a commit that defines it and read again. The second call still reports it added.
  2. The same call twice with the target branch's tip moved between them, and its merge-base with the PR head. The second call returns the overlay of the old merge-base.
  3. One mirror, one PR head. load_pr_overlay(..., branch="master") and then load_pr_overlay(..., branch="release") for the same namespace and PR. The second call returns the first call's overlay (its base_sha, its diff, its modified set). Swapping the order swaps the wrong answer.
  4. The same call with path_prefixes=("src/",) and then ("lib/",). The second returns the first's symbols.
Expected behavior

An overlay is served from the cache only for the inputs it was built from: the PR head, the target branch's tip, the namespace's indexed commit, the path scope and the diff cut. Any of them changing is a miss, as a pushed PR head already is.

Environment

main at 3058a5816, Python 3.12, unit tests only.

Related issues and pull requests

Related: https://github.com/ClickHouse/loom/issues/1680

How this was found

An AI tool helped find it, and I reproduced it myself

Additional context

The cache holds a namespace in its key since an earlier fix, so two namespaces on one mirror (one per branch) do not share an overlay today. A design that indexes several branches in one namespace (#1680) makes the target branch an input of every overlay read, which is why the key should hold every input first.

Redaction
  • I removed tokens, keys, passwords and personal or customer data from everything above.
Ngôn ngữ chính
Python
Star
263
Fork
47
Merge trung bình
14 giờ 21 phút
Pull request đã merge (30 ngày)
873

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ClickHouse/loom

Tất cả issue của ClickHouse/loom

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.