Skip to content

Phase 7 Step 3d (leaf 1/5): thread config into consensus-extraction#19

Closed
ethanj wants to merge 1 commit intoarchitecture2from
phase7-3d-consensus-extraction
Closed

Phase 7 Step 3d (leaf 1/5): thread config into consensus-extraction#19
ethanj wants to merge 1 commit intoarchitecture2from
phase7-3d-consensus-extraction

Conversation

@ethanj
Copy link
Copy Markdown
Contributor

@ethanj ethanj commented Apr 18, 2026

Summary

Phase 7 Step 3d leaf 1/5 — thread config explicitly through consensus-extraction.ts instead of reading the module singleton. First drop in the MAX_SINGLETON_IMPORTS ratcheting sequence: 33 → 32.

Plan: atomicmemory-research/docs/core-repo/rearchitecture/phase7-v1-parity/phase7plan.md Item 3d.

What changed

  • src/services/consensus-extraction.ts — dropped the import { config } singleton binding. consensusExtractFacts now takes config as a required parameter typed ConsensusExtractionConfig (Pick-style: consensusExtractionEnabled, consensusExtractionRuns, chunkedExtractionEnabled). New type exported.
  • src/services/memory-ingest.ts — both call sites (performIngest, workspace ingest) pass deps.config explicitly. No signature ripple upstream.
  • src/services/memory-service-types.tsIngestRuntimeConfig gains the three fields the leaf needs, so deps.config satisfies the new parameter type structurally.
  • src/__tests__/config-singleton-audit.test.tsMAX_SINGLETON_IMPORTS ratcheted 33 → 32 with updated comment.

Why defaulting happens at the caller, not the leaf

The plan's load-bearing rule: defaulting to the singleton inside the leaf module would keep the import { config } binding in the file, so the audit count wouldn't drop. Conversion must move the binding out entirely. In this case, deps.config is already built at the composition root (runtime-container.ts) and flows through MemoryServiceDeps, so memory-ingest.ts threads it through — no new defaulting infrastructure needed.

Test plan

  • npx tsc --noEmit clean
  • npm test 963/963 pass (no change in count — no new tests, just signature threading)
  • fallow --no-cache 0 above threshold
  • config-singleton-audit.test.ts passes at the new threshold 32
  • Mocks in dependent test files (smoke.test.ts, memory-ingest-runtime-config.test.ts, etc.) continue to work — mock implementations accept fewer args than the real signature, which JavaScript tolerates

Out of scope

  • Four more leaves in the ratcheting sequence: write-security.ts, cost-telemetry.ts, embedding.ts, llm.ts. Each will land as a separate PR per the plan.
  • The pre-existing process.env.CONSENSUS_MODE read inside the same file (line 44) is not a config-singleton binding, so the audit doesn't flag it. Cleaning that up is a separate concern not covered by Item 3d.

🤖 Generated with Claude Code

First leaf conversion in the singleton-audit ratcheting sequence. Drops
consensus-extraction.ts from the singleton importer set (33 → 32).

- src/services/consensus-extraction.ts: dropped the `import { config }`
  singleton binding. `consensusExtractFacts` now takes config as a
  required parameter typed `ConsensusExtractionConfig`
  (Pick-style: consensusExtractionEnabled, consensusExtractionRuns,
  chunkedExtractionEnabled). The new type is co-located and exported so
  orchestration files importing it get the narrow contract.
- src/services/memory-ingest.ts: both call sites (performIngest line 66,
  workspace line 191) now pass `deps.config` explicitly. Already had
  deps.config in scope — no signature ripple into performIngest/
  performWorkspaceIngest callers.
- src/services/memory-service-types.ts: IngestRuntimeConfig gains
  chunkedExtractionEnabled, consensusExtractionEnabled,
  consensusExtractionRuns so deps.config satisfies the new parameter
  type structurally.
- src/__tests__/config-singleton-audit.test.ts: MAX_SINGLETON_IMPORTS
  ratcheted 33 → 32 with updated justification comment referencing this
  step.

Defaulting location: at the composition root (runtime-container builds
deps.config once from the singleton), not inside the leaf module — so
the leaf file itself no longer binds `config`, which is how it drops
out of the audit. Any alternative where the leaf kept a
"if (!config) fall back to singleton" path would have left the import
in place and made the ratcheting theatre.

963/963 tests pass. tsc --noEmit clean. fallow --no-cache 0 above
threshold.

Plan: phase7-v1-parity item 3d, four leaves remaining
(write-security.ts, cost-telemetry.ts, embedding.ts, llm.ts).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ethanj added a commit that referenced this pull request Apr 18, 2026
Second leaf conversion. Drops write-security.ts from the singleton
importer set (32 → 31). Stacked on PR #19 until it merges.

- src/services/write-security.ts: dropped `import { config }`. Both
  exported functions now take config explicitly:
    - assessWriteSecurity(content, sourceSite, WriteSecurityAssessConfig)
      — reads trustScoringEnabled, trustScoreMinThreshold.
    - recordRejectedWrite(userId, content, sourceSite, decision,
      WriteSecurityRecordConfig, lessons?) — reads auditLoggingEnabled,
      lessonsEnabled, trustScoreMinThreshold (the last is used to build
      the `trust:below-threshold` audit payload, which previously read
      the singleton at emit time).
  Two new exported config interfaces (Pick-style) keep the contract
  narrow; IngestRuntimeConfig satisfies both structurally.
- src/services/memory-ingest.ts:143 + src/services/ingest-fact-
  pipeline.ts:84/130/168/87/170: all 6 call sites thread deps.config.
  No signature ripple — every caller already had deps in scope.
- src/services/memory-service-types.ts: IngestRuntimeConfig gains
  trustScoringEnabled + trustScoreMinThreshold so deps.config satisfies
  both new config interfaces structurally.
- src/services/__tests__/write-security.test.ts: stopped importing and
  mutating the runtime config singleton; builds its own config object
  per test instead. Cleaner — the tests are now pure unit tests with
  explicit inputs.
- src/__tests__/config-singleton-audit.test.ts: MAX_SINGLETON_IMPORTS
  ratcheted 32 → 31.

963/963 tests pass. tsc --noEmit clean. fallow --no-cache 0 above
threshold.

Plan: phase7-v1-parity item 3d. Three leaves remain: cost-telemetry.ts,
embedding.ts, llm.ts.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ethanj
Copy link
Copy Markdown
Contributor Author

ethanj commented Apr 18, 2026

Superseded — bundling all 3d leaves into a single PR per updated review direction. Leaf 1 commits will land on the combined branch.

@ethanj ethanj closed this Apr 18, 2026
@ethanj ethanj deleted the phase7-3d-consensus-extraction branch April 20, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant