Repository navigation
chore(native): enforce a single libdatadog release tag across cargo manifests - #21692
dd-apm-ecosystems[bot] wants to merge 3 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83a0af85f5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| case "$line" in | ||
| *"libdatadog-pin: allow"*) continue ;; | ||
| esac | ||
| if [[ "$line" =~ $tag_re ]]; then |
There was a problem hiding this comment.
Handle table-form Cargo dependencies
Cargo accepts dependencies written as [dependencies.libdd-common] with git = ".../libdatadog" and rev = "v48.0.0" on separate lines, but this condition searches for rev only on the line containing git. Such a correctly pinned manifest therefore fails the new blocking CI check; associate the fields across the dependency table rather than requiring an inline-table layout.
Useful? React with 👍 / 👎.
| case "$line" in | ||
| *"libdatadog-pin: allow"*) continue ;; |
There was a problem hiding this comment.
Still compare opted-out release tags
The marker is documented as an escape hatch for a temporary non-release pin, but this unconditional skip also removes a valid release tag from the consistency check. If a temporary SHA is later changed to an older release tag while its marker remains, a manifest can combine (for example) v47.0.0 and v48.0.0 and this job exits successfully; skip validation only when the pin is actually non-release, while continuing to collect release tags for comparison.
Useful? React with 👍 / 👎.
| done < <(git ls-files | grep -E '(^|/)Cargo\.toml$' || true) | ||
|
|
||
| if [ "${#tags[@]}" -gt 0 ]; then | ||
| distinct=$(printf '%s\n' "${tags[@]}" | sort -uV | paste -sd' ' -) |
There was a problem hiding this comment.
Avoid GNU-only version sorting
On macOS and other BSD-based development environments, the system sort does not support -V, so this command terminates the script under set -e whenever at least one matching dependency exists—even when every pin is valid. Since the script explicitly advertises itself as a local check and only needs to deduplicate tags here, use portable sorting (such as sort -u) or another cross-platform comparison.
Useful? React with 👍 / 👎.
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 83a0af8 | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
Two distinct regex bugs exist in scripts/check-libdatadog-pins.sh: the URL-matching expression (line 26) does not recognise single-quoted TOML strings, silently bypassing pin validation, and the revision-extraction expression (line 35) matches version strings inside inline comments, allowing a non-release SHA pin to pass the CI gate when a release tag appears only in a comment.
🤖 Bits Code Review · Commit 83a0af8
| dep_re='^[^#]*git[[:space:]]*=[[:space:]]*"[^"]*github\.com[/:]DataDog/libdatadog(\.git)?/?"' | ||
| tag_re='rev[[:space:]]*=[[:space:]]*"(v[0-9]+\.[0-9]+\.[0-9]+)"' |
There was a problem hiding this comment.
Recognize single-quoted TOML strings
A valid TOML dependency using git = 'https://github.com/DataDog/libdatadog', rev = 'deadbeef' is ignored entirely, allowing a non-release pin through CI. Conversely, a double-quoted URL with rev = 'v48.0.0' incorrectly fails. Both TOML string syntaxes need to participate in pin validation and release comparison.
| dep_re='^[^#]*git[[:space:]]*=[[:space:]]*"[^"]*github\.com[/:]DataDog/libdatadog(\.git)?/?"' | |
| tag_re='rev[[:space:]]*=[[:space:]]*"(v[0-9]+\.[0-9]+\.[0-9]+)"' | |
| dep_re="^[^#]*git[[:space:]]*=[[:space:]]*[\"'][^\"']*github\.com[/:]DataDog/libdatadog(\.git)?/?[\"']" | |
| tag_re="rev[[:space:]]*=[[:space:]]*[\"'](v[0-9]+\.[0-9]+\.[0-9]+)[\"']" |
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
| case "$line" in | ||
| *"libdatadog-pin: allow"*) continue ;; | ||
| esac | ||
| if [[ "$line" =~ $tag_re ]]; then |
There was a problem hiding this comment.
Exclude inline comments when extracting revisions
With rev = "deadbeef" followed by an inline comment such as # previously rev = "v48.0.0", the regex extracts the release tag from the comment and reports success. Cargo still uses the SHA, so the new CI gate accepts precisely the unreleased dependency it should reject.
| if [[ "$line" =~ $tag_re ]]; then | |
| if [[ "${line%%#*}" =~ $tag_re ]]; then |
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
BenchmarksBenchmark execution time: 2026-11-12 00:02:10 Comparing candidate commit 83a0af8 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 615 metrics, 9 unstable metrics, 1 flaky benchmarks without significant changes.
|
|
A nice idea, but this implementation is flawed enough to consider re-writing. |
<!-- dd-meta {"pullId":"74e89509-77c1-4c57-b00c-ab363be5abeb","source":"chat","resourceId":"8c626a5a-8c1b-489f-bd4d-302ed1d4a215","workflowId":"8c803024-e883-44c5-b25b-a76477bd46b0","codeChangeId":"8c803024-e883-44c5-b25b-a76477bd46b0","sourceType":"code_channel"} -->
## Description
The libdatadog project releases all its crates together. dd-trace-py must thus depend on libdatadog through exactly one release tag. A commit SHA, a branch, the default branch or a mix of releases can ship unreleased native code or put two copies of libdatadog into the native extension. Reviewers check this by hand at this time.
This PR adds a CI check for this rule. It replaces the approach in #21692 (Bash and regular expressions) with a small Python script that uses the `tomllib` TOML parser. There is no opt-out marker.
`scripts/check_libdatadog_pins.py` finds all tracked `Cargo.toml` and `Cargo.lock` files with `git ls-files`, and makes sure that:
- Each libdatadog git dependency in a `Cargo.toml` sets `rev` or `tag` to a `vX.Y.Z` release tag. The script examines all tables, which includes `[dependencies]`, `[dev-dependencies]`, `[build-dependencies]`, `[target.*.dependencies]`, `[workspace.dependencies]` and `[patch.*]`.
- Each libdatadog `[[package]].source` in a `Cargo.lock` uses `rev=` or `tag=` with a `vX.Y.Z` release tag.
- All `Cargo.lock` files together have exactly one libdatadog source. This includes the commit hash, thus two lockfiles that resolve the same tag to different commits also fail.
- The release tag in the `Cargo.toml` files is the same as the release tag in the `Cargo.lock` files.
Other changes:
- `.gitlab/native.yml`: new `libdatadog pins` job. It extends `.ci_utils` (small image with Python 3.14) and runs `python3 scripts/check_libdatadog_pins.py`.
- `scripts/run-script-doctests.py`: runs the doctests of the new script. The `requires-python` value changes from `>=3.9` to `>=3.11` because the script uses `tomllib`.
The script uses a TOML parser, thus these edge cases from the #21692 review are not a problem:
- Table-form dependencies (`[dependencies.libdd-common]` with `git` and `rev` on different lines) are accepted.
- Single-quoted TOML strings are read correctly.
- A release tag in a comment (`rev = "deadbeef" # rev = "v49.0.0"`) does not hide a SHA pin.
- `tag = "vX.Y.Z"` is accepted, and `rev = "vX.Y.Z"` is also accepted.
- There is no opt-out marker, thus an opted-out pin cannot skip the tag comparison.
- The script does not use GNU-only tools such as `sort -V`.
- The error output is plain text, not GitHub Actions annotations, because the job runs in GitLab.
## Testing
- `python3 scripts/check_libdatadog_pins.py` on this branch passes: `OK: libdatadog source is git+https://github.com/DataDog/libdatadog?rev=v49.0.0#34293ad2...`.
- Doctests in the script cover URL matching (`.git` suffix, trailing slash, case, `ssh://`, other repositories), table-form dependencies, single quotes, inline comments, `branch`, the default branch, `[target.*]` and `[patch.*]` tables, and `Cargo.lock` `rev=`/`tag=`/`branch=`/no query. They run in the `Run scripts/*.py tests` precheck.
- Manual checks in a temporary git repository with copies of the real Cargo files. Each of these fails: SHA pin in `Cargo.toml` and `Cargo.lock`, mixed `v48.0.0`/`v49.0.0` tags, stale `Cargo.lock` (`Cargo.toml` at `v50.0.0`, lock at `v49.0.0`), `branch` and default branch, a second lockfile with a different libdatadog source, a SHA hidden by a comment, a `[patch]` entry on a branch, and no libdatadog source. Table-form, single-quoted, commented and `tag =` dependencies (with a `?tag=` lock source) pass.
- `scripts/lint checks` passes.
- The GitLab job itself did not run locally.
## Risks
- A PR that needs an unreleased libdatadog commit for a short time fails this job until libdatadog makes a release. This is intended.
- The job fails if no libdatadog git source is found. If dd-trace-py stops using libdatadog through git (for example, it moves to crates.io), update or remove this check.
- crates.io dependencies on libdatadog crates (for example `libdd-profiling-heap-gotter` in `src/native_heap_gotter`) are not checked. They do not use a git tag.
- `scripts/run-script-doctests.py` now needs Python 3.11 or later.
## Additional Notes
- Replaces #21692.
- No release note: this is a CI-only change.
🤖 Generated with <span>Claude Code</span> (<span>https://claude.com/claude-code</span>)
---
PR by Bits - [View session in Datadog](https://app.datadoghq.com/code/8c626a5a-8c1b-489f-bd4d-302ed1d4a215) • [Open in Slack](https://app.slack.com/client/T024FSN2Y/C0CJA6RJGN7)
Comment @DataDog to request changes
Co-authored-by: datadog-bits <263423550+datadog-bits@users.noreply.github.com>
Co-authored-by: brett.langdon <brett.langdon@datadoghq.com>
Description
Adds a small CI check that every
Cargo.tomldependency onlibdatadogpins a release tag (rev = "vX.Y.Z") and that all of them pin the same tag.Theme: libdatadog crates are released together, and reviewers repeatedly ask that
revs stay in sync and that a commit SHA is replaced by a release tag before merge.Recurrence (all-time, distinct PRs): 2, both raised by a human maintainer (
brettlangdon) and accepted by the PR author:revs in sync". The author moved to the v47.0.0 tag in8f735659fc.Related, not counted as recurrence: #21522 had a human ask "I'm not sure about the hash here instead of a released version", and #21346 and #21618 have similar open threads. I did not record those as occurrences yet because the thread is unresolved or the PR is still open.
Why it is mechanically detectable: the rule is a line-level property of
Cargo.toml(git URL isDataDog/libdatadog,revis avX.Y.Ztag, and all tags agree). There is no semantic judgement involved.Tool added vs extended: nothing existing fits. The repo has no
cargo-denyor other Cargo policy config, ruff/ast-grep do not parse TOML, andscripts/check-dependency-boundsonly readspyproject.toml. I added one ~50-line bash script rather than a Python dependency, and wired it into the existing native CI file.gitlab/native.yml, next torust ci, instead of creating a new pipeline.Per the maintainer-feedback memory on a previous automation PR (#21010, comments 4292422565 and 4292434731, recorded as feedback_ids
rst-in-private-docstrings|pr21010|4292422565and...|4292434731, implement_differently=1), this change is deliberately wired into a blocking CI job in the same PR and I looked for an existing tool first. I am not claiming this is the same theme; I applied the guidance to this implementation.Testing
bash scripts/check-libdatadog-pins.shon currentmain:OK: 21 libdatadog dependencies pinned to v48.0.0. No existing code is flagged, so there is no mass breakage.tests/internal/test_check_libdatadog_pins.py, 11 cases): SHA pin fails, short SHA fails,branch =fails,tag =key fails, mixed tags in one or across two manifests fail,.gitURL suffix still checked, commented-out lines and unrelated git deps ignored, the opt-out marker exempts only its own line, no libdatadog deps is a silent no-op.pytestcould not be installed in my sandbox (no network); I have not run them under the repo's real pytest/suitespec.ruff formatandruff checkpass on the new test file..gitlab/native.ymlas YAML (with the!referencetag) but could not run the GitLab job itself.Risks
libdd-ai-usagewhile waiting on a release). They can opt out per line with a trailing# libdatadog-pin: allow, which shows up in review.git = ".../DataDog/libdatadog"dependencies in trackedCargo.tomlfiles. Registry or path deps are not touched.Cargo.lockis not parsed.testsstage (libdatadog pinsjob,needs: [], norules:so it runs on every pipeline). It is not in the GitHub Actionson: pull_requestset because my token could not create a.github/workflowsfile (403 on contents API). If you prefer it as a GitHub Action, the job body is one line:bash scripts/check-libdatadog-pins.sh.scripts/lint/ the prechecks generator /tests/suitespec.yml, so the unit test file will not auto-trigger when only the script changes. Happy to follow up.Additional Notes
bash scripts/check-libdatadog-pins.shscripts/check-libdatadog-pins.sh(new),tests/internal/test_check_libdatadog_pins.py(new),.gitlab/native.yml(new joblibdatadog pins)..gitlab/native.yml, joblibdatadog pins, stagetests, runs on every pipeline including PR pipelines.libdatadog-release-pins|pr21459|4495911878(human, brettlangdon, accepted by danyal002),libdatadog-release-pins|pr20892|4402283777(human, brettlangdon, accepted by elihschiff).