Skip to content

refactor(domain): compare snapshot targets through one target identity key - #11341

Merged
morluto merged 2 commits into
mainfrom
refactor/target-identity-key
Nov 15, 2026
Merged

morluto merged 2 commits into
mainfrom
refactor/target-identity-key

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Slice 1 of the accepted target-identity ADR (docs/adr/evidence/target-identity.md): adds src/domain/targetIdentity.ts with a tagged TargetIdentity (the file kind for now) and targetIdentityKey, an RFC 8785 canonical digest. Snapshot target comparison now goes through that key only. No Evidence ID, snapshot format or query ID changes. Refs #10510.

Problem and expected behavior

Target comparison for analysis snapshots had two implementations: a field-by-field snapshotMatchesTarget and a JSON.stringify compare in AnalysisSnapshotCache.stage, which depends on member order. Both compare the same facts. They should use one comparison owned by the domain.

Change and scope

  • src/domain/targetIdentity.ts: FileTargetIdentity (sha256, format, architecture, selection), FileTargetSelection (entry-point for raw and DOL targets, esp-flash for ESP flash offsets), targetIdentityKey and sameTargetIdentity.
  • src/domain/analysisSnapshot.ts: snapshotTargetIdentity projects the persisted snapshot target into the identity. snapshotMatchesTarget compares keys instead of fields.
  • AnalysisSnapshotCache.stage compares keys instead of JSON.stringify output.
  • BINARY_TARGET_FORMAT_KINDS (src/domain/binaryTargetTypes.ts) owns each format's single kind, type-checked against every BinaryTarget variant. The snapshot target schema refuses a kind its format cannot have: query IDs commit to the kind, so such a header would stage entries no lookup or export can reach (Greptile finding). BinaryTargetResolver's archive check reads the map instead of its own format list.
  • Not included (later slices of the ADR):
    • the url, process, session and unknown kinds;
    • the Evidence subject change and format revision 2 (slice 2, breaking);
    • sameEvidenceSubjectTargetIdentity in evidence.ts, which compares Evidence subjects and is replaced in slice 2;
    • universal Mach-O slice selection, which the revision 1 snapshot target does not persist.
  • BinaryTargetResolver already hashes through the shared stable file hasher (hashStableRegularFileDescriptor) on main, so that part of the slice needs no change.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/targetIdentity.ts (new); snapshotTargetIdentity in src/domain/analysisSnapshot.ts.
  • Contribution scope fit and linked maintainer decision: structural cleanup plan W12 step 3; ADR accepted by the coordinator (docs(adr): accept the target identity decision #11340).
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none. Persisted snapshots, query IDs and Evidence IDs are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: binary kind is no longer compared on its own. Every format has exactly one kind, and the snapshot schema now enforces it. A snapshot whose target kind disagrees with its format is refused at parse; no REA producer writes one.
  • 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: analysisSnapshot.test.ts "refuses a snapshot target whose kind its format cannot have"; src/domain/targetIdentity.test.ts. The key ignores member order (two spellings whose JSON.stringify output differs get the same key). The same bytes with a different raw entry point or ESP flash offset are different targets. The path is display only, not identity.
  • Existing coverage kept: analysisSnapshot.test.ts (raw entry partitioning, foreign target), AnalysisSnapshotCache.test.ts.
  • Remaining proof gaps: the JSON.stringify compare has no reproducible failure today, because zod's parsed member order matches snapshotTarget's construction order. This change removes the order dependence; it does not fix an observed bug.

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 check:fast: passed (typecheck, lint, architecture guards)
  • npm run test:focused -- src/domain/targetIdentity.test.ts src/domain/analysisSnapshot.test.ts src/application/binary/AnalysisSnapshotCache.test.ts src/application/binary/TargetFormatVocabularies.test.ts: 4 files, 107 passed (after the kind fix)
  • npm run test:focused -- the 8 test files importing BinaryTargetResolver (IdaWorkspaceThinning, GhidraDolLoadImage, GhidraDolProfile, BinarySessionBundleResources, LazyAnalysisProvider, auxiliaryDeclarations, managedMemberComparison, managedNativeOsMachine): 99 passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (domain comparison only).
  • Package or release metadata impact: 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

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-15T16:38:44.384854Z
We couldn’t complete this review. Comment @codex review to try again.
01d654c 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.

@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.

@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, with no outstanding actionable findings.

Summary

Snapshot comparisons now share targetIdentityKey. The latest change makes BINARY_TARGET_FORMAT_KINDS own the format-to-kind relationship.

  • Snapshot matching and cache staging use one canonical file identity.
  • Snapshot targets keep each file format paired with its one allowed kind.

Reviews (4) · Last reviewed commit: "fix(domain): refuse snapshot targets who..." · Reviewed by Greptile

Comment thread src/domain/analysisSnapshot.ts Resolved
@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

@greptileai please review the latest commit (8e90b81), which addresses the kind/format finding.

@morluto
morluto merged commit aba42b4 into main Nov 15, 2026
7 of 9 checks passed
@morluto
morluto deleted the refactor/target-identity-key branch November 15, 2026 19:07
@morluto morluto added the area: domain Domain logic, errors, and pure functions label 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant