Skip to content

fix(targethasher): make directory hashing cancellation-aware (audit #14.3) - #269

Merged
sbalabanov merged 2 commits into
mainfrom
audit/fix-14-3-targethasher-cancellation
Aug 4, 2026
Merged

fix(targethasher): make directory hashing cancellation-aware (audit #14.3)#269
sbalabanov merged 2 commits into
mainfrom
audit/fix-14-3-targethasher-cancellation

Conversation

@sbalabanov

@sbalabanov sbalabanov commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Audit #14.3. Propagate cancellation into source-directory hashing across both target graph implementations.

Intent

Stop expensive directory traversal when graph computation is canceled and preserve custom cancellation causes through the hashing boundary.

Changes

  • Add context.Context to the SourceHasher contract and update all implementations, callers, fakes, and mocks.
  • Check cancellation before directory traversal and periodically while hashing files.
  • Preserve context.Cause and verify both graph paths pass the original context.

Test Plan

  • go test ./core/targethasher ./core/itg/graph
  • ./tools/bazel test //core/targethasher:targethasher_test //core/itg/graph:graph_test --test_output=errors
  • make gazelle
  • aifx verify

Revert Plan

Revert this PR to restore the context-free source hashing interface and traversal behavior.

Jira Issues

None.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread core/targethasher/sourcehasher.go Outdated
)

// cancelCheckInterval is how often the directory walk checks for cancellation,
// measured in files hashed. Matches the convention used elsewhere in the

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use words "matches the convention", just describe what this setting is for.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment in 35d2ee5 to directly state that the setting controls how many files are hashed between cancellation checks during a directory walk.

[addressed by agent]

….3)

Summary:
Audit #14.3 extracts targethasher cancellation propagation from #262.

Intent:
- Stop directory hashing promptly when graph computation is canceled.
- Preserve cancellation causes through both target graph implementations.

Changes:
- Thread context through SourceHasher and all callers.
- Check cancellation before and periodically during directory traversal.
- Cover public hasher cancellation and context propagation through both graph paths.
@sbalabanov
sbalabanov marked this pull request as ready for review August 3, 2026 23:57
@sbalabanov
sbalabanov requested review from a team as code owners August 3, 2026 23:57
@sbalabanov
sbalabanov force-pushed the audit/fix-14-3-targethasher-cancellation branch from 77f0d98 to 35d2ee5 Compare August 3, 2026 23:57
@sbalabanov
sbalabanov merged commit 2300f98 into main Aug 4, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants