Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,46 @@ child replies and discards undisplayed text. See the
[reply ordering tests](tests/engine/test_response_reply_ordering.py) for
buffering and continuation after item failure.

For a root-only pause, save runtime and filter checkpoints from the same pause
after consuming the filtered stream. Rebuild the engine and load the filter
checkpoint into a fresh filter before consuming resumed events. The
[response filter snapshot module](src/graphon/engine/filter/builtin/response_stream/snapshot.py)
parses saved state and migrates older versions when bound to their graph. The
[paired checkpoint tests](tests/engine/test_response_stream_pause.py) exercise
both historical and current snapshots through command and human-input pauses.

Filter checkpoints cover root responses only. Both `dumps()` and `loads()`
reject state with a pending container reply reservation or a child frame that
has started with an Answer or End template. The latter restriction lasts for
the whole run, even after that frame finishes. The filter also rejects resumption
of a child frame in a container with descendant responses. Follow
[child response checkpoint work](https://github.com/langgenius/graphon/issues/356)
for that extension.
The filter's [v4 snapshot](src/graphon/engine/filter/builtin/response_stream/v4.py)
persists the run identity, detached values and templates, source attempts and
occurrence positions, traversal, pending replies, and numeric/nested display order.
Each frame stores either consumed edge decisions or retained legacy residual paths;
native decisions and legacy paths cannot be mixed.
Queued replies survive removal of their execution frames. Repeated frame-start
observations and `initialize()` calls preserve progress for the same persisted
root execution identity; a new run of the same workflow starts fresh. Snapshot
validation completes before replacing live progress, and missing or mismatched
resumed frame progress raises an explicit error.

Fully consume `filter_engine_events(engine.run(), ...)` through a pause and iterator
exhaustion before saving both `engine.runtime_state.dumps()` and
`response_filter.dumps()`. Restore the engine from that runtime snapshot and call
`response_filter.loads()` with its paired filter snapshot before filtering the
resumed run. Use `EngineEventFilterContext.from_engine()` with the rebuilt engine;
rebind host file adapters there. Runtime snapshots alone cannot recover display
history. The once-only guarantee covers this drained, quiescent pause boundary,
not network acknowledgements or crash recovery.

The [v1](src/graphon/engine/filter/builtin/response_stream/v1.py),
[v2](src/graphon/engine/filter/builtin/response_stream/v2.py), and
[v3](src/graphon/engine/filter/builtin/response_stream/v3.py) readers retain root
response progress. Versions 1 and 2 retain their residual blocking paths; v1 also
maps full-graph IDs to root-scoped IDs. Version 3 preserves residual paths or
consumed edge decisions, with rejection winning when historical taken/rejected
lists overlap. Old snapshots without observed skipped edges retain the paired
graph's skip lookup. These historical snapshots cannot establish child display
history or ordering, so their restored run suppresses child presentation, including
newly scheduled rounds; completed legacy frames are treated as drained. Root replies
and ordinary Answer `answer`/`files` results remain available alongside graph, node, and frame-finish
lifecycle events. A later snapshot preserves this suppression policy; a new run
starts with child streaming enabled.
The [pause/resume tests](tests/engine/test_response_stream_resume.py) cover paired
restoration, removed frames, between-round pauses, repeated observations, legacy
child suppression, invalid state, and host file adapter rebinding.
The [response filter tests](tests/engine/test_response_stream_filter.py) cover
native and historical gating state; [paired pause checkpoints](tests/engine/test_response_stream_pause.py)
exercise historical runtime/filter snapshots. The [version isolation test](tests/test_snapshot_version_isolation.py)
keeps current snapshots independent of historical readers.

## State and execution invariants

Expand Down Expand Up @@ -258,9 +283,10 @@ wire response filters. Supply host adapters again when rebuilding from snapshots
See [host file conversion tests](tests/variables/test_workflow_type_encoder.py)
for rendering within that adapter scope.

Persist after fully consuming the run iterator or from a quiescent `on_graph_end`
hook. Hosts must also coordinate direct mutation of exposed runtime objects: the
snapshot guard tracks engine activity, so it cannot protect arbitrary host writes.
Persist runtime state after fully consuming the run iterator or from a quiescent
`on_graph_end` hook. Hosts must also coordinate direct mutation of exposed runtime
objects: the snapshot guard tracks engine activity, so it cannot protect arbitrary
host writes.

## Extension seams

Expand Down
4 changes: 2 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ when changing runtime types, state transfers, or presentation values.
| Change dispatch, scheduling, or containers | [engine](../src/graphon/engine/), [container effects](../src/graphon/nodes/container_effects.py) | [engine tests](../tests/engine/), [container values](../tests/nodes/test_container_effects.py), [container dispatch](../tests/nodes/test_container_dispatch.py), [workflow events](../tests/workflows/test_full_engine_events.py) |
| Change event payloads or response streaming | [raw frame observations](../ARCHITECTURE.md#raw-frame-observations), [response sessions](../ARCHITECTURE.md#response-sessions), [node events](../src/graphon/node_events/), [engine events](../src/graphon/engine_events/), [filters](../src/graphon/engine/filter/) | [frame observation tests](../tests/engine/test_frame_observations.py), [frame failure tests](../tests/engine/test_frame_failures.py), [node event tests](../tests/node_events/), [engine event tests](../tests/engine_events/), [response filter tests](../tests/engine/test_response_stream_filter.py), [response traversal regressions](../tests/engine/test_response_stream_filter_performance.py), [gating regressions](#response-gating-regressions), [container response tests](../tests/engine/test_container_response_streaming.py), [reply ordering tests](../tests/engine/test_response_reply_ordering.py) |
| Change variables or secrets | [variable pool](../src/graphon/runtime/variable_pool.py), [segment models](../src/graphon/variables/segments.py), [variable models](../src/graphon/variables/variables.py), [conversion](../src/graphon/variables/factory.py), [variable assignment](../src/graphon/nodes/variable_assigner/) | [variable pool tests](../tests/runtime/test_variable_pool.py), [Iteration variable ownership](../tests/engine/test_iteration_variable_scopes.py), [variable tests](../tests/variables/), [assignment tests](../tests/nodes/variable_assigner/), [HTTP secret masking](../tests/http/test_executor_secret_masking.py) |
| Change persistence or resume | [runtime state](../src/graphon/runtime/runtime_state/), [container state](../src/graphon/runtime/container_state.py), [nested file snapshots](../src/graphon/variables/file_snapshot.py) | [runtime tests](../tests/runtime/), [file snapshots](../tests/variables/test_file_snapshots.py), [engine serialization](../tests/engine/test_runtime_state_serialization.py), [frame failure restoration](../tests/engine/test_frame_failures.py), [version isolation](../tests/test_snapshot_version_isolation.py) |
| Change persistence or resume | [response sessions](../ARCHITECTURE.md#response-sessions), [filter codecs](../src/graphon/engine/filter/builtin/response_stream/), [runtime state](../src/graphon/runtime/runtime_state/), [container state](../src/graphon/runtime/container_state.py), [nested file snapshots](../src/graphon/variables/file_snapshot.py) | [filter pause/resume](../tests/engine/test_response_stream_resume.py), [runtime tests](../tests/runtime/), [file snapshots](../tests/variables/test_file_snapshots.py), [engine serialization](../tests/engine/test_runtime_state_serialization.py), [frame failure restoration](../tests/engine/test_frame_failures.py), [version isolation](../tests/test_snapshot_version_isolation.py) |
| Change model invocation | [graph-facing LLM protocol](../src/graphon/nodes/llm/runtime_protocols.py), [Slim adapter](../src/graphon/dsl/slim/llm.py), [model runtime](../src/graphon/model_runtime/) | [LLM node tests](../tests/nodes/llm/), [Slim tests](../tests/dsl/test_slim_llm.py), [model dispatch](../tests/model_runtime/test_model_dispatch.py) |
| Change file or HTTP integration | [file](../src/graphon/file/), [engine adapter binding](../src/graphon/engine/engine.py), [HTTP](../src/graphon/http/), [node ports](../src/graphon/nodes/protocols.py) | [file tests](../tests/file/), [execution file isolation](../tests/engine/test_file_runtime.py), [HTTP tests](../tests/http/), [HTTP node tests](../tests/nodes/http_request/), [extractor tests](../tests/nodes/document_extractor/) |

Expand Down Expand Up @@ -120,7 +120,7 @@ and the [independent review sequence](../CONTRIBUTING.md#context-free-reviews).
responses on a connected graph with `E` edges. Doubling the stages approaches
four times that budget because nodes and edges both grow linearly with stages.
The size checks cover one response without buffered source text and exclude
borrowed graph and value-pool objects.
the caller-supplied context and the objects it references.
- [Differential tests](../tests/engine/test_response_stream_filter_differential.py)
compare response activation after each event against the previous path-based
behavior, including repeated and conflicting traversal observations.
Expand Down
Loading
Loading