Skip to content

feat(provider): import Diaphora binary-diff evidence - #252

Open
2233admin wants to merge 1 commit into
mainfrom
codex/issue-251-diaphora-provider
Open

feat(provider): import Diaphora binary-diff evidence#252
2233admin wants to merge 1 commit into
mainfrom
codex/issue-251-diaphora-provider

Conversation

@2233admin

Copy link
Copy Markdown
Owner

Closes #251

Summary

  • import pre-produced Diaphora SQLite result databases without installing, embedding, or executing Diaphora / IDA
  • bind the observation to SHA-256 digests of both binaries and the result database, validate the native result schema, and emit bounded advisory findings
  • register the optional verification-stage provider and document the explicit AGPL external boundary

Verification

  • cargo fmt --all --check
  • cargo test -p code-intel --quiet
  • cargo build --release -p code-intel
  • release CLI smoke and orchestration manifest validation

@repowise-bot

repowise-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

✅ Health of changed files: 5.3 → 6.1 (+0.7)
🚨 Change risk: high, riskier than 86% of this repo's commits.

📋 At a glance
4 hotspots touched · 5 new findings introduced · 2 co-change pairs left out · 2 files with recent fix history. Scoped to crates.

✅ Health gate: passed

📌 Before you merge

  • orchestration/integrations.json changed together with .../src/main.rs in 19 past commits and isn't in this PR
  • orchestration/internalization/sentrux.json changed together with .../src/main.rs in 12 past commits and isn't in this PR
  • Docs that usually track this code: README.md, CHANGELOG.md
🔎 More signals (3)

🗺️ Change map

flowchart LR
  subgraph PR ["Changed in this PR (1 with dependents)"]
    f_crates_code_intel_cli_src_main_rs[".../src/main.rs 🔥"]:::changed
  end
  f_crates_code_intel_cli_src_change_risk_git_rs[".../change_risk/git.rs"]
  f_crates_code_intel_cli_src_main_rs --> f_crates_code_intel_cli_src_change_risk_git_rs
  f_crates_code_intel_cli_src_doctor_adapter_rs[".../src/doctor_adapter.rs"]
  f_crates_code_intel_cli_src_main_rs --> f_crates_code_intel_cli_src_doctor_adapter_rs
  w_orchestration_integrations_json(["⚠️ orchestration/integrations.json changed together 19×, not in PR"]):::warn
  f_crates_code_intel_cli_src_main_rs -.- w_orchestration_integrations_json
  w_orchestration_internalization_sentrux_json(["⚠️ orchestration/internalization/sentrux.json changed together 12×, not in PR"]):::warn
  f_crates_code_intel_cli_src_main_rs -.- w_orchestration_internalization_sentrux_json
  classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
  classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
  classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Loading

Solid arrows: code that imports the changed files (2 direct dependents, from the last indexed snapshot). Dashed: history/tests.

🔥 Hotspots touched (4)

  • .../src/main.rs: 39 commits/90d, 6 dependents
  • .../command_catalog/mod.rs: 9 commits/90d, 1 dependents
  • .../cli/legacy.rs: 7 commits/90d, 4 dependents
1 more
  • .../command_catalog/tests.rs: 8 commits/90d, 3 dependents

🔗 Hidden coupling (1 file)

  • .../src/main.rs co-changes with these files (not in this PR):
    • orchestration/integrations.json (19×, 🟡 notable)
    • orchestration/internalization/sentrux.json (12×, 🟡 notable)
    • README.md (11×, 🟡 notable)

📊 See the full report for this PR
Your repo map with this PR's blast radius lit up, every caller of the contracts it changes, and health before and after. No sign-in. · ⭐ Star Repowise · 📥 Install bot · Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot · Updated 2026-08-09 03:28 UTC

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added read-only Diaphora result-database inspection through the CLI.
    • Reports comparison hashes, match summaries, bounded top matches, and provider status.
    • Added optional Diaphora verification integration with structured observation output.
    • Added validation for required database content and input arguments.
  • Documentation

    • Documented setup, usage, output, failure handling, and authority boundaries.
  • Tests

    • Added coverage for successful results, unavailable or rejected databases, invalid arguments, hashes, and output schema.

Walkthrough

Adds an optional, read-only Diaphora provider. The CLI validates SQLite result databases, hashes inputs, emits bounded observation artifacts, and reports unavailable or rejected states. Route metadata, orchestration integration, schema contracts, tests, help output, and documentation are included.

Changes

Diaphora provider integration

Layer / File(s) Summary
Observation contract and integration metadata
orchestration/schemas/code-intel-diaphora-observation.v1.schema.json, orchestration/integrations.json
Defines status-dependent observation fields, comparison digests, match summaries, failure details, and observation-only authority. Registers the optional provider.diaphora integration.
Read-only database inspection
crates/code-intel-cli/Cargo.toml, crates/code-intel-cli/src/main.rs, crates/code-intel-cli/src/diaphora_provider.rs
Adds SQLite and SHA-256 support. Parses and validates arguments, inspects required Diaphora tables, summarizes results, hashes inputs, constructs observations, and writes JSON output.
CLI route registration and dispatch
crates/code-intel-cli/src/cli/command_catalog/routes/*, crates/code-intel-cli/src/cli/command_catalog/mod.rs, crates/code-intel-cli/src/cli/command_catalog/tests.rs, crates/code-intel-cli/src/cli/legacy.rs, crates/code-intel-cli/tests/fixtures/cli-head-parity.v2.json
Registers typed provider routes, dispatches ProviderDiaphoraInspect, updates route counts, and documents the command in help output.
Provider validation and documentation
crates/code-intel-cli/tests/diaphora_provider.rs, docs/diaphora-provider-adapter.md
Tests successful imports, unavailable databases, rejected databases, invalid arguments, path redaction, schema restrictions, and authority boundaries. Documents commands, outputs, statuses, and exit codes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant diaphora_provider
  participant SQLiteDatabase
  participant ObservationArtifact
  CLI->>diaphora_provider: run_raw arguments
  diaphora_provider->>SQLiteDatabase: open read-only and inspect schema
  SQLiteDatabase-->>diaphora_provider: configuration, matches, and unmatched results
  diaphora_provider->>ObservationArtifact: serialize observation with hashes and summaries
  ObservationArtifact-->>CLI: write and print JSON
Loading

Possibly related PRs

Suggested labels: risk-accepted

Poem

A rabbit checks the SQLite night,
Hashes binaries left and right.
Matches peek from bounded rows,
Unavailable status plainly shows.
No gate is claimed, no facts are spun—
Diaphora’s quiet work is done.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: importing Diaphora binary-diff evidence through a provider.
Description check ✅ Passed The description directly explains the Diaphora provider, evidence handling, external boundary, and verification steps.
Linked Issues check ✅ Passed The changes implement the Rust-only provider, evidence contract, bounded advisory output, tests, documentation, and optional external Diaphora boundary.
Out of Scope Changes check ✅ Passed The route registration, CLI documentation, schema, tests, and dependency changes support the linked issue objectives.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the risk-accepted 人已审阅并接受高风险评分,放行 pr-gate label Aug 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/code-intel-cli/src/diaphora_provider.rs`:
- Around line 143-151: Update inspect so result_database_sha256 is computed from
the same stable SQLite state that the read-only Connection inspects: either
reject journal/WAL sidecars before hashing and opening, or create a stable
snapshot, hash it, and inspect that snapshot. Ensure the emitted rows remain
cryptographically bound to result_database_sha256 while preserving the existing
base and candidate hashing.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e2bdcbcb-fbe8-4e43-ad38-2d6237bd65d2

📥 Commits

Reviewing files that changed from the base of the PR and between f9bbe2b and 7e84aab.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • crates/code-intel-cli/Cargo.toml
  • crates/code-intel-cli/src/cli/command_catalog/mod.rs
  • crates/code-intel-cli/src/cli/command_catalog/routes/mod.rs
  • crates/code-intel-cli/src/cli/command_catalog/routes/provider_routes.rs
  • crates/code-intel-cli/src/cli/command_catalog/tests.rs
  • crates/code-intel-cli/src/cli/legacy.rs
  • crates/code-intel-cli/src/diaphora_provider.rs
  • crates/code-intel-cli/src/main.rs
  • crates/code-intel-cli/tests/diaphora_provider.rs
  • crates/code-intel-cli/tests/fixtures/cli-head-parity.v2.json
  • docs/diaphora-provider-adapter.md
  • orchestration/integrations.json
  • orchestration/schemas/code-intel-diaphora-observation.v1.schema.json

Comment on lines +143 to +151
fn inspect(cli: &Cli) -> Result<Value, InspectionError> {
let base_binary_sha256 = file_sha256(&cli.base_binary, "base binary")?;
let candidate_binary_sha256 = file_sha256(&cli.candidate_binary, "candidate binary")?;
let result_database_sha256 = file_sha256(&cli.result_db, "Diaphora result database")?;
let connection = Connection::open_with_flags(
&cli.result_db,
OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_NO_MUTEX,
)
.map_err(|_| InspectionError::Rejected("Diaphora result database is unreadable".into()))?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== repository files around target =="
git ls-files | rg '(^|/)diaphora_provider\.rs$|crates/code-intel-cli/src|Cargo\.toml'

echo "== target file outline =="
ast-grep outline crates/code-intel-cli/src/diaphora_provider.rs --view expanded || true

echo "== target file relevant lines =="
nl -ba crates/code-intel-cli/src/diaphora_provider.rs | sed -n '1,260p'

echo "== search for resultDatabaseSha256 and related hashes =="
rg -n "resultDatabaseSha256|base_binary_sha256|candidate_binary_sha256|file_sha256|result_db|wal|WAL|journal" crates/code-intel-cli/src -S

Repository: 2233admin/code-intel-pipeline

Length of output: 9824


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files mentioning Diaphora sqlite inspection =="
rg -n "Diaphora|diaphora|sqlite|Sqlite|OpenFlags|SQLITE_OPEN" -S .

echo "== tests for inspect/result database =="
rg -n "#\\[test\\]|inspections|Inspect|Inspection|result database|result_db|wal|WAL" crates/code-intel-cli/src tests integration-test -S 2>/dev/null || true

Repository: 2233admin/code-intel-pipeline

Length of output: 50385


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target file relevant sections =="
sed -n '130,215p' crates/code-intel-cli/src/diaphora_provider.rs
echo "== tail =="
sed -n '320,435p' crates/code-intel-cli/src/diaphora_provider.rs

echo "== tests relevant sections =="
sed -n '1,260p' crates/code-intel-cli/tests/diaphora_provider.rs

echo "== schema relevant fields =="
sed -n '1,130p' orchestration/schemas/code-intel-diaphora-observation.v1.schema.json

echo "== docs relevant sections =="
sed -n '1,55p' docs/diaphora-provider-adapter.md

Repository: 2233admin/code-intel-pipeline

Length of output: 22172


🌐 Web query:

SQLite WAL mode read transactions read-only connection includes WAL file

💡 Result:

In SQLite WAL (Write-Ahead Logging) mode, a read-only database connection can indeed read from the WAL file, and this is a core part of how WAL mode enables concurrent reading and writing [1][2]. When a connection performs a read transaction in WAL mode, it does not exclusively rely on the main database file. Instead, it uses the WAL file and the associated shared memory (-shm) file to access a consistent "snapshot" of the database as it existed when the read transaction began [1][2][3]. If a requested page has been modified by a committed transaction, the reader retrieves the most recent version of that page from the WAL file rather than the main database file [1]. Historically, all connections to a WAL-mode database—including read-only ones—required write permission to the directory containing the database to create or access the -shm and -wal files [1][4]. However, as of SQLite version 3.22.0, this constraint has been relaxed [1]. A read-only process can now access a WAL-mode database without needing write permissions, provided one of the following conditions is met [1]: 1. The -shm and -wal files already exist and are readable by the process [1]. 2. The database connection is opened using the "immutable" query parameter (e.g., in a URI filename), which signals that the database is on read-only media and cannot change, thereby bypassing locking and change detection [1][5][6]. 3. The process has write permission on the directory to create the -shm and -wal files if they are missing [1]. If a database is intended to be used on read-only media, it is generally recommended to convert it to a different journal mode (such as journal_mode=DELETE) to avoid the dependencies and potential file-access issues associated with WAL files and -shm files [1][7].

Citations:


Use one stable digest for the inspected SQLite snapshot.

resultDatabaseSha256 only hashes cli.result_db before SQLite opens it. A WAL-backed database can expose -wal contents through this read-only connection while that digest does not cover them. Reject journal/WAL sidecars, or take one stable SQLite snapshot and hash the snapshot before inspection so resultDatabaseSha256 actually binds the emitted rows.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/code-intel-cli/src/diaphora_provider.rs` around lines 143 - 151,
Update inspect so result_database_sha256 is computed from the same stable SQLite
state that the read-only Connection inspects: either reject journal/WAL sidecars
before hashing and opening, or create a stable snapshot, hash it, and inspect
that snapshot. Ensure the emitted rows remain cryptographically bound to
result_database_sha256 while preserving the existing base and candidate hashing.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Code Intel change risk

Score Percentile Level
66/100 82th (vs last 49 commits) 🟡 medium

Top signals

  • Diff shape: 14 file(s), +1106/-21 (max file share 0.39)
  • Test asymmetry: source changed, tests touched
  • Bug-magnet: 34 fix commit(s) in touched files (180d)
  • Churn: 175 commit(s) touching these files (90d)

revspec: origin/main..HEAD · threshold: percentile >= 90 blocks unless labeled risk-accepted · code-intel change risk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-accepted 人已审阅并接受高风险评分,放行 pr-gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(provider): import Diaphora binary-diff evidence

1 participant