You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression: with get [email protected] fails (Conan package-revision query miscompiled) after generational-ownership Stage 2 #617
After the generational-ownership Stage 2 codegen changes (reset-on-move + guarded drop + zero-const struct memset + removal of cancel-on-move), with get [email protected] fails with:
resolving zlib/1.3.1...
revision: cac0f6daea04
binary: ca639360bb68
error: failed to get package revision for zlib/1.3.1
error: no prebuilt binary for your platform, source build not supported for zlib/1.3.1
This is a regression, verified — the installed compiler (none of these changes) fetches the same package fine:
Surfaced by the cli-selfhost-project-tests case get-zlib-1-3-1 (build/selfhost.w:2026). Everything else is green: full behavior suite (737), compile-error (641), codegen, spec, phase, internals, lexer, parser, the debug-alloc soundness suite, and fixpoint.
Repro (fast, no full build)
mkdir /tmp/ztest && cd /tmp/ztest
printf 'name = "ztest"\nversion = "0.1.0"\n' > with.toml
with get [email protected] # fails under the Stage-2 compiler, succeeds on the installed one
Diagnosis (where it's narrowed to)
src/compiler/ConanClient.w, conan_install_binary:
line 928 prints binary: <package_id> — so conan_find_matching_package succeeded (package_id valid).
line 929 let package_rev = conan_get_latest_package_rev(name, version, recipe_rev, pick.package_id) returns empty under the Stage-2 compiler.
line 930-931 → failed to get package revision → the no prebuilt binary fallthrough.
So conan_get_latest_package_rev either is miscompiled internally or one of its string args (recipe_rev/package_id) is corrupted between resolve and download. The resolve step printed both a valid revision and binary, so the value is corrupted after that point — consistent with a generational-ownership codegen interaction (most likely reset-on-move zeroing a value the rev-query path still reads, the zero-const→memset Assign early-return skipping post-store work, or the cancel-removal changing drop scheduling). The package-fetch path isn't exercised by the behavior/debug-alloc suites, which is why only this case caught it.
Spec reference
§2.5 Generational Ownership (the Stage-2 model under implementation). This is implementation work tracking a regression introduced by it, not a spec defect.
⚠️ Blocks seed update
The committed compiler carries this regression. Do not run with build :update-seed / :install until this is fixed — only the local build artifacts and a normal with build are unaffected (the bug is confined to with get's Conan package-revision query).
Confirmed a real, non-deterministic regression (not a network flake), via direct comparison:
My (Stage-2) compiler: with get [email protected] failed 1 of 5 isolated runs.
Installed compiler (no Stage-2 changes): 0 of 5 failures.
The failure point varies between runs — failed to get package revision and failed to download conaninfo.txt — both reduce to conan_http_get returning "" (curl rc != 0 or empty body).
So it is a heap-dependent memory corruption introduced by the generational-ownership Stage-2 codegen (reset-on-move / zero-const memset / cancel-removal), confined to the Conan HTTP-download path. Not a double-free: the debug allocator caught nothing, and both debug prints and --debug-allocmask it (layout-sensitive), which is why it only surfaced under the network-heavy :test run.
Prime suspect: conan_curl_to_file builds its argv via 11 chained argv = argv ++ arg ++ "\\0" reassignments (ConanClient.w:46-58) — a reassign-after-move pattern on a heap str, exactly what no-cancel + reset-on-move touch. Next: minimal repro of repeated str-reassign under the Stage-2 compiler, or trace the argv/exec path; bisecting needs many runs per step due to the ~20% hit rate.
Investigation update — bisect is confounded, root cause NOT yet pinned
Correcting an earlier premature claim ('memset confirmed'). Deeper testing shows the bug's runtime manifestation is exquisitely sensitive to the exact stage2 binary layout, which confounds the standard toolchain:
Committed binary (965a7e8): get-zlib fails ~20% (reproduced across 2 builds).
Disable the memset (semantic change) → 0/20.
A proven no-op edit (added a memset size-clamp that an in-process compile shows never fires — MSOVERRUN_COUNT=0) → also 0/20.
A no-op edit cannot change byte-identical deterministic codegen (fixpoint holds), yet it flips 20%→0%. The only consistent explanation: the overrun/corruption is emitted into byte-identical Conan-callee code, but its runtime effect (which live value it lands on) depends on stage2's overall memory layout — and any change to the compiler binary (semantic or no-op) shifts that layout and masks the symptom.
Consequence — the usual tools are all defeated:
Bisection by edit+rebuild: every rebuild masks it.
Instrumentation: debug prints, --debug-alloc, and WITH_DEBUG_ALLOC_SCRIBBLE all mask it (the latter two also change the allocator layout).
lldb: source-line breakpoints don't resolve (-O1 inlines the small Conan fns); function bps + ~20% non-determinism make a live catch impractical.
So this is a real heap corruption from the generational Stage-2 changes, but it is not pinned to a line, and the memset is not confirmed as the cause (the no-op edit masks it identically).
Right next tool: a layout-INDEPENDENT memory-access catcher — guard pages / ASan that traps the bad access itself regardless of whether it hits a live value. The With compiler doesn't currently emit ASan-instrumented code, so this needs build-system work, or sustained debugging of a single manifesting binary without modifying it.
Still blocks :update-seed. The committed Stage 2/3 work otherwise passes the full suite + fixpoint.
The decisive control — a clean HEAD~1 worktree at 1ee372c9 ('Loops: sound conditional Drop moves #613'), which has the M7 drop-flag work but none of the Stage-2 generational changes (no reset-on-move, no zero-const memset, no guarded drop, no cancel-removal):
The pre-Stage-2 build fails the same way (1/30). So the failure manifests without any of the ownership changes — Stage 2 did not introduce it. Per the clean-worktree criterion, this is pre-existing, not my regression.
Correction
My earlier 'memset overrun / Stage-2 regression' analysis was wrong. It was confounded by (a) thin samples and (b) the failure's manifestation being build-layout-sensitive — any rebuild or instrumentation shifts the rate (0%↔~20%), which made bisection-by-rebuild look like the memset mattered when a proven-no-op edit masked it identically.
Reclassified
Low-rate, build-layout-sensitive flaky failure of the 1.3.1 package-revision fetch (conan_get_latest_package_rev → conan_http_get → curl returns empty). Likely a transient registry/network blip and/or a rare latent heap issue in the package-fetch path that predates Stage 2. It does not block the Stage 2/3 increment (green on build, debug-alloc, fixpoint, and the full behavior/native/spec/phase/parser suites). Removing the 'blocks seed update' flag — that was based on the incorrect regression premise.
Leaving open as a low-priority pre-existing flaky-fetch issue to revisit if it recurs in CI.
Deep-dive update (2026-07): three allocator hypotheses refuted; "#617" is likely 2+ distinct bugs
Method: env-gated allocator toggles compared on the same binary (poison-on vs off, gate-on vs off, no-reuse-on vs off) so the layout-luck confounder (any rebuild flips manifestation 0%↔20%) is removed — the two arms share one build/layout. Repro used: a standalone parallel(workspaces) build (network-free, faster + higher rate than get-zlib, which was 0% on the builds tested).
Refuted (each a clean same-binary experiment)
Hypothesis
Toggle
Result
Recycle-path under-zeroing (rt_core.w freelist-pop memsets size, not cls_size)
WITH_ALLOC_POISON (fill tail [size,cls_size) with 0xAA)
no effect — also: a string's NUL sits in the already-zeroed [0,size), and large allocs are kernel-zeroed, so the dirty tail is unread
String move-first opt frees/mutates an aliased buffer (with_str_concat_n_move_first via rt_payload_start_is_owned)
WITH_ALLOC_NO_REUSE (freed small blocks dropped + header-poisoned; double-free would then trap)
3/40 == 3/40, zero effect
So the invalid free is not a heap-allocator bug (not the zeroing, not the string opt, not reuse). It points to uninitialized stack/struct memory, the parallel-orchestration code, or a codegen miscompile — allocator tooling is exhausted for it.
cannot read member: out/tmp/with_runtime/<X>.o (~47%, network-free) — memory-independent (unchanged by all three toggles) and parallel-only. This is a file/resource race on the shared out/tmp/with_runtime/ between parallel workspace subprocesses (concurrent archive write/read), not memory corruption. It is the most likely actual cause of the build-w-workspace-parallel-* failures that block clean :test/bootstrap. Should be split into its own issue.
invalid free: pointer is not an allocated payload start (~7.5%) — the genuine memory-corruption face; non-heap (see refutations). Next step to localize: lldb on a manifesting run (it's in a subprocess) to read the freed pointer's value + backtrace.
get-zlib single-process corruption — the originally-reported symptom; 0% on the builds tested here (layout-luck), so not reproducible on demand right now.
Reusable tooling produced
WITH_ALLOC_NO_REUSE — a never-reuse debug-allocator mode (freed small blocks dropped, header poisoned so double-frees trap deterministically; large allocs already munmap). Complements the existing WITH_DEBUG_ALLOC_SCRIBBLE. Useful for future memory hunts to discriminate reuse-dependent corruption. (Currently on a local branch, off by default.)
Recommended next steps
Split the parallel cannot read member file race into its own issue and fix it (likely the real bootstrap blocker; higher rate; probably tractable — isolate per-workspace out/tmp/with_runtime/ or serialize archive access).
For the invalid free: lldb-catch a manifesting subprocess run, inspect the freed pointer (stack-garbage pattern? corrupted struct field?), backtrace to origin.
The ~15-20% framing and the "generational-ownership Stage 2 regression" title are stale — verified pre-existing (1ee372c9) and layout-dependent (0%↔~13% across builds).
Root-caused and fixed: three thread-race bugs behind the intermittent corruption
The pivotal fact all prior investigation missed: comptime parallel(workspaces) runs full in-process Compilations on threads (with_thread_spawn, src/ComptimeEval.w:6794 → comptime_workspace_thread_entry → frontend + codegen + link per thread) — not subprocesses. Every symptom is a thread race, which is why all single-threaded theories (layout luck, allocator poison/no-reuse toggles) came back null. The bugs were then caught live in lldb (breakpoint set -n with_panic_core in a loop over an 8-workspace parallel() repro, bt all at the trap — it fires ~1 in 10-14 runs; it does not "defeat instrumentation" once you know it's threads).
Bug 1 — invalid free: pointer is not an allocated payload start
Double free of the global memo mir_local_key_cache: Vec[str] (src/Mir.w:1490, added in 965a7e89 for the #614 perf work — so this face was a generational-ownership-era regression, as this issue's title originally claimed). Two workspace threads race the unguarded push → simultaneous vec_grow → both free the old buffer → the second rt_free reads a freelist-link header, fails the size-class check, and panics. Caught 3/3 times with identical stacks:
Note: the earlier WITH_ALLOC_NO_REUSE A/B result (3/40 == 3/40) did not exonerate double-frees — this trap fires identically in both modes (freelist-link header vs -1 sentinel both fail the check). That experiment was misread.
Fix: spinlock (Atomic[i32], same idiom as cstr_slot_lock/frontend_cimport_lock_word) bracketing the cache's grow-and-read.
rt_alloc_with_origin ran its fresh-payload sanity check afterrt_allocator_unlock() (rt/rt_core.w). The ownership range tables mutate under the lock (rt_record_slab_range shift-insert, rt_forget_large_range swap-remove), so the unlocked check read a torn table and panicked on a perfectly valid allocation. Caught live: panicking thread inside the check; a second thread holding the lock mid-munmap in rt_free_unlocked.
Fix: compute the verdict before unlocking (only the panic itself is deferred past unlock so the panic path can't deadlock).
Not memory at all: a file race. link_stage_extract_runtime_obj (src/compiler/Link.w) unconditionally truncate-rewrote the shared extraction path on every link; a concurrent linking thread (or separate process) read it empty (Archive.wdata.len() == 0) or mid-write. This was the face that actually failed :test/bootstraps in the build-w-workspace-parallel-* lanes. Pre-existing (predates the generational-ownership work).
Fix: reuse a complete matching extraction, else write a unique temp file and rename() it into place — atomic on all platforms (POSIX rename; Windows backend already uses MoveFileExW + MOVEFILE_REPLACE_EXISTING), so readers only ever observe a complete file. Also guarded the shared link_stage_temp_archives registry (same unguarded-global-push class) with a spinlock.
Verification
8-workspace parallel() stress repro: 0/30 runs with any symptom (previously ~50% combined).
Original 2-workspace repro: 0/15 (previously ~7-8/15 cannot read member, plus intermittent invalid free). At the old ~47% rate, 15 clean runs by luck is p ≈ 7×10⁻⁵.
The originally-reported with get [email protected] face is NOT explained by these fixes: with get spawns no threads, and that symptom has not reproduced in 40+ attempts across two investigations. It may have been a distinct (possibly since-fixed) bug. Suggest keeping this issue open (or splitting a fresh issue) for the zlib symptom specifically until it recurs or a soak passes.
Latent same-class issues found in the audit, not yet fixed (lower priority, filed here for the record): setenv from linking threads (link_stage_apply_env — libc UB), unlocked rt_payload_start_is_owned reads in with_str_concat_n_move_first/str_owned_capacity_from_ptr (failure mode analyzed as leak-shaped, matches the earlier null gate experiment), ClangBridge's unlocked globals (c_import path only), BuildGraphCache fingerprint globals.
Activity
ehartford commentedon Jun 29, 2026
Confirmed a real, non-deterministic regression (not a network flake), via direct comparison:
with get [email protected]failed 1 of 5 isolated runs.failed to get package revisionandfailed to download conaninfo.txt— both reduce toconan_http_getreturning""(curl rc != 0 or empty body).So it is a heap-dependent memory corruption introduced by the generational-ownership Stage-2 codegen (reset-on-move / zero-const memset / cancel-removal), confined to the Conan HTTP-download path. Not a double-free: the debug allocator caught nothing, and both debug prints and
--debug-allocmask it (layout-sensitive), which is why it only surfaced under the network-heavy:testrun.Prime suspect:
conan_curl_to_filebuilds its argv via 11 chainedargv = argv ++ arg ++ "\\0"reassignments (ConanClient.w:46-58) — a reassign-after-move pattern on a heap str, exactly what no-cancel + reset-on-move touch. Next: minimal repro of repeated str-reassign under the Stage-2 compiler, or trace the argv/exec path; bisecting needs many runs per step due to the ~20% hit rate.Still blocks
:update-seed.ehartford commentedon Jun 29, 2026
Investigation update — bisect is confounded, root cause NOT yet pinned
Correcting an earlier premature claim ('memset confirmed'). Deeper testing shows the bug's runtime manifestation is exquisitely sensitive to the exact stage2 binary layout, which confounds the standard toolchain:
MSOVERRUN_COUNT=0) → also 0/20.A no-op edit cannot change byte-identical deterministic codegen (fixpoint holds), yet it flips 20%→0%. The only consistent explanation: the overrun/corruption is emitted into byte-identical Conan-callee code, but its runtime effect (which live value it lands on) depends on stage2's overall memory layout — and any change to the compiler binary (semantic or no-op) shifts that layout and masks the symptom.
Consequence — the usual tools are all defeated:
--debug-alloc, andWITH_DEBUG_ALLOC_SCRIBBLEall mask it (the latter two also change the allocator layout).-O1inlines the small Conan fns); function bps + ~20% non-determinism make a live catch impractical.So this is a real heap corruption from the generational Stage-2 changes, but it is not pinned to a line, and the memset is not confirmed as the cause (the no-op edit masks it identically).
Right next tool: a layout-INDEPENDENT memory-access catcher — guard pages / ASan that traps the bad access itself regardless of whether it hits a live value. The With compiler doesn't currently emit ASan-instrumented code, so this needs build-system work, or sustained debugging of a single manifesting binary without modifying it.
Still blocks
:update-seed. The committed Stage 2/3 work otherwise passes the full suite + fixpoint.ehartford commentedon Jun 29, 2026
Verdict: PRE-EXISTING, not a Stage-2 regression
The decisive control — a clean
HEAD~1worktree at1ee372c9('Loops: sound conditional Drop moves #613'), which has the M7 drop-flag work but none of the Stage-2 generational changes (no reset-on-move, no zero-const memset, no guarded drop, no cancel-removal):1ee372c9(pre-Stage-2)965a7e89The pre-Stage-2 build fails the same way (1/30). So the failure manifests without any of the ownership changes — Stage 2 did not introduce it. Per the clean-worktree criterion, this is pre-existing, not my regression.
Correction
My earlier 'memset overrun / Stage-2 regression' analysis was wrong. It was confounded by (a) thin samples and (b) the failure's manifestation being build-layout-sensitive — any rebuild or instrumentation shifts the rate (0%↔~20%), which made bisection-by-rebuild look like the memset mattered when a proven-no-op edit masked it identically.
Reclassified
Low-rate, build-layout-sensitive flaky failure of the 1.3.1 package-revision fetch (
conan_get_latest_package_rev→conan_http_get→ curl returns empty). Likely a transient registry/network blip and/or a rare latent heap issue in the package-fetch path that predates Stage 2. It does not block the Stage 2/3 increment (green on build, debug-alloc, fixpoint, and the full behavior/native/spec/phase/parser suites). Removing the 'blocks seed update' flag — that was based on the incorrect regression premise.Leaving open as a low-priority pre-existing flaky-fetch issue to revisit if it recurs in CI.
Generational ownership Stage 2/3: reset-on-move + guarded drop
ehartford commentedon Jul 1, 2026
Deep-dive update (2026-07): three allocator hypotheses refuted; "#617" is likely 2+ distinct bugs
Method: env-gated allocator toggles compared on the same binary (poison-on vs off, gate-on vs off, no-reuse-on vs off) so the layout-luck confounder (any rebuild flips manifestation 0%↔20%) is removed — the two arms share one build/layout. Repro used: a standalone
parallel(workspaces)build (network-free, faster + higher rate than get-zlib, which was 0% on the builds tested).Refuted (each a clean same-binary experiment)
rt_core.wfreelist-pop memsetssize, notcls_size)WITH_ALLOC_POISON(fill tail[size,cls_size)with 0xAA)[0,size), and large allocs are kernel-zeroed, so the dirty tail is unreadwith_str_concat_n_move_firstviart_payload_start_is_owned)WITH_NO_STR_MOVE_FIRST(force safe fresh-alloc path)WITH_ALLOC_NO_REUSE(freed small blocks dropped + header-poisoned; double-free would then trap)So the
invalid freeis not a heap-allocator bug (not the zeroing, not the string opt, not reuse). It points to uninitialized stack/struct memory, the parallel-orchestration code, or a codegen miscompile — allocator tooling is exhausted for it."#617" is really 2+ conflated bugs
cannot read member: out/tmp/with_runtime/<X>.o(~47%, network-free) — memory-independent (unchanged by all three toggles) and parallel-only. This is a file/resource race on the sharedout/tmp/with_runtime/between parallel workspace subprocesses (concurrent archive write/read), not memory corruption. It is the most likely actual cause of thebuild-w-workspace-parallel-*failures that block clean:test/bootstrap. Should be split into its own issue.invalid free: pointer is not an allocated payload start(~7.5%) — the genuine memory-corruption face; non-heap (see refutations). Next step to localize: lldb on a manifesting run (it's in a subprocess) to read the freed pointer's value + backtrace.Reusable tooling produced
WITH_ALLOC_NO_REUSE— a never-reuse debug-allocator mode (freed small blocks dropped, header poisoned so double-frees trap deterministically; large allocs alreadymunmap). Complements the existingWITH_DEBUG_ALLOC_SCRIBBLE. Useful for future memory hunts to discriminate reuse-dependent corruption. (Currently on a local branch, off by default.)Recommended next steps
cannot read memberfile race into its own issue and fix it (likely the real bootstrap blocker; higher rate; probably tractable — isolate per-workspaceout/tmp/with_runtime/or serialize archive access).invalid free: lldb-catch a manifesting subprocess run, inspect the freed pointer (stack-garbage pattern? corrupted struct field?), backtrace to origin.~15-20%framing and the "generational-ownership Stage 2 regression" title are stale — verified pre-existing (1ee372c9) and layout-dependent (0%↔~13% across builds).ehartford commentedon Jul 1, 2026
Root-caused and fixed: three thread-race bugs behind the intermittent corruption
The pivotal fact all prior investigation missed: comptime
parallel(workspaces)runs full in-processCompilations on threads (with_thread_spawn,src/ComptimeEval.w:6794→comptime_workspace_thread_entry→ frontend + codegen + link per thread) — not subprocesses. Every symptom is a thread race, which is why all single-threaded theories (layout luck, allocator poison/no-reuse toggles) came back null. The bugs were then caught live in lldb (breakpoint set -n with_panic_corein a loop over an 8-workspaceparallel()repro,bt allat the trap — it fires ~1 in 10-14 runs; it does not "defeat instrumentation" once you know it's threads).Bug 1 —
invalid free: pointer is not an allocated payload startDouble free of the global memo
mir_local_key_cache: Vec[str](src/Mir.w:1490, added in965a7e89for the #614 perf work — so this face was a generational-ownership-era regression, as this issue's title originally claimed). Two workspace threads race the unguardedpush→ simultaneousvec_grow→ both free the old buffer → the secondrt_freereads a freelist-link header, fails the size-class check, and panics. Caught 3/3 times with identical stacks:Note: the earlier
WITH_ALLOC_NO_REUSEA/B result (3/40 == 3/40) did not exonerate double-frees — this trap fires identically in both modes (freelist-link header vs-1sentinel both fail the check). That experiment was misread.Fix: spinlock (
Atomic[i32], same idiom ascstr_slot_lock/frontend_cimport_lock_word) bracketing the cache's grow-and-read.Bug 2 —
allocator returned invalid payload(spurious panic, healthy heap)rt_alloc_with_originran its fresh-payload sanity check afterrt_allocator_unlock()(rt/rt_core.w). The ownership range tables mutate under the lock (rt_record_slab_rangeshift-insert,rt_forget_large_rangeswap-remove), so the unlocked check read a torn table and panicked on a perfectly valid allocation. Caught live: panicking thread inside the check; a second thread holding the lock mid-munmapinrt_free_unlocked.Fix: compute the verdict before unlocking (only the panic itself is deferred past unlock so the panic path can't deadlock).
Bug 3 —
cannot read member: out/tmp/with_runtime/<X>.o(~47% of parallel runs)Not memory at all: a file race.
link_stage_extract_runtime_obj(src/compiler/Link.w) unconditionally truncate-rewrote the shared extraction path on every link; a concurrent linking thread (or separate process) read it empty (Archive.wdata.len() == 0) or mid-write. This was the face that actually failed:test/bootstraps in thebuild-w-workspace-parallel-*lanes. Pre-existing (predates the generational-ownership work).Fix: reuse a complete matching extraction, else write a unique temp file and
rename()it into place — atomic on all platforms (POSIXrename; Windows backend already usesMoveFileExW+MOVEFILE_REPLACE_EXISTING), so readers only ever observe a complete file. Also guarded the sharedlink_stage_temp_archivesregistry (same unguarded-global-push class) with a spinlock.Verification
parallel()stress repro: 0/30 runs with any symptom (previously ~50% combined).cannot read member, plus intermittentinvalid free). At the old ~47% rate, 15 clean runs by luck is p ≈ 7×10⁻⁵.with build+with build :fixpointbyte-identical for both commits;:debug-alloc-testsand full:testgreen (:testrun withWITH_MEMORY_LIMIT_BYTES=0solely for the known emit-c self-compile OOMs (>32 GiB): single ~12.9 GB allocation duringwith --emit-con the compiler #619 emit-c cap trip).Commits:
e8a01e48(rt sanity check),da6176fb(Mir cache lock, atomic extraction, registry lock,runtime_renamewrapper).Still open / honest caveats
with get [email protected]face is NOT explained by these fixes:with getspawns no threads, and that symptom has not reproduced in 40+ attempts across two investigations. It may have been a distinct (possibly since-fixed) bug. Suggest keeping this issue open (or splitting a fresh issue) for the zlib symptom specifically until it recurs or a soak passes.setenvfrom linking threads (link_stage_apply_env— libc UB), unlockedrt_payload_start_is_ownedreads inwith_str_concat_n_move_first/str_owned_capacity_from_ptr(failure mode analyzed as leak-shaped, matches the earlier null gate experiment), ClangBridge's unlocked globals (c_import path only),BuildGraphCachefingerprint globals.Add WITH_ALLOC_NO_REUSE never-reuse debug-allocator mode (#617 diagno…
rt: check fresh-payload sanity under the allocator lock (#617)
docs: archive drop-move-ownership and a5_handoff to docs/completed/
docs: record 2026-07-01 session state in resume_later.md