Skip to content

Architecture: chain sync mixes fetch, parse, and side effects with no seam between them #74

@heyitsStylez

Description

@heyitsStylez

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageMaintainer needs to evaluate this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions