Skip to content

fix(cache): tolerate small future cache timestamps - #759

Merged
NewFuture merged 3 commits into
masterfrom
newfuture-cache-mtime-tolerance
Oct 22, 2026
Merged

NewFuture merged 3 commits into
masterfrom
newfuture-cache-mtime-tolerance

Conversation

@NewFuture

Copy link
Copy Markdown
Owner

Summary

Windows file timestamps can be slightly ahead of time(). Cache.new treated any future mtime as expired, so a just-written cache could be discarded and a successful DNS write repeated. This showed up as a flaky Windows ARM standalone E2E failure in test_partial_domain_failure_is_a_tool_error.

A cache file up to 2 seconds ahead of the clock is now kept, matching the existing dashboard read tolerance. Files further in the future, and caches past cache_max_age, are still discarded.

Scope

  • In scope: runtime cache expiry when the file mtime is slightly in the future
  • Out of scope: dashboard cache reads, explicit cache flush timing, CI job policy
  • Development lane: Core IP/HTTP/cache

Risk and compatibility

  • Risk: low
  • CLI/config/schema/provider/cache compatibility: no key, flag, or schema changes. A cache whose mtime is at most 2 seconds ahead is no longer cleared; larger future skew and normal expiry are unchanged.
  • Security or credential impact: none

Changes

  • Code: Cache.new allows up to 2 seconds of future file-time skew before treating the cache as outdated
  • Tests: boundary coverage keeps a 2-second skew and still clears a 3-second skew
  • Schema/metadata: N/A
  • Chinese documentation: N/A
  • English documentation: N/A

Validation

uv run --no-project --python 3.12 python -m unittest tests.test_cache -v
passed (43 tests)

D:\tools\uv\python\cpython-3.12.13-windows-x86_64-none\python.exe -m unittest discover tests -v
passed (1160 tests, 22 skipped)

D:\tools\uv\python\cpython-3.12.13-windows-x86_64-none\python.exe tools/check.py --changed
passed (core unit tests and offline E2E, including test_partial_domain_failure_is_a_tool_error)

ruff check ddns/cache.py tests/test_cache.py
passed

ruff format --check ddns/cache.py tests/test_cache.py
passed

The Windows ARM Nuitka standalone job was not rerun locally.

Review notes

  • Generated files: none
  • Platform limitations: the original failure depends on Windows file-time skew and was not reproduced outside CI
  • Follow-up work: none
  • Agent-authored: yes

Windows file mtimes can be slightly ahead of time(), which made Cache.new discard a just-written cache and repeat successful DNS writes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 12:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approved

The narrow logic change matches the intended behavior, preserves normal expiry, and has focused boundary coverage.

No open issues 🎉

What changed in this PR

This PR prevents freshly written runtime caches from being discarded when Windows file timestamps are slightly ahead of the clock, avoiding unnecessary repeated DNS writes.

Changes:

  • Accepts future cache timestamps up to 2 seconds ahead.
  • Preserves rejection of larger future skew and normal age-based expiry.
  • Adds deterministic coverage for the 2-second acceptance and 3-second rejection boundaries.
File Description
tests/​test_cache.py Tests future timestamp tolerance alongside the existing expiry boundary.
ddns/​cache.py Adds a 2-second timestamp tolerance to runtime cache expiry checks.

Review effort: Balanced

The entrypoint shell exited as soon as tini forwarded SIGTERM, so container teardown could kill the initial DDNS child before it handled the signal.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@NewFuture
NewFuture enabled auto-merge (squash) October 22, 2026 14:37
@NewFuture
NewFuture merged commit ac2e4a1 into master Oct 22, 2026
34 checks passed
@NewFuture
NewFuture deleted the newfuture-cache-mtime-tolerance branch October 22, 2026 14:58
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