JuliusBrussee/caveman · error

write report: %w

Error message

write report: %w

What it means

The engine CLI could not write the JSON compress report line to stderr. Like a stdout failure this is a pipe/filesystem condition: stderr is closed, the pipe consumer exited, or the redirect target rejects writes. The payload has already been written to stdout, so only telemetry is lost.

Source

Thrown at engine/cmd/caveman-engine/main.go:141

	if compressErr != nil {
		if !bytes.Equal(res.Output, input) || !res.PassedThrough() || res.TokensAfter != res.TokensBefore {
			return fmt.Errorf("unsafe recovery failure result: %w", compressErr)
		}
		code = "cave_ccr_unavailable"
		if errors.Is(compressErr, ccr.ErrBudgetExceeded) {
			code = "cave_ccr_budget_exceeded"
		}
	}
	if _, err := stdout.Write(res.Output); err != nil {
		return fmt.Errorf("write stdout: %w", err)
	}
	// Report stays on stderr so stdout remains clean payload bytes.
	report, err := json.Marshal(compressReport{Result: res, Error: code})
	if err != nil {
		return fmt.Errorf("encode report: %w", err)
	}
	if _, err := fmt.Fprintln(stderr, string(report)); err != nil {
		return fmt.Errorf("write report: %w", err)
	}
	return nil
}

func runDetect() {
	input, err := readBoundedInput(os.Stdin, maxStdinBytes)
	if err != nil {
		fatal("read stdin: %v", err)
	}
	// Detection needs no store.
	eng := engine.New(nil, nil)
	fmt.Println(eng.Detect(input))
}

func runRetrieve(args []string) {
	if len(args) < 1 {
		fatal("usage: caveman-engine retrieve <handle> [query]")
	}

View on GitHub (pinned to 27d5a3981a)

Solutions

  1. Check where stderr points and that it is writable and has space.
  2. Avoid closing stderr; redirect it to a file with headroom or to /dev/null deliberately.
  3. If you depend on the report, capture stderr to a file rather than a pipe with an early-exiting reader.
  4. Remember stdout already got the payload — a retry is safe and idempotent for pass-through inputs.

Example fix

# before: stderr closed
caveman-engine compress < in 2>&-

# after: capture the report
caveman-engine compress < in 2>report.json
Defensive patterns

Strategy: validation

Validate before calling

// Ensure stderr is writable before the run
if _, err := os.Stderr.Write(nil); err != nil {
    return fmt.Errorf("stderr unavailable: %w", err)
}

Prevention

When it happens

Trigger: Running with stderr redirected to a full or read-only file, or 2>n where the reader exits early; stderr explicitly closed (e.g. 2>&-).

Common situations: CI systems that discard or cap stderr; scripts redirecting stderr to a small tmpfs; daemonized invocation with all descriptors closed.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@27d5a3981a (2026-08-15). Data as JSON: /api/errors/fac8d52fc3e2a56e. Report an issue: GitHub.