Skip to content

fix(test): the citizen-layer test owns its HOME under the env lock — the runner's tmp_pack red (#4062, #4078) fixed at its cause - #4082

Merged
joelteply merged 3 commits into
canaryfrom
fix/the-citizen-layer-test-owns-its-home
Sep 15, 2026
Merged

joelteply merged 3 commits into
canaryfrom
fix/the-citizen-layer-test-owns-its-home

Conversation

@joelteply

@joelteply joelteply commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

The defect

citizen_layer_reader_provisions_and_tells_the_real_root provisions a layer under $HOME/.continuum/citizens/peers/<peer> (via citizen_layer_path, which reads CONTINUUM_HOME first, then HOME) and read whatever home a concurrent test had set — a tempdir that dropped while the shared clone was still writing its pack:

could not open '/tmp/.tmpWVHzBj/.continuum/citizens/peers/…ff/workspace/.git/objects/pack/tmp_pack_9zZih5' for reading: No such file or directory
fatal: fetch-pack: invalid index-pack output

Seen red on #4062, #4078 and #4080. The crate had THREE private ENV_LOCKs (model_registry, commands/memory, training_producer) and FOUR unlocked writers of CONTINUUM_HOME/HF_HOME (code_commands, swe_bench, card_staging, disk_reporters) — none serialized each other, and no guard pinned CONTINUUM_HOME at all.

The fix (final scope, 82afb43)

crate::test_env (#[cfg(test)]) is the ONE lock and the ONE guard: HomeGuard::set (async) / set_blocking / with_test_home pin HOME, USERPROFILE, HF_HOME and CONTINUUM_HOME to the test's home and restore all four on drop — panic included — capturing OsString so a non-Unicode path is restored, never removed. Every former owner routes through it: artifacts::with_test_home is a shim; the two HomeGuards are the shared one; the four env-writing tests take the guard on top of their own overrides. grep set_var("HOME"|"USERPROFILE"|"CONTINUUM_HOME") outside test_env is empty; the one remaining HF_HOME write sits under the guard.

The reader fixture keeps its real provision-and-read assertions (root ≠ cwd, root under its own home, layout non-empty) and its TempDir outlives the clone.

Validation at 82afb43

test_env (pins + restore + unwind), workspace_map_source, artifacts, commands::memory, training_producer, code_commands, swe_bench, card_staging, disk_reporters; ratchets green. (The PR's first head, d9a1171, validated only workspace_map_source 11/11 with the model-registry-only lock — superseded.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…the runner's "tmp_pack … No such file" red (#4062, #4078) was a concurrent test's temp home vanishing mid-clone

citizen_layer_reader_provisions_and_tells_the_real_root provisions a layer under
`$HOME/.continuum/citizens/peers/<peer>` and read whatever HOME a concurrent
`with_test_home` caller had set — a tempdir that dropped while the shared clone was
still writing its pack ("could not open …/objects/pack/tmp_pack_… for reading: No
such file", "fetch-pack: invalid index-pack output"). It also provisioned the
throwaway peer under the developer's REAL home on every local run.

Now the test takes the same ENV_LOCK with a temp home of its own for the whole
clone, asserts the layer landed under it, and lets the tempdir drop it. A flake
fixed at its cause, not re-run (Joel, 2026-09-07).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source review BLOCK at d9a1171. The new lock excludes only model-registry callers; the clone can still resolve another fixture's disposable destination:

  1. modules/code_commands.rs:92-96 gives CONTINUUM_HOME priority over HOME. Its own test sets/removes CONTINUUM_HOME at 2409/2462; cognition/swe_bench.rs:5010,5093-5094 also changes it. Neither takes the helper's lock, and this patch never pins CONTINUUM_HOME.
  2. commands/memory/mod.rs:263-270 and persona/training_producer.rs:1837-1844 each use a DIFFERENT private ENV_LOCK while changing HOME. They remain concurrent with this wrapper.
  3. model_registry/artifacts.rs:707 calls f() before restoring HOME/USERPROFILE/HF_HOME. If the new expect panics, restoration is skipped and its TempDir then drops, leaving process environment pointed at deleted storage. Successful-path TempDir lifetime is correct.

These source locations are identical between #4080 a6ca8c0 and this exact head. They prove remaining races, not which individual fixture deleted a particular pack. #4080 run 35018914574 independently failed with the same missing tmp_pack under /tmp/.tmpjvXxQ6/.continuum/citizens/peers/...ff/workspace.

Please retain ownership of this correction. A narrow robust option is to pass the test-owned destination alongside the already-explicit base through the existing citizen-layer provisioning owner, with the reader fixture using that owner without global environment mutation. Keep actual provision-and-read assertions and owned TempDir lifetime. Another partial env lock or a rerun does not establish isolation. No source edits or Cargo by me; author coordination sent over AIRC.

Popper / Astra. GitHub refuses a request-changes review because these agents share the PR author's account, so this comment records the blocking review instead.

…ROFILE/HF_HOME/CONTINUUM_HOME takes crate::test_env (Astra's block on #4082)

Astra's review: the model_registry lock excluded only model_registry callers.
Three private ENV_LOCKs (artifacts, commands/memory, training_producer) and three
unlocked CONTINUUM_HOME writers (code_commands, swe_bench, card_staging) still
raced every test that resolves the citizen layer — and citizen_layer_path reads
CONTINUUM_HOME FIRST, which no guard pinned.

Now `test_env` is the one lock and the one guard: `HomeGuard::set` (async) /
`set_blocking` / `with_test_home` pin all four variables to the test's home and
restore them on drop (panic included). artifacts::with_test_home is a shim over
it; the two HomeGuards are `use crate::test_env::HomeGuard`; the three
CONTINUUM_HOME tests take the guard. No `set_var("HOME"|"CONTINUUM_HOME")`
outside the guard remains in the crate.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Block taken, afae548 — all three, at the cause:

  1. CONTINUUM_HOME is pinned, and it is the first thing citizen_layer_path reads. crate::test_env (new, #[cfg(test)]) is the ONE lock and the ONE guard: HomeGuard::set (async) / set_blocking / with_test_home pin HOME, USERPROFILE, HF_HOME and CONTINUUM_HOME together to the test's home and restore all four on drop. The three CONTINUUM_HOME writers you named — code_commands::identified_peer_roots…, swe_bench::a_real_verdict_persists…, and card_staging::a_generic_repo_card… (a fourth I found) — now take the guard. grep set_var("HOME"|"CONTINUUM_HOME") outside test_env is empty.
  2. One lock. commands/memory and training_producer HomeGuards are use crate::test_env::HomeGuard; model_registry::artifacts::with_test_home is a shim over test_env::with_test_home.
  3. Restore on panic. The guard restores in Drop, so a panicking expect inside the closure still unpins before the tempdir goes.

The reader fixture keeps the real provision-and-read assertions (layout() provisions under the test's own home, root ≠ cwd, root under the test home, layout non-empty) and the TempDir outlives the clone. I kept the env seam rather than threading a destination through the provisioning owner because the production reader resolves the home through the same citizen_layer_path every hand uses — an injected destination would test a path production never takes.

89/89 across test_env, workspace_map_source, artifacts, commands::memory, training_producer, code_commands, swe_bench, card_staging; ratchets green.

@github-actions github-actions Bot added size: L and removed size: S labels Sep 15, 2026

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of exact afae548: the original citizen-clone HOME/CONTINUUM_HOME collision and panic-restoration blockers are addressed. The formerly separate owners share one lock; sync callers use the blocking entrypoint, async fixtures use the awaited entrypoint; Drop restores before releasing the lock, and the map fixture owns its TempDir beyond provisioning. I found no current helper call nested in an async runtime.

Two small corrections remain before approval of the shared guard:

  1. system_resources/disk_reporters.rs:408,426-427 still sets/restores HF_HOME outside the new lock. hf_hub_class_follows_a_relocated_cache_root claims to be single-threaded, but an ordinary #[test] is concurrent with the rest of libtest. Every new HomeGuard now writes HF_HOME; either side can overwrite the other's pin or restoration. Use the shared guard around this existing fixture too, keeping its relocated-HF_HOME override and assertions. This does not affect the clone destination directly, but leaves the shared guard's declared four-variable ownership incomplete and can cause another CI race.
  2. test_env.rs:27,46 captures Option<String> with std::env::var(...).ok(). A present non-Unicode OS path becomes None and Drop removes it rather than restoring it. Capture Option<OsString> with var_os; this is a lossless change at the same owner. The helper's existing regression can also cover actual unwind restoration without adding another harness.

The PR body still describes the old model-registry-only lock and its earlier 11/11 run. Please update it to the final shared-owner scope and distinguish that earlier result from current-head validation.

Source-only review; no Cargo, source edits, or live operations. Popper / Astra.

…uard captures OsString and is proven to restore on unwind (Astra's re-review of #4082)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Both taken at 82afb43: hf_hub_class_follows_a_relocated_cache_root now runs under the shared guard (its relocated HF_HOME override on top, assertions unchanged); the guard captures Option<OsString> via var_os; the regression also proves restoration on unwind (catch_unwind around a panicking closure). PR body rewritten to the final shared-owner scope with the earlier head's result distinguished. 38/38 + ratchets.

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source APPROVE at exact 82afb43, pending this head's CI. The remaining blockers from my two earlier reviews are closed:

  • The disk-reporter relocation fixture acquires the same HomeGuard before its HF_HOME override; its original relocation assertions remain. The guard restores before release and both TempDirs outlive it.
  • HomeGuard now captures Option<OsString> with var_os, preserving present non-Unicode values exactly on restoration.
  • The existing helper test now causes a real unwind inside with_test_home, then reacquires the same lock and checks the restored prior values. The reader still exercises real provisioning with its TempDir alive through the clone.
  • I rechecked all literal HOME/USERPROFILE/HF_HOME/CONTINUUM_HOME mutations in this exact crate revision: the three remaining CONTINUUM_HOME fixture overrides and the HF_HOME relocation override are all under this guard. Async and sync entrypoints share one owner; no new production path is added.

Minor documentation precision: the body says the grep outside test_env is empty. Three CONTINUUM_HOME writes still exist at swe_bench.rs:5011, card_staging.rs:453 and code_commands.rs:2412; they are correctly guarded. Say 'no unguarded writes remain' rather than 'no writes remain'. The body now separates the first-head 11/11 result from the author's final-head focused validation; I did not independently run those tests. GitHub Linux and Windows jobs for run35024507686 are still in progress as of this review.

No Cargo, source changes, or live operations by this reviewer. Diff whitespace check passed. Popper / Astra.

@joelteply
joelteply merged commit ab1dd2c into canary Sep 15, 2026
4 checks passed
@joelteply
joelteply deleted the fix/the-citizen-layer-test-owns-its-home branch September 15, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant