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
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"
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 threeDragDrop.spec.mjsreset witnesses (:639reset during initial drain,:679older native completion inert,:895reset 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 asfd8dc1105a) reads:document.body?.classList?.remove('neo-drag-active');The optional chaining guards
bodyandclassList— but not thedocumentroot itself. In any context whereglobalThis.documentis entirely absent, the line throwsReferenceError: document is not definedbefore any property access. The guard comment directly above promises bare-harness safety ("bare test harnesses may stubdocumentwithout a body/classList") — the code does not deliver it when the harness provides nodocumentat all.The three failing witnesses drive
resetDragState()directly with hand-built addon objects — a legitimate harness use that hits this line. Whetherdocumentexists at that moment is schedule-dependent: the suite's global-stubbing spec files installglobalThis.documentat import and delete it inafterAllwhen 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 at63149823e2, and never in exact-file or small-slice runs.Reproduction dossier (all at clean
63149823e2, this host):ReferenceError: document is not definedatDragDrop.mjs:362, stack in the run artifacts).unit/main/addonslice /unit/mainslice / pair withMouse.spec.mjsin both orders: all green.Mouse.spec.mjsas 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=1/2green;--shard=2/2fails 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:362is the proven throw site:resetDragStateis driven directly by harnesses without anyattach()/DOM lifecycle, so it is reachable document-less.#16381guard commit (e20c425e2d) fixed thebody/classListtier after the first bare-harness CI failure and stopped one tier short of the root.The Fix
Root the optional chain at
globalThisin the proven site:globalThis.document?.body?.classList?.remove('neo-drag-active');globalThis.documentis always a defined binding (valueundefinedwhen 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.mjssites were dropped from this ticket. The sensor's methods requiredocumenton 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'sdocument.body?.classListshape (from #16381) is browser-correct as-is.Acceptance Criteria
DragDrop.mjs:362rooted atglobalThis.document?with the guard comment naming the no-documentcaseReferenceErrorinunit/main/addon/DragDrop.spec.mjs— red against the pre-fix line, green with it; no dependence on full-suite orderingunit/main/addon/DragDroptargeted run green (the witnesses' own file, 23/23-class)unit/main/draggable/sensor/Mousetargeted run green (4/4 — the terminal-contract pins; the sensor itself is untouched after the RA-2 scope narrowing)Out of Scope
HealthService,Provider,FileUpload,Env— separate latent class, separate ticket if it recurs)TextEmbeddingServicefailures (environmental)document)Related
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"