Skip to content

fix(hopper): validate every bridge reply against one contract table - #10662

Merged
morluto merged 4 commits into
mainfrom
fix/hopper-reply-contracts
Nov 14, 2026
Merged

morluto merged 4 commits into
mainfrom
fix/hopper-reply-contracts

Conversation

@morluto

@morluto morluto commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Hopper validated only the bridge response envelope. Operation replies passed through as untyped JsonValue, and later readers applied contract schemas, each with its own policy. One of them, projectHopperNameInventory, returned a malformed list_names reply unchanged.

This PR adds the owner, as Ghidra already has: a reply-contract table that covers every bridge method REA reads and is built from the shared src/domain/native schemas. Each reply is validated once, at the provider edge or by the reconciler that reads it.

Refs #8067. Structural audit 2026-11, report 16 finding F1 (Run P1).

Problem and expected behavior

  • Trigger: list_names returns {"unexpected":"shape"}, rows without value, or an out-of-contract objc_class_label. The same applies to a drifted reply from any other Hopper method.
  • Before: the reply passed through unchanged and became Evidence.
  • After: the provider returns AnalysisOutputError ("Hopper bridge output did not match the contract").
  • Both entry paths validate: execute and executeIfReady.
  • Valid replies keep every source field. The validated source value itself is returned, not a stripped copy.

Change and scope

  • src/hopper/HopperReplyContracts.ts:
    • hopperReplySchemas is typed satisfies Record<HopperBridgeMethod, ZodType>, so a new bridge method cannot compile without a contract.
    • hopperBridgeMethod(operation) is the one mapping from an operation to its bridge method, e.g. procedure_callers → rea_caller_base. It replaces the provider's inline ternary.
    • parseHopperReply validates a reply and returns the source value unchanged.
  • HopperProvider: validates each reply that reconciliation and regex search don't read. list_names and address_to_file_offset are passed to their projections as typed values. executeIfReady validates every contracted operation.
  • HopperFileOffset.mapHopperFileOffset takes the validated observation; its local schema and malformed branch are deleted.
  • HopperCallerReconciliation: its local schemas (page, target, base, references) move into the table. The native reply is now parsed once, not three times (the old flow ran safeParse and then .parse again).
  • projectHopperNameInventory: its pass-through branch is deleted.
  • HopperRegexSearch: its own inventory schema check is deleted.
  • The segment-list schema moves from src/contracts/toolOutputSchemaPrimitives.ts into its domain owner, src/domain/native/nativeSegments.ts (nativeSegmentListSchema). The contracts module reuses it.

Intentionally not included: the cross-provider readers (nativeInventoryView, functionInventory, NativeDispatchMetadataInspection, EnhancedLiteralTracing), which also serve Ghidra and IDA. Typing HopperClient.callTool by method is also not done.

Contribution scope: not applicable. This is a fix within existing boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the Hopper reply-contract table at the provider edge. Superseded: the pass-through branch and local row schema in HopperNameInventory.ts, and the inventory schema check in HopperRegexSearch.ts.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: unchanged. The advertised output schemas already use these same row schemas.
  • Provider, bridge, target-format, or platform compatibility: the shipped bridge/hopper_bridge.py emits {address, value} names and {address, value, provider_value, string|decoding} strings, which satisfy the contracts. A drifted or foreign bridge reply now fails instead of passing through.
  • Evidence, artifact, provenance, or reconstruction contract: malformed inventory replies no longer enter Evidence. Valid replies keep every source field, and rawResult is still retained when the class-label projection changes rows.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • 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:
    • src/hopper/HopperNameInventory.test.ts: malformed list_names replies are rejected through the real provider client.
    • src/hopper/HopperReplyContracts.test.ts:
      • Every operation's bridge method has a contract.
      • The source value is preserved.
      • Failures are named by operation and bridge method.
      • Table-driven provider tests cover execute (list_procedures, list_strings, search_procedures, search_strings, list_documents) and executeIfReady (list_procedures, list_documents).
    • tests/boundary/filesystem/hopperFatCoordinates.test.ts routes its observations through the contract.
  • Base reproduction: the list_names rejection cases fail against origin/main (3 failed, 3 passed).
  • Remaining proof gaps: no real Hopper was run. The contracts were derived from bridge/hopper_bridge.py and the existing fakes.

Validation performed

  • npm run test:local -- src/hopper/HopperReplyContracts.test.ts src/hopper/HopperNameInventory.test.ts src/hopper/HopperCallerReconciliation.test.ts src/hopper/HopperProvider.test.ts src/hopper/HopperRegexSearch.test.ts: 54 passed, before the latest test additions
  • npm run test:local -- src/hopper/HopperReplyContracts.test.ts: 10 passed, after the Greptile fixes
  • npm run test:focused -- tests/boundary/providers/hopper/hopperCallerReconciliation.test.ts tests/boundary/providers/hopper/hopperFileOffsetClose.test.ts tests/boundary/providers/hopper/hopperBookmarks.test.ts tests/boundary/providers/hopper/hopperInstructions.test.ts tests/boundary/filesystem/hopperFatCoordinates.test.ts: 34 passed, 8 s
  • Earlier commit: 8 Hopper boundary files (50 passed) and 6 related files (35 passed)
  • npm run check:fast and pre-push typecheck/lint: passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none for the shipped bridge.
  • Real Hopper/Ghidra, browser, or OS coverage: none.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: not applicable.

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.

…e provider edge

Hopper validated only the response envelope. list_names replies outside
the inventory contract were returned unchanged (projectHopperNameInventory
passed them through), and the regex search re-parsed its inventory with
its own policy. A per-method reply contract table built from the shared
native inventory schemas now validates list_names, list_procedures,
list_strings, search_procedures and search_strings once; a reply outside
the contract is an AnalysisOutputError. The remaining 31 operations are a
counted pending list that may only shrink.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T20:34:49.063195Z 20991b8 New commits
ℹ️ 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 Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge.

Summary

Adds one reply-contract table for all advertised Hopper operations and the private methods used by caller scans.

  • Hopper checks bridge replies against their method contracts before using them.
  • Hopper checks inventory rows before name projection and regex matching.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Hopper bridge reply] --> B[Method reply contract]
  B -->|Invalid| C[AnalysisOutputError]
  B -->|Valid source preserved| D[Direct reply or checked projection]
  D --> E[Analysis result and Evidence]
Loading

Reviews (3) · Last reviewed commit: "fix(hopper): apply reply contracts on th..." · Reviewed by Greptile

Comment thread src/hopper/HopperProvider.ts Resolved
Comment thread src/hopper/HopperReplyContracts.test.ts Resolved
… operations

Twenty-two more Hopper operations are validated against reply contracts
built from the shared native schemas. The pending list shrinks from 31
to 9 operations.
Comment thread src/hopper/HopperReplyContracts.ts Resolved
The reply table now covers every bridge method REA reads, including the
private caller-reconciliation methods. HopperFileOffset receives a
validated observation and HopperCallerReconciliation reads typed replies
instead of keeping its own schemas and re-parsing the native result. The
segment list schema moves from contracts into its domain owner.
…ntry path

executeIfReady validated only list_procedures, so a malformed
list_documents reply could reach the completion path. Every contracted
operation is now validated there, and provider-level tests cover the
direct and ready paths for each inventory and document operation.
@morluto

morluto commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

I've pushed changes for all three Greptile findings.

  • Issue 1 (ready path skips the contract): valid, fixed. executeIfReady checked the reply only for list_procedures, so a malformed list_documents reply could reach the completion path. It now validates every operation that has a reply contract (hasHopperReplyContract), the same check execute applies.
  • Issue 2 (mode: "regex" skips reply checks): valid, fixed. The check is now skipped only when the request actually went through regexSearch.execute (isRegexSearch), not whenever parameters.mode === "regex".
  • Issue 3 (provider paths lack rejection tests): valid, fixed. src/hopper/HopperReplyContracts.test.ts now drives the real HopperProvider client through two table-driven tests:
    • execute covers list_procedures, list_strings, search_procedures, search_strings and list_documents. Each case checks that a valid reply keeps its unlisted source fields and that a malformed one fails with AnalysisOutputError.
    • executeIfReady covers list_procedures and list_documents.

Related work in the same PR: the contract table now covers every bridge method REA reads. That includes the caller-reconciliation methods (rea_caller_base, rea_caller_scan_page, rea_caller_scan_target), analyze_function, procedure_references and address_to_file_offset. HopperFileOffset and HopperCallerReconciliation now read typed replies instead of their own schemas. The guard test requires every operation's bridge method to have a contract.

Validation:

  • npm run test:local -- src/hopper/HopperReplyContracts.test.ts: 10 passed
  • Pre-push typecheck and lint passed

@morluto morluto changed the title fix(hopper): validate inventory replies against their contracts at the provider edge fix(hopper): validate every bridge reply against one contract table Nov 14, 2026
@morluto
morluto merged commit f88d896 into main Nov 14, 2026
55 of 57 checks passed
@morluto
morluto deleted the fix/hopper-reply-contracts branch November 14, 2026 23:59
morluto added a commit that referenced this pull request Nov 15, 2026
#10662 validates every Hopper bridge reply. The fake Hopper behind the darwin packaged-CLI baseline still served list_segments without permissions, provenance and sections, so 'rea analyze --provider hopper' failed as unreadable output on every PR that ran that lane. The fixture's replies move to fakeHopperReplies.mjs, list_segments takes the real bridge's shape, and a test checks every served reply against the contract table.
morluto added a commit that referenced this pull request Nov 15, 2026
…10734)

* fix(test): serve fake Hopper segments in the bridge's reply contract

#10662 validates every Hopper bridge reply. The fake Hopper behind the darwin packaged-CLI baseline still served list_segments without permissions, provenance and sections, so 'rea analyze --provider hopper' failed as unreadable output on every PR that ran that lane. The fixture's replies move to fakeHopperReplies.mjs, list_segments takes the real bridge's shape, and a test checks every served reply against the contract table.

* test(hopper): derive the fake reply method list from one keyed factory object

The contract test iterated a hand-kept method list beside the reply switch, so
a reply added without updating the list would go unchecked. Replies are now
factories in one keyed object; fakeHopperReply looks them up by key and
FAKE_HOPPER_REPLY_METHODS is the object's keys, so every served reply is
validated against its contract.

* test(hopper): serve containing-procedure and reference replies from the keyed factories
@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working provider: hopper Analysis provider / engine: hopper labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working provider: hopper Analysis provider / engine: hopper

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant