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

未关闭
#1,968 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@KaloyanNaumov 已经在做这个了。

开始于 2026年12月1日。

  • #1969 来自 @KaloyanNaumov —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend, databases

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
Python
星标
221
派生
35
平均合并
14 小时 21 分钟
30 天内合并 PR
873

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ClickHouse/loom 的其他 Issue

查看 ClickHouse/loom 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。