Problem
syncRysk() fetches, parses, applies to trades, calls save(), and calls render() — all inline. autoDetectOutcomes() follows the same mutation pattern but deliberately does not call save/render, leaving that responsibility to the caller. There is no documented contract for which functions own persistence.
The execution order in autoLoadChain() is:
autoLoadChain()
→ migrateCloseTrades() [mutates trades, calls save/render]
→ syncRysk() [mutates trades, calls save/render]
→ resolveRyskOutcomes() [mutates trades, no save/render]
→ syncHypersurface() [mutates trades, calls save/render]
→ autoDetectOutcomes() [mutates trades, requires caller to save/render]
Adding a new sync source requires inferring the ownership pattern from existing code — there is no seam to hang a new adapter from.
Files involved
src/js/18-chain-sync.js
src/js/18b-chain-apply.js
Proposed solution
Split the sync pipeline into two explicit halves:
- Pure half: parse and classify trades (no side effects) — extends
18b-chain-apply.js's existing intent
- Impure half: apply, save, render — consolidated in
autoLoadChain as one explicit step
Benefits
resolveRyskOutcomes, resolveHsfcOutcomes, and autoDetectOutcomes become pure classifiers testable in Node without fetch mocks
- The save/render cycle is one place in
autoLoadChain instead of four
- Consistent ownership contract — no ambiguity about who calls
save/render
Category
Deepening opportunity — architecture review
Problem
syncRysk()fetches, parses, applies totrades, callssave(), and callsrender()— all inline.autoDetectOutcomes()follows the same mutation pattern but deliberately does not callsave/render, leaving that responsibility to the caller. There is no documented contract for which functions own persistence.The execution order in
autoLoadChain()is:Adding a new sync source requires inferring the ownership pattern from existing code — there is no seam to hang a new adapter from.
Files involved
src/js/18-chain-sync.jssrc/js/18b-chain-apply.jsProposed solution
Split the sync pipeline into two explicit halves:
18b-chain-apply.js's existing intentautoLoadChainas one explicit stepBenefits
resolveRyskOutcomes,resolveHsfcOutcomes, andautoDetectOutcomesbecome pure classifiers testable in Node without fetch mocksautoLoadChaininstead of foursave/renderCategory
Deepening opportunity — architecture review