Skip to content

audio_noise draws rand() seeded by srand(time(NULL)) and is not taped, so EIGS_REPLAY re-draws different samples #1803

Closed

Description

@InauguralPhysicist

Found by the #1758 R1.1 round-2 blind critic (PR #1776), 2026-10-15. Pre-existing on main: measured on 0740af0; the code is unchanged on e48c4a0.

audio_noise draws its samples from libc rand() (src/ext_gfx.c:2084), which main seeds with srand(time(NULL)) (src/main.c:279 and 340). The builtin has no TRACE_NONDET_* wrapper, so the tape records nothing for it, and EIGS_REPLAY re-draws live samples from a clock seed. This breaks docs/PRINCIPLES.md 3 ("every source of nondeterminism is either recorded on the tape or visible in the source; no capability bypasses the tape"). seed_random cannot pin it either, because it seeds the drand48 stream, not rand(). #960 moved random_normal off rand() for exactly this reason.

Reproduce

printf 'n is audio_noise of [0.0002, 0.5]\nprint of n\n' > noise.eigs
EIGS_TRACE=t.tape eigenscript noise.eigs            # [0.15880738508832049, 0.07401254799869494, ...
sleep 1; EIGS_REPLAY=t.tape eigenscript noise.eigs  # [0.3682035710048879, -0.10699624503357164, ...
sleep 1; EIGS_REPLAY=t.tape eigenscript noise.eigs  # [-0.2702109747427567, -0.1919600016865693, ...
grep -c audio_noise t.tape                          # 0

The replay exits 0 and prints different values. The divergence is silent: nothing reports it.

Done when

  • audio_noise draws from the shared stream that seed_random pins (as eigen_generate: sampled tokens bypass the trace tape (untraced nondeterminism) #960 did for random_normal), and its result is recorded on the tape, so EIGS_REPLAY reproduces the recording byte for byte.
  • A test records the program above, then replays it twice across a one-second boundary, and requires all three outputs to be byte-identical. It fails on the current code.
  • grep -n '\brand()' src/*.c lists no hosted-build caller (src/freestanding excepted).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:gfxSubsystem: gfxarea:trace-tapeSubsystem: trace-tapefound-by:criticInstrument that surfaced it: critickind:silent-wrongWrong answer with rc 0 -- the worst class; outranks every other kind

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions