Repository navigation
Description
Problem Statement
The CI cache can certify a tree that no check ran on, in two ways. Evidence checked at 9c879ae (branch release/v0.2.25); paths are under src/devops_cli/ unless stated.
1. File arguments.
devops ci <file>anddevops ci --files <file>narrow no check.FileOrSubcommandGrouproutes an unknown token to the group callback as a file (commands/ci.py:46-69), and the callback collects it with_collect_ci_target_files(commands/ci.py:535-544, called at:715)._run_all_checks_asynctakes no files (:723-727), so the whole gate runs regardless.- Those files reach only the cache lookup:
_try_fast_cached_ci(commands/ci.py:614-630) passes them toget_ci_cache, which returns the last passing entry whenever the named files' hashes match the entry'sfile_hashes, even though the workspace fingerprint differs (ci/cache.py:336-338, via_check_pre_commit_subset_matchat:297-305and_is_subset_file_matchingat:285-294). - Reproduced at 308a71f in a scratch repo. After a recorded pass, with
src/b.pycontainingdef b(:,devops ci src/a.pyexits 0 and printsCodebase unchanged since last verification. Utilizing CI cache (all checks passed).(MESSAGES.ci.cache_hit,lang/en/messages.py:731-733).devops ci pyproject.tomlhits the cache too. tests/test_ci_cache.py:126-175(test_get_ci_cache_pre_commit_subset_match) and:247-264(test_ci_cli_positional_files_pre_commit) assert this as intended behaviour. The path came from feat(ci): fast execution caching when unchanged & pre-commit file change tracking integration #256 (docs/agent/tasks/task-256-ci-execution-caching-pre-commit.md:18), whosepass_filenames: truehook no longer exists: the pre-push hook setspass_filenames: false(.pre-commit-config.yaml:75).
2. Fingerprint timing.
_try_save_ci_cache(commands/ci.py:575-611) computes the fingerprint after every check has finished (compute_workspace_fingerprintat:588, reached from_handle_ci_resultsat:666-667).- An agent that keeps editing while the gate runs in the background gets the edited content cached as passing.
- The next pre-push run is then a cache hit on content that no check saw.
No caller passes files to the full gate:
.pre-commit-config.yaml:70-77(devops-ci-pre-push) setspass_filenames: false.commands/release.py:1287callsdevops ci run, a separate subcommand (commands/ci.py:1126-1145) that neither reads nor writes the cache.- The
devops-ci-test-changedhook (.pre-commit-config.yaml:62-68) passes staged files to thetestsubcommand's ownpathsargument (commands/ci.py:800), not to the group callback. feat(cli):devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406 owns that path. - No doc,
AGENTS.md,README.mdor test outsidetests/test_ci_cache.pyspells--filesfordevops ci(grep -rn -- '--files' docs AGENTS.md README.md testsfinds no gate use).
Proposed Solution
Remove the file-subset path. Nothing that remains needs it.
commands/ci.py: the--filesoption (:695-698) and its help stringCICommandHelp.files(lang/en/help.py:528-530);_collect_ci_target_files(:535-544); thefiles/all_filesparameters of_try_get_ci_cache(:547),_try_save_ci_cache(:575),_try_fast_cached_ci(:614) and_handle_ci_results(:652); theresolve_commandoverride and thecmd is Nonebranch ofFileOrSubcommandGroup.invoke(:49-55,:61-67). Keep the subcommand-help detection (:69,_asks_for_helpat:37-43,CONST_CI_SUBCOMMAND_SHOWS_HELP_META_KEY). With the override gone, typer'sTyperGroup.resolve_command(plain click resolution plus a "Did you mean" suggestion) turnsdevops ci src/a.pyintoNo such command 'src/a.py', exit 2, and--files src/a.pyintoNo such option, exit 2; thecigroup sets neitherallow_extra_argsnorignore_unknown_options(core/cli.py:172-176sets onlyhelp_option_names;:145-150applies to lazy root proxies only). Checked by invoking the app with the override swapped forTyperGroup's and the runner patched to raise:src/a.pyandpyproject.tomlexit 2 with zero runner calls,test --helpexits 0.ci/cache.py: thefilesparameter ofget_ci_cache(:308-340),_check_pre_commit_subset_match(:297-305),_is_subset_file_matching(:285-294),_compute_file_hashes(:137-147), the third element of thecompute_workspace_fingerprinttuple and its comment (:279-282; the function returns(fingerprint, head_sha)), thefile_hashesfield ofCICacheEntry(:62) and thefile_hashesparameter ofsave_ci_cache(:343-375), and_collect_modified_git_files(:150-162), which nothing calls today (grep -rn _collect_modified_git_files src testsreturns only the definition). Update the module docstring (:1-6), which still describes "pre-commit file change tracking". Existing cache files that carryfile_hasheskeep parsing:CICacheEntry(:53) has nomodel_configforbidding extra fields.- Tests: replace
test_get_ci_cache_pre_commit_subset_matchandtest_ci_cli_positional_files_pre_commit(tests/test_ci_cache.py:126-175,:247-264) with the tests below; update the three-tuple unpack attests/test_ci_cache.py:47-48, thefile_hashes=arguments at:75-82,:114,:215, and the patched three-tuple returns attests/test_ci_cache.py:220-223andtests/test_ci.py:703; drop theNone/all_files=Nonearguments intests/test_ci.py:705,:712,:720,:738,:747,:760.
Take the fingerprint before the checks start. In all_checks (commands/ci.py:676-731):
- Compute the fingerprint once, before the cache lookup, and use that one value both for the lookup (which computes it today at
:555) and as the "before" value. Compute it also when the lookup is skipped by--forceor--no-cache, because those runs still record their result (:652-667). A dry run records nothing (:666) and needs no "before" value. - After the checks pass, recompute. If it equals the "before" value, save as today. Otherwise print a
MESSAGES.ciwarning (new entry next tocache_hit,lang/en/messages.py:731) saying the tree changed while the gate ran and the result was not recorded, and save nothing. The run's exit status is the checks' verdict, unchanged. The existing entry is neither overwritten nor cleared: it certifies the tree it was recorded for, and a later tree can only hit it by matching that fingerprint. run(commands/ci.py:1126-1145) and the per-check subcommands do not touch the cache and do not change.
Docs. docs/ROADMAP.md:1146-1149 already carries this item; the cut updates it. The changelog entry goes in changelog.d/838.md.
Scope
One pull request. Files: src/devops_cli/commands/ci.py, src/devops_cli/ci/cache.py, src/devops_cli/lang/en/help.py, src/devops_cli/lang/en/messages.py, tests/test_ci_cache.py, tests/test_ci.py, docs/agent/tasks/task-838-<slug>.md, changelog.d/838.md.
Key Questions
- Does a passing run whose tree changed while the gate ran exit 0 or non-zero? Answered by the deliverable: it says the tree changed and saves nothing, and changes nothing else, so the exit status stays the checks' verdict (0 when every check passed). The checks passed on the tree they read; only the cache cannot vouch for the tree that exists now, and the next run re-verifies it. A non-zero exit would make the pre-push hook block a push because an editor saved a file during the run, which is the background-agent case this item is written for.
- Does a changed-during-run pass clear the existing cache entry? Answered by the deliverable: "save nothing" means the cache file is not touched, neither written nor cleared (clearing is what a failed run does,
commands/ci.py:670-672). The entry still certifies the tree it was recorded for; a later run hits it only if its fingerprint matches, which is exactly the tree the entry verified. - Should the fingerprint for the lookup and the "before" value be one computation? Answered: yes.
_try_get_ci_cachealready computes it (commands/ci.py:555); computing it twice would open a window between the two reads. - Does
devops ci runor any per-check subcommand change? Answered: no. They never touch the cache (commands/ci.py:1126-1145). - Does the
testsubcommand'spathsargument stay? Answered: yes. It belongs todevops ci testand thedevops-ci-test-changedhook (commands/ci.py:800,.pre-commit-config.yaml:62-68); feat(cli):devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406 owns it. - Does refactor(ci): github ci runs the gate through
devops cifrom one check table #843's narrowed run (--only/--skip) interact with the cache? Answered in refactor(ci): github ci runs the gate throughdevops cifrom one check table #843: a narrowed run neither reads nor saves the cache. This item's before/after check applies to full runs only, which is all that saves.
Acceptance Criteria
- In a
tmp_pathgit repository (reuse therepofixture pattern oftests/test_ci_cache_fingerprint.py:16-27) with a recorded pass, changing one tracked file makesget_ci_cache(fingerprint=compute_workspace_fingerprint(...)[0], ...)returnNone. The test is parametrised over asrc/file, atests/file, adocs/file andpyproject.toml. Test: newtests/test_ci_cache.py::test_any_tracked_change_misses_the_cache[...]. -
devops ci src/a.pyanddevops ci --files src/a.pyexit 2 with a usage error, and a patched_run_all_checks_asyncrecords zero calls. Test: newtests/test_ci_cache.py::test_a_file_argument_is_a_usage_error(parametrised over the two spellings) usingCliRunner. - A run in which the patched runner edits a tracked file prints the new warning, exits 0 and saves no entry; an entry recorded before the run is still there, byte for byte. Test: new
tests/test_ci_cache.py::test_a_tree_edited_during_the_run_is_not_recorded, in atmp_pathgit repository with_run_all_checks_asyncpatched to write to a tracked file before returning passing results, asserting the exit code, the warning in the output, and thatresolve_ci_cache_path(root)is unchanged. - A run in which nothing changes still records its entry. Test: existing
tests/test_ci.py::test_try_save_ci_cache_and_handle_results(:694-722),test_a_no_cache_run_still_records_its_result(:724-740) andtests/test_ci_cache.py::test_ci_cli_cache_hit_and_force(:188-244), updated for the new signatures and the two-tuple fingerprint, keep passing. -
devops ci test --helpanddevops ci lint --helpstill print help. Test: existingtests/test_ci.py::test_a_single_checks_help_does_not_name_the_gate_root[test|lint](:1281-1298) andtest_help_after_the_separator_is_a_path_and_the_check_names_its_root(:1301-1317) keep passing. -
rg -n 'subset_match|_is_subset_file_matching|_collect_ci_target_files|_compute_file_hashes|_collect_modified_git_files|file_hashes' src tests -g '!src/devops_cli/ai/rag/**'returns nothing (file_hashesinai/rag/indexer.pybelongs to a different feature). The two old tests attests/test_ci_cache.py:126-175and:247-264are replaced, not skipped. - The new tests together take at most 1 s on one worker, measured with
uv run pytest tests/test_ci_cache.py -p no:cacheprovider --durations=0 -o addopts=""and recorded in the task file. (The whole file plustest_ci_cache_fingerprint.pyruns in about 8 s today, mostly import and git setup; individual cache tests take 0.01-0.03 s.) - Tests stay offline: none of the new tests runs a check, reaches the network or DNS, or needs a real scanner.
-
uv run devops cipasses, and the PR addschangelog.d/838.mdanddocs/agent/tasks/task-838-<slug>.md.
Out of Scope
- No new gate stage.
- No change to
devops ci run, the per-check subcommands, or thetestsubcommand'spathsargument (feat(cli):devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406). - No per-check input scoping (chore(ci): per-check input scoping — investigated, not building #405 is recorded as done in v0.2.23,
docs/agent/tasks/task-405-per-check-input-scoping-for-the-ci-cache.md:4-5; the cache at HEAD is one whole-workspace fingerprint, and this item keeps it that way). - No change to how
--cache/--no-cache/--forcedecide whether an entry is trusted (commands/ci.py:623,:652-667). - No edits to
CHANGELOG.mdordocs/ROADMAP.md.
Dependencies
Order on src/devops_cli/commands/ci.py: #832 -> #843 -> #406 in v0.2.26, then #885 -> #838 -> #858 in v0.2.27. This item blocks on nothing; every line below is a rebase fact.
- refactor(ci): github ci runs the gate through
devops cifrom one check table #843 (v0.2.26, lands before this item): rewritesall_checksandruninto the check table and adds--only/--skip, naming fix(ci): the gate cache certifies only the tree it checked #838 as a co-editor ofall_checks; this item rebases on the table and keeps refactor(ci): github ci runs the gate throughdevops cifrom one check table #843's rule that a narrowed run neither reads nor saves the cache. - feat(cli):
devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406 (v0.2.26 for now; whether it moves to v0.2.28 is decided at the v0.2.25 cut): moves the git blob map ofcompute_workspace_fingerprint(ci/cache.py:253-268) into a shared helper; whichever of feat(cli):devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406/fix(ci): the gate cache certifies only the tree it checked #838 lands second rebases the helper, and this item keeps feat(cli):devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406's constraint that no subset shortcut returns to the cache. - fix(ci):
devops cichecks run for real under their own--dry-run#885 (v0.2.27, lands before this item): edits_runand_execute_check_asyncincommands/ci.pyand cites the dry-run cache bypass in_try_fast_cached_ci(:623); different functions, and the larger change lands first so this item rebases once. - fix(cli): cli start-up imports no telemetry when the bridge is off, and timing tests stop asserting host speed #858 (v0.2.27, lands after this item): changes one row of refactor(ci): github ci runs the gate through
devops cifrom one check table #843's table so the coverage row no longer copies the test row's duration; that duration reaches the cache entry through the save path this item edits, and the one-row change rebases last.
Readiness check (2026-10-04)
Re-checked at b61e5a0 (release/v0.2.26). #843 and #406 are merged, and #885 lands first in v0.2.27. The design is unchanged, but every commands/ci.py line and some test lines moved.
Corrected locations (under src/devops_cli/):
commands/ci.py:FileOrSubcommandGroupis at:48-72:resolve_commandoverride:51-57, thecmd is Nonebranch:64-70, help detection:71._asks_for_helpis at:39-45.--filesoption:971-974._collect_ci_target_filesis at:796-805, called at:994._try_get_ci_cacheis at:808-833(fingerprint at:816),_try_save_ci_cacheat:836-872(fingerprint at:849)._try_fast_cached_ciis at:875-891(dry-run bypass at:884)._handle_ci_resultsis at:914-937: save:930-931, clear on failure:936-937.all_checksis at:940-1015. A narrowed run (is_narrowed,:990) neither reads (:996) nor saves (:1015).runis at:1614-1633;test'spathsargument is at:1251.
ci/cache.py:CICacheEntryis at:54, withfile_hashesat:63._compute_file_hashesis at:150-160._collect_modified_git_files(:163) is still uncalled.compute_workspace_fingerprintis at:275-312; its third element is at:309-312._is_subset_file_matchingis at:315-324,_check_pre_commit_subset_matchat:327-335.get_ci_cacheis at:338-370(subset branch:367-368);save_ci_cachestarts at:373.
- feat(cli):
devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406's shared helper iscompute_worktree_blob_hashes(ci/cache.py:251-272), which the fingerprint now calls. The rebase between feat(cli):devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406 and this item is done, and no subset shortcut may return. - Other moved lines:
lang/en/help.py:586(CICommandHelp.files) andlang/en/messages.py:831(cache_hit).core/cli.py: the lazy-proxy context settings are at:155-161,help_option_namesat:189.commands/release.py:1556runsdevops ci run.
tests/test_ci.py:- The three-tuple patch is at
:849. - The
None/all_files=Nonearguments are at:852,:859,:867,:885,:894and:907. test_try_save_ci_cache_and_handle_resultsis at:841-869,test_a_no_cache_run_still_records_its_resultat:871-887, and the two help tests at:1429and:1448.
- The three-tuple patch is at
- Unchanged: the
tests/test_ci_cache.pyand.pre-commit-config.yamllines.
Cross-item consistency with #885. Fingerprinting runs git through run_subprocess (ci/cache.py:115-135, :215-248). A "before" fingerprint taken ahead of the dry-run check would break #885's zero-call recorder tests on devops ci --dry-run.
- The "before" fingerprint is computed only for full, non-dry runs.
devops ci --dry-runand narrowed runs (--only/--skip) compute none. Test: fix(ci):devops cichecks run for real under their own--dry-run#885'sdevops ci --dry-runrecorder test keeps passing with this change applied.
Lint rule now in force. ruff selects C901 with max-complexity = 10 (pyproject.toml:94-97, :109-110, #586). The before/after branch keeps all_checks within it without noqa, using a helper if needed.
Ready: no open question, dependencies merged or earlier in v0.2.27, one PR.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(ci): the gate cache certifies only the tree it checked (#838) (#1233
dan-petty-bot commentedon Oct 5, 2026
What changed
#1233, merged into
release/v0.2.27as 895841c.11 file(s) changed.
How it was verified
Check runs at 48d553e:
Acceptance Criteria of
docs/agent/tasks/task-838-ci-cache-certifies-checked-tree.md:--files,FileOrSubcommandGroupfile routing,_collect_ci_target_files,_compute_file_hashes,_collect_modified_git_files,_is_subset_file_matching,_check_pre_commit_subset_match, andfile_hashesonCICacheEntry) is completely removed.compute_workspace_fingerprintreturns a 2-tuple(fingerprint, head_sha).all_checks, fingerprint is computed before checks execute for full, non-dry runs. Recomputed upon completion: if tree mutated during run,MESSAGES.ci.cache_tree_changedwarning is printed, existing cache is untouched, and exit code is 0.--filesoptions raise ClickUsageErrorwith exit code 2 and 0 check executions.changelog.d/838.mdcreated;CHANGELOG.mdanddocs/ROADMAP.mdremain untouched.uv run devops cipasses on this branch.feat(release): v0.2.27 (#1257)