Path-filtered totals (components, `paths:` statuses) read the wrong chunks: ReadOnlyReport maps files to chunks by dict position, which jsonb commits.report reorders
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend, data, performance
Hướng nghiên cứu
The bug is in ReadOnlyReport.from_chunks in libs/shared/shared/reports/readonly.py, where filename_mapping uses dict position instead of files[name][0]. Start with the self-contained reproduction in the issue, which should fail on main, then check Report.init in libs/shared/shared/reports/resources.py to confirm how chunks_index is read. Done means the reproduction passes and the existing report tests still pass, with a note on whether stored timeseries need correcting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
On self-hosted Codecov, any total computed through ReadOnlyReport.filter(paths=...) can read the wrong file's line data. That covers component statuses, the component table in PR comments, component timeseries, project statuses scoped with paths:, and the API's component views. It happens on commits whose report gained files its parent didn't have, which is most PRs that add source files. Unfiltered totals and flag-only filters are correct, so the overall project % looks fine while the component numbers are wildly off.
Real example, with a few dozen path-based components:
- a component with 0 of 89 lines hit (at both base and head) was reported at 57.45%
- another was reported at 65.14% when its stored line data gives 26.35%
- others swung by ±20–55% while the overall project changed by −0.89% and no individual module moved by more than 5%
Root cause
ReadOnlyReport.from_chunks in libs/shared/shared/reports/readonly.py (on main at de0a8097, lines 57-59) tells the Rust analyzer which chunk each file lives in by dict position:
filename_mapping = {
filename: idx for idx, filename in enumerate(inner_report._files.keys())
}
Each file's real chunk index is stored in its summary, files[name][0]. The Python Report.__init__ (libs/shared/shared/reports/resources.py, chunks_index = summary[0]) already uses it, but the Rust mapping ignores it.
Position and chunk index only agree if the files dict comes back in the order it was serialized. It doesn't when the report is stored in the Postgres jsonb commits.report column, because jsonb doesn't keep key insertion order: it sorts object keys by length, then bytewise. When a merge appends new files, their chunks go at the end, but after the jsonb round-trip those files sort somewhere in the middle. Every file after them then maps to another file's chunk.
On the affected commit, 4,537 of 4,572 files had dict position ≠ files[name][0]. Its parent, which added no files, had 0 mismatches, and its component numbers were correct.
Recomputing every path-based component from the stored report (commits.report plus chunks.txt):
- reading chunk = dict position reproduced Codecov's reported values for 58 of 58 components, exactly to 2 decimals
- reading chunk =
files[name][0]gave the correct values
The bug seems to come from the change that hard-enabled RustReport (#582) together with the Report._files/_chunks merge (#553).
Environment
- Self-hosted,
codecov/self-hosted-apiandcodecov/self-hosted-workerlatest-stable(26.5.18), report stored inline incommits.report(jsonb) - The same code is unchanged on
codecov/umbrellamainas of 2026-11 - Codecov SaaS may never see this if it doesn't keep reports in jsonb
To Reproduce
Self-contained; the files order differs from chunk order, which is exactly what a jsonb round-trip produces:
from shared.reports.readonly import ReadOnlyReport
# a.py lives in chunk 0 (fully covered), b.py in chunk 1 (uncovered), but b.py is listed first.
files = {
"b.py": [1, [0, 1, 0, 1, 0, "0"]],
"a.py": [0, [0, 1, 1, 0, 0, "100"]],
}
chunks = "\n".join(
[
"{}",
"[1, null, [[0, 1]]]",
"<<<<< end_of_chunk >>>>>",
"{}",
"[0, null, [[0, 0]]]",
]
)
sessions = {0: {"t": None, "f": None}}
report = ReadOnlyReport.from_chunks(files=files, sessions=sessions, totals=None, chunks=chunks)
for path, want_hits in (("a.py", 1), ("b.py", 0)):
got = report.filter(paths=[path]).totals
assert (got.lines, got.hits) == (1, want_hits), (
f"filter(paths=[{path!r}]) -> lines={got.lines} hits={got.hits}, want lines=1 hits={want_hits}"
)
On main this fails: filter(paths=["a.py"]) returns b.py's lines, and vice versa. With the patch below it passes.
Expected behavior
Path-filtered totals read each file's own chunk, so component and paths: statuses match the stored line data.
Fix
files is the raw dict passed to from_chunks. create_from_report passes freshly serialized files, where position == index, so it keeps working.
diff --git a/libs/shared/shared/reports/readonly.py b/libs/shared/shared/reports/readonly.py
--- a/libs/shared/shared/reports/readonly.py
+++ b/libs/shared/shared/reports/readonly.py
@@ -54,8 +54,10 @@ class ReadOnlyReport:
files=files, sessions=sessions, totals=totals, chunks=chunks
)
totals = inner_report._totals
+ # Map each file to the chunk index stored in its summary, not to its
+ # position in `files`: commits.report is jsonb, which reorders keys.
filename_mapping = {
- filename: idx for idx, filename in enumerate(inner_report._files.keys())
+ filename: summary[0] for filename, summary in (files or {}).items()
}
session_mapping = {
sid: (session.flags or []) for sid, session in inner_report.sessions.items()
I applied this patch to the 26.5.18 self-hosted api and worker images and re-ran the affected commit's stored report through them. Every component came out correct, and the overall total was unchanged.
Additional context
Component values already written to the timeseries tables were computed with the bad mapping. The fix corrects new measurements but not existing points.
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 52
- Fork
- 25
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của codecov/feedback
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Bundle analysis: `normalizePath` replaces everything after the first `-` in a file name, so different assets collideCó thể đã có người làm @ChiptenIsCool đã nhận 16 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Docs Waiting for: Product Owner
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
Tất cả issue của codecov/feedback
Issue tương tự
-
Grok provider voice list shows 5 of xAI's 28 built-in voicesCó thể đã có người làm @hkjarral đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
hkjarral/AVA-AI-Voice-Agent-for-Asterisk#883 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: layer.move to the place a layer already has fails and stops a script; with several layers it leaves an empty undo stepCó thể đã có người làm @jgregoriorincon đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
opengeos/RustGIS#2621 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:api bug finding
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Alexa HelpIntent and exception handler format HELP_MSG using audio data instead of the skill nameĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Hono path parameters with a regex pattern keep the pattern in the OpenAPI pathCó thể đã có người làm @0z5a đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/chanfana#400 ·
Maintainer thường phản hồi trong vòng 1 ngày