Skip to content

fix(agent): count a script's write the file clock dates a tick early - #8130

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/main-coarse-file-clock
Nov 13, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/main-coarse-file-clock

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

A file a script wrote at the very start of its run could be reported to the user as never written ("No successful write to recon_tables.xlsx is recorded for this turn"), even though it was on disk. The same race made test_a_bare_output_a_script_wrote_beside_the_named_input_is_found fail now and then on Linux CI, on branches that never touched the agent. After this, such a write counts, and the test is stable.

The run's window started at the precise wall clock, while Linux and Windows date file writes by a coarser clock that trails it by up to one tick. The window now opens 20 ms earlier.

Test plan

  • New test_a_write_the_file_clock_dates_a_tick_early_is_still_the_runs fails before the change with the CI message, passes after
  • Every test file that exercises completion evidence passes (test_completion_evidence.py, test_agent_loop_completion_scope.py, test_grounding.py and six others)

A file a script wrote at the start of its run could be reported as
never written ("No successful write to `recon_tables.xlsx` is recorded
for this turn"), and the bare-output test failed now and then on Linux
CI on unrelated branches.

A run's window started at time.time_ns(), but Linux and Windows date
file writes by a coarser clock that trails it by up to one tick (4 ms
and 15.6 ms), so a write in the run's first few milliseconds looked
older than the run. The window now opens 20 ms earlier: longer than
either tick, and far shorter than any gap between two tool calls.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

This fixes a real false alarm. The agent could tell the user a file was "never written" when a script had in fact written it right at the start of its run. That happened because the file system stamps writes slightly behind the precise clock the run's start time came from. Opening each run's window 20 ms earlier covers one clock tick on Linux and Windows, and the new test reproduces the race without relying on timing luck. I found nothing blocking.

Real-world evidence

N/A: no evidence bundle was produced for this PR. The change is an internal timing margin with no CLI, UI or API surface to exercise directly. The verdict rests on static review alone; I couldn't run the tests here because pytest isn't installed in the review environment.

🔍 Technical details

Issues found

🟢 Shifted windows can now overlap back-to-back runs (src/gaia/agents/base/completion.py:621)

  • _written_by_executor requires every run whose window contains the mtime to have succeeded (all(ok for ok, _ in during)).
  • Suppose run N starts less than 20 ms after run N−1 ends. A file that N−1 wrote in its last tick now also falls inside N's window:
    • If N failed, the file is reported as unwritten.
    • If N succeeded, the write is credited to N instead of N−1.
  • In the agent loop an LLM turn always sits between two executor runs, so this can't realistically happen. No change needed; noting it in case the slack is ever raised.

Strengths

  • The fix is a single named constant at the one place the window opens. The end bound stays at time.time_ns(), which is correct because a lagging file clock can only stamp a write earlier, never later.
  • The test forces the mtime 10 ms early with os.utime instead of hoping CI hits the race, so it fails deterministically before the change and passes after it.
  • _compared_every_run still runs first, so before/after stat comparison wins over the widened mtime window wherever it's available.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 13, 2026
Merged via the queue into amd:main with commit 57356d8 Nov 13, 2026
39 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/main-coarse-file-clock branch November 13, 2026 18:13
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Nov 13, 2026
Main now starts a run's window 20 ms early for the file clock (amd#8130); the
PR also dates a file by its ctime so a copy counts. Together they credited a
file created a few ms before the run, which is what failed the Windows unit
lane, not a metadata-change stamp: the earlier st_birthtime change is backed
out. The stale-file test now creates its file before that slack, as a real
file from an earlier turn is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants