Skip to content

test(agent-core-v2): make zero-timeout task wait deterministic - #4925

Merged
wbxl2000 merged 1 commit into
release/2026-11-13-2from
test/agent-task-zero-timeout-deterministic
Nov 13, 2026
Merged

wbxl2000 merged 1 commit into
release/2026-11-13-2from
test/agent-task-zero-timeout-deterministic

Conversation

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator

Root cause

The zero-timeout test passed Promise.resolve('done') as task completion and then awaited controlled(), which itself yields through microtasks. AgentTaskService.wait(taskId, 0) races the task's already-settled promise against a zero-delay timer, so the first snapshot depends on runner scheduling. GitHub CI returned completed instead of the expected immediate running snapshot in attempts 2 and 3.

Attempts 1 and 2/3 do not share a product-code root cause: attempt 1 failed in the loop harness's persisted/resumed history comparison, while attempts 2/3 are this task-wait scheduling race. This PR only fixes the deterministic task-wait fixture; it does not change the loop harness or any product behavior.

What changed

  • Replace the already-resolved completion promise with a 10 ms delayed completion, putting completion outside the microtask queue.
  • Keep the behavioral assertions unchanged: a zero-timeout wait returns running, and a subsequent unbounded wait returns completed.
  • Rename the test to describe task completion rather than next-tick completion.
  • Test-only change; no product code and no changeset.

Before

const task = await controlled(fixture, { completion: Promise.resolve('done') });

After

// Delay completion beyond the microtask queue so the zero-timeout snapshot
// cannot race Promise.resolve() scheduling in different test runners.
const completion = new Promise<string>((resolve) => {
  setTimeout(() => resolve('done'), 10);
});
const task = await controlled(fixture, { completion });

Verification

@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5619699

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T13:35:29.759639Z 5619699 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@5619699
npx https://pkg.pr.new/@moonshot-ai/kimi-code@5619699

commit: 5619699

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56196994cd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +669 to +670
const completion = new Promise<string>((resolve) => {
setTimeout(() => resolve('done'), 10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Control completion instead of relying on a 10 ms timer

On a loaded CI worker, the process can be descheduled for more than 10 ms between registering this timer and calling wait(..., 0); the completion timer is then already due and can run before the newly registered zero-delay wait timer, returning completed and preserving the flake this commit is intended to remove. Keep completion manually pending and resolve it only after asserting the zero-timeout snapshot.

Useful? React with 👍 / 👎.

Comment on lines +667 to +668
// Delay completion beyond the microtask queue so the zero-timeout snapshot
// cannot race Promise.resolve() scheduling in different test runners.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the newly added explanatory comment

Unless the original task explicitly requested this comment, adding it violates the repository-wide rule prohibiting comment additions; the descriptive test name and completion setup can express the intent without these lines.

AGENTS.md reference: AGENTS.md:L48-L50

Useful? React with 👍 / 👎.

@wbxl2000
wbxl2000 merged commit 546fbba into release/2026-11-13-2 Nov 13, 2026
15 checks passed
@wbxl2000
wbxl2000 deleted the test/agent-task-zero-timeout-deterministic branch November 13, 2026 15:01
wbxl2000 pushed a commit that referenced this pull request Nov 16, 2026
* fix(agent-core-v2): avoid quadratic cloning during session replay (#4885)

* fix(agent-core-v2): avoid quadratic cloning during session replay

* fix(agent-core-v2): isolate replay assignments and preserve rollback order

* refactor(agent-core-v2): make participant mutable replay explicit opt-in

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(agent-core-v2): validate Kimi media upload status (#4905)

* fix(agent-core-v2): reject failed Kimi image extraction

* chore: add Kimi image extraction changeset

* fix(agent-core-v2): validate Kimi media upload status

* fix(kap-server): forward swarm member task events (#4922)

* test(agent-core-v2): make zero-timeout task wait deterministic (#4925)

Co-authored-by: kimi-agent-bot <[email protected]>

* feat(registry): support search_url and feedback_url on custom registry providers (#4875)

* feat(registry): support search_url and feedback_url on custom registry providers

* fix(sdk): honor provider.env credentials and custom_headers for feedback_url

* refactor(core): submit feedback through the engine

Web and desktop reach this machine through kap-server, so feedback submission resolves the active model's provider in the engine and is exposed on the same route and klient method. The SDK facade keeps the managed OAuth path and no longer re-derives provider credentials.

* refactor(sdk): drop the unused feedback facade

Product clients submit feedback through the engine. The SDK facade and oauth toolkit no longer keep a second managed-only submission path.

* refactor(feedback): share engine schemas across route and klient

The HTTP body uses the engine field names, so the route forwards it and the klient contract imports the same schemas.

* refactor(feedback): drop unused kap and klient surfaces

TUI reaches IFeedbackService through the harness. The HTTP routes, klient facade, and the schemas that only served them have no caller.

* refactor(feedback): package and upload feedback attachments in the engine

* refactor(feedback): keep FeedbackService internal to agent-core-v2

* test(cli): provide execFile in node:child_process mocks

The feedback codebase scanner added in this branch calls
promisify(execFile) at module scope and is now reachable from the
agent-core-v2 index, so partial child_process mocks in these suites
failed module evaluation.

* feat(feedback): disclose submitted files, attach request_id, and drop text-only option (#4876)

* feat(registry): support search_url and feedback_url on custom registry providers

* fix(sdk): honor provider.env credentials and custom_headers for feedback_url

* refactor(core): submit feedback through the engine

Web and desktop reach this machine through kap-server, so feedback submission resolves the active model's provider in the engine and is exposed on the same route and klient method. The SDK facade keeps the managed OAuth path and no longer re-derives provider credentials.

* refactor(sdk): drop the unused feedback facade

Product clients submit feedback through the engine. The SDK facade and oauth toolkit no longer keep a second managed-only submission path.

* refactor(feedback): share engine schemas across route and klient

The HTTP body uses the engine field names, so the route forwards it and the klient contract imports the same schemas.

* refactor(feedback): drop unused kap and klient surfaces

TUI reaches IFeedbackService through the harness. The HTTP routes, klient facade, and the schemas that only served them have no caller.

* refactor(feedback): package and upload feedback attachments in the engine

* refactor(feedback): keep FeedbackService internal to agent-core-v2

* test(cli): provide execFile in node:child_process mocks

The feedback codebase scanner added in this branch calls
promisify(execFile) at module scope and is now reachable from the
agent-core-v2 index, so partial child_process mocks in these suites
failed module evaluation.

* feat(feedback): disclose submitted files, attach request_id, and drop text-only option

* fix(session-export): keep SESSION_NOT_FOUND for missing non-empty session ids

The global-log-only fallback exists for feedback submissions without an
active session (empty id). Scoping it to empty ids restores the 40401
envelope that kap-server's export route promises for unknown sessions.

* test(agent-core-v2): pin retained request id semantics in llmRequester assertions

* chore: sync web dist from code-app

code-app: 11563df26b92f0035659083327976a2e9b8e6727

code-app-release: b0b6d9c7a45c96ca48039ff05789c6e90f76ef20

code-app-local-build: 005d2b437493b7ab04d01f70542f3b6356699f4d

* ci: release packages (#4918)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(agent-core-v2): align request id back-sync with main

---------

Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: Haozhe <[email protected]>
Co-authored-by: 7Sageer <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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