[PR #4287] [CLOSED] fix(native): keep undecoded swift-demangle echoes out of demangled status #6160

Closed
opened 2026-10-31 01:12:19 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4287
Author: @viniciusdsandrade
Created: 10/15/2026
Status: ❌ Closed

Base: main ← Head: fix/native-swift-demangle-undecoded-echo


📝 Commits (3)

  • 3b1e00c fix(native): keep undecoded swift-demangle echoes out of demangled status
  • 0dbcf05 test(native): cover swift-demangle spellings of undecoded names
  • 580c38e test(native): demangle undecoded linkage and $-less names through MCP

📊 Changes

3 files changed (+70 additions, -12 deletions)

View changed files

📝 src/native/parsers/demangle.test.ts (+37 -0)
📝 src/native/parsers/demangle.ts (+17 -7)
📝 tests/boundary/mcp/nativeDemangleMcp.test.ts (+16 -5)

📄 Description

Summary

Fixes #4215

Keep demangle_swift from reporting a name as demangled when swift-demangle only printed its adjusted spelling of a name it could not decode. __T0Bogus now reports invalid, and non-Swift names such as ___stack_chk_fail and strlen report unchanged. Undecoded results keep the caller's input as output.

Problem and expected behavior

parseDemangledSymbols treated any output line that differed from its input as a successful decode. swift-demangle adjusts some names before demangling and prints that adjusted spelling when demangling fails (tools/swift-demangle/swift-demangle.cpp in swiftlang/swift):

  • a name starting with __ loses one underscore (hadLeadingUnderscore, name.substr(1)), so __T0Bogus prints _T0Bogus and ___stack_chk_fail prints __stack_chk_fail;
  • a command-line argument starting with S, s or e gets a $ prefix (correctedName), so strlen prints $strlen.

REA passes symbols as arguments (--compact -- ...symbols), so each of these became demangled with an output that is not a demangling. The issue reproduced __T0Bogus -> _T0Bogus, demangled with Xcode 27. The ___stack_chk_fail and strlen cases follow from the same source and are not separately reproduced here.

Expected behavior: an undecoded name is invalid when it is a Swift mangling and unchanged otherwise, and its output is the caller's input.

Change and scope

  • src/native/parsers/demangle.ts: compare the output with both the input and the spelling swift-demangle prints for an undecoded name. Decide invalid on the name the demangler examined after removing the linkage underscore, using the existing isSwiftMangledSymbolName. Names that genuinely decode, including __T04main3FooV and s4main3FooV, stay demangled.
  • An output equal to the input is still treated as undecoded, so toolchains without either adjustment keep their current results.
  • Not included: other swift-demangle argument handling, such as the tool skipping a lone _ argument.

Contract and boundary impact

  • Semantic owner and earliest changed stage: swift-demangle output interpretation in src/native/parsers/demangle.ts.
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix within the existing native macOS provider).
  • CLI and MCP/tool-catalog contract: unchanged schemas. status now matches the documented demangled, unchanged or invalid meaning for these inputs.
  • Provider, bridge, target-format, or platform compatibility: native macOS provider with Xcode swift-demangle.
  • Evidence, artifact, provenance, or reconstruction contract: undecoded names are no longer reported as decoded. output for undecoded names is the caller's input; the printed spelling is a fixed transform of that input.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/native/parsers/demangle.test.ts: the underscore-stripped and $-prefixed spellings for __T0Bogus, __$sBogus, ___stack_chk_fail, strlen, Symbol and entry keep invalid or unchanged with the input as output; __T04main3FooV and s4main3FooV still demangle.
    • tests/boundary/mcp/nativeDemangleMcp.test.ts (darwin): __T0Bogus, ___stack_chk_fail and strlen through the production demangle_swift tool return invalid, unchanged and unchanged with the input as output.
  • Base reproduction or other evidence: the issue's executed CLI matrix shows __T0Bogus -> _T0Bogus, demangled. The other cases are derived from the cited swift-demangle source.
  • User-visible CLI/MCP output (if applicable): {"input":"__T0Bogus","output":"__T0Bogus","status":"invalid"} instead of {"input":"__T0Bogus","output":"_T0Bogus","status":"demangled"}.
  • Remaining proof gaps: swift-demangle was not run locally; the darwin MCP test runs it in CI where available.

For evidence-bearing changes:

  • 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

  • No local test commands were run: verification is source-derived; CI executes the deterministic suite.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: none run locally.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no change to how swift-demangle is invoked.

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.

🔄 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/4287 **Author:** [@viniciusdsandrade](https://github.com/viniciusdsandrade) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/native-swift-demangle-undecoded-echo` --- ### 📝 Commits (3) - [`3b1e00c`](https://github.com/morluto/rea/commit/3b1e00c74c73a1cc61e33154aa7d7a4c83f07c82) fix(native): keep undecoded swift-demangle echoes out of demangled status - [`0dbcf05`](https://github.com/morluto/rea/commit/0dbcf053ce1f24f0fb5040bcd795539a0b2102bd) test(native): cover swift-demangle spellings of undecoded names - [`580c38e`](https://github.com/morluto/rea/commit/580c38e1c19959dfe23ac8975c5b53880122619a) test(native): demangle undecoded linkage and $-less names through MCP ### 📊 Changes **3 files changed** (+70 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `src/native/parsers/demangle.test.ts` (+37 -0) 📝 `src/native/parsers/demangle.ts` (+17 -7) 📝 `tests/boundary/mcp/nativeDemangleMcp.test.ts` (+16 -5) </details> ### 📄 Description ## Summary Fixes #4215 Keep `demangle_swift` from reporting a name as `demangled` when `swift-demangle` only printed its adjusted spelling of a name it could not decode. `__T0Bogus` now reports `invalid`, and non-Swift names such as `___stack_chk_fail` and `strlen` report `unchanged`. Undecoded results keep the caller's input as `output`. ## Problem and expected behavior `parseDemangledSymbols` treated any output line that differed from its input as a successful decode. `swift-demangle` adjusts some names before demangling and prints that adjusted spelling when demangling fails (`tools/swift-demangle/swift-demangle.cpp` in swiftlang/swift): - a name starting with `__` loses one underscore (`hadLeadingUnderscore`, `name.substr(1)`), so `__T0Bogus` prints `_T0Bogus` and `___stack_chk_fail` prints `__stack_chk_fail`; - a command-line argument starting with `S`, `s` or `e` gets a `$` prefix (`correctedName`), so `strlen` prints `$strlen`. REA passes symbols as arguments (`--compact -- ...symbols`), so each of these became `demangled` with an output that is not a demangling. The issue reproduced `__T0Bogus -> _T0Bogus, demangled` with Xcode 27. The `___stack_chk_fail` and `strlen` cases follow from the same source and are not separately reproduced here. Expected behavior: an undecoded name is `invalid` when it is a Swift mangling and `unchanged` otherwise, and its `output` is the caller's input. ## Change and scope - `src/native/parsers/demangle.ts`: compare the output with both the input and the spelling `swift-demangle` prints for an undecoded name. Decide `invalid` on the name the demangler examined after removing the linkage underscore, using the existing `isSwiftMangledSymbolName`. Names that genuinely decode, including `__T04main3FooV` and `s4main3FooV`, stay `demangled`. - An output equal to the input is still treated as undecoded, so toolchains without either adjustment keep their current results. - Not included: other `swift-demangle` argument handling, such as the tool skipping a lone `_` argument. ## Contract and boundary impact - Semantic owner and earliest changed stage: `swift-demangle` output interpretation in `src/native/parsers/demangle.ts`. - Contribution scope fit and linked maintainer decision: not applicable (bug fix within the existing native macOS provider). - CLI and MCP/tool-catalog contract: unchanged schemas. `status` now matches the documented demangled, unchanged or invalid meaning for these inputs. - Provider, bridge, target-format, or platform compatibility: native macOS provider with Xcode `swift-demangle`. - Evidence, artifact, provenance, or reconstruction contract: undecoded names are no longer reported as decoded. `output` for undecoded names is the caller's input; the printed spelling is a fixed transform of that input. - Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none. Expected effects: - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: - `src/native/parsers/demangle.test.ts`: the underscore-stripped and `$`-prefixed spellings for `__T0Bogus`, `__$sBogus`, `___stack_chk_fail`, `strlen`, `Symbol` and `entry` keep `invalid` or `unchanged` with the input as output; `__T04main3FooV` and `s4main3FooV` still demangle. - `tests/boundary/mcp/nativeDemangleMcp.test.ts` (darwin): `__T0Bogus`, `___stack_chk_fail` and `strlen` through the production `demangle_swift` tool return `invalid`, `unchanged` and `unchanged` with the input as output. - Base reproduction or other evidence: the issue's executed CLI matrix shows `__T0Bogus -> _T0Bogus, demangled`. The other cases are derived from the cited `swift-demangle` source. - User-visible CLI/MCP output (if applicable): `{"input":"__T0Bogus","output":"__T0Bogus","status":"invalid"}` instead of `{"input":"__T0Bogus","output":"_T0Bogus","status":"demangled"}`. - Remaining proof gaps: `swift-demangle` was not run locally; the darwin MCP test runs it in CI where available. For evidence-bearing changes: - [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 - No local test commands were run: verification is source-derived; CI executes the deterministic suite. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: none run locally. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no change to how `swift-demangle` is invoked. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:12:19 +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#6160
No description provided.