Repository navigation
test(dev): add inflight-staging contention e2e; drop migration test - #1373
Conversation
Add a multi-replica contention driver that actually activates in-flight NAR staging — the fix for the #660 download-window and #1289 chunking-window incomplete-NAR bugs. Staging only engages under contention (a reader racing an in-flight download with a distributed locker), which Go unit tests cover only in-process and the k8s HA permutations merely enable in config without ever driving. PR #1372 added run.py --inflight-staging, making a dev-level driver possible. The driver (test-inflight-staging-contention-e2e.py) launches >=2 ncps replicas via run.py with --locker redis --inflight-staging, verifies effective config from state.json, then races N barrier-synchronized HTTP clients on one uncached NAR. It asserts every reader gets a complete NAR byte-identical to the canonical `nix-store --dump`, across the download and chunking windows and the local/s3 backends, and fails loudly (with producer-error vs. no-contention classification) if staging never activated. A fixed-port wrapper and `task test:inflight-staging- contention` mirror the CDC-lifecycle driver; it is opt-in, not part of nix flake check. Remove the obsolete test-migration-e2e.py: it validated the one-time dbmate->Ent cutover, which has shipped, and is unwired (no Taskfile/CI/ nix/importer). The shared dbmate create/drop in run.py and migrate-all.py are retained. Lineage comments in the CDC driver are cleaned up. Validated live against real Garage/Postgres/Redis: cluster, config checks, the cross-replica race, and byte-identity all pass. The harness immediately surfaced a real ncps bug (staging producer races into the holder's deleted temp file on fast downloads, so staging never serves); the fix is deferred to a separate change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
This change is part of the following stack: Change managed by git-spice. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis pull request adds a new e2e harness to validate in‑flight NAR staging under multi‑replica contention: spec/design docs, a fixed‑port bash wrapper and Taskfile task, a Python driver that runs contention races and validates byte‑identical NAR delivery across CDC windows and storage backends, and minor doc cleanups. ChangesIn-flight staging contention e2e harness
Sequence Diagram(s)sequenceDiagram
participant Wrapper as test-inflight-staging-contention-auto.sh
participant DepsStack as nix run .#deps
participant Driver as test-inflight-staging-contention-e2e.py
participant Cluster as dev-scripts/run.py (multi-replica)
participant Replica1 as ncps replica 1
participant Replica2 as ncps replica 2
Wrapper->>DepsStack: start services (Redis, S3, Postgres, MariaDB)
DepsStack-->>Wrapper: services ready on fixed ports
Wrapper->>Driver: invoke with CLI args
Driver->>Cluster: start with --locker redis --inflight-staging
Cluster->>Replica1: launch replica 1
Cluster->>Replica2: launch replica 2
Replica1-->>Driver: state.json (inflight_staging enabled)
Replica2-->>Driver: state.json (inflight_staging enabled)
Driver->>Driver: realise flake, compute canonical NAR digest
Driver->>Replica1: fetch .narinfo for target store-path
Replica1-->>Driver: narinfo with URL/compression
par Concurrent NAR fetches
Driver->>Replica1: GET NAR (client 1)
Driver->>Replica2: GET NAR (client 2)
Driver->>Replica1: GET NAR (client N)
end
Replica1-->>Driver: HTTP 200 + compressed NAR (client 1)
Replica2-->>Driver: HTTP 200 + compressed NAR (client 2)
Driver->>Driver: decompress all NARs, compute digests
Driver->>Driver: assert all digests match canonical
Driver->>Replica1: scan logs for staging activation evidence
Replica1-->>Driver: debug log: staging activated
Driver->>Driver: write phase result (PASS/FAIL)
Driver->>Cluster: stop cluster
Wrapper->>DepsStack: teardown services
DepsStack-->>Wrapper: services stopped
Wrapper-->>Driver: exit with aggregated summary
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a new end-to-end test harness (test-inflight-staging-contention-e2e.py) and an automated wrapper script to validate in-flight NAR staging under multi-replica contention using a Redis locker. It also removes the obsolete test-migration-e2e.py script and updates related documentation and task configurations. The review feedback focuses on improving the robustness of the new Python test script, specifically by enhancing HTTP error handling in the http_get helper to prevent dead code, opening subprocess logs in binary mode to avoid encoding issues, and explicitly specifying UTF-8 encoding when reading logs and state files.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
dev-scripts/test-cdc-lifecycle-e2e.py (1)
165-176:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winFile handle leak if
subprocess.Popenraises.Same issue as in
test-inflight-staging-contention-e2e.py: the file is opened beforesubprocess.Popen, and ifPopenraises, the file handle leaks.🛡️ Proposed fix using try/except pattern
- f = open(log_path, "w") - # start_new_session=True puts the child in its own session/process group - # (like os.setsid) so stop_ncps can kill the whole group via os.killpg — - # the modern, fork-safe replacement for preexec_fn=os.setsid. - p = subprocess.Popen( - args, - cwd=REPO_ROOT, - stdout=f, - stderr=subprocess.STDOUT, - start_new_session=True, - ) - return p, f + try: + f = open(log_path, "w") + # start_new_session=True puts the child in its own session/process group + # (like os.setsid) so stop_ncps can kill the whole group via os.killpg — + # the modern, fork-safe replacement for preexec_fn=os.setsid. + p = subprocess.Popen( + args, + cwd=REPO_ROOT, + stdout=f, + stderr=subprocess.STDOUT, + start_new_session=True, + ) + return p, f + except Exception: + if 'f' in locals(): + f.close() + raise🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dev-scripts/test-cdc-lifecycle-e2e.py` around lines 165 - 176, The file handle f opened with open(log_path, "w") may leak if subprocess.Popen(...) raises; wrap the Popen call so f is always closed on error (either open the file with a context manager around Popen or use try/except/finally to close f on exception). Specifically, change the behavior around subprocess.Popen (the call that creates p) so that if Popen fails you close f rather than returning; ensure the function that returns p, f still returns a valid pair only when Popen succeeds, referencing the variables f, log_path, args, REPO_ROOT, and the subprocess.Popen invocation (with start_new_session=True).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dev-scripts/test-inflight-staging-contention-auto.sh`:
- Around line 23-24: The direnv bootstrap is split across two separate commands
so the unset/eval runs even if `direnv allow .` fails; change the two-line
sequence (`direnv status | grep -q "Found RC allowed 0" || direnv allow .` and
`unset DIRENV_DIR DIRENV_FILE DIRENV_WATCHES DIRENV_DIFF && eval "$(direnv
export bash)"`) into a single chained expression using `||` and `&&` as: run the
status check OR attempt `direnv allow .` and only if one of those succeeds then
run the `unset DIRENV_*` and `eval "$(direnv export bash)"`, ensuring the
unset/eval only executes on success.
In `@dev-scripts/test-inflight-staging-contention-e2e.py`:
- Around line 155-165: Open handle 'f' may leak if subprocess.Popen(args, ...)
raises; change the logic around the open(log_path, "w") and subprocess.Popen
call so the file is always closed on error: open the file, call
subprocess.Popen, and if Popen raises close 'f' and re-raise (or use a context
manager/try/finally) so you only return (p, f) when Popen succeeds. Update the
code that uses log_path, f, subprocess.Popen, args, REPO_ROOT, and
start_new_session to implement this cleanup.
---
Outside diff comments:
In `@dev-scripts/test-cdc-lifecycle-e2e.py`:
- Around line 165-176: The file handle f opened with open(log_path, "w") may
leak if subprocess.Popen(...) raises; wrap the Popen call so f is always closed
on error (either open the file with a context manager around Popen or use
try/except/finally to close f on exception). Specifically, change the behavior
around subprocess.Popen (the call that creates p) so that if Popen fails you
close f rather than returning; ensure the function that returns p, f still
returns a valid pair only when Popen succeeds, referencing the variables f,
log_path, args, REPO_ROOT, and the subprocess.Popen invocation (with
start_new_session=True).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9cef3caf-84d9-4920-a82e-ee9bfdd79948
📒 Files selected for processing (11)
Taskfile.ymldev-scripts/test-cdc-lifecycle-e2e.pydev-scripts/test-inflight-staging-contention-auto.shdev-scripts/test-inflight-staging-contention-e2e.pydev-scripts/test-migration-e2e.pyopenspec/changes/archive/2026-06-08-test-harness-coverage-audit/.openspec.yamlopenspec/changes/archive/2026-06-08-test-harness-coverage-audit/design.mdopenspec/changes/archive/2026-06-08-test-harness-coverage-audit/proposal.mdopenspec/changes/archive/2026-06-08-test-harness-coverage-audit/specs/inflight-staging-contention-e2e/spec.mdopenspec/changes/archive/2026-06-08-test-harness-coverage-audit/tasks.mdopenspec/specs/inflight-staging-contention-e2e/spec.md
💤 Files with no reviewable changes (1)
- dev-scripts/test-migration-e2e.py
Address review feedback on the contention e2e driver: - scan_logs / read_state / the cluster log file now open with encoding="utf-8" (errors="replace" for the ncps logs, which can carry non-UTF-8 bytes from Nix build output) so reads never crash on locale or non-ASCII content. (threads PRRT_kwDONV6tZs6H_Vpz, _Vp1, _Vpu) - start_cluster closes the log file if subprocess.Popen raises, so the handle never leaks. (thread PRRT_kwDONV6tZs6H_XpY)
Summary
dev-scripts/test-inflight-staging-contention-e2e.py+test-inflight-staging-contention-auto.sh(and atask test:inflight-staging-contentiontarget): a multi-replica + Redis-locker contention driver that activates in-flight NAR staging by racing concurrent readers against an in-flight download, asserting every reader gets a complete, byte-identical NAR (vs.nix-store --dump) across the download/chunking windows and local/s3 backends. Fails loudly if staging never activates.dev-scripts/test-migration-e2e.py(the dbmate→Ent cutover it validated has shipped; unwired, no importers). The shareddbmatecreate/drop inrun.py/migrate-all.pyis retained.This harness drove the discovery and validation of the in-flight-staging fixes stacked on top of it.
Test plan
task fmt/task lint/task testpass