fix(ci_visibility): encode bytearray bitmaps in payload files mode #22186
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.68) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.68 · 432 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.363
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.068
Real PR Conversation Timeline
1 comments
"Review active on #22186"
general
weight: 0.35
gnufede
Description
In payload-files mode (Bazel offline,
DD_TEST_OPTIMIZATION_PAYLOADS_IN_FILES=true), no coverage payload files were ever written: only.tmpleftovers remained, while test-event payloads were written fine.Root cause:
CoverageLines.to_bytes()returns its internalbytearray, notbytes. Theisinstance(..., bytes)check inPayloadFileCoverageWriter._send_eventsleft such bitmaps unencoded, sojson.dumprejected the payload andwrite_payload_filedropped it (logging only a warning), never performing the atomic rename.The check is broadened to accept
bytearrayalongsidebytesso bitmaps are base64-encoded and the coverage payload file is written. The fix is made in the payload writer rather than inCoverageLines.to_bytes(): that method feeds the hot per-test HTTP coverage path (where msgpack handlesbytearrayfine), and returning realbyteswould add a buffer copy per file there; the payload-files writer is the only consumer that needsbytessemantics and is cold-path.Reproduced externally with ddtrace 4.16.1 from PyPI running pygments' test suite (5308 tests, zero coverage payload files).
Testing
test_coverage_bytearray_bitmaps_are_base64_encodedsources its bitmap fromCoverageLines.from_list(...).to_bytes()(the actualbytearrayproducer) and asserts the coverage JSON file is written and decodes with the bitmap round-tripping through base64..tmp).tests/testing/internal/test_payload_files.py,test_offline_mode.py,test_bazel_offline_session_manager.py: 81 passed (Python 3.12,ci_visibility::testingsuite env).tests/testing/suite: 1584 passed; the single failure (test_pytest_xdist.py::TestResolveInheritedManifestEnv::test_discards_manifest_generated_by_unrelated_process) reproduces on a clean tree and is unrelated/pre-existing.scripts/lint fmt,typing, andchecksall pass.Risks
None: the change is confined to the payload-files-mode writer, which previously produced zero usable output for coverage payloads.
Additional Notes
No runtime benchmarks run — the change affects only the cold offline-mode write path. Also fixes a pre-existing mypy
type-argerror in the same test file that blocked the pre-commit hook.End-to-end verification (payload-files mode against a real test suite)
Reproduced the reported scenario with pygments' test suite (GitHub
main) on Python 3.12, two clean venvs, run withDD_TEST_OPTIMIZATION_PAYLOADS_IN_FILES=true,TEST_UNDECLARED_OUTPUTS_DIR=...,_DD_CIVISIBILITY_ITR_FORCE_ENABLE_COVERAGE=trueandpytest --ddtrace(tests/contrastexcluded — missingwcag_contrast_ratiodependency, unrelated):| Payload files | ddtrace 4.16.1 (PyPI) | This branch |
|---|---|---|
|
tests-.json| 15 | 15 ||
telemetry-.json| 2 | 2 ||
coverage-.json| 0 | 11 ||
coverage-.json.tmpleftovers | 11 | 0 |Baseline shows the reported warning on every coverage flush (
Error writing payload file ... Object of type bytearray is not JSON serializable); the branch run has zero such warnings. All 11 coverage payload files decode as JSON with the expectedversion/test_session_id/test_suite_id/span_id/filesstructure, and every bitmap is valid strict base64 decoding to non-empty bytes (e.g./tests/conftest.py).