mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 18:06:46 +00:00
* feat(providers): retain provider selection provenance with session evidence The registry records how a deep provider became selected and why every other candidate was rejected, and binary_session exposes those facts for the active route. Evidence already carried provider identity, but nothing recorded which candidates the session evaluated, so a retained record could not explain why this engine produced the observation or what the alternatives were. Attach provider_selection to Evidence admitted by the session: the selection source and, for each evaluated candidate, its identity and version, selection state, availability and target-support outcome, and the stable rejection codes. The field is optional and excluded from semantic identity, following caller_input_path, so each admitted record stays attributable to the exact provider instance without changing observation identity, evidence IDs or replay. Copy only stable selection facts. Candidate diagnostics, remediation prose and target content stay in the session status projection instead of being repeated in every record. * style(domain): reformat the provider-selection assertion oxfmt --check rejected the three-line expect() call; the formatter's single-line layout is the canonical one, so Static checks failed only on formatting. * fix(evidence): keep a rejected record inside the Result boundary `recordEvidence` ran `withEvidenceProviderSelection` before handing the record to the ledger. That helper parses to seal the rebound envelope, so a tampered or otherwise invalid record threw a `ZodError` from the attribution step and never reached `EvidenceLedger.record`, which is where the declared `Result` is produced. `tests/boundary/mcp/processEvidenceIdentityMcp.test.ts:454` asserts `session.recordEvidence(tampered).ok === false` and fails on the throw. Authenticate the input first and return the ledger's own rejection for a value it would refuse anyway; attribution then only ever sees a record its reader accepts. * fix(binary): attribute imported records to the recording session Import replaces a same-ID record's presentation metadata, and provider_selection is part of that metadata. When runDirectAnalysis imports the provider's own bundle, the copy it rebuilds carries no selection, so the import erased the attribution the session had stamped and the caller kept an unattributed record instead. Attribute at both merge sites, where the session already authenticates everything it admits. A refreshed route after a failed switch can bind a different selection than the one the earlier binding held, so re-derive it there as the initial open does; spreading the previous binding kept the stale value. * fix(binary): admit record input before sealing it for attribution recordEvidence and the two bundle import paths seal Evidence through withEvidenceProviderSelection before handing it to the ledger. A sealed value skips the ledger's ordinary-JSON and heap-headroom admission, so a session with no authentication allowance accepted a mutable record and a large record was copied and traversed before the guard ran. Hold the caller's own value to that admission first, then attribute. The import paths also refuse with a Result instead of falling through to an unattributed import when admission fails. * fix(binary): re-attribute a sealed record without traversing it again recordEvidence now admits the caller's value before attributing it, but a record returned by evidenceForAnalysis has already been through that admission and is sealed. Running the ordinary-JSON walk and the heap-headroom check over it again repeats the work the ledger itself skips for a sealed value. Ask the ledger first: a value it holds is the admission it made, so the check costs one lookup. Only a value the ledger has not seen pays for the full walk. * fix(providers): return the recorded Evidence after import Import re-stamps session provenance onto the Evidence it records, but callers kept the pre-import copy, so retained selection attribution and cache metadata were dropped from what analysis reported. Read the recorded record back after a successful import, and leave an already-retained record as the ledger attributed it instead of re-deriving attribution from the caller's copy. * fix(providers): keep the caller's copy when re-attributing an imported record The merge with main brought in the unchanged-record path, where an import whose only change is display metadata now replaces the ledger's record. Re-attributing that incoming value put the session's provider selection on the caller's copy, so the import reported a record that differed from what the caller sent. Attribution now applies only to records the ledger does not already hold. The snapshot cache test now asserts the session's attribution explicitly instead of byte equality with the un-attributed source. * fix(providers): keep the caller's record when importing over a retained one The previous change skipped attribution for a record the ledger already held, which left the imported copy's own selection — missing or from another session — in place. Import replaces a same-ID record's presentation metadata, and provider_selection is part of it, so the session's attribution wins over the caller's copy while the caller's other display metadata is kept untouched. * fix(providers): attribute staged snapshot and unknown-mutation Evidence Address the open review findings on session provider provenance: - importAnalysisSnapshot merged the re-attributed bundle into the ledger but staged the snapshot's own bundle, so AnalysisSnapshotCache rebuilt replay bindings from records the merge had replaced. Hand the merged bundle back to the stage so replays bind to the attributed evidence. - recordResult recorded an attributed record and then serialized the caller's copy, so successful MCP responses omitted provider_selection while the ledger and exports carried it. Read the recorded Evidence back before delivery, as the direct analysis path already does. - recordUnknown and updateUnknown synthesized unknown-mutation Evidence without the active session's provider selection, so those exported records were unattributed. Thread the binding's selection through to unknownMutationEvidence, which is where the record is produced. * fix(providers): attribute the atomic Evidence-and-Unknown mutation record recordEvidenceWithUnknown synthesizes its own rea.residual-unknown-mutation record, so the selection the session threads into recordUnknown and updateUnknown never reached it. The atomic comparison workflows therefore exported one record without provider_selection, contradicting the guarantee that every admitted record carries the recording session's selection. Thread the active binding through the atomic method as well; analyst-authored mutation records still keep analyst-inference authority and gain only the session selection. * fix(evidence): require one selected candidate in provider provenance provider_selection carries no separate selected-provider id, so a reader can only name the recording session's provider when exactly one candidate claims the selection. The schema accepted any candidates array, so an imported bundle could re-export zero or several selected candidates under a stable Evidence id and consumers would have no way to resolve the provider. The recording paths always derive the selection from a single bound provider (AnalysisProviderRegistry selects one usable candidate, and SessionProviderRouter marks only the bound id selected), so the refine rejects only foreign input. * fix(evidence): adopt the recording session's selection on a duplicate record Recording an observation the ledger already holds under the same semantic ID returned duplicate and discarded the attributed object, so lookup and export kept the imported record's missing or foreign provider_selection. Replace the retained display metadata with the active selection on that path; semantic identity and the stored payload stay the same record. The provenance schema also accepted a selected candidate that is unavailable or unsupported, which no registry path can bind. Require the selected candidate to be available and supported so an imported bundle cannot re-export a selection that never occurred. * fix(evidence): keep retained display metadata and notify observers on duplicate Attribution replaced the whole stored record with the incoming copy, so a provider-produced duplicate without the caller-selected path, alias set or subject display erased the metadata the recording session retained merely to add provider_selection. Adopt only the display facts the incoming copy actually carries; omission is not deletion. Import keeps its documented replace semantics. The duplicate branch also returned before refreshEvidenceMetadata and #emitSnapshotChanged, so replay caches and snapshot subscribers kept the old metadata after a successful replacement. Treat a non-no-op replacement exactly as the import path does. * fix(artifacts): compare Evidence by identity across a replay session The composed-workflow test opened a second fixture, which writes its own temp artifact, so a replay record's subject path and the session-attributed provider selection no longer matched the snapshot copy. Both are display metadata outside the Evidence id; the provider call is what establishes the binding here, so compare the content the id commits to and assert the ids separately, which the test already does. Also apply the formatter to BinarySessionInvestigation.test.ts, which fails format:check on its own. * fix(server): deliver the retained copy that carries the session selection Recording stamps the active session's provider selection onto the ledger copy of a semantic ID. The tools that build or project their own Evidence value then delivered that unattributed copy, so the MCP response and the snapshot export disagreed for the same evidence_id: Ghidra reference and evidence flows, composed workflow overviews, analysis functions and the process capture tools all failed deep-equality against the retained record. Hand the delivered copy the session's selection when the ID is retained. Other retained display metadata, such as a caller path carried by an imported record, stays as the caller built it. * test(investigation): keep the session test within its lint and format limits Two checks on this branch failed for reasons the branch itself introduced: format:check wants the withEvidenceProviderSelection call in UnknownEvidence.ts wrapped at its argument list, which the branch's edit moved off. lint reports max-lines-per-function (152 lines, limit 150) for the "reobserves resource-scoped ..." case after the branch expanded two assertions in it. The provider-selection expectation is a fixed value, so it moves to a module-level constant and the case drops back under the limit without weakening either assertion. * fix(server): carry the session selection on the workflow copy delivered Commit76d14ff9fstamped the delivered copy with the retained session selection by patching registerEnhancedTools and registerEvidenceTools. Upstream #11617 replaced both with the shared contract bindings, so the merge dropped the stamp and the composed-workflow tools delivered an unattributed copy again: workflowSnapshotReplayMcp compares the live binary_overview response against the replayed Evidence and saw 19 fields against 18. Stamp at createAnalysisToolHandler, where every analysis workflow's Evidence leaves for delivery, using the retention lookup already passed in. A call whose ID is not retained, or whose record carries no selection, is delivered unchanged. * chore(schemas): record the provider_selection evidence schema digest Adding provider_selection to the shared Evidence schema changes the output compact schema of every tool that returns Evidence, so Build package rejects 211 stale advertised catalog summaries. The summaries were refreshed by running npm run verify:advertised-schemas -- --update-summary; each file changes only its output compact digest. * test(mcp): assert retained provider attribution instead of producer identity Recording now stamps the session's provider selection onto retained Evidence, so a producer-built copy and the retained record share every semantic member but differ in provider_selection. Replace raw object identity/equality assertions with display-metadata agreement plus a selection-neutral deep comparison, and deliver the retained selection from contract tools so callers do not receive an unattributed copy of the same evidence_id. Verified: tests/boundary/mcp (345 files, 2289 passed / 12 skipped after generating .cache/mcp-tool-catalog.json); npx tsc --noEmit exit 0. * test(mcp): share the selection-neutral comparison across provenance assertions Seven sites repeated the same spread-and-mask expression, which pushed the test past the 150-line function limit and failed Static checks. Move it into a withoutSelection helper that drops the session's provider_selection stamp and compare both sides through it. Verified: npm run check:fast (typecheck, lint, architecture guards); the six boundary files CI reported, 37 passed. * test(mcp): fold repeated retention checks into one helper Static checks failed on format:check for three files and then on max-lines-per-function after oxfmt re-wrapped the assertions. Run oxfmt on the three files and replace the repeated selection-neutral comparisons with an expectRetained helper so the test stays under the 150-line limit. Verified: npm run check:fast (typecheck, lint, architecture guards); npm run format:check; the six boundary files CI reported, 37 passed. * test(snapshot): compare retained records without the session selection stamp The same attribution change makes a fixture-built record differ from the retained one by provider_selection alone, so the equality assertion failed in both the portable and sharded lanes. Mask the stamp and keep every semantic member under strict comparison. Verified: npx vitest run tests/boundary/filesystem/analysisSnapshotProvenance.test.ts, 2 passed; npm run lint (0 errors); oxfmt --check. * chore(schemas): record the provider_selection output digest on five tools The session_provider_facts binding gained a .describe() explaining that the selection source and candidate outcomes are retained with each admitted Evidence record. That text is part of the advertised output schema, so every tool whose output embeds the binding has a new compact digest. Regenerate the committed catalog summaries with npm run verify:advertised-schemas -- --update-summary. Only the five output compact hashes change; no tool's shape or pattern changes. * fix(evidence): keep a retained record's caller-selected path when adopting metadata adoptEvidenceDisplayMetadata let a later copy's caller_input_path overwrite the value already held under the same semantic id, so a second selection through a different alias rewrote the display path the first selection recorded. Prefer the retained value and take the incoming one only as a fact the retained record lacks. * fix(evidence): stamp the session provider selection on summarized delivery Recording stamps the active session's provider_selection onto the retained record under the same Evidence id. The summary delivery path re-admitted the summarized copy without that stamp, so a caller reading a summarized result saw no provider_selection while the retained record carried one, and the response and the retained view disagreed for a single id. Pass the retention lookup to deliverEvidenceResult on both the analyze_function and external-mutation summary paths so the delivered copy carries the same stamp. * chore(schemas): refresh UEFI tool summaries for the Evidence schema change main added the UEFI inspection and extraction tools after this branch regenerated the advertised catalog summaries, so their output compact digest still recorded the pre-provider_selection value. Regenerate them so the shared Evidence schema digest matches the branch. * test(investigation): compare borrowed records without the selection stamp Importing a sealed bundle stamps the session's provider_selection onto every retained record, so a borrowed record no longer shares object identity with the caller's unstamped bundle record. Replace the identity and equality assertions with a selection-neutral deep comparison, matching the attribution handling already applied to the snapshot and MCP provenance tests. * fix(investigation): admit unknown mutations against their expanded Evidence record_unknown and update_unknown check authentication headroom against the caller's input before building the mutation Evidence. The Evidence repeats parts of the input (for example the question in both parameters and the normalized result), so with live headroom that admits the input but not the larger record, the operation authenticated and sealed a representation past the stated bound. #readEvidence skips the admission for immutable records, so nothing downstream re-checked it. Charge the derived Evidence's authentication cost in addition to the input before sealing it, across the record, atomic record-with-unknown and update paths. The regression test finds an allowance between the two sizes and asserts the operation is refused with no Evidence recorded. * chore(schemas): refresh advertised summaries after the provider-selection change The advertised-schema catalog digests still described the pre-change input schemas, so the Build package lane failed with 28 missing or stale summary files and skipped every lane downstream of it. Regenerate the summaries with npm run verify:advertised-schemas -- --update-summary. * test(deno): damage Deno PE resource framing at the directory entry The fixed-allowance case shrank the language directory Size to make the 65,535-row table malformed, but #14253 now walks resource trees at their RVA whatever Size declares, so the table stayed well-formed and the run reported the entry allowance (truncated/limit) instead of malformed framing (unsupported_target/malformed). Point the type directory's entry at a language directory outside the file-backed resource bytes, whose header cannot be read. This mirrors the fix already on main (271bad782). * fix(evidence): preserve source provenance and admit before copying * fix(providers): scope selection provenance to native executions * fix(providers): carry native provenance through workflow projections * fix(providers): retain selection on shared session limitations * fix(providers): preserve provenance during source recovery * test(contracts): refresh combined Android reference schema * fix(evidence): admit provider metadata before copying observations * fix(evidence): recover completed calls after context refusal * test(contracts): format merged call path schema summary --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>