Skip to content

fix(contracts): refuse empty address and procedure selectors in the contracts - #10753

Merged
morluto merged 7 commits into
mainfrom
fix/selector-contracts-refuse-empty
Nov 15, 2026
Merged

morluto merged 7 commits into
mainfrom
fix/selector-contracts-refuse-empty

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Next slice of plan W1, stacked on #10738 (which now also carries #10747). Refs #10583.

An empty address or procedure is now refused by the tool contracts themselves, so MCP and the CLI agree. The CLI-only empty-selector rule added in #10738/#10747 is replaced by a check that every CLI selector field's contract already refuses "".

Problem and expected behavior

xrefs.address, read_function_instructions.procedure, procedure_references.procedure and the other official fields built from the shared address / procedure helpers were plain z.string(). An MCP call such as xrefs {"address": ""} passed input validation and reached the provider. The CLI refused the same value only because the contract-derived selector projection added its own .min(1). The two adapters disagreed on what the contract admits.

Expected: a selector names one object, so "" is refused at admission by the contract, for both adapters, before any provider work.

Change and scope

  • src/contracts/toolContractHelpers.ts: the shared address and procedure fields are .min(1). optionalAddress still admits omission (Hopper's cursor fallback is unchanged).
  • src/contracts/functionInstructionContract.ts: read_function_instructions.procedure reuses the shared procedure field instead of its own copy.
  • src/cli/contractCliDescription.ts: the selector projection no longer adds .min(1). It throws at description time if a selector field's contract admits "", so a future selector cannot reintroduce a CLI-only rule or a silent CLI/MCP disagreement. (The build fails with xrefs.address admits an empty selector if the contract change is reverted.)
  • cliContractCommandParity.test.ts: the oracle's special case for empty selectors is removed; the contract decides.

Not included: other contract string fields that might also be meaningless when empty (names, comments, patterns). set_comment.comment and set_bookmark.name deliberately use "" to clear and are unchanged.

Contribution scope: admission change approved by the maintainer for W1 (CLI and MCP must agree).

  • Startup stays lazy: commands read their contracts from their own groups (contractNamed(OFFICIAL_TOOL_CONTRACTS, …), ENHANCED_TOOL_CONTRACTS, NATIVE_TOOL_CONTRACTS, ELECTRON_TOOL_CONTRACTS, OPEN_BINARY_TOOL_CONTRACT) instead of toolContract from toolContracts.ts, which loaded the complete catalog at CLI startup (tests/boundary/cli/cliStartupImports.test.ts). The lint rule added in refactor(cli): project inspect-artifact and extract-artifact with open_binary target options #10722 keeps it out.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the shared official contract fields own selector admission; the CLI selector projection now only asserts it. Removed: the CLI-only .min(1) and the parity oracle's empty-selector exception.
  • Contribution scope fit and linked maintainer decision: maintainer-approved admission change (W1 coordination).
  • CLI and MCP/tool-catalog contract:
    • MCP-visible: official tools whose input uses the shared address or procedure field (for example xrefs, next_address, prev_address, procedure_address, procedure_assembly, procedure_callees, procedure_callers, procedure_info, procedure_references, procedure_pseudo_code, read_function_instructions, resolve_containing_procedure, set_address_name, set_bookmark, set_comment, unset_bookmark and the Hopper memory tools) now refuse "" as an SDK input-validation error, and their advertised JSON Schema gains minLength: 1. Omitting an optional address is unchanged.
    • CLI: unchanged behavior; empty selectors were already refused (VALIDATION_ERROR).
  • Provider, bridge, target-format, or platform compatibility: providers no longer receive empty selectors.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: none.
  • Generated metadata, package, or installation impact: catalog digests change (recorded at build time).

Expected effects (unchanged; left for the human owner to check):

  • 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:
    • tests/boundary/mcp/enhancedTools.inputValidation.test.ts: MCP calls to xrefs, read_function_instructions, procedure_references, procedure_pseudo_code and set_comment with an empty selector are errors and never reach the provider; xrefs {} still runs.
    • cliContractCommandParity.test.ts: the oracle now takes empty-selector admission from the contract.
  • Base reproduction: with the contract change reverted (and the CLI guard reverted so the build completes), the new MCP test fails (xrefs: expected undefined to be true). With only the contract change reverted, the build fails at the new guard (xrefs.address admits an empty selector).
  • Remaining proof gaps: no real Hopper/Ghidra run; the change is at schema admission before any provider call.

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

  • npm run test:focused -- tests/boundary/mcp/enhancedTools.inputValidation.test.ts tests/boundary/mcp/compactInputSchemaMcp.test.ts tests/boundary/mcp/mcpSchemaValidation.test.ts tests/boundary/mcp/toolSchemaValidity.test.ts tests/boundary/mcp/packageCatalogVerification.test.ts tests/boundary/cli/cliInputSchemaRequired.test.ts tests/boundary/cli/analysisSelectorCli.test.ts tests/boundary/cli/cliContractCommandParity.test.ts tests/boundary/cli/cliDomainFieldSchema.test.ts tests/boundary/cli/rawBinaryCli.test.ts — 595 passed.

  • npm run test:focused -- src/contracts/*.test.ts plus the three CLI selector/parity tests — 801 passed, 3 skipped.

  • npm run check:fast — passed. npm run docs:check — passed.

  • This branch now also carries refactor(cli): project decompile from its contract with --file-offset as an alternative selector #10756 (decompile from procedure_pseudo_code, collapsed into it); see that PR for its validation.

  • After rebasing onto main with the startup-import fix: npm run check:fast passed (pre-push) at this branch; at the top of the stack npm run test:focused -- tests/boundary/cli/cliStartupImports.test.ts tests/boundary/cli/cliContractCommandParity.test.ts tests/boundary/cli/nativePlistCli.test.ts tests/boundary/cli/nativePlistSelectionFailureCli.test.ts tests/boundary/cli/contractCommandInputFields.test.ts tests/boundary/cli/nativeMachoEvidenceDeliveryCli.test.ts: 660 passed.

  • After the restack onto main with test(cli): report CLI fields that admit values their contract refuses #10575: npm run test:focused -- tests/boundary/cli/cliContractSchemaParity.test.ts failed because the four empty-selector mismatches this PR fixes (inspect-native-api options.procedure, inspect-native-data-type options.address/options.type, search-bytes options.cursor) were still in its shrinking baseline; removed them, then it passed (4 tests).

Compatibility, safety, and release

  • Breaking changes or migration steps: an MCP call passing "" for one of these fields used to reach the provider (which had no defined meaning for it) and is now refused at input validation; callers that meant "current cursor" for xrefs/next_address/prev_address should omit address. Not marked breaking because "" never selected an object.
  • Real Hopper/Ghidra, browser, or OS coverage: none.
  • Package or release metadata impact: catalog digest changes.
  • Security, privacy, process, or containment review: none.

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.

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T13:56:28.633579Z
We couldn’t complete this review. Comment @codex review to try again.
6244b57 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 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no actionable correctness or security issues were found.

Summary

The PR makes shared address and procedure contracts reject empty strings while preserving optional address omission.

  • Tool contracts refuse empty address and procedure selectors.
  • Decompilation commands take their inputs from tool contracts.
  • Search uses the selected inventory contract for each search.
  • Native UI and inspection commands derive their inputs from contracts.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  CLI[CLI arguments] --> Projection[Contract-derived fields]
  Projection --> Selection[Choose selector and operation]
  Selection --> Admission[Check contract input]
  MCP[MCP request] --> Admission
  Admission -->|Empty selector| Refusal[Reject before provider work]
  Admission -->|Accepted input| Provider[Run selected operation]
Loading

Reviews (6) · Last reviewed commit: "test(cli): drop the empty-selector admis..." · Reviewed by Greptile

@morluto
morluto force-pushed the refactor/cli-contract-selector-options branch from 3bebed9 to 5dead85 Compare November 15, 2026 05:58
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from 175d82a to 2720e58 Compare November 15, 2026 05:58
@morluto
morluto force-pushed the refactor/cli-contract-selector-options branch from 5dead85 to bb60c95 Compare November 15, 2026 07:35
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from de7d5ad to f0671e1 Compare November 15, 2026 07:35
Base automatically changed from refactor/cli-contract-selector-options to refactor/cli-contract-native-open November 15, 2026 07:55
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from f0671e1 to 5d54b49 Compare November 15, 2026 08:00
@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from b8f774f to 8b730fc Compare November 15, 2026 09:37
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch 2 times, most recently from 6c83ed9 to 8829bc3 Compare November 15, 2026 10:08
@morluto
morluto force-pushed the refactor/cli-contract-native-open branch 2 times, most recently from 314a029 to 74f1dec Compare November 15, 2026 11:18
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from 313e44e to b45a717 Compare November 15, 2026 11:18
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from b45a717 to f580815 Compare November 15, 2026 11:26
@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from 74f1dec to e05806c Compare November 15, 2026 11:26
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from e05806c to 59190c5 Compare November 15, 2026 12:19
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from f580815 to 5e16992 Compare November 15, 2026 12:19
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto force-pushed the refactor/cli-contract-native-open branch from 59190c5 to a8bd2c7 Compare November 15, 2026 13:05
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from 5e16992 to 79b6610 Compare November 15, 2026 13:05
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto changed the base branch from refactor/cli-contract-native-open to main November 15, 2026 13:32
… the operation (#10761)

* refactor(cli): project search from its contracts with --kind choosing the operation

* fix(cli): check operation choices' option rules and bind errors to the selected contract
…session target (#10778)

* refactor(cli): project decompile-all from its contract onto a native session target

* refactor(cli): project native Mach-O, Swift and native UI commands from their contracts
@morluto
morluto force-pushed the fix/selector-contracts-refuse-empty branch from 79b6610 to 6244b57 Compare November 15, 2026 13:56
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto merged commit 104b1a3 into main Nov 15, 2026
6 checks passed
@morluto
morluto deleted the fix/selector-contracts-refuse-empty branch November 15, 2026 14:03
morluto added a commit that referenced this pull request Nov 15, 2026
… summary

#10753 changed 26 tools' advertised input schemas without regenerating the
committed catalog summary, so verify:advertised-schemas failed on main.
@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant