[PR #5566] [CLOSED] fix(native): keep per-input demangle outcomes when swift-demangle skips _ #6966

Closed
opened 2026-11-01 21:44:23 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5566
Author: @kaoru0822-kitauji
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: fix/demangle-swift-omitted-record


📝 Commits (2)

  • 426dd64 fix(native): keep per-input demangle outcomes when swift-demangle skips _
  • b97ed43 Merge origin/main into fix/demangle-swift-omitted-record

📊 Changes

4 files changed (+150 additions, -40 deletions)

View changed files

📝 src/native/NativeMacOSProvider.ts (+8 -8)
📝 src/native/parsers/demangle.test.ts (+39 -8)
📝 src/native/parsers/demangle.ts (+57 -24)
📝 tests/boundary/mcp/nativeDemangleMcp.test.ts (+46 -0)

📄 Description

What broke: demangle_swift failed the whole batch when swift-demangle skipped _ without a record, and (found in review) LLVM expanded any @-prefixed symbol as a response file, so @/dev/null dropped a record and @<path> read that file (#5552).
Fix: the demangle parser owns argument selection: _ and non-Swift @ symbols are reported unchanged with a limitation, and @__swiftmacro_ manglings are forwarded in their equivalent $s spelling, so no forwarded argument starts with @.
Risk: low; only _ and @-prefixed inputs change behavior, verified against real swift-demangle (LLVM 21) on macOS.

Summary

Fixes #5552. demangle_swift reported an input of _ as demangled to an empty name. A batch that mixed _ with valid symbols failed with unreadable_output, so the valid symbols' results were lost too. Every input now gets one outcome, in input order.

Problem and expected behavior

Current swift-demangle skips an argument spelled exactly _ (upstream check if (name == "_") { warning…; continue; }). It exits 0, prints a warning on stderr and writes no output record for it. Older toolchains print _ unchanged. REA assumed one output line per argument. Splitting empty stdout produced one empty line, so ['_'] became {"output":"","status":"demangled"}. With ['_', '$s4main3FooV'] there were fewer records than inputs, so the count check threw and the whole call failed. The contract promises a demangled, unchanged or invalid status for each input.

Change and scope

  • src/native/parsers/demangle.ts now owns which symbols are forwarded (swiftDemangleArguments) as well as how the output is parsed. _ is never passed to the demangler, so each forwarded argument has exactly one output record on every toolchain. _ is reported as {"input":"_","output":"_","status":"unchanged"}, because it is not a Swift mangling. The result also gets a limitation saying the demangler skips it and was not given it.
  • LLVM expands an argument starting with @ as a response file even after -- (verified with swift-demangle from LLVM 21: @/dev/null prints nothing; @<file> demangles the file's contents, and a same-named file in the working directory is read for @__swiftmacro_…). @__swiftmacro_X is the demangler's alternative spelling of $sX and is forwarded that way; when it cannot be decoded, the caller's spelling is reported. Every other @ symbol is reported unchanged with a limitation and is never passed to the demangler.
  • Output is split into LF-terminated records. Empty output holds no record. Output that ends partway through a record, or has a record count that differs from the forwarded arguments, still fails closed. REA never guesses which record belongs to which input.
  • NativeMacOSProvider uses the parser's argument list and passes its limitations through. No contract or schema change. Ordinary fix within existing boundaries; scope decision not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the native demangle parser (src/native/parsers/demangle.ts), which now selects the arguments.

  • Contribution scope fit and linked maintainer decision: ordinary fix; not applicable.

  • CLI and MCP/tool-catalog contract: unchanged schema. _ now reports unchanged and a limitation instead of demangled/"". Mixed batches succeed.

  • Provider, bridge, target-format, or platform compatibility: native macOS provider only. Toolchains that print _ unchanged give the same result, because _ is no longer forwarded.

  • Evidence, artifact, provenance, or reconstruction contract: the provenance command shows exactly the forwarded arguments. The limitation records that _ was not passed.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added or updated: src/native/parsers/demangle.test.ts covers _ alone, _ mixed with valid symbols, and an omitted or unterminated record failing closed. Existing assertions were adapted to the { symbols, limitations } return. tests/boundary/mcp/nativeDemangleMcp.test.ts adds a real swift-demangle MCP workflow for ['_'] and ['_', '$s4main3FooV', '_Sa'].

  • Base reproduction or other evidence: xcrun swift-demangle --compact -- '_' '$s4main3FooV' '_' 'x' '__' '$' '_T' '$s' '_$s' 'a_' printed records for every argument except both _ (two stderr warnings). xcrun swift-demangle --compact -- '_' exited 0 with empty stdout. The base-revision failure is from the issue report and the source. I did not re-run it on base.

  • User-visible CLI output with this change (node scripts/rea.mjs demangle-swift <copy of /usr/bin/true> --format json …, disposable XDG/TMPDIR state):

    • '_' → exit 0, [{"input":"_","output":"_","status":"unchanged"}], limitation present, args ["--compact","--"]
    • '_' '$s4main3FooV' → exit 0, [{"input":"_","output":"_","status":"unchanged"},{"input":"$s4main3FooV","output":"main.Foo","status":"demangled"}]
    • '$s4main3FooV' '_Sa' (control) → exit 0, main.Foo/demangled, _Sa/unchanged, no limitation
  • Remaining proof gaps: only one Swift toolchain was checked (Apple Swift, LLVM 21.0.0 swift-demangle). Behavior on older toolchains that print _ is source-derived.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/native/parsers/demangle.test.ts: passed (10 tests)
  • npm run test:focused -- tests/boundary/mcp/nativeDemangleMcp.test.ts: passed (3 tests, real swift-demangle on macOS)
  • npm run test:focused -- tests/boundary/providers/native/nativeProvider.test.ts: passed (54 tests)
  • npm run check:fast: passed (typecheck, lint)
  • CLI reproduction above: passed
  • After the review fix and update from main: npm run test:focused -- src/native/parsers/demangle.test.ts tests/boundary/mcp/nativeDemangleMcp.test.ts tests/boundary/cli/nativeDemangleCli.test.ts tests/boundary/providers/native/nativeProvider.test.ts: 71 passed (MCP cases use real swift-demangle, including a real response file and a valid macro mangling); npm run check:fast and npm run format:check: passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The output schema is unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: real macOS swift-demangle only. No Hopper or Ghidra.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: one fewer argument is passed to the existing demangler process. No new process or side effect.

Author readiness

Human owner: @kaoru0822-kitauji

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5566 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/demangle-swift-omitted-record` --- ### 📝 Commits (2) - [`426dd64`](https://github.com/morluto/rea/commit/426dd648053ba65505a998d903895aadebb792c9) fix(native): keep per-input demangle outcomes when swift-demangle skips `_` - [`b97ed43`](https://github.com/morluto/rea/commit/b97ed4335297c6782ec6787c433a64ce73b5cf1e) Merge origin/main into fix/demangle-swift-omitted-record ### 📊 Changes **4 files changed** (+150 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `src/native/NativeMacOSProvider.ts` (+8 -8) 📝 `src/native/parsers/demangle.test.ts` (+39 -8) 📝 `src/native/parsers/demangle.ts` (+57 -24) 📝 `tests/boundary/mcp/nativeDemangleMcp.test.ts` (+46 -0) </details> ### 📄 Description **What broke:** `demangle_swift` failed the whole batch when swift-demangle skipped `_` without a record, and (found in review) LLVM expanded any `@`-prefixed symbol as a response file, so `@/dev/null` dropped a record and `@<path>` read that file (#5552). **Fix:** the demangle parser owns argument selection: `_` and non-Swift `@` symbols are reported unchanged with a limitation, and `@__swiftmacro_` manglings are forwarded in their equivalent `$s` spelling, so no forwarded argument starts with `@`. **Risk:** low; only `_` and `@`-prefixed inputs change behavior, verified against real swift-demangle (LLVM 21) on macOS. ## Summary Fixes #5552. `demangle_swift` reported an input of `_` as `demangled` to an empty name. A batch that mixed `_` with valid symbols failed with `unreadable_output`, so the valid symbols' results were lost too. Every input now gets one outcome, in input order. ## Problem and expected behavior Current `swift-demangle` skips an argument spelled exactly `_` (upstream check `if (name == "_") { warning…; continue; }`). It exits 0, prints a warning on stderr and writes no output record for it. Older toolchains print `_` unchanged. REA assumed one output line per argument. Splitting empty stdout produced one empty line, so `['_']` became `{"output":"","status":"demangled"}`. With `['_', '$s4main3FooV']` there were fewer records than inputs, so the count check threw and the whole call failed. The contract promises a demangled, unchanged or invalid status for each input. ## Change and scope - `src/native/parsers/demangle.ts` now owns which symbols are forwarded (`swiftDemangleArguments`) as well as how the output is parsed. `_` is never passed to the demangler, so each forwarded argument has exactly one output record on every toolchain. `_` is reported as `{"input":"_","output":"_","status":"unchanged"}`, because it is not a Swift mangling. The result also gets a limitation saying the demangler skips it and was not given it. - LLVM expands an argument starting with `@` as a response file even after `--` (verified with swift-demangle from LLVM 21: `@/dev/null` prints nothing; `@<file>` demangles the file's contents, and a same-named file in the working directory is read for `@__swiftmacro_…`). `@__swiftmacro_X` is the demangler's alternative spelling of `$sX` and is forwarded that way; when it cannot be decoded, the caller's spelling is reported. Every other `@` symbol is reported unchanged with a limitation and is never passed to the demangler. - Output is split into LF-terminated records. Empty output holds no record. Output that ends partway through a record, or has a record count that differs from the forwarded arguments, still fails closed. REA never guesses which record belongs to which input. - `NativeMacOSProvider` uses the parser's argument list and passes its limitations through. No contract or schema change. Ordinary fix within existing boundaries; scope decision not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: the native demangle parser (`src/native/parsers/demangle.ts`), which now selects the arguments. - Contribution scope fit and linked maintainer decision: ordinary fix; not applicable. - CLI and MCP/tool-catalog contract: unchanged schema. `_` now reports `unchanged` and a limitation instead of `demangled`/`""`. Mixed batches succeed. - Provider, bridge, target-format, or platform compatibility: native macOS provider only. Toolchains that print `_` unchanged give the same result, because `_` is no longer forwarded. - Evidence, artifact, provenance, or reconstruction contract: the provenance command shows exactly the forwarded arguments. The limitation records that `_` was not passed. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. - [x] Read existing files or captured data. ## Evidence and regression coverage - Tests added or updated: `src/native/parsers/demangle.test.ts` covers `_` alone, `_` mixed with valid symbols, and an omitted or unterminated record failing closed. Existing assertions were adapted to the `{ symbols, limitations }` return. `tests/boundary/mcp/nativeDemangleMcp.test.ts` adds a real `swift-demangle` MCP workflow for `['_']` and `['_', '$s4main3FooV', '_Sa']`. - Base reproduction or other evidence: `xcrun swift-demangle --compact -- '_' '$s4main3FooV' '_' 'x' '__' '$' '_T' '$s' '_$s' 'a_'` printed records for every argument except both `_` (two stderr warnings). `xcrun swift-demangle --compact -- '_'` exited 0 with empty stdout. The base-revision failure is from the issue report and the source. I did not re-run it on base. - User-visible CLI output with this change (`node scripts/rea.mjs demangle-swift <copy of /usr/bin/true> --format json …`, disposable XDG/TMPDIR state): - `'_'` → exit 0, `[{"input":"_","output":"_","status":"unchanged"}]`, limitation present, args `["--compact","--"]` - `'_' '$s4main3FooV'` → exit 0, `[{"input":"_","output":"_","status":"unchanged"},{"input":"$s4main3FooV","output":"main.Foo","status":"demangled"}]` - `'$s4main3FooV' '_Sa'` (control) → exit 0, `main.Foo`/`demangled`, `_Sa`/`unchanged`, no limitation - Remaining proof gaps: only one Swift toolchain was checked (Apple Swift, LLVM 21.0.0 `swift-demangle`). Behavior on older toolchains that print `_` is source-derived. - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/native/parsers/demangle.test.ts`: passed (10 tests) - `npm run test:focused -- tests/boundary/mcp/nativeDemangleMcp.test.ts`: passed (3 tests, real `swift-demangle` on macOS) - `npm run test:focused -- tests/boundary/providers/native/nativeProvider.test.ts`: passed (54 tests) - `npm run check:fast`: passed (typecheck, lint) - CLI reproduction above: passed - After the review fix and update from main: `npm run test:focused -- src/native/parsers/demangle.test.ts tests/boundary/mcp/nativeDemangleMcp.test.ts tests/boundary/cli/nativeDemangleCli.test.ts tests/boundary/providers/native/nativeProvider.test.ts`: 71 passed (MCP cases use real `swift-demangle`, including a real response file and a valid macro mangling); `npm run check:fast` and `npm run format:check`: passed ## Compatibility, safety, and release - Breaking changes or migration steps: none. The output schema is unchanged. - Real Hopper/Ghidra, browser, or OS coverage: real macOS `swift-demangle` only. No Hopper or Ghidra. - Package or release metadata impact: none. - Security, privacy, process, or containment review: one fewer argument is passed to the existing demangler process. No new process or side effect. ## Author readiness Human owner: @kaoru0822-kitauji - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:44:23 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6966
No description provided.