DevWeave logoDevWeave
CommunitiesDiscoverHelp ForumFeaturesWhy DevWeaveAI & Verification
Log inGet started
Back to Issue Discovery
neomjs/neo-agent-brain #2007openJavaScriptJavaScript & TypeScript

Fix ENOTEMPTY rmdir race in providerActivityStatusStore.spec.mjs

Opened by @neo-gemini-maryam · Assignees: @neo-gemini-julia

View on GitHub
buggood first issuehelp wantedaitestingagent-os

Solve & Merge Reward: Up to +210 XP & +60 Coins

+30 XP on PR open · +180 XP & +60 coins on merge

15 GitHub Stars

Claim Status & GitHub Signal

Assigned on GitHub (@neo-gemini-julia). Check recent comments before starting duplicate work.

AI Issue Assessment · Grounded Analyzer
2.8 / 10 · 3–4 · Beginner

Estimated from issue labels (bug, good first issue, help wanted, ai, testing, agent-os), JavaScript context, and discussion depth. No comments are posted yet, so check repository conventions carefully. Note: this is an estimate, not a guarantee.

What It's About

Fix ENOTEMPTY rmdir race in providerActivityStatusStore.spec.mjs. Please comment to claim before starting; check current assignees and linked PRs. Live latest-open + closed sweep: checked latest 20 of 162 open issues (red backlog band 50), open and closed searches (providerActivityStatusStore OR lifecycle-guard OR ENOTEMPTY;

Why It Matters

Resolving #2007 improves reliability and developer experience in neomjs/neo-agent-brain.

Expected Outcome

A focused pull request addressing #2007 with relevant checks or tests verified locally.

Skill Match Breakdown

Log in to compare this issue's requirements against your profile skills. Required concepts: JavaScript, SQL & Databases, Git & Collaboration, C / C++ & Memory.

Progressive AI Hints

Hint #1 is always free and calibrated to your experience level. Extra hints unlock with coins without spoiling the full solution.

Log in to receive your free level-adapted Hint #1 grounded in this repository's files.

Skill-Gap Learning

Gap-Targeted
Learn Git

Branching, commits, rebasing, and collaborative Git workflows.

Addresses skill gap: Git & Collaboration

Learn SQL

Relational modeling, joins, constraints, and query optimization.

Addresses skill gap: SQL & Databases

Learn Memory Management in C

Stack vs. heap allocation, pointers, and low-level memory patterns.

Addresses skill gap: C / C++ & Memory

Hands-On CodeCrafters Practice
Skill-Gap Challenge
Build your own Shell
JavaScript

Parse commands, manage PATH lookups, pipes, and process execution.

Practice skill gap: JavaScript

Build your own Git
JavaScript

Implement .git storage, blob/tree objects, SHA hashing, and plumbing commands.

Practice skill gap: Git & Collaboration

Issue Description

Please comment to claim before starting; check current assignees and linked PRs.

Live latest-open + closed sweep: checked latest 20 of 162 open issues (red backlog band >50), open and closed searches (providerActivityStatusStore OR lifecycle-guard OR ENOTEMPTY; read closed #440 which covered TenantRepoSyncService lease-loss specs, not providerActivityStatusStore.spec.mjs), A2A in-flight claim sweep (list_messages last 30 across all read states), Memory Core rationale sweep (query_raw_memories), own-assignment sweep (#1948 only, non-overlapping), Knowledge Base ticket sweep (ask_knowledge_base), and npm run ai:structure-map -- --files --loc at 2026-12-02T04:50Z; no equivalent open ticket found.

Context

test/playwright/unit/ai/services/shared/providerActivityStatusStore.spec.mjs:168 (never deletes a foreign failure after exhausting guard acquisition) failed on dev push run 45797781167 (2026-11-26, job 139837073455) with:

Error: ENOTEMPTY: directory not empty, rmdir '/tmp/provider-activity-status-GuJiyn/shared.sqlite.provider-activity-memory-core.json.lifecycle-guard'

The Problem

Both live-contention tests in test/playwright/unit/ai/services/shared/providerActivityStatusStore.spec.mjs (lines 140–152 and 188–200) manually release the simulated foreign lifecycle guard with two separate await calls instead of using exitLifecycleGuard:

setTimeout(async () => {
    try {
        await fs.unlink(ownerPath);
        await fs.rmdir(guardPath);
        resolve();
    } catch (error) {
        reject(error);
    }
}, 1100);

Between await fs.unlink(ownerPath) (which leaves guardPath as an empty directory) and await fs.rmdir(guardPath), writer's concurrent enterLifecycleGuard (ai/daemons/shared/lifecycleGuard.mjs:90) executes fsModule.rename(stagingPath, guardPath). On POSIX, rename(nonEmptyStagingDir, emptyGuardDir) succeeds atomically and repopulates guardPath with writer's owner-<token> file. The test's subsequent await fs.rmdir(guardPath) then fails with ENOTEMPTY.

Production exitLifecycleGuard (ai/daemons/shared/lifecycleGuard.mjs:345-352) explicitly catches ENOENT and ENOTEMPTY on rmdir for this exact POSIX race window, which the test's manual unlink + rmdir bypassed.

(Secondary check for implementation: verify whether 1100ms actually exhausts STATUS_PUBLICATION_ATTEMPTS = 3 × ~1s guard polling in test 168, or whether holding the foreign guard until after await writer.flush() tests post-exhaustion deterministically without a timing window at all.)

The Architectural Reality

  • Design authority: ai/daemons/shared/lifecycleGuard.mjs:336-353 (exitLifecycleGuard) is the canonical guard-release contract and documents why ENOTEMPTY / ENOENT on rmdir is benign when another contender acquires the empty directory in between.
  • Structure map: Owned by test/playwright/unit/ai/services/shared/providerActivityStatusStore.spec.mjs; lifecycleGuard.mjs already handles this window safely.

The Fix

  1. In test/playwright/unit/ai/services/shared/providerActivityStatusStore.spec.mjs (both lines 145–146 and lines 193–194), release the foreign guard via exitLifecycleGuard (or ignore ENOENT/ENOTEMPTY on rmdir matching lifecycleGuard.mjs:345-352).
  2. In test 168 (never deletes a foreign failure after exhausting guard acquisition), ensure the test deterministically exercises exhausted acquisition (e.g., verify writer.flush() completes while the foreign guard still holds, or assert the exact retry-exhaustion branch without racing a 1100ms timer against enterLifecycleGuard).
  3. Verify cleanly under --repeat-each=20 with the Brain unit Playwright config.

Decision Record impact

none — aligns test teardown with lifecycleGuard.mjs's existing POSIX-safe release contract.

Acceptance Criteria

  • Both live-contention tests in test/playwright/unit/ai/services/shared/providerActivityStatusStore.spec.mjs (119–166 and 168–210) release the simulated foreign guard without throwing ENOTEMPTY / ENOENT when enterLifecycleGuard atomically claims the emptied directory.
  • Test 168 deterministically verifies foreign-failure preservation after guard acquisition exhaustion.
  • npx playwright test --config=test/playwright/playwright.config.unit.mjs test/playwright/unit/ai/services/shared/providerActivityStatusStore.spec.mjs --repeat-each=20 passes 20/20 cleanly.

Out of Scope

  • Changing ai/daemons/shared/lifecycleGuard.mjs or ai/services/shared/providerActivityStatusStore.mjs locking protocol (already POSIX-safe).

Avoided Traps

  • Using fs.rm(guardPath, {recursive: true, force: true}): That would delete writer's newly renamed owner-<token> file inside guardPath, breaking the live contender's guard ownership instead of letting writer keep it.

Related

  • Live dev CI receipt: run 45797781167 (job 139837073455, 2026-11-26)
  • Sibling historical lifecycle-guard race: #440

unowned-rationale: Ready for a contributor; maintainers provide planning and review. Origin Session ID: d3b824ff-9083-4a90-af0d-da54110872be Retrieval Hint: "providerActivityStatusStore.spec.mjs ENOTEMPTY rmdir lifecycle-guard exitLifecycleGuard POSIX rename race"

Linked Pull Requests (0)

No linked or cross-referenced pull requests detected via GitHub timeline. Check comments below for informal claims before starting.

GitHub Comments (0)

No comments on this issue yet.

Peer Help Forum · neomjs/neo-agent-brain #2007

Issue Troubleshooting Threads (0)

Ask Peers for Help

No troubleshooting threads opened for this issue yet. If you hit a test, build, or navigation blocker, post what you've tried so fellow contributors can help.

PR Verification & Rewards

Sign in and link GitHub to verify your PR against this issue and earn XP + coins.

Sign In

Contribution Workflow

Track your local progress before opening a pull request on GitHub.

Repository Context

Top Repository Paths

[dir] .github
.github/PULL_REQUEST_TEMPLATE.md
.github/dependabot.yml
[dir] .github/workflows
.github/workflows/brain-integration.yml
.github/workflows/brain-lint.yml
.github/workflows/brain-unit.yml
.github/workflows/claim-responder.yml
.github/workflows/codeql-analysis.yml
.github/workflows/dependabot-automerge.yml
.github/workflows/detection-retention-sla.yml
.github/workflows/merge-comment.yml
.github/workflows/publish-mcp-registry.yml
.github/workflows/shared-pr-baseline.yml
.github/workflows/substrate-sync.yml
.gitignore
.npmrc
CONTRIBUTING.md
LICENSE
README.md
[dir] ai
ai/Agent.mjs
ai/ConfigProvider.mjs
ai/Env.mjs

CONTRIBUTING.md Excerpt

Neo.mjs Brain Contributing Guide

We are very excited that you are interested in contributing to the Neo.mjs Brain (neo-agent-brain, the Agent OS).<br> No worries, you don't need to be a guru, ninja or rockstar to support the project.

Which starting point is yours?

Three different things get called "getting started", and picking the wrong one costs an evening:

  • Running or observing an AI engineering team? Start with Agent Institution (neomjs/neo-agent-institution), the operator-facing cockpit application, or see Run Your Own Agent Team.
  • Building an app with the Neo.mjs UI Engine? See neomjs/neo and the <a href="https://neomjs.com/#/learn/gettingstarted/Setup">Setup guide</a>.
  • Changing the Brain itself — fixing a bug in src/ or ai/, adding a unit test, improving an MCP service or guide? That is this page, and the loop below is the whole of it.

Set up the Brain from a clone

You need Node.js 24 or newer and Git. For the isolated unit suite, nothing else is required: no Docker, no external database server, no API key, and no Neo maintainer credentials.

git clone https://github.com/neomjs/neo-agent-brain.git   # or your fork
cd neo-agent-brain
npm install
npm run test-unit

Every test command takes a path, so you can run just the area you touched:

npm run test-unit -- test/playwright/unit/ai/services/memory-core

Before opening a pull request, run the mechanical pre-flight checks on your branch:

npm run agent-preflight

The integration suites exercise live cross-service composition and parity contracts when a local or containerized service stack is available:

npm run test-integration-unified   # unified service integration suite
npm run test-integration-parity    # Host-Edge / Container-Cloud parity suite

Container-Cloud operations live in the independent cloud/ package (cd cloud && npm ci; see Cloud Overview and ADR 0040). If you are fixing a unit test or a pure service module, you do not need cloud/ or Docker.

⚠️ Run the npm run test-* scripts, not npx playwright test directly. There is no Playwright config at the repo

... (truncated)

Advisory PR Assistant

Helps structure your PR description or unpack reviewer feedback. Does not perform GitHub actions.