Repository navigation
feat(replay): add deterministic shadow replay and tool-output differential isolation - #793
Merged
SHAURYASANYAL3 merged 1 commit intoOct 29, 2026
Conversation
Contributor
🧪 PR Test Results
Python 3.12 · commit ec30304 |
SHAURYASANYAL3
approved these changes
Oct 29, 2026
SHAURYASANYAL3
left a comment
Collaborator
There was a problem hiding this comment.
NSoC '26 Maintainer Verification & Level 3 Approval 🚀
Exceptional engineering work @chanchall26!
- Architecture & Determinism: Pure Plane E shadow replay isolating model stochasticity from recorded tool states without side effects or external HTTP mocks.
- Evidence Integrity: Immutable deep copying in
ToolEvidenceStorewith canonical JSON and argument order invariance. - Classification Engine: Precise categorization across
IDENTICAL_REPLAY,DETERMINISTIC_CORROBORATION,STOCHASTIC_MODEL_DIVERGENCE, andINSUFFICIENT_EVIDENCE. - Quality Gate: 100% green CI across all matrix environments (12/12 successful checks), 42 dedicated unit tests in
tests/replay/test_shadow_replay.py, and comprehensive documentation indocs/v3/SHADOW_REPLAY.md. - Accreditation: Scored for NSoC '26 (Level 3,
soc26).
Merging into main! 🛡️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Description
Adds
agentwatch/replay/shadow.py: a shadow replay engine that isolates whether an observed agent failure came from model stochasticity or from the recorded tool states. A recorded session is re-driven against a model while every tool call is answered from the recorded evidence. Nothing is executed, so replay has no side effects and needs no HTTP mock server. The shadow trace is then compared with the historical one and classified. Full description:docs/v3/SHADOW_REPLAY.md.Fixes #751
ToolEvidenceStore: read-only lookup built from the recorded events. Calls are matched on tool name plus canonical arguments (key order never matters), a repeated identical call gets the first and then the second recorded answer in order, parallel calls are paired bytool_id, and orphan results are counted. Everything served is a deep copy, so a replay cannot change the recording or poison a later run.ShadowReplayRunner/run_shadow_replay: asks aShadowModelfor each decision (temperature 0 and an optional seed inShadowConfig), serves tool results from evidence, and stops when a call has no recorded answer, because everything after it would rest on a made-up value. A terminal event ends the replay, and a bounded number of extra decisions lets a shadow that keeps going show up as a divergence.replay.divergence.IDENTICAL_REPLAY,DETERMINISTIC_CORROBORATION(exact match and the recorded run failed, so the failure reproduces from the recorded tool states),STOCHASTIC_MODEL_DIVERGENCE(the model branched although every tool result matched), andINSUFFICIENT_EVIDENCE(a call had no recorded answer, or evidence was not served faithfully).AgentEvent,canonical_json/sha256_hex, andreplay.divergence.from_step_fnadapts an existing counterfactualStepFn, andPromptCompletionModelre-sends recorded prompts through anycomplete(prompt, config)callable.agentwatch.replay.CHANGELOG.mdanddocs/v3/SHADOW_REPLAY.mdupdated.🏛️ Architectural Plane & Classification
🧪 Verification & Evidence of Testing
ruff check .over the whole repo reports 33 findings inpanopti/andtests/sensors/; none are in files this PR touches.The tests cover: each of the four classifications; a recorded failure that reproduces versus one that does not; a model that diverges on the first decision, stops early, or keeps going; missing evidence (an unrecorded tool, the same tool with different arguments, a call whose result was never captured, more calls than were recorded); argument key order; repeated identical calls served in order; parallel calls paired by
tool_id; orphan results; unused evidence; no network access during replay (sockets are blocked in the test); a model that mutates its history, the recorded decision or the served result cannot change the recording or a later run; repeatability; the temperature and seed reaching the model;PromptCompletionModelandfrom_step_fn; signature behaviour; the divergence cap; JSON-serialisable reports; and the public exports.pytest tests/).🛡️ Security & Linter Quality Checklist
bandit -r agentwatchwith 0 issues found.bandit-baseline.jsonwas NOT created or edited.ruff format --check agentwatch/(Clean pass).ruff check agentwatch/(Clean pass).core,evidence.canonicalandreplay.divergenceonly).✍️ Contributor Integrity Declaration
The declaration is left for the account owner to confirm after reviewing the code.
origin/main.Discord Handle: @chanchalguptacse_70080