Miniature set material totals remain stale after incremental recalculation
Level 3 · node · Data · Incorrect topological order in incremental dependency graph recomputation
Scenario
A fictional miniature stage workshop tracks raw material quantities, intermediate bundles, and final material budgets. Budget items are defined as sums of other items, and calculated values are stored in memory. Editing a raw material recalculates only related items. A final budget referencing the same material directly and indirectly through multiple intermediate bundles sometimes retains part of the previous quantity. Trace the dependency index, calculator, value store, and incremental refresh flow.
Requirements
Inputs are raw material values with distinct identifiers and a list of sum formulas. Formulas are provided in topological order, with dependencies declared first; all references are valid and acyclic. Values are finite numbers. Initially calculate every formula in declaration order. When one raw material is updated, calculate each directly or indirectly dependent formula exactly once, after its prerequisites have been updated. All lookups must be current immediately after the update. Do not calculate unrelated formulas. The trace shows the actual order of formula IDs calculated during the last update. Return null for unknown items and do not mutate input objects.
Acceptance criteria
- Initial and unknown item lookups follow the specified contract.
- All derived totals reflect current values even when direct and longer indirect paths converge.
- Each update calculates only affected formulas exactly once, with prerequisite formulas before their consumers.
- Consecutive updates of different materials preserve correct calculation state without mutating input data.