Skip to content

test(agent-core-v2): dispose task fixtures before deleting their session dir - #216

Merged
elkaix merged 2 commits into
mainfrom
fix/task-test-teardown-race
Aug 27, 2026
Merged

test(agent-core-v2): dispose task fixtures before deleting their session dir#216
elkaix merged 2 commits into
mainfrom
fix/task-test-teardown-race

Conversation

@elkaix

@elkaix elkaix commented Aug 27, 2026

Copy link
Copy Markdown
Member

Related Issue

No issue. Found when a CI shard failed on an unrelated PR with ENOTEMPTY: directory not empty, rmdir '/tmp/pythinker-bg-limit-agent-*/sessions/test-workspace/test-session'.

Problem

Five AgentTaskService cases create a temporary session directory and an agent context over it, then delete the directory in their finally block. None of them disposed the context first, so the context was still writing session state into that directory while the delete walked it. On a loaded CI machine the two race and the run fails with ENOTEMPTY. The tests also leaked six agent contexts per run.

One case already worked around a symptom of this by awaiting ISessionMetadata.ready; the other four had nothing.

What changed

  • New cleanupSessionDir(sessionDir, ...contexts) test helper: disposes every context, then removes the directory with fs.rm's own maxRetries / retryDelay — the documented remedy for ENOTEMPTY / EBUSY / EPERM from a concurrent writer.
  • All five cases now hoist their fixture above the try and clean up through the helper. No production code changes; no changeset, since nothing user-visible changes.

Verification

  • Instrumented the helper once locally: exactly 6 contexts are now disposed per run of this file, none of which were disposed before.
  • test/agent/task/taskManager.test.ts — 48 passed, 3 consecutive runs
  • pnpm --filter @pymodel/agent-core-v2 exec vitest run — 347 files, 5,723 tests passed
  • typecheck, tsgo, check-no-comments, oxlint — exit 0

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.

Summary by CodeRabbit

  • Tests
    • Improved cleanup of temporary session data after test runs.
    • Ensured test-agent contexts are properly disposed of.
    • Updated session-based tests to use separate reader and writer fixtures where needed.

…ion dir

Five task-manager cases created a temp session dir and an agent context,
then deleted the dir in their finally block without disposing the
context. The context kept writing session state into that dir while the
delete walked it, which failed the run with ENOTEMPTY on a loaded CI
machine. Dispose every context first, and let fs.rm retry the delete,
which is what its maxRetries option exists for.
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 041733b4-b888-4737-98bb-9e3a6bb647c2

📥 Commits

Reviewing files that changed from the base of the PR and between e4ed37f and 09c1265.

📒 Files selected for processing (1)
  • packages/agent-core-v2/test/agent/task/taskManager.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The test suite now disposes supplied agent contexts before removing temporary session directories. Session persistence tests retain contexts, and the persistence race test uses separate writer and reader fixtures.

Changes

Task manager test cleanup

Layer / File(s) Summary
Shared context cleanup and test adoption
packages/agent-core-v2/test/agent/task/taskManager.test.ts
Added cleanupSessionDir to dispose contexts before directory removal. Updated session-backed tests to retain contexts and use the helper.
Persistence race fixture separation
packages/agent-core-v2/test/agent/task/taskManager.test.ts
The race test now uses distinct writer and reader fixtures and disposes both contexts during cleanup.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Merge Risk: ⚪ Minimal · up to 09c12

This localized test-only change disposes agent contexts before removing their temporary session directories, preventing teardown races and leaked test resources. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title uses the required test: conventional-commit prefix, uses imperative wording, and describes the change. It is 76 characters, which exceeds the 72-character limit. Shorten the title to 72 characters or fewer while preserving the main change.
Description check ⚠️ Warning The description clearly explains the problem, implementation, verification, and lack of production changes. However, it states that no issue exists while marking the related-issue checklist item compl… Link the related approved issue and keep the checklist item checked. If no issue is required for this PR, uncheck that item and state the repository-approved exception explicitly.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the problem, implementation, verification, and lack of production changes. However, it states that no issue exists while marking the related-issue checklist item complete, and it does not provide the issue link required by the template.

  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@pymodel/pythinker-code@07bad55
npx https://pkg.pr.new/@pymodel/pythinker-code@07bad55

commit: 07bad55

@elkaix
elkaix merged commit 84fc9d7 into main Aug 27, 2026
24 checks passed
@elkaix
elkaix deleted the fix/task-test-teardown-race branch August 27, 2026 02:21
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