LearnNewsExamplesServices
Frontmatter
id11831
titleOrchestrator.mjs masterclass-reference: 4-way Service-DI classification + Neo.util.Env substrate + 2-value chain
stateClosed
labels
enhancementepicairefactoringarchitecturemodel-experience
assigneesneo-opus-ada
createdAtMay 23, 2026, 1:20 PM
updatedAtJun 7, 2026, 7:14 PM
githubUrlhttps://github.com/neomjs/neo/issues/11831
authorneo-opus-ada
commentsCount5
parentIssuenull
subIssues
11832 Sub 6: Neo.util.Env THIN substrate primitive (lift EnvConfig.mjs parsers to src/util/Env.mjs)
11833 Sub 1: Orchestrator masterclass-reference refactor (4-way Service-DI + 2-value chain + configure() removal)
11834 Sub 2: Orchestrator test-fixture + invariant coverage for new config substrate
11835 Sub 3: Removal of DEFAULT_* constants + parser surfaces made obsolete by Orchestrator refactor
11836 Sub 4: Sibling daemon propagation of masterclass-reference pattern (5-6 daemon files)
11837 Sub 5: External-user configurability audit (forks, npx neo-app workspaces, non-Neo-team clients)
11840 Sub 7: Bump swarmHeartbeatMs wake interval 5m → 15m
11844 Sub 8: Orchestrator-cluster co-location (ai/daemons/orchestrator/) + daemon.mjs naming + test mirror + package.json
11845 Sub 9: Sub-daemon cluster co-location (bridge + kb-alerting + kb-gc + kb-reconciliation) with daemon.mjs naming
11846 Sub 10: Cross-daemon services bucket (ai/services/graph/ + ai/services/ingestion/)
11847 Sub 11: ai/scripts/ thematic split (lifecycle/maintenance/migrations/diagnostics/runners/setup/lint)
11848 Sub 12: Collapse buildScripts/ai/ into ai/scripts/{maintenance,migrations,diagnostics,runners,setup}/
11854 Sub 13: Collapse over-engineered Orchestrator Service-DI (Class C field deletion + historical-context comment strip)
11855 Sub 14: Centralize env-binding registry — ai/config/env.mjs + dotenv lift
11858 Sub 15: Extract DreamCoordinatorService — getDueTask only, due-trigger selection only
11859 Sub 16: Extract SwarmHeartbeatCoordinatorService — getDueTask only, initAsync stays in service
11860 Sub 17: Extract GoldenPathCoordinatorService — due/dependency trigger only, synthesizer stays as execution service
11861 Sub 19: Extract MaintenanceBackpressureService — heavy/golden predicates + deferral recording + lease/dependency executor wrappers (B-prime)
11862 Sub 18: Orchestrator generic registry wire-up + CadenceEngine pure-trigger-builder correction + collector/pickNextCandidate (Round-2 closer)
11864 Sub 20: Harmonize existing Coordinator services to scheduling/.mjs pure-function pattern\_ \_
12130 IssueIngestor community-multiplier hardcodes operator login ''tobiu''
subIssuesCompleted21
subIssuesTotal21
blockedBy[]
blocking[]
closedAtJun 7, 2026, 10:17 AM

Orchestrator.mjs masterclass-reference: 4-way Service-DI classification + Neo.util.Env substrate + 2-value chain

Closed Backlog/active-chunk-14 enhancementepicairefactoringarchitecturemodel-experience
neo-opus-ada
neo-opus-ada commented on May 23, 2026, 1:20 PM

Epic Origin

Graduated from Discussion #11828 (Cycle-3.3 [GRADUATION_APPROVED by @neo-gpt @ DC_kwDODSospM4BA-Ic] at body anchor 2026-05-23T10:58:31Z).

Originating empirical anchor: operator-triggered substrate-quality crisis 2026-05-23. Operator framing: "current version: not maintainable, bloats your context window... this is the worst code i have seen in over a year. junior cowboy coding SHIT. quality scale 1 to 100 => a 5. neo standards is 90+. let us turn the orchestrator into a masterclass elegant solution." PR #11825 closed Drop+Supersede; #11827 captured only ~5% of the actual anti-pattern stack.

Concept

Redesign ai/daemons/Orchestrator.mjs as a masterclass-reference implementation of the Neo daemon config substrate. Eliminates the layered anti-pattern stack (~30 cargo-cult reactive configs, configure() shadow-resolver, 6-value fallback chains, DEFAULT_X constants in TaskDefinitions.mjs, domain-class env-parser ownership). Then propagate the pattern to ~6+ sibling daemon files.

Tier classification

Tier-2 (substrate-architecture, touches core/Base.mjs consumption pattern + propagation to ~6+ daemon files + sets cross-substrate config contract).

Acceptance Criteria

  1. AC1 — No cargo-cult _-suffix configs: Orchestrator.mjs has no _-suffix reactive config unless the PR introduces real beforeGet* / beforeSet* / afterSet* hook for that property. Legitimate reactive collaborators (e.g., cadenceEngine_) keep _-suffix with hooks + ClassSystemUtil.beforeSetInstance(value, DefaultClass, defaults) — DefaultClass passed DIRECTLY as 2nd arg (NOT via {module: DefaultClass} config). NO beforeGet* + NO manual backing assignment; reactive setter handles defaulting naturally.
  2. AC2 — 2-value policy chain: Operator-tunable daemon values resolve through exactly two policy sources: canonical env var OR AiConfig. No options.X, no DEFAULT_X constant fallback, no env-alias chain.
  3. AC3 — Explicit env decoding: Env decoding handles unset, empty string, zero, invalid numeric values, and boolean false explicitly. Invalid env operator-visible (warn-and-undefined per Neo.util.Env semantics).
  4. AC4 — 4-way Service-DI classification: (A) class-system-managed utility collaborators with hooks + ClassSystemUtil; (B) parent-configured child collaborators with creation hooks + parent afterSet* propagation hooks (covers processSupervisorService_; explicit removal of processSupervisorService.set({...this...}) context-replay block in start()); (C) simple direct-import instance-fields ONLY when no class-system conversion / no parent-child propagation / no lifecycle side effect; (D) operator policy values via lazy getter + 2-value chain. Mis-classification = Tier-2 revalidation trigger. Logger function passed to child services must be a stable function seam (not per-call .bind(this) allocation).
  5. AC5 — configure() removed: REMOVED as runtime-policy resolver. start(options) may keep narrow boot-wrapper seams for paths/process/test harnesses, but not as a second default system for intervals/toggles/services.
  6. AC6 — Thin daemon wrapper: orchestrator-daemon.mjs remains a thin process wrapper (PID, cleanup, local config loading, start invocation). NOT new policy-translation dumping ground.
  7. AC7 — Test coverage of real surfaces: Unit tests prove config precedence through real surfaces: env over AiConfig, gitignored config mutation via AiConfig.data, service override by instance field, singleton leak prevention, source-level invariants for removed anti-patterns. Tests must prove parent-config mutations on Orchestrator propagate to ProcessSupervisorService via afterSet* hooks (NOT via start() context replay).
  8. AC8 — Tier-2 liveness + revalidationTrigger: Gemini benched on this convergence pass → Epic carries ## Unresolved Liveness + revalidationTrigger AC. Revalidation triggers if implementation chooses eager snapshotting / keeps configure() as policy resolver / reintroduces env aliases / adds shared helper that knows fallback policy / places env-parser on a domain class.
  9. AC9 — Neo.util.Env substrate primitive: Lives at src/util/Env.mjs, mirrors Neo.util.String static-class precedent. API: parseNumber, parseBool, parsePort, parseUrl, parseString, applyEnvBindings, setDeep. Availability: added to src/util/_export.mjs barrel AND consumers use direct import Env from '<path>/src/util/Env.mjs'. Boolean compatibility: parseBool MUST preserve PrimaryRepoSyncService.parseEnabledFlag token semantics ('0', 'false', 'no', 'off' → false) OR Epic explicitly declares hard-cut behavior change with tests + env-var migration notes. All env-parser surfaces at lower tiers (EnvConfig.mjs, CadenceEngine.parseInterval, PrimaryRepoSyncService.parseEnabledFlag) retire or rewire through Neo.util.Env. No env-parser methods on domain classes. Test surface: test/playwright/unit/util/Env.spec.mjs.

Sub-decomposition (6 subs)

Sub 6 is the substrate-prerequisite; Sub 1 depends on Sub 6; Subs 2-5 parallel after Sub 1.

  1. Orchestrator masterclass-reference refactor — primary lane; DEPENDS ON Sub 6.
  2. Test-fixture + invariant coverage for the new config substrate.
  3. Removal/narrowing of DEFAULT_* / parser surfaces (subsumes #11827).
  4. Sibling daemon propagation (SwarmHeartbeatService, KbAlertingService, KbReconciliationService, KbGarbageCollectionService, GapInferenceEngine).
  5. External-user configurability audit — forks, npx neo-app workspaces, non-Neo-team clients.
  6. Neo.util.Env THIN substrate primitive — create + register + Orchestrator-needed parser surface + EnvConfig.mjs consumer rewire + test surface. Full 61-file consumer migration decomposes into Sub 6a/6b/6c follow-up tickets.

Avoided Traps

  • Defense-in-depth fallback layers (2 values max per operator).
  • Keeping _-suffix configs for "future hooks" (YAGNI; cargo-cult).
  • Treating configure() as a Neo-class idiom (it isn't).
  • Placing env-parser methods on domain classes (Cycle-3 anti-pattern; Tier-1 Neo substrate is the correct landing).
  • Making the full 61-file env-var migration a Sub-1 prerequisite (Sub 6 stays THIN).
  • Manual backing-assignment + beforeGet* defaulting for reactive configs (Cycle-3.2 lesson; reactive setter handles defaulting through ClassSystemUtil.beforeSetInstance directly).
  • Citing non-existent import paths in body authority snippets (Cycle-3.3 lesson; V-B-A import paths against actual file tree before body-finalization).

Unresolved Liveness

  • gemini (@neo-gemini-pro): participationStatus: operator_benched since 2026-05-18T00:00:00.000Z. reactivationTrigger per ai/graph/identityRoots.mjs. STATUS: pending Gemini reactivation; Epic carries revalidationTrigger AC per §6.2(c) Tier-2 requirement (AC8 explicitly). Sub #11803 mechanism (npm run ai:revalidation-sweep -- --family gemini) notifies Gemini at reactivation.

Related substrate anchors

  • Originating Discussion: #11828 (Cycle-3.3 [GRADUATION_APPROVED] at body updatedAt 2026-05-23T10:58:31Z)
  • src/core/Base.mjs:64-93 — reactive vs non-reactive config primitive documentation
  • src/util/ClassSystem.mjs:23-60beforeSetInstance(value, DefaultClass, defaults) API (V-B-A: file exists; sibling consumers Breadcrumb.mjs:1, Loop.mjs:3, Database.mjs:2)
  • src/util/String.mjs — substrate-utility static-class precedent for Neo.util.Env
  • src/toolbar/Breadcrumb.mjs:38-126store_ reactive-config-with-hooks precedent (Service-DI Class A)
  • src/grid/Container.mjs:520-540 — parent-store-propagation precedent (Service-DI Class B)
  • ai/config.template.mjs — canonical defaults substrate
  • ai/mcp/server/shared/helpers/EnvConfig.mjs — 95% correct env-parser surface at wrong (T2) tier; lifts to Neo.util.Env
  • ai/daemons/services/CadenceEngine.mjs / ProcessSupervisorService.mjssingleton: true examples (named-class import required for ClassSystemUtil)
  • #11825 — closed Drop+Supersede (~5% capture)
  • #11827 — narrow audit-record (subsumed by Sub 3)
  • #11075 — original "exploration: migrate orchestrator magic numbers" ticket

Discussion Cycle History (compressed)

  • Cycle-1: original 5-layer proposal
  • Cycle-2 [GRADUATION_APPROVED] (superseded): env-decoder substrate correction per GPT node -e falsification — Number(undefined) === NaN, NaN ?? fallback === NaN
  • Cycle-2.5: CadenceEngine reactive correction per @tobiu — class-system-managed collaborator with hooks
  • Cycle-3 (STRONG VETO from @tobiu): env-parser primitive lifted Tier-3 → Tier-1 (Neo.util.Env); Epic 5→6 subs
  • Cycle-3.1: 8 body-anchor fixups per GPT
  • Cycle-3.2: CadenceEngine direct-class-arg pattern
  • Cycle-3.3 [GRADUATION_APPROVED]: 3 narrow snippet-authority fixes (import path, semantics callout, ProcessSupervisorService symmetric correction)

Authored by: [Claude Opus 4.7] (Claude Code)

tobiu referenced in commit 27f7a65 - "refactor(agentos): Orchestrator masterclass-reference (4-way Service-DI + Neo.util.Env + configure() removal) (#11833) (#11842) on May 23, 2026, 3:10 PM
tobiu referenced in commit 7e7adb2 - "refactor(agentos): delete obsolete CadenceEngine.parseInterval + PrimaryRepoSyncService.parseEnabledFlag (#11835) (#11843) on May 23, 2026, 3:28 PM
tobiu referenced in commit 6cc9179 - "refactor(agentos): orchestrator-cluster co-location ai/daemons/orchestrator/ + daemon.mjs (#11844) (#11849) on May 23, 2026, 4:57 PM
tobiu referenced in commit 91366d2 - "refactor(agentos): sub-daemon cluster co-location ai/daemons/{bridge,kb-alerting,kb-gc,kb-reconciliation}/ + daemon.mjs (#11845) (#11850) on May 23, 2026, 5:26 PM
tobiu referenced in commit 32893c1 - "refactor(agentos): cross-daemon services bucket ai/services/{graph,ingestion}/ (#11846) (#11851) on May 23, 2026, 5:44 PM
tobiu referenced in commit e207fa3 - "refactor(agentos): ai/scripts/ thematic split lifecycle|migrations|diagnostics|setup|lint (#11847) (#11852) on May 23, 2026, 6:37 PM
tobiu referenced in commit e6c9df0 - "refactor(agentos): buildScripts/ai/ collapse into ai/scripts/{maintenance,migrations,diagnostics,runners,setup}/ (#11848) (#11853) on May 23, 2026, 7:42 PM
tobiu referenced in commit e365943 - "feat(agentos): extract DreamCoordinatorService — getDueTask only (#11858) (#11863) on May 23, 2026, 10:37 PM
tobiu referenced in commit ac2fecf - "feat(agentos): extract swarm-heartbeat due-trigger projection (#11859) (#11865) on May 23, 2026, 10:50 PM
tobiu referenced in commit 9836060 - "refactor(agentos): harmonize 3 Coordinator services to scheduling/.mjs (#11864) (#11941) on May 25, 2026, 7:26 AM
tobiu referenced in commit 193b5f5 - "test(orchestrator): add Sub-1 invariant + config-precedence + propagation coverage (#11834) (#11945) on May 25, 2026, 7:49 AM
tobiu referenced in commit 5d428ab - "test(orchestrator): external-config audit invariants AC1-3 + AC4-5 findings (#11837) (#11946) on May 25, 2026, 7:50 AM