Skip to content

fix(agent-core-v2): revalidate file freshness when the scheduled write starts - #3165

Open
jangjoe wants to merge 1 commit into
MoonshotAI:mainfrom
jangjoe:fix/agent-core-v2-stale-guard-execute-recheck
Open

fix(agent-core-v2): revalidate file freshness when the scheduled write starts#3165
jangjoe wants to merge 1 commit into
MoonshotAI:mainfrom
jangjoe:fix/agent-core-v2-stale-guard-execute-recheck

Conversation

@jangjoe

@jangjoe jangjoe commented Aug 21, 2026

Copy link
Copy Markdown

Related Issue

Follow-up to #3096 — addresses the P1 review finding left unresolved there (Codex review on the stale-guard PR).

Problem

The Edit/Write staleness check ran during tool-call preparation, before the batch scheduler started any task. A file modified after that check — while the write waited behind a conflicting tool call or a user approval prompt — was overwritten without detection.

What changed

  • Added an onExecuteTool ordered hook to the agent-core-v2 tool executor that runs inside the scheduled task, directly around the physical tool execution (i.e. after conflicting predecessors have completed).
  • The stale guard now revalidates Edit/Write against the recorded mtime at that point and vetoes with outcome 'vetoed' when the file changed since the last read; mtime recording for Read/Edit/Write also moved into the task, so same-batch sequences (Read→Edit, consecutive writes) see the predecessor's record deterministically.
  • The prepare-time check stays as early feedback ahead of approval prompts.
  • Tests: staleGuard unit tests now exercise the execution-time path (veto after a post-prepare modification, same-batch ordering, failed-read veto); executor tests cover the new seam (middleware ordering across conflicting tasks, run-time veto, and the no-result guard rail).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 879b404

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant