LearnNewsExamplesServices
Frontmatter
id16419
titleresetDragState throws ReferenceError when document is entirely absent
stateClosed
labels
bugaitesting
assigneesneo-kimi-phoebe
createdAtAug 3, 2026, 1:27 AM
updatedAtAug 3, 2026, 12:23 PM
githubUrlhttps://github.com/neomjs/neo/issues/16419
authorneo-kimi-phoebe
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtAug 3, 2026, 12:23 PM

resetDragState throws ReferenceError when document is entirely absent

Closed Backlog/active-chunk-12 bugaitesting
neo-kimi-phoebe
neo-kimi-phoebe commented on Aug 3, 2026, 1:27 AM

Context

@neo-gpt surfaced the gate interference while validating #16417 (A2A 2026-08-02T22:54Z): two consecutive full unit-suite runs on 63149823e2 + a backup-only diff failed the same three DragDrop.spec.mjs reset witnesses (:639 reset during initial drain, :679 older native completion inert, :895 reset during park resize), with immediate exact-file reruns green. He asked for a collision-check/reproduction before any public claim. The reproduction is complete and the mechanism is named below — the defect is real, on dev, and it is mine.

The Problem

src/main/addon/DragDrop.mjs:362 (from #16381, merged as fd8dc1105a) reads:

document.body?.classList?.remove('neo-drag-active');

The optional chaining guards body and classList — but not the document root itself. In any context where globalThis.document is entirely absent, the line throws ReferenceError: document is not defined before any property access. The guard comment directly above promises bare-harness safety ("bare test harnesses may stub document without a body/classList") — the code does not deliver it when the harness provides no document at all.

The three failing witnesses drive resetDragState() directly with hand-built addon objects — a legitimate harness use that hits this line. Whether document exists at that moment is schedule-dependent: the suite's global-stubbing spec files install globalThis.document at import and delete it in afterAll when their saved original was undefined, so a file whose tests run between another file's stub-install and the witness execution leaves the global absent. That is why the failure appears only inside the full 11k suite, twice deterministically at 63149823e2, and never in exact-file or small-slice runs.

Reproduction dossier (all at clean 63149823e2, this host):

  • Full suite ×2: the same 3 witnesses fail (ReferenceError: document is not defined at DragDrop.mjs:362, stack in the run artifacts).
  • Exact-file / unit/main/addon slice / unit/main slice / pair with Mouse.spec.mjs in both orders: all green.
  • Falsified alternates: my Mouse.spec.mjs as the poisoner (full suite run with it temporarily removed → failures persist, 8 failed — not the cause); pure CPU load (concurrent 3704-test services suite alongside exact-file → green); unit/main-internal interference (slice green).
  • Shard bisection: --shard=1/2 green; --shard=2/2 fails the 3 (+ a wider order-sensitive set: HealthService:1228, Provider:656/:693, FileUpload:231, Env:192 — same latent class of schedule-sensitive witnesses, NOT this ticket's scope).

The Architectural Reality

  • DragDrop.mjs:362 is the proven throw site: resetDragState is driven directly by harnesses without any attach()/DOM lifecycle, so it is reachable document-less.
  • The #16381 guard commit (e20c425e2d) fixed the body/classList tier after the first bare-harness CI failure and stopped one tier short of the root.

The Fix

Root the optional chain at globalThis in the proven site:

globalThis.document?.body?.classList?.remove('neo-drag-active');

globalThis.document is always a defined binding (value undefined when absent), so the chain no-ops safely in document-less contexts; browser behavior is unchanged. Guard comment extended to name the no-document case.

Scope narrowed at review (PR #16422 cycle 1, @neo-gpt RA-2): the two Mouse.mjs sites were dropped from this ticket. The sensor's methods require document on the very next statements (document.addEventListener / removeEventListener), so guarding only the class-list side effect there would promise a no-document method contract the lifecycle does not deliver. The Mouse bracket's document.body?.classList shape (from #16381) is browser-correct as-is.

Acceptance Criteria

  • DragDrop.mjs:362 rooted at globalThis.document? with the guard comment naming the no-document case
  • A deterministic no-document reset witness pins the exact ReferenceError in unit/main/addon/DragDrop.spec.mjs — red against the pre-fix line, green with it; no dependence on full-suite ordering
  • The three reset witnesses green in TWO consecutive full-suite runs at the fix head (the failing configuration, not just targeted runs)
  • unit/main/addon/DragDrop targeted run green (the witnesses' own file, 23/23-class)
  • unit/main/draggable/sensor/Mouse targeted run green (4/4 — the terminal-contract pins; the sensor itself is untouched after the RA-2 scope narrowing)

Out of Scope

  • The wider shard-2 order-sensitive witness set (HealthService, Provider, FileUpload, Env — separate latent class, separate ticket if it recurs)
  • The session-local Ollama-gated TextEmbeddingService failures (environmental)
  • Any rework of the suite's global-stubbing harness pattern (the production fix makes the witnesses robust regardless of which file provides or removes document)

Related

  • #16381 / PR #16403-orbit (fd8dc1105a, the merge that introduced the line) · #16417 (@neo-gpt's gated lane) · PR #16405-era reset witnesses (Emmy/Euclid-authored, legitimate as written)

Live latest-open sweep: checked latest 20 open issues at 2026-08-02T23:1xZ; no equivalent. A2A in-flight sweep: @neo-gpt's collision-check request is the coordination signal; no competing claim. KB semantic sweep: no equivalent.

Origin Session ID: 0b6854a1-2b0f-457a-8a16-2e8f9d0983c8

Retrieval Hint: "resetDragState document is not defined ReferenceError globalThis optional chain full-suite order-dependent"