Repository navigation
perf(response-stream): replace path enumeration with O(V+E) reachability gating - #399
tang-ontheway wants to merge 2 commits into
Conversation
|
All contributors on this pull request have signed the CLA. |
|
I have read the CLA Document and I hereby sign the CLA |
QuantumGhost
left a comment
There was a problem hiding this comment.
The new representation removes the exponential path enumeration reported in #398, but two issues need to be addressed before merging: the persisted snapshot compatibility break (P1) and the repeated-traversal performance regression (P2). See the inline comments for reproductions and deterministic operation counts.
AI disclosure: This review was drafted with Codex using gpt-6.1-sol and is submitted under the human reviewer's direction and responsibility.
| version: Literal["2.0"] = "2.0" | ||
| # Missing metadata retains the historical paired-graph skip lookup. | ||
| skipped_edges: list[str] | None = None | ||
| taken_edges: list[str] = Field(default_factory=list) |
There was a problem hiding this comment.
[P1] Version the new persisted representation instead of reusing 2.0
This changes the meaning of the persisted state, rather than merely adding an optional field: newly initialized sessions now write an empty paths_map and rely on taken_edges plus graph reachability. The existing 2.0 reader accepts that snapshot, ignores the new field, and restores no blocking paths. Pending responses then never activate, even after their blocking edges are taken, without any error indicating an incompatible snapshot.
Reproduced against base 069cd554: buffer hello before the blocking edge, save a snapshot with this PR, restore it, and deliver the edge-taken event. This PR's reader emits hello; the base reader accepts the same 2.0 snapshot and emits nothing. Loading an old snapshot with the new reader works, but that does not protect mixed-version workers or rollback.
A workflow with multiple HITL nodes can remain alive across deployments and suspend/resume repeatedly. Any such boundary can hand a new-format instance to an old reader, so silently accepting an incompatible format is a correctness issue for persisted workflows. This is a cross-version risk; the reproduction does not imply that repeated suspensions within the same new version fail.
Please write the new representation as a new snapshot version (for example, v3), keep the v1/v2 loading and migration paths, and cover version rejection and repeated suspend/resume recovery.
| has_reachable_path = True | ||
|
|
||
| if has_reachable_path: | ||
| if self._is_response_unblocked(response_node_id): |
There was a problem hiding this comment.
[P2] Avoid restarting a full reachability walk for every taken edge
Every traversal event now restarts BFS from the root for every pending response, including events on nonblocking edges that cannot change its eligibility. Consider an N-edge linear graph whose only blocking edge is the final branch before Answer: handling the N edge events performs N full walks. This is quadratic with indexed root adjacency. In child frames, _GraphDefinition.get_outgoing_edges() scans the entire edge dictionary on each query, making the same event-handling phase cubic.
A deterministic counter using the actual child _GraphDefinition and _FrameSession produces 10,000 / 40,000 / 160,000 adjacency queries for N = 100 / 200 / 400. Because each query tests all N edges, that is 1,000,000 / 8,000,000 / 64,000,000 edge-tail tests during edge-event handling alone, excluding initialization and initial activation. The previous implementation needs only one blocking-path update per event on this single-path graph. The existing diamond test does not exercise this regression.
Please retain and advance reachability incrementally per response, and avoid the full-edge scan in child adjacency lookup. Add a deterministic work-budget regression for a long nonblocking prefix followed by a blocking branch, covering the complete traversal rather than initialization alone.
|
Thanks for the detailed review @QuantumGhost! Both points are addressed in b8a1949:
|
|
Thanks @QuantumGhost for the detailed review and deterministic reproductions! Both issues have been addressed in commit
Verified locally with |
Fixes #398
Summary
_find_all_pathsduring_register_response) inResponseStreamFilter's_FrameSessionwithO(V + E)edge classification (_compute_blocking_edges) and BFS reachability (_is_response_unblocked) over non-skipped, non-blocking-or-taken edges.taken_edgestov2.Snapshot(src/graphon/engine/filter/builtin/response_stream/v2.py) so mid-traversal snapshots stayO(V + E)in size without materializing exponentialpaths_maplists, while preserving backward compatibility with v1/v2 snapshots that carry explicitpaths_mapentries.tests/engine/test_response_stream_filter_performance.pyand addedtest_response_filter_handles_diamond_dag_without_path_enumeration(12-stage diamond DAG, 4,096 paths) asserting deterministic graph-query budget, compact snapshot size, and mid-traversal snapshot restore + final chunk output.Testing
uv run pytest tests/engine/test_response_stream_filter.py tests/engine/test_response_stream_filter_performance.py -q->69 passeduv run ruff check src/graphon/engine/filter/builtin/response_stream/ tests/engine/test_response_stream_filter_performance.py->All checks passed!uv run ty check src/graphon/engine/filter/builtin/response_stream/->All checks passed!