Skip to content

fix(kuna): verify a warm export once for concurrent first requests - #4049

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/kuna-share-export-adoption
Oct 15, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/kuna-share-export-adoption

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

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

Every request a session admitted checked `#project` before awaiting the
cache lookup, so concurrent first requests, such as batch_decompile's
parallel resolutions on a fresh server, each re-hashed every export file
and re-parsed the export. Concurrent first requests now share one lookup.

Refs #1957

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added bug Something isn't working track:kuna Kuna decompiler provider series (#1957) labels Oct 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

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 ✅ Completed 2026-10-15T09:25:30.044573Z 9944762 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.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable regressions were found.

Summary

Concurrent first requests in one Kuna session now share the cache lookup through #starting.

  • Concurrent Kuna requests share one export lookup.

No actionable issues were found. Tests were not run during this review. The supersession check could not be completed because GitHub access required authentication.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Concurrent first requests] --> B{Project already started?}
  B -->|Yes| C[Use existing project]
  B -->|No| D[Share one startup promise]
  D --> E[Verify cached export]
  E -->|Found| F[Adopt verified export]
  E -->|Missing| G[Start background build]
  E -->|Error| H[Return error]
  F --> I[Clear startup promise]
  G --> I
  H --> I
Loading

Reviews (1) · Last reviewed commit: "fix(kuna): verify a warm export once for..." · Reviewed by Greptile

@kaoru0822-kitauji
kaoru0822-kitauji merged commit b6529bf into main Oct 15, 2026
34 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/kuna-share-export-adoption branch October 15, 2026 10:41
@morluto morluto added area: tests Test suite and verification provider: kuna Analysis provider / engine: kuna labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Test suite and verification bug Something isn't working provider: kuna Analysis provider / engine: kuna track:kuna Kuna decompiler provider series (#1957)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants