Skip to content

test(core): await debounced sessions.json flush in plan-store test#90

Merged
deepagent-ai merged 1 commit into
deepagent-ltd:devfrom
thomas-yanga:fix/plan-store-test-async-flush
Jul 24, 2026
Merged

test(core): await debounced sessions.json flush in plan-store test#90
deepagent-ai merged 1 commit into
deepagent-ltd:devfrom
thomas-yanga:fix/plan-store-test-async-flush

Conversation

@thomas-yanga

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

(no tracking issue — this fixes the unit (macos) CI failure seen on #89)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

c0b79979 ("perf(core): 修复启动慢根因 — sessions.json 防抖") changed session-state.ts saveToDisk() from a synchronous write to a debounced
setImmediate(flushToDisk). The I33-1 plan-store test (packages/core/test/deepagent/plan-store.test.ts) predates that change and still assumed synchronous
persistence:

SessionState.setPlan("s3", p)   // only schedules setImmediate(flushToDisk), nothing on disk yet
const raw = readFileSync(path.join(stateDir, "sessions.json"), "utf8")  // ENOENT

The test body is fully synchronous, so whether the file exists at read time depends on event-loop timing — on the macOS runner it consistently fails with
ENOENT, which is what failed unit (macos) (@deepagent-code/core#test:ci exit 1) on #89. The linux/windows jobs in that run were cancelled (fail-fast) before
executing, so this is not actually macOS-specific.

Fix: make the test async and yield one event-loop turn (await new Promise((resolve) => setImmediate(resolve))) after setPlan, so the debounced flushToDisk lands
sessions.json before the assertion reads it. No production code changes. I also replaced the inline require("node:fs").readFileSync with the top-level
readFileSync import.

I verified the root cause by checking out c0b7997^ in a worktree: the test passes there and fails at dev HEAD, so the debounce commit is what broke it.

How did you verify your code works?

  • cd packages/core && bun test test/deepagent/plan-store.test.ts → 8 pass / 0 fail (previously 7 pass / 1 fail with ENOENT)
  • Full package suite bun test (2236 tests / 225 files): this test was the only failure before the fix
  • bun run typecheck in packages/core passes

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

N/A — test-only change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

saveToDisk() became setImmediate-debounced in c0b7997, but the I33-1
plan-store test still read sessions.json synchronously right after
SessionState.setPlan, racing the deferred flush and failing with ENOENT
(observed as the unit (macos) CI failure on deepagent-ltd#89). Yield one event-loop
turn before the assertion so flushToDisk lands the file first.

Signed-off-by: thomas-yanga <odie_majere@outlook.com>
@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@deepagent-ai
deepagent-ai merged commit 7652f1b into deepagent-ltd:dev Jul 24, 2026
4 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants