ReviewOS

home-lang/home

Parser hangs on syntactically invalid input (`home ast`/`home check` block indefinitely)

#16
Closed glennmichael123 opened this 24 days ago · 1 comment
24 days ago

Context

The parser doesn't gracefully fail on certain malformed inputs — it loops or blocks instead of emitting a diagnostic and exiting. Two independent observations point at the same underlying issue:

1. Diagnostic snapshot harness (issue #9)

While seeding the diagnostic test corpus at `tests/diagnostics/cases/`, this input was found to hang the parser indefinitely:

fn 123 invalid() {}

The case had to be dropped from the corpus, and a 30 s per-case wall-clock timeout was added to the harness so future hangs fail loudly in CI rather than wedging the runner. See `tests/diagnostics/harness.zig` and the `tests/diagnostics/README.md` skipped-categories note.

2. home-os kernel audit (2026-05-01)

Auditing 404 home-os kernel modules with `home ast`, 110 out of 166 parse-failing modules could not be classified by error message because `home ast` hangs after surfacing the first parse error rather than exiting. The audit had to fall back to a 15 s wall-clock timeout per file and bucket those modules as "parse failure, error message unavailable".

This makes the parser-failure bucket essentially un-triagable without additional work — it took ~1 s per OK file and 15 s per failing file, throttling the audit's iteration speed significantly.

Symptoms

  • `home ast <bad-file>` and `home check <bad-file>` block past any reasonable timeout
  • No diagnostic emitted on stderr before the hang
  • Process appears to be doing work (not deadlocked) — likely an infinite loop in the parser's error recovery path

Why this matters

  • Tooling that walks a corpus (snapshot harnesses, audits, IDE features, fuzzers) cannot rely on the compiler terminating
  • The diagnostic snapshot harness can't include genuinely malformed cases without per-case timeouts
  • Future fuzzing work (issue #10) will need every fuzzer-found input wrapped in a timeout, which adds noise to crash classification

Proposal

  • Reproduce both inputs (`fn 123 invalid() {}` and a known-hanging kernel module) — start with the simpler one
  • Bisect the parser path to find the loop. Likely candidates: error-recovery loop with no progress guard, infinite token-reuse, retry-on-failure without advancing the cursor
  • Add a progress-guard invariant: every iteration of the recovery loop must consume at least one token, otherwise bail
  • Once fixed, re-run the home-os audit with `home ast`'s 15 s timeout removed and re-classify the previously-timed-out modules; expect a much sharper picture
  • Once fixed, attempt to add the dropped `fn 123 invalid()` case back to the diagnostic corpus

Reproduction

```bash cd /path/to/home echo 'fn 123 invalid() {}' > /tmp/hang.home ./zig-out/bin/home-debug ast /tmp/hang.home # hangs ```

For the kernel-module case, see `~/Desktop/home-os-kernel-audit-2026-05-01.tsv` rows where `parse_status=FAIL` and `first_error` is empty.

24 days ago

Two more reproductions

The fuzz CI harness (#10) surfaced two additional shapes during smoke testing — both hang the parser:

else keyword as enum variant

enum Color { Red Green else Blue }

Overlong int literal followed by adjacent identifier

match 0xFFFFFFFFFFFFFFFFn { 0 => 0 }

The n is an identifier with no whitespace separator after the overlong hex literal. Suspect interaction between numeric-literal scanning and identifier-merge.

Combined with the original fn 123 invalid() {} repro, the failing inputs all touch token-level error recovery, which lines up with the loop-without-progress-guard hypothesis.

The fuzz harness reproduces all three within seconds when seeded with them — see `tests/fuzz/corpus/parse/10_known_hang.home` and the harness's per-input 2s timeout that captures these cases as `timeout-NNNN.home` artifacts in CI.

Sign in to comment on this issue.