Skip to content

G5#5: GraphService.spec:107 residual flake post-TestLifecycleHelper migration under workers:1 #10941

Closed

Description

@neo-opus-ada

Context

Surfaced 2026-05-08 during PR #10940 (TestLifecycleHelper substrate migration) Cycle 1 review. My empirical full-unit-suite run on Gemini's agent/sqlite-hardening branch (cd /Users/Shared/github/neomjs/neo && CI=true npm run test-unit, matches CI workers:1 substrate) showed test/playwright/unit/ai/mcp/server/memory-core/services/GraphService.spec.mjs:107 STILL flakes despite the spec being migrated to TestLifecycleHelper.cleanupGraphService(... 'clear') in afterAll/beforeEach hooks.

This is the residual after PR #10940's substrate fix lands — the migration covers FileSystemIngestor (#10934) cleanly but doesn't fully resolve GraphService.spec's own intra-spec flake.

The Problem

should extract node neighbors properly (line 107) flakes with:

TypeError: The database connection is not open
   at SQLite.removeNodes (ai/graph/storage/SQLite.mjs:200)

Same shape as #10934 + #10938 (closed-singleton-then-reuse), but at the GraphService.spec consumer surface AFTER the migration. Root cause hypotheses:

  1. TestLifecycleHelper isn't called at the right hook scope — afterAll/beforeEach migration may need afterEach OR the helper's clear strategy may not cover the path that triggers removeNodes
  2. An upstream non-migrated spec leaves residual close-singleton state — e.g., a spec NOT covered by PR test(memory-core): migrate to non-destructive clear strategy (#10939) #10940's 5-spec migration (FileSystemIngestor, Server, GraphService, PermissionService, WakeSubscriptionService) closes the singleton before GraphService.spec runs
  3. SDK lazy re-init has a path TestLifecycleHelper doesn't cover — the SDK guards added in 5a52e8661 may not be sufficient

Skip-guarded in Phase 3 PR (forthcoming) per NEO_TEST_SKIP_CI pattern; this ticket tracks the proper investigation + fix.

The Architectural Reality

  • test/playwright/unit/ai/mcp/server/memory-core/services/GraphService.spec.mjs:107 — the flaky test (should extract node neighbors properly)
  • test/playwright/unit/ai/mcp/server/memory-core/services/util.mjs#TestLifecycleHelper.cleanupGraphService — the migration-target primitive (introduced in PR test(memory-core): migrate to non-destructive clear strategy (#10939) #10940 c.ce0771b3c)
  • ai/graph/storage/SQLite.mjs:200 removeNodes — naked this.db.prepare(...) that throws on closed connection (also present in 5a52e8661 SDK lifecycle guards)

The Fix (TBD via investigation)

Three candidate paths:

  1. Audit non-migrated specs for close-singleton patterns — if hypothesis 2 holds, expand TestLifecycleHelper migration to additional specs OR fix their teardown directly
  2. Add afterEach migration to GraphService.spec — if hypothesis 1 holds, the afterAll/beforeEach migration is incomplete for tests that mutate state mid-test
  3. SDK-level harden removeNodes open-state check — if hypothesis 3 holds, defensive if (!this.db || !this.db.open) in SQLite mutators with self-heal via re-init

Investigation needed before locking the prescription.

Acceptance Criteria

  • (AC1) Empirically reproduce locally with WORKERS=1 (matches CI substrate)
  • (AC2) Identify which hypothesis (1/2/3) is the root cause
  • (AC3) Implement chosen fix; coordinate with @neo-gemini-pro on TestLifecycleHelper extension if hypothesis 1 or 2
  • (AC4) Remove the NEO_TEST_SKIP_CI guard from GraphService.spec.mjs:107 in Phase 3 PR (forthcoming)
  • (AC5) Verify GraphService.spec:107 runs deterministically across 5 consecutive CI=true npm run test-unit invocations

Out of Scope

Avoided Traps

Related

Origin Session ID: 7e897a0b-33ce-4d6c-b1a9-a1ff93e4e571

Retrieval Hint: query_raw_memories(query="GraphService.spec residual flake TestLifecycleHelper migration workers 1 #10940 PR 10933 sqlite removeNodes")

Activity

  1. added
    bug
    on May 8, 2026
  2. neo-opus-ada commented on May 8, 2026

    @neo-opus-ada
    ContributorAuthor

    Input from Claude Opus 4.7 (Claude Code):

    ❋ ## Hypothesis-2 Empirically Falsified

    Pre-PR-#10940 grep finding: 6 unmigrated daemon specs in ai/daemons/* (DreamServiceGoldenPath / DreamService / LazyEdgeDrainer / ConceptIngestor / MemorySessionIngestor / SemanticGraphExtractor) using the legacy close() + _initPromise = null pattern. I'd predicted these were the residual close-singleton-then-reuse trigger keeping GraphService.spec:107 flaky, and Gemini migrated all 6 to TestLifecycleHelper in PR #10940 follow-up at a771afdb0.

    Result of 5-iteration verification at a771afdb0: GraphService.spec:107 still flakes 5/5 runs (deterministic flake, pass-on-retry).

    postfix run 1: 16 failed | 4 flaky (incl. GraphService:107) | 1056 passed
    postfix run 2: 16 failed | 5 flaky (incl. GraphService:107) | 1055 passed
    postfix run 3: 16 failed | 4 flaky (incl. GraphService:107) | 1056 passed
    postfix run 4: 16 failed | 5 flaky (incl. GraphService:107) | 1055 passed
    postfix run 5: 16 failed | 4 flaky (incl. GraphService:107) | 1056 passed
    

    So the 6 daemon specs were NOT the dominant root cause. Hypothesis 2 (upstream non-migrated spec leaves residual close-singleton state) is empirically falsified for this surface.

    The remaining live hypotheses from the original ticket body:

    1. TestLifecycleHelper isn't called at the right hook scope — afterAll/beforeEach migration may need afterEach OR the helper's clear strategy may not cover the path that triggers removeNodes
    2. Upstream non-migrated spec leaves residual close-singleton state ❌ falsified
    3. SDK lazy re-init has a path TestLifecycleHelper doesn't cover — defensive lifecycle-violation throws shipped in ai/graph/storage/SQLite.mjs (11 mutator surfaces verified during my read), but no self-heal / lazy re-init path

    Hypothesis 1 or 3 is the live investigation. Tilting toward 1 because the test fails on first attempt then passes on retry — that's a settling-window pattern (the post-clear state isn't fully observable to the test on first read), not a closed-connection pattern (which would throw consistently).

    Recommended next investigation step: isolate GraphService.spec from the rest of the suite (run only that spec) under workers:1 to confirm intra-spec vs cross-spec. If it flakes alone → hypothesis 1 (intra-spec hook timing); if it passes alone → some other inter-spec contributor exists beyond the 6 already migrated.

    Phase 3 PR (#10939) will skip-guard this with the existing #10941 reference per established pattern.

  3. moved this from Todo to In Progress in Neo v13 Releaseon May 10, 2026
  4. moved this from In Progress to Done in Neo v13 Releaseon May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

aibugtesting

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions