[PR #4049] [MERGED] fix(kuna): verify a warm export once for concurrent first requests #6019

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4049
Author: @kaoru0822-kitauji
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/kuna-share-export-adoption


📝 Commits (1)

  • 9944762 fix(kuna): verify a warm export once for concurrent first requests

📊 Changes

3 files changed (+46 additions, -4 deletions)

View changed files

📝 docs/kuna-provider.md (+1 -1)
📝 src/kuna/KunaSessionClient.ts (+13 -2)
📝 tests/boundary/providers/kuna/kunaProvider.test.ts (+32 -1)

📄 Description

Summary

A Kuna session decided whether to reuse a cached export by checking #project and then awaiting cache.lookup(). Concurrent first requests all passed that check before any lookup finished, so each one ran its own lookup. On a fresh server a lookup re-hashes every export file and re-parses the .c and inventory. batch_decompile resolves its addresses in parallel, so it verified a warm export once per address. Refs #1957.

Problem and expected behavior

Smallest trigger: warm cache, new MCP server, open_binary with provider_id: "kuna", then one batch_decompile with N addresses. Expected: one verification per session, as for a single first request. Observed: N verifications; the cost grows with N × export size.

Change and scope

#startProject now keeps the in-flight lookup in #starting. Concurrent first requests await that one lookup, which then adopts the export or starts the background build. The promise is cleared when it settles, so a failed lookup is retried by the next request, and the existing eviction recovery (#invalidateProject followed by #startProject) works as before. One line in docs/kuna-provider.md states the behavior.

Not included: a lookup shared across sessions of one process. Verification stays per session; concurrent sessions for one target in one process are uncommon, and sharing it would need waiter-owned cancellation in the cache.

Scope: an ordinary fix within the existing Kuna provider boundary; no maintainer scope decision applies.

Contract and boundary impact

  • Semantic owner and earliest changed stage: KunaSessionClient.#startProject (session-level adoption of the cache's verified export).
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: unchanged.
  • Provider, bridge, target-format, or platform compatibility: Kuna only.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged. Answers still name the same verified export and file spans.
  • Target selection, authority, upstream behavior, and cleanup details: no new processes or writes. The lookup still uses the session signal, so close_binary cancels it as before.
  • Generated metadata, 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: kunaProvider.test.ts gets "verifies a warm export once for concurrent first requests on a fresh server". It builds an export, opens a new KunaProvider (a fresh cache instance, like a new server) over the same cache root, sends four concurrent pseudocode requests (names, an address and a duplicate), and asserts all four come from project-export with exactly one KunaProjectCache.lookup call.

  • Base reproduction: the new test fails on the base revision (git stash of src/kuna/KunaSessionClient.ts) at toHaveBeenCalledTimes(1).

  • Real Kuna 1.833, macOS arm64, fresh MCP server, warm 29 MiB export of mDNSResponder thinned to arm64e (1.7 MiB, 3750 inventory entries, REA_KUNA_JOBS=8), batch_decompile of 12 sized entries, 3 runs per build:

    Build batch_decompile Whole process wall Whole process user CPU
    main 668 / 671 / 671 ms 1.20 / 1.20 / 1.21 s 1.43 / 1.44 / 1.44 s
    this PR 91 / 94 / 100 ms 0.64 / 0.61 / 0.62 s 0.87 / 0.79 / 0.80 s

    For comparison, a single first procedure_pseudo_code on the same warm export takes 88–93 ms on both builds. Response bytes are identical (156318). Process figures come from /usr/bin/time -p around the harness and include the MCP client process. Model tokens were not measured. The time saved grows with export size and the number of addresses.

  • Remaining proof gaps: no Linux host run of this change; cross-session duplicate lookups in one process remain (see scope).

  • 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:focused -- tests/boundary/providers/kuna/*.test.ts: 90 passed (10 files), three consecutive runs.
  • New test on the base revision: failed as described above.
  • npm run check:fast: typecheck and lint passed.
  • npm run docs:check: passed.
  • REA_KUNA_COMMAND=… npm run verify:kuna (real Kuna 1.833, darwin/arm64): passed, process lineage verified, cleanup: "complete".
  • Real MCP measurements above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: real Kuna on macOS arm64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new side effects. The same verification runs fewer times.

Author readiness

Human owner:

  • 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/4049 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/kuna-share-export-adoption` --- ### 📝 Commits (1) - [`9944762`](https://github.com/morluto/rea/commit/9944762dc3f62fd95dc6b829b7bbaa8496e804cc) fix(kuna): verify a warm export once for concurrent first requests ### 📊 Changes **3 files changed** (+46 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/kuna-provider.md` (+1 -1) 📝 `src/kuna/KunaSessionClient.ts` (+13 -2) 📝 `tests/boundary/providers/kuna/kunaProvider.test.ts` (+32 -1) </details> ### 📄 Description ## Summary A Kuna session decided whether to reuse a cached export by checking `#project` and then awaiting `cache.lookup()`. Concurrent first requests all passed that check before any lookup finished, so each one ran its own lookup. On a fresh server a lookup re-hashes every export file and re-parses the `.c` and inventory. `batch_decompile` resolves its addresses in parallel, so it verified a warm export once per address. Refs #1957. ## Problem and expected behavior Smallest trigger: warm cache, new MCP server, `open_binary` with `provider_id: "kuna"`, then one `batch_decompile` with N addresses. Expected: one verification per session, as for a single first request. Observed: N verifications; the cost grows with N × export size. ## Change and scope `#startProject` now keeps the in-flight lookup in `#starting`. Concurrent first requests await that one lookup, which then adopts the export or starts the background build. The promise is cleared when it settles, so a failed lookup is retried by the next request, and the existing eviction recovery (`#invalidateProject` followed by `#startProject`) works as before. One line in `docs/kuna-provider.md` states the behavior. Not included: a lookup shared across sessions of one process. Verification stays per session; concurrent sessions for one target in one process are uncommon, and sharing it would need waiter-owned cancellation in the cache. Scope: an ordinary fix within the existing Kuna provider boundary; no maintainer scope decision applies. ## Contract and boundary impact - Semantic owner and earliest changed stage: `KunaSessionClient.#startProject` (session-level adoption of the cache's verified export). - Contribution scope fit and linked maintainer decision: not applicable. - CLI and MCP/tool-catalog contract: unchanged. - Provider, bridge, target-format, or platform compatibility: Kuna only. - Evidence, artifact, provenance, or reconstruction contract: unchanged. Answers still name the same verified export and file spans. - Target selection, authority, upstream behavior, and cleanup details: no new processes or writes. The lookup still uses the session signal, so `close_binary` cancels it as before. - Generated metadata, 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: `kunaProvider.test.ts` gets "verifies a warm export once for concurrent first requests on a fresh server". It builds an export, opens a new `KunaProvider` (a fresh cache instance, like a new server) over the same cache root, sends four concurrent pseudocode requests (names, an address and a duplicate), and asserts all four come from `project-export` with exactly one `KunaProjectCache.lookup` call. - Base reproduction: the new test fails on the base revision (`git stash` of `src/kuna/KunaSessionClient.ts`) at `toHaveBeenCalledTimes(1)`. - Real Kuna 1.833, macOS arm64, fresh MCP server, warm 29 MiB export of `mDNSResponder` thinned to arm64e (1.7 MiB, 3750 inventory entries, `REA_KUNA_JOBS=8`), `batch_decompile` of 12 sized entries, 3 runs per build: | Build | `batch_decompile` | Whole process wall | Whole process user CPU | | --- | --- | --- | --- | | main | 668 / 671 / 671 ms | 1.20 / 1.20 / 1.21 s | 1.43 / 1.44 / 1.44 s | | this PR | 91 / 94 / 100 ms | 0.64 / 0.61 / 0.62 s | 0.87 / 0.79 / 0.80 s | For comparison, a single first `procedure_pseudo_code` on the same warm export takes 88–93 ms on both builds. Response bytes are identical (156318). Process figures come from `/usr/bin/time -p` around the harness and include the MCP client process. Model tokens were not measured. The time saved grows with export size and the number of addresses. - Remaining proof gaps: no Linux host run of this change; cross-session duplicate lookups in one process remain (see scope). - [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:focused -- tests/boundary/providers/kuna/*.test.ts`: 90 passed (10 files), three consecutive runs. - New test on the base revision: failed as described above. - `npm run check:fast`: typecheck and lint passed. - `npm run docs:check`: passed. - `REA_KUNA_COMMAND=… npm run verify:kuna` (real Kuna 1.833, darwin/arm64): passed, process lineage verified, `cleanup: "complete"`. - Real MCP measurements above. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: real Kuna on macOS arm64 only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new side effects. The same verification runs fewer times. ## Author readiness Human owner: <!-- @GitHub-handle --> - [ ] 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](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-10-31 01:11:12 +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#6019
No description provided.