Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(rust): stop rebuilding every crate when Cargo.lock changes (#78462)

Georges-Antoine Assi50b48ab6c3f6
diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml
index 75213d5c3b31..9a76a4e49d1e 100644
--- a/.github/workflows/ci-rust.yml
+++ b/.github/workflows/ci-rust.yml
@@ -221,11 +221,13 @@ jobs:
f.write(f"matrix={json.dumps(matrix)}\n")
build:
- name: Build Rust services (depot-ubuntu-22.04-4)
+ name: Build Rust (${{ matrix.packages }})
+ strategy:
+ matrix: ${{ fromJSON(needs.affected.outputs.matrix) }}
needs: [changes, affected]
if: needs.changes.outputs.rust == 'true'
runs-on: depot-ubuntu-22.04-4
- timeout-minutes: 15
+ timeout-minutes: 20
permissions:
contents: read
@@ -279,16 +281,13 @@ jobs:
env:
# Use system OpenSSL instead of vendored to avoid assembly build issue (2026-01-13)
OPENSSL_NO_VENDOR: '1'
- AFFECTED_CRATES: ${{ needs.affected.outputs.affected_crates }}
+ SHARD_PACKAGES: ${{ matrix.packages }}
run: |
- crates=$(echo "$AFFECTED_CRATES" | python3 -c "import json,sys; print(' '.join(f'-p {c}' for c in json.load(sys.stdin)))")
- if [ -z "$crates" ]; then
- echo "No affected crates — skipping build"
- else
- echo "Building affected crates: $crates"
- cargo build $crates --locked --release
- find target/release/ -maxdepth 1 -executable -type f -exec strip {} +
- fi
+ crates=()
+ for c in $SHARD_PACKAGES; do crates+=(-p "$c"); done
+ echo "Building shard crates: ${crates[*]}"
+ cargo build "${crates[@]}" --locked --release
+ find target/release/ -maxdepth 1 -executable -type f -exec strip {} +
test:
name: Test Rust (${{ matrix.packages }})
diff --git a/rust/affected-services/determinator-rules.toml b/rust/affected-services/determinator-rules.toml
index 4afb273c7ba9..989a2511a09d 100644
--- a/rust/affected-services/determinator-rules.toml
+++ b/rust/affected-services/determinator-rules.toml
@@ -3,21 +3,20 @@
# Custom rules are processed before default rules. Default rules already handle:
# - .cargo/config, .cargo/config.toml → mark-changed = "all"
# - Cargo.toml (workspace root) → mark-changed = "all"
-# - Cargo.lock → mark-changed = [] (ignored — we override below)
+# - Cargo.lock → mark-changed = [] (ignored; the graph diff covers it)
# - README, LICENSE, .gitignore, etc. → mark-changed = []
#
# Paths are workspace-relative (strip the `rust/` repo prefix before passing).
use-default-rules = true
-# Cargo.lock: the determinator diffs resolved package graphs but does NOT
-# detect per-crate feature narrowing as a change — a crate whose enabled
-# feature set shrinks (or grows) only shows up in Cargo.lock, not in the
-# determinator's affected set. Force rebuild-all whenever Cargo.lock changes.
-# This overrides the default determinator rule (mark-changed = []).
-[[path-rule]]
-globs = ["Cargo.lock"]
-mark-changed = "all"
+# Cargo.lock intentionally has no rule: the default (mark-changed = []) is
+# correct, because the determinator's graph diff already re-simulates each
+# member's feature sets and marks every dependent of a changed dependency.
+# Do not re-add mark-changed = "all" — it fires on every lockfile touch, so one
+# added dev-dependency rebuilds the whole workspace and blows the build timeout.
+# When the old graph is missing there is nothing to diff, and compute_affected()
+# forces rebuild-all in code instead.
# Dockerfiles and CI image config — cross-cutting build changes.
[[path-rule]]
diff --git a/rust/affected-services/tests/integration.rs b/rust/affected-services/tests/integration.rs
index a8a757b13cfb..128763df94a9 100644
--- a/rust/affected-services/tests/integration.rs
+++ b/rust/affected-services/tests/integration.rs
@@ -369,16 +369,16 @@ fn old_graph_no_changed_files_produces_empty() {
}
#[test]
-fn two_graph_lockfile_triggers_rebuild_all() {
+fn two_graph_lockfile_alone_does_not_rebuild_all() {
let (graph, images) = load_test_fixtures();
let result =
compute_affected(&["rust/Cargo.lock".into()], Some(&graph), &graph, &images).unwrap();
assert!(
- result.rebuild_all,
- "Cargo.lock change should force rebuild-all even with two graphs (feature narrowing is invisible to the determinator)"
+ !result.rebuild_all,
+ "a lockfile change with an old graph to diff against must not force rebuild-all — the determinator's summary diff decides what is affected"
);
- let workspace_count = graph.workspace().iter().count();
- assert_eq!(result.crates.len(), workspace_count);
+ assert!(result.crates.is_empty());
+ assert!(result.images.is_empty());
}
#[test]