fix(reactor): merge causal wake references across fan-in and in-flight coalescing - #9
Open
Adityakk9031 wants to merge 1 commit into
Open
Conversation
Author
|
@josemontesdeoca have a look |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fixes a critical flaw in the reconciler where multiple wake events targeting the same downstream node clobbered each other, resulting in the permanent erasure of causal provenance references (
wake.refs) from the immutable ledger and rendering prompt context ("waking receipt refs") blind to preceding producers.Problem & Architectural Invariant
According to
SHAPES.md §1andspec/02-ReactorHarness.md:In fan-in/diamond topology merges (e.g.$P_1 \to S$ and $P_2 \to S$ ) or concurrent in-flight renders, when multiple wakes are delivered to the same node:
startFrontier.commit:wakeFor.set(target, p.wake)unconditionally overwrote any previous producer's wake fortarget.startFrontier: iteratinginitialseeds unconditionally overwrote duplicate seed wakes for the same node.reconcileandreconcileAsync:state.pendingWake = wakeunconditionally overwrote any prior coalesced wakes that arrived while a render was in flight.As a result, downstream receipts were committed with only the last producer's receipt reference in
wake.refs. The causal trail of preceding producers was severed from the ledger, andcomposeWakeHeaderinjected incomplete pointers into LLM agent prompts.Proposed Changes
packages/reactor/src/sdk/wake.ts:mergeWakes(existing: Wake, incoming: Wake): Wake.refsvia an order-preserving, deduplicated union (Set).external>input>self).packages/reactor/src/reactor/index.ts:startFrontierto merge duplicate initial seed wakes.startFrontier.committo merge propagated wakes intowakeFor.reconcileand asyncreconcileAsyncsingle-flight coalescing to merge in-flight wakes intostate.pendingWake.packages/reactor/src/index.ts&packages/reactor/src/sdk/index.ts:mergeWakesas part of the public@openprose/reactorAPI.packages/reactor/src/reactor/__tests__/wake-merge.test.ts:mergeWakes(order, deduplication, source precedence, freezing).Verification
wake-merge.test.ts(5/5 passed).