Skip to content

features review context

bondiano edited this page Nov 12, 2026 · 1 revision

Evidence and context

Active contributors: Vassiliy Kuzenkov (also recorded as bondiano).

The ContextBroker builds addressable, budgeted source packets instead of an unexplained context string. Rendering adds bounded change metadata and typed query answers, while preserving which snapshot and source side every readable span belongs to.

Packet assembly

build_packets in crates/sych-core/src/broker/build.rs builds discovery packets per review unit, followed by verification packets per obligation linked to units. Required spans that do not fit together can be split into up to four filled chunks, including discovery chunks. An obligation can also get an empty final packet recording required material that fit nowhere.

flowchart TD
    Diff["BASE and HEAD hunks"] --> Required["Required spans and obligation seeds"]
    Facts["Collected semantic facts"] --> Neighbours["Depth-1 constructs and neighbours"]
    Other["Syntax, lint, CI and effects"] --> Observations["Risk and contract observations"]
    Required --> Select["Merge and select by priority"]
    Neighbours --> Select
    Observations --> Select
    Select --> Shown["Exact CodeRefs, reasons and links"]
    Select --> Left["Excluded spans, query records and gaps"]
    Shown --> Render["Hash-checked source DATA blocks"]
    Left --> Render
Loading

The broker considers both sides of each changed file:

  • Changed lines and enclosing constructs are required. Hunks get up to three supporting lines before and after, including the insertion point of a pure deletion.
  • Collected callers, callees, used types, implementations, references, readers, writers and tests form a depth-1 neighborhood. Another writer is refuting evidence; most other neighbors support.
  • Syntax risk shapes, lint diagnostics and CI diagnostics can refute. Effect-ledger observations retain their evidence and resolution gaps.
  • Generated files are never packed. Unsupported language semantics, missing facts, unexpanded/gated code and visual-evidence needs are named rather than treated as an empty call graph.

The adapters collected these facts earlier. The broker is not launching live LSP requests while filling packets. See Facts for providers and provenance.

Selection and limits

crates/sych-core/src/broker/select.rs merges overlapping or adjacent spans on one side/path while respecting the span limit. Priority is required → refuting → supporting; within a priority, code precedes prose and HEAD precedes BASE. A tight budget therefore tends to retain the changed implementation before notes or its old version.

The configured budgets are context.initial_tokens_per_unit, context.max_tokens_per_request and context.max_source_files. Broker token estimates are source-byte upper bounds, not a model tokenizer. Limits::from_settings also fixes 160 lines per span, 24 semantic-context items per unit request and 160 across the run. Source-file tracking in packet selection uses (side, path) pairs; it is not identical to the planner's changed-file cap.

A supporting span that does not fit can keep its first line, marked transformation: signature, with its full extent excluded as SIGNATURE_ONLY. A missing required span is REQUIRED_OVER_BUDGET; missing refuting material also adds REFUTING_OVER_BUDGET. Neither is silently presented as full context.

crates/sych-app/src/review/outcome.rs estimates run demand as twice the selected packet bytes, for search and verification. If it exceeds the analysis input cap, packets can be rebuilt with proportionally smaller request budgets, no lower than a quarter of the original and preserving the largest already-selected required span where possible. This is compression by selection, not model-written source summaries; it does not guarantee that every later call fits.

Each packet records fragments, selection reasons, evidence IDs, relations, semantic-query status/completeness, exclusions, gaps, usage and PacketResolution. Raw source is read back from pinned blobs, not stored inside the packet. SATISFIED describes source availability, not the truth of an obligation. Planning and reduction explains which gaps force UNKNOWN or partial coverage.

What the prompt can name

crates/sych-core/src/analysis/context.rs assigns local ref-N IDs to numbered spans and ev-N IDs to evidence; templates assign ob-N, c-N and cand-N. The model returns an anchor {ref_id, start_line, end_line}. The harness resolves it into a CodeRef; it does not accept model-authored hashes or finding coordinates.

An anchor must name an existing reference. If its lines fall outside that named span, they may still resolve through another shown span of the same file and side that contains them. Lines shown only on HEAD do not authorize a BASE anchor. Unreadable or hash-invalid source becomes a limitation, not fabricated text.

Packet source evidence is kind SOURCE, trust SOURCE_OBSERVATION, VALID, and bound to the snapshot. It is COMPLETE_FOR_QUERY for exactly its selected spans when no required span is excluded, otherwise PARTIAL. Selection's semantic facts can still be partial. Redaction occurs when prompts render: source, broker answers and candidate text remain untrusted DATA, while accepted target-tip rules/contracts are trusted task text. Models and Security cover prompt fencing and transport boundaries.

Change metadata beyond selected spans

The renderer adds:

DATA block Scope and bound
Shown-file changes Every hunk coordinate and total removed/added line counts for changed files with a shown path
Other file changes Added, deleted, renamed or copied files outside the spans, up to 50 entries, remainder counted
Generated changes Paths, status and line counts only, up to 50 entries; no generated content
Test/CI removals For the shipped test-integrity obligation, recognized changed test/CI paths even if their spans were omitted
Moved blocks Moves touching a shown file, up to 40 entries, remainder counted

The hunk index says -start,count +start,count; it is not a second full textual diff. Test-removal rendering separately reads up to 40 genuinely removed BASE lines per recognized file and up to 40 replacing HEAD lines from replacement hunks. Add-only files explicitly say 0 lines removed. Moved lines are described as moves instead of consuming that removal excerpt.

Recognizing moved code

moves in crates/sych-core/src/analysis/context/moves.rs compares removed BASE hunk runs with added HEAD hunk runs across the nonhidden change. It is a deterministic text matcher, separate from Git rename status and semantic effect matching.

  1. Read the pinned old/new file texts. Trim leading and trailing whitespace from each compared line; internal text and order must still match.
  2. Index added runs by their first three lines. A start line must contain a letter or digit; a brace or blank line alone cannot start a block. Repeated starts such as #[test] remain eligible.
  3. Extend matching runs. A block needs at least 3 lines and 20 alphanumeric characters.
  4. Choose longest blocks first globally, with manifest-order tie breaking. Each removed line and each added line can belong to at most one move.
  5. If a longer match consumes part of another block, return its qualifying free sub-blocks to the competition rather than discarding the entire shorter match.
  6. Stop candidate-place enumeration after 1,000,000 pairs and disclose that later moves may still read as removed/new.

The resulting summary names inclusive source and destination ranges, for example tests/lint.rs:15-40 moved to tests/common/repo.rs:14-39. General assessment, discovery and audit contexts list relevant moves; verification extends those contexts, so it sees them too. Test-removal context reports totals such as 51 lines removed, 40 of them moved, then shows only the genuinely removed lines as removals.

This observation prevents a test extraction from being described merely as lost coverage. It does not prove behavior preservation: changes to names, scopes, imports, registration or surrounding guards still require review. A changed function signature can leave only the unchanged body recognized as a move. Blocks across different hunk runs are not joined, and unreadable/hidden source cannot supply a match. The work-bound disclosure is prompt metadata, not by itself a reducer task gap.

Tests in crates/sych-core/tests/analysis/moves.rs cover indentation, short noise, test/helper extraction, longest-first selection, partially consumed blocks, repeated starts and the work bound.

Typed evidence requests

Models may request read_lines, find_references, find_callers, find_callees, find_implementations or search_source. ContextAsk translates these into the broker's closed Operation enum; there is no shell, URL or database operation.

Per discovery/verifier reply, at most four nonblank-question asks are accepted. read_lines permits at most 160 lines and stays exact. Semantic edge queries use collected changed-construct facts; a construct not in those facts is UNSUPPORTED, and an answered edge is still PARTIAL because an empty semantic answer does not prove absence. At most three answer spans are added by the review engine, with the reason answer to: …; further matches make the displayed answer partial.

Generated read_span/read_symbol content is unsupported. Search excludes generated hits and states how many it dropped; secret paths are not shown. These exclusions are not bypassed by expansion.

Search windows

search_source searches file contents, never paths, with a one-line fixed string of 1 to 200 characters. Model asks use a 10-hit result limit. The Git reader in crates/sych-adapters/src/git/reader.rs runs literal git grep -F against the selected pinned commit with a five-second timeout.

For each selected search hit, around in crates/sych-core/src/analysis/search_context.rs tries up to eight neighboring lines on each side from the same snapshot and blob. A one-line Git hit therefore expands to at most 17 lines and 4096 source bytes:

  • Clamp at file edges.
  • If the byte cap is exceeded, halve the radius from 8 to 4, 2 and 1.
  • Verify the expanded reference and read its hash-checked source.
  • If expansion fails, the blob/snapshot differs, or no window fits, retain the original exact hit. The 4096-byte cap applies to an expanded span, not a promise that an original oversized line is truncated.

The answer explicitly says these are bounded windows, not necessarily whole constructs. A helper's nearby guard or return can be visible without pretending to supply its entire body. Explicit read_lines and semantic edge spans are not expanded.

BASE and HEAD counterpart summaries

Every literal answer states where it searched and independently runs the same literal across the counterpart tree:

Requested side Counterpart
DIFF_BASE, displayed as BASE HEAD
HEAD BASE
TARGET_TIP HEAD

The counterpart query uses a 10-hit limit and lists up to three path:line locations, counting further hits. A cut result says at least that many matches; an unsupported/failed counterpart says it was not searched. This summary is DATA text, not extra anchored counterpart spans.

When the requested search is complete and empty, matching HEAD text can be described as added, or matching BASE text as removed. A failed or partial requested search never earns that inference. For example:

no matches in file contents (paths are not searched)
searched BASE (before this change); HEAD (this change) has 2 matches: src/a.rs:15, src/b.rs:374: the change adds them

This does not upgrade an incomplete requested answer or prove semantic usage. The shared prompt rule is explicit: “Unused” or “missing” needs a complete HEAD search: BASE predates this change. File existence comes from change metadata, not from a failed content lookup.

Cross-file removal context

For candidates anchored on removed BASE lines of a file that still exists, crates/sych-core/src/analysis/context/lost_names.rs follows up to 12 identifiers no longer present anywhere in that file's HEAD. It tokenizes identifiers of at least three bytes; it is not name resolution.

For each name it scans other nonhidden changed files: up to three removed lines per file and 40 verbatim lines overall, counts of additional removals, deleted files naming it, and added lines naming it. A guard removed together with its field can then be judged as one change rather than “nothing replaces it.” If the guarded file is deleted or its new text is unreadable, this particular summary is not produced.

Key source files and change entry points

Source Change here for
crates/sych-core/src/broker/build.rs Packet construction, diff context and fixed broker limits
crates/sych-core/src/broker/neighbours.rs Collected semantic neighborhoods and query-limit gaps
crates/sych-core/src/broker/observations.rs Syntax, effect, lint and CI selection
crates/sych-core/src/broker/select.rs Priority, merging, chunking and signature fallback
crates/sych-core/src/broker/ops.rs Typed read/search exclusions and completeness
crates/sych-core/src/analysis/context.rs Reference resolution, change metadata and test-removal rendering
crates/sych-core/src/analysis/context/moves.rs Text-move matching, overlap policy and work bound
crates/sych-core/src/analysis/context/lost_names.rs Cross-file evidence for removed-name hypotheses
crates/sych-core/src/analysis/search_context.rs Neighboring windows and counterpart summaries
crates/sych-core/src/analysis/discovery.rs Ask validation, answer limits and explanatory DATA

crates/sych-core/tests/analysis/answers.rs tests exact reads, partial answers and two-sided summaries. crates/sych-adapters/tests/git_snapshot/search_context.rs tests pinned blobs despite a dirty working tree, Unicode/file edges, exact byte boundaries, expansion failure and exclusions. Its selected safe/unsafe cases measure evidence availability, not model accuracy. crates/sych-app/tests/verify_search.rs checks that an unchanged helper's guard and cross-file field removal reach verification.

See Review analysis for counting definitions and Model passes for when these bounded requests run.

Clone this wiki locally