Repository navigation
feat(trace): a contract action can match writes that add a file or modify one - #1408
Conversation
…dify one `change: add` or `change: modify` on an action of `trace consistency --contract` narrows it to the writes the trace labels so. A whole-file write (Write, >, tee) to a file no earlier call read or wrote is an add; Edit, MultiEdit, NotebookEdit, sed -i, >> and tee -a are modifies. The label is from the trace alone, so a file that existed and was never read in it can be labelled add; the limits are in docs/run-consistency.md. Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…unts as a write, and the redirect that names the file sets the mode Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Mutation of changed linesAt f06a42c: 69 caught · 11 missed Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put
Not checked:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1408 +/- ##
==========================================
+ Coverage 96.48% 96.51% +0.03%
==========================================
Files 533 542 +9
Lines 71339 72587 +1248
Branches 12333 12532 +199
==========================================
+ Hits 68829 70059 +1230
- Misses 1536 1546 +10
- Partials 974 982 +8
🚀 New features to boost your workflow:
|
|
OpenCodeReview: Commit f06a42c was not reviewed. This PR has reached its review limit (6 reviews). CI at `f06a42c`: 6 still running, 20 passing, 3 skipped
To review this commit: re-request review from exai-bot in the Reviewers list. Last review (02db372): no findingsOpen threads from the bot: 0 |
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869L34Q Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869L34R Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869L34U Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869L34Y Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869L34R Thread: PRRT_kwDOVBg7g869L34Y Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869L34R Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869N20r Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869N20t Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869OCzS Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869OKz2 Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869OWAd Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟡 Changes needed · reviewed 02db372
To fix: a change: add contract can pass when it could not label a write, and a cd after || gives the wrong label (line comments); the smaller gaps there are optional.
✅ make ci-local --offline: 31,429 passed, changed lines 100% covered, changed tests pass with 20 seeds · ✅ strict docs build · ✅ the fixes from the earlier exai-bot threads hold (tee -ai, empty change, assignment, ANSI-C and CDPATH prefixes)
Labelling writes as added or modified is a useful split for test-file contracts, and it is documented with its limits.
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869fgjJ Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869fgjX Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g869fgja Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
|
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
Event.directoryand the parsing pipeline use\"\"as the initial/default directory, but the… · NewEvent.directoryand the parsing pipeline use\"\"as the initial/default directory, but the… · NewEvent.directoryand the parsing pipeline use\"\"as the initial/default directory, but the… · Newwrite_directories()computesbackground_start()by scanning backward for every&, making this… · New
What changed in this PR
Adds write-change labeling (add vs modify) to trace consistency --contract, enabling contracts to distinguish new-file writes from edits, and introduces “inconclusive” reporting when a write can’t be safely labeled.
Changes:
- Add
change: add|modifysupport in contract actions, plus “unlabelled write” tracking and inconclusive rule evaluation. - Improve shell write identity by tracking per-command working directories (including CDPATH, subshells, backgrounding, and virtualenv activation) and detecting dynamically-expanded write paths.
- Update CLI reporting/docs and add extensive regression tests, including exit code
3for inconclusive contract outcomes.
| File | Description |
|---|---|
| dokimi/tests/test_context_change_review.py | Adds regression coverage for add/modify labeling, unknown directories, dynamic paths, subagents, and CLI reporting. |
| dokimi/dokimi/repos/shell_words.py | Renames virtualenv activation helper to activates_virtualenv and updates call sites. |
| dokimi/dokimi/repos/shell_walk.py | Moves brace/function-definition tracking helpers into shell_functions and uses the new API. |
| dokimi/dokimi/repos/shell_functions.py | Introduces reusable regex/constants and FunctionDefinition / track_bodies helpers. |
| dokimi/dokimi/context/shell_edit.py | Extracts in-place edit operand parsing (sed/perl) into a dedicated module. |
| dokimi/dokimi/context/shell.py | Adds write mode detection, dynamic-path detection, and per-command directory inference for split shell calls. |
| dokimi/dokimi/context/contract.py | New module: contract parsing + evaluation with change filters and inconclusive verdicts for unlabelled writes. |
| dokimi/dokimi/context/consistency.py | Adds Event.write/change/directory/dynamic_path, labels writes post-parse, and integrates new contract reporting. |
| dokimi/dokimi/commands/context.py | CLI emits “partial” when contract is inconclusive and exits with EXIT_INCONCLUSIVE (3). |
| dokimi/docs/run-consistency.md | Documents change filters, labeling rules, limitations, and new exit semantics. |
| dokimi/changelog.d/20261125_210000_napetrov_contract-modifies.md | Changelog entry describing the feature and limitations. |
Review effort: Lite
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-Lkfc Thread: PRRT_kwDOVBg7g86-LkgV Thread: PRRT_kwDOVBg7g86-Lkg5 Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-Lkhq Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…n add Claude Code's Edit and MultiEdit create a missing file when the (first) old_string is empty, so labelling every Edit as modify let `forbids: new_test` pass for a run that created a new test file. Such an edit is now a whole-file write, labelled like Write. Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
`echo x > tests/test_ol?.py` rewrites tests/test_old.py, but the target was compared literally and labelled add, giving a confirmed `forbids: new_test` violation. Unquoted *, ?, [ and a word-initial ~ now count as expansion, so the rule is inconclusive, as for $name. Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
|
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Comment: IC_kwDOVBg7g88AAAABtTnMpw Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
|
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟡 Changes needed · re-checked 3401d0a
To fix: a new test file written after a cd can still pass forbids: new_test as conforming (reply in its thread), and a function definition keeps a cd that may not have run (line comment).
✅ make ci-local --offline: 33,478 passed, mutation and docs build included · ✅ the round-1 repros: cd a || cd /b, venv activation, subagent cd, CDPATH=/export, functions and loops now give the right directory or none · ✅ tee old new reports the new file
The earlier points are fixed apart from one, and inconclusive rules are now reported, not counted as passes.
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com> # Conflicts: # dokimi/docs/quickstart.md
Thread: PRRT_kwDOVBg7g869fgjX Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-pOp_ Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com> Review: PRR_kwDOVBg7g88AAAABbrQALg
|
Re: review by vlad-perevezentsev
|
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com> (cherry picked from commit e249323eb321bbc70ac425c03170071d835a143c)
antonwolfy
left a comment
There was a problem hiding this comment.
One thing to fix before merge: a brace-expanded tee target is labelled from its literal spelling (inline). The rest holds up.
What I ran, on a Linux review host at c8e0279:
make ci-local: 38 passed, 0 failed, 16 skipped; 34,161 tests pass.- Reproductions for the finding and about 70 shell write forms through
parse_run(cdchains with&&,;,||,&, subshells, groups,if,tee,sed -i,perl -i, redirect forms, quoting, substitutions, globs,~), with no model call. - Mutation: four mutants from the bot's survivor table (
NotebookEditdropped from_WRITE_TOOLS, thekey not in (...)clause in_matches_pattern,e.write = ""inrun_from_events, thecontractclause of the--shell callrefusal) are all caught by the wider context, CLI and repo test files, though not by the two test files that cover this feature.
Checked, no issues
- Directory tracking:
cd /w/tests; ...,cdafter||,{ cd x; },if cd x; then,cd -P, a backgroundedcd,$(cd ...)and a latercd /elsewhereall give the right directory or none. - Verdicts: the lower and upper bounds in
_rule_verdictforrequires,forbids,beforeandafter_lastmatch the docs, and the exit code 3 text inquickstart.mdmatches_emit_consistency. - Repo rules: no schema change; all 40 non-merge commits carry
Signed-off-by; a changelog fragment is present.
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-3Qlp Thread: PRR_kwDOVBg7g88AAAABbyjtPg Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
|
… hit Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟢 LGTM · checked f06a42c · nothing required from @napetrov
🔀 Merge: safe now · merges cleanly into current main, 14 commits behind; its tests pass on the merge · after it, #1190 needs a rebase (commands/context.py) and #1450 too (context/shell.py)
✅ make ci-local --offline: 34,080 passed · test_cli_fault_contract.py[eval score ragas]) and schema_compat come from the base, not this PR · ✅ the new test fails with the fix reverted (2 failed)
The earlier points are fixed, and rules now say inconclusive wherever a write's path is unknown.
Fixed in this branch, up to f06a42c:
- A
change: modifyrule decided with certainty onsed -iafter an unknowncd: 21bb79b counts it as a possible hit, soforbidsandrequiresare inconclusive; tests cover both rules.


Summary
trace consistency --contractcan distinguish new test files from edits to existing tests.Change filters use stream-json traces and require split shell steps. A rule whose verdict depends on an unlabelled write is reported as inconclusive, with counts by action. A confirmed violation makes its run nonconforming. When a run's contract outcome remains inconclusive, the command exits 3.
Evidence
A multi-target
teeproduces one event per path, so one call can modify a previously read file and add another.cd a || cd /b && echo x > f.pycould report an addition under/beven whencd asucceeded. A matching replacement in an unresolved directory could makeforbids: new_testappear to pass without qualification.cd /w/tests && echo x > test_new.pymatches the new-test filter. Regression cases also cover literal virtualenv activation, subagent shell moves, same-callCDPATH, functions, loops and normalized repo events.Merge Danger
An action with
changetests the captured and resolved spellings of a known path. An unlabelled replacement with an unknown path can make a matching action inconclusive. This includes writes whose target depends on shell variable, glob or~expansion.Door: Two-way. The change affects
trace consistency --contractand can be reverted without a persisted schema migration.Blast radius: Trace reporting. Labels come from the recorded path and tool calls. An unread existing file can look new, and an append to a missing file still looks like a modification. See the trace limitations in Run consistency.