Skip to content

Record per-file mtimes in .kati_stamp for accurate regen detection - #310

Merged
Colecf merged 1 commit into
google:masterfrom
jihoonkang0829:fix-kati-stamp-mtime
Sep 19, 2026
Merged

Colecf merged 1 commit into
google:masterfrom
jihoonkang0829:fix-kati-stamp-mtime

Conversation

@jihoonkang0829

Copy link
Copy Markdown
Contributor

Previously, Kati recorded a single process start time (gen_time) in .kati_stamp and compared every makefile and extra file dependency against it during --regen check.

This caused false invalidations in two common scenarios:

  1. Virtual or on-demand filesystems where uncached source files are materialized on first read during evaluation, assigning them an mtime of TimeNow() which is later than Kati's start time.
  2. Build-generated intermediate staging files written during Make evaluation with an mtime later than Kati's start time.

On subsequent builds, Kati would see file.mtime > gen_time and falsely conclude that the files were modified, triggering unnecessary full reanalysis.

This change stores each file's observed mtime alongside its path in .kati_stamp (both in ckati and rkati). During --regen, each file's current mtime is compared against its recorded mtime. If the file's mtime has not advanced, it is recognized as clean.

@jihoonkang0829
jihoonkang0829 requested a review from a team as a code owner September 18, 2026 01:57
@jihoonkang0829
jihoonkang0829 force-pushed the fix-kati-stamp-mtime branch 2 times, most recently from e1bfb54 to b81ee57 Compare September 18, 2026 17:16
@Colecf

Colecf commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Could you add a test?

@jihoonkang0829

Copy link
Copy Markdown
Contributor Author

Added ninja_regen_stamp_mtime.sh and ran the followings:

go test -ninja -run TestKati/ninja_regen_stamp_mtime.sh
go test -ninja -rkati -run TestKati/ninja_regen_stamp_mtime.sh

Comment thread testcase/ninja_regen_stamp_mtime.sh Outdated
# Set mtime to a future timestamp (later than Kati's process start time).
# Previously, Kati compared file mtime against the generation start time,
# falsely marking files with mtime > gen_time as modified on subsequent runs.
touch -d "2030-01-01 00:00:00" dep.mk extra.txt

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you do dates in like 2050 or later? I could see these tests breaking / becoming ineffective in 4 years.

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 timestamp.

Previously, Kati recorded a single process start time (gen_time) in
.kati_stamp and compared every makefile and extra file dependency against
it during --regen check.

This caused false invalidations in two common scenarios:
1. Virtual or on-demand filesystems where uncached source
   files are materialized on first read during evaluation, assigning them
   an mtime of TimeNow() which is later than Kati's start time.
2. Build-generated intermediate staging files
   written during Make evaluation with an mtime later than Kati's start time.

On subsequent builds, Kati would see file.mtime > gen_time and falsely
conclude that the files were modified, triggering unnecessary full reanalysis.

This change stores each file's observed mtime alongside its path in
.kati_stamp (both in ckati and rkati). During --regen, each file's current
mtime is compared against its recorded mtime. If the file's mtime has not
advanced, it is recognized as clean.
@Colecf
Colecf merged commit 55ea1e2 into google:master Sep 19, 2026
8 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.

2 participants