Skip to content

feat(erlang): inspect BEAM IFF chunks and tables - #4833

Merged
morluto merged 2 commits into
morluto:mainfrom
mvanhorn:fix/erlang-beam
Oct 22, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
mvanhorn:fix/erlang-beam

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add inspect_erlang_beam / inspect-erlang-beam for one explicit local
FOR1/BEAM IFF file. The workflow returns chunk names and payload SHA-256,
Atom/AtU8 names, export/import/lambda tables with resolved atom names when
present, and the Code chunk instruction-set header.

It does not execute bytecode or require an Erlang installation. Missing optional
tables stay null. Malformed FOR1/BEAM headers, truncated chunks, and exhausted
budgets fail without partial success. LitT inflation and Attr/CInf external-term
decoding remain out of scope.

Usage

rea inspect-erlang-beam /absolute/path/to/app.beam --json

MCP: inspect_erlang_beam with an absolute path.

Tests

  • npm run check:fast
  • npm run test:local -- domain, parser, and service tests (8 passed)
  • npm run test:focused -- CLI, MCP, and filesystem tests (7 passed)

Demo

demo

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-17T16:22:21.268839Z 1ca0b5e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the latest change addresses the previous input-policy finding.

Summary

Adds inspect_erlang_beam and inspect-erlang-beam for offline BEAM chunk and table inspection.

  • A local BEAM file produces a bounded report of its chunks and tables.
  • The BEAM inspection report is available through the CLI and MCP.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI or MCP] --> B[BeamService checks input]
  B --> C[BeamProvider reads a stable file]
  C --> D[BeamParser checks bounds and budgets]
  D --> E[Chunks and decoded tables]
  E --> F[BeamService returns Evidence]
Loading

Reviews (7) · Last reviewed commit: "fix(erlang): use publicInputStrictObject..." · Reviewed by Greptile

Comment thread src/erlang/BeamParser.ts Resolved
Comment thread src/erlang/BeamParser.ts Resolved
Comment thread src/erlang/BeamParser.ts Resolved
Comment thread src/erlang/BeamParser.test.ts Resolved
Comment thread website/locales/languages.json Resolved

@CassieFox23 CassieFox23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TL;DR: I checked the 4 open Greptile threads against c9d1532. Three bugs reproduce. Table rows have no cap. A truncated chunk header passes. And bad UTF-8 in atom names turns into a replacement character. The fourth thread is right too: the tests have no real compiled BEAM file. A hand-built OTP 28 atom table also fails to parse.

I only ran small files I made myself and the 8 test files this PR touches. The 8 test files all pass on Node 24.

Findings and verdicts

Head c9d1532. "Reproduces" means a file I built byte by byte shows the bug through the same service the CLI and MCP tool use.

# Thread Sev Verdict What I saw
1 Tables can exhaust memory P1 Reproduces A 66,000,024-byte file with 5,500,000 ExpT rows is under the 64 MiB limit. It parsed with no error, took about 15 seconds and about 2.1 GB of memory. With a 512 MB heap, Node crashed with out of memory. 5,000 atoms get a clean limit error. Rows get none
2 Truncated headers pass P2 Reproduces The 16-byte file FOR1, size 8, BEAM, four zero bytes returns chunks: [] with complete coverage. The CLI (inspect-erlang-beam) exits 0 on it
3 Invalid atom bytes change silently P2 Reproduces Atom bytes ff give the name U+FFFD and the same module. A fatal UTF-8 decoder throws on the same byte
4 Tests lack real BEAM files P2 Accurate No .beam file is in the tree. The tests only use the hand-built fixture. See the OTP 28 note below

OTP 28 note for row 4. In beam_asm.erl on OTP master, build_atom_table has the comment "Build an atom table for Erlang/OTP 28 and later". It writes the AtU8 count as a negative number, and each atom length with encode(?tag_u, Len). The tag u is number 0 in beam_makeops, so for a short atom the length byte is the length shifted left by 4. This parser reads a plain positive count and a plain one-byte length. I built one atom a in the OTP 28 layout by hand (FFFFFFFF 10 61). The parser rejects it with "BEAM atom table exceeds the 4096-atom budget". The CLI exits 1 with that message and tells the user to raise max_atoms, which would not help. The older layout matches the parser. I could not build a real file, since there is no erlc on my box. So please treat this as a lead. A compiler-built fixture would settle it.

For row 1, I only timed the service. I did not run the CLI or MCP path end to end. The default heap on my box coped with 66 MB. A smaller heap or a larger max_file_bytes would not.

Test results, 8 test files this PR touches:

Node Result
24.18.0 27 tests passed in 8 files

Not run

  • A compiler-built BEAM file. There is no erlc on my box.
  • The CLI and MCP path end to end on the 66 MB file, and files over 64 MiB.
  • Node 22 and Node 26.
  • I skipped the resolved Malayalam thread. I did not retest scripts/website.py check.
  • The full suite, typecheck and lint. Only named test files ran.
  • Main at d6ca7b3. I tested the head only.

Thanks, mvanhorn, for the work on this.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 24.18.0
  • Head / base: c9d1532 / 23f984b (main was d6ca7b3)
  • Other: the box was shared with other test jobs, so the timing is rough. Memory runs used a 4 GB cgroup cap.
Commands
npm ci --ignore-scripts; npm run build:cached; npm run test:prepare   (Node 24, tree at c9d15327c)
npm run test:focused -- <my probe file>   (7 cases, files built by a script)
systemd-run --user --scope -p MemoryMax=4G -- /usr/bin/time -v npm run test:focused -- <my rows probe>
the same with NODE_OPTIONS=--max-old-space-size=512
npm run test:focused -- <the 8 touched test files>
node scripts/rea.mjs inspect-erlang-beam <file> --json   (CLI check of rows 2 and 4)

The 8 files: src/application/erlang/BeamService.test.ts, src/domain/erlang/beam.test.ts, src/erlang/BeamParser.test.ts, src/contracts/toolEffects.test.ts, tests/acceptance/erlangBeamCli.test.ts, tests/acceptance/tools/localToolContracts.test.ts, tests/boundary/filesystem/erlangBeam.test.ts, tests/boundary/mcp/erlangBeamMcp.test.ts.

None of them mentions doctor. I checked with grep first.

Fixture bytes (hex of the OTP 28 file, 28 bytes): 464f5231 00000014 4245414d 41745538 00000006 ffffffff 1061 0000.

The other fixtures: row 1 is FOR1, form size, BEAM, one ExpT chunk with count 5,500,000 and 12 zero bytes per row. Row 2 is 16 bytes: FOR1, size 8, BEAM, four zero bytes. Row 3 is one AtU8 chunk with payload 00 00 00 01 01 ff.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks. dd22424 caps export, import and lambda rows at 65536 combined before any row is allocated, rejects a form remainder shorter than a chunk header, and rejects AtU8 names that are not valid UTF-8. On the OTP 28 lead: the parser now reads the compact AtU8 layout (negated count, u-tag name lengths). There is also a compiler-produced OTP 29 BEAM fixture whose expected atoms, table rows and Code header come from beam_lib on the same file. I also merged current main; format, lint, typecheck, build and the focused BEAM tests pass locally.

Comment thread src/domain/erlang/beam.ts Resolved
@cursor
cursor Bot force-pushed the fix/erlang-beam branch from 4113431 to 94f95a6 Compare October 21, 2026 23:39
@cursor

cursor Bot commented Oct 21, 2026

Copy link
Copy Markdown

Restacked onto current main and kept the BEAM IFF workflow. Tip: bf9c4c8f3856f117a1d6ea0f0c1c3ec148bc7fa3.

inspect_erlang_beam now uses absoluteLocalPathStringSchema for its public input, and the CLI path uses localPathStringSchema before resolution. This repo does not have publicInputStrictObject; that is the shared local-path policy.

npm run typecheck passed. Focused BEAM domain, parser, service, filesystem, CLI, and MCP tests passed.

This token cannot update .github/workflows/ci.yml (no workflows permission), so GitHub still reports the PR conflicting. The branch content matches a merge with current main except that workflow file. Not merged.

Comment thread src/gpu/GpuElfKernels.ts Resolved
Comment thread src/artifacts/apple/PlistScalars.ts Resolved
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown

Restack is ready, but this token cannot update mvanhorn:fix/erlang-beam.

Force-with-lease from bf9c4c8f3856f117a1d6ea0f0c1c3ec148bc7fa3 was rejected:

refusing to allow a GitHub App to create or update workflow .github/workflows/ci.yml without workflows permission

The only workflow file that differs from the fork tip is .github/workflows/ci.yml, and its blob is 21f317fdeafc87538f2fad1f67b1dd21a297d639 (current main). That blob is not the ci.yml of any branch on mvanhorn/rea, so the identical-file exemption does not apply. No second pull request was opened.

Ready tip: 8eb1be90c44eef7fe2e10580373e33888a098aef

Fetch it from morluto/rea branch cursor/erlang-beam-restack-4476. origin/main (c537c52c96b7f24ea2d2c1b5ae8055fbf6d99ffa) is an ancestor. The diff against main is 57 files, the BEAM inspection work plus publicInputStrictObject.

A credential that may update workflow files on the fork can move the existing PR with:

git fetch https://github.com/morluto/rea.git cursor/erlang-beam-restack-4476
git push --force-with-lease=refs/heads/fix/erlang-beam:bf9c4c8f3856f117a1d6ea0f0c1c3ec148bc7fa3 \
  https://github.com/mvanhorn/rea.git \
  FETCH_HEAD:refs/heads/fix/erlang-beam

On that tip, inspectErlangBeamInputSchema is built with publicInputStrictObject. src/gpu/GpuElfKernels.ts and src/artifacts/apple/PlistScalars.ts match main and are not in the diff. The fork tip is still bf9c4c8f3856f117a1d6ea0f0c1c3ec148bc7fa3.

Replay the Erlang BEAM inspection workflow, including table bounds,
OTP 28+ atom layouts, the shared absolute-path policy, and empty-path
CLI coverage, without carrying GitHub workflow edits.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@cursor
cursor Bot force-pushed the fix/erlang-beam branch from bf9c4c8 to 3714cdd Compare October 22, 2026 09:28
inspect_erlang_beam advertised a public input built with bare
z.strictObject, so later shared input-policy changes would miss it.
Result and internal objects stay on their own constructors.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@morluto
morluto merged commit bfba998 into morluto:main Oct 22, 2026
40 of 42 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added enhancement New feature or request provider: erlang Analysis provider / engine: erlang labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request provider: erlang Analysis provider / engine: erlang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants