Make NodeRunStreamChunkEvent immutable
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 50/100
Research direction
Start with the NodeRunStreamChunkEvent definition in the graphon engine_events node module, then read how ResponseStreamFilter buffers and forwards events in src/graphon/engine/filter/builtin/response_stream/template_stream.py. Run the reproduction script against tests/engine/test_response_stream_filter.py helpers to confirm the shared-reference checkpoint. Done when assigning to event.chunk fails, the downstream copy pattern still works, and the existing response-filter tests pass.
Written by the indexing model from the issue text.
Description
AI disclosure — I discussed this behavior with Codex (gpt-6.2-astra), which verified the example and helped draft this report. I am responsible for the report.
Description
ResponseStreamFilter can yield a NodeRunStreamChunkEvent while keeping a reference to that same object in its root stream buffer. A later filter can assign a new string to event.chunk. The next checkpoint of the earlier filter then contains the downstream edit. Python strings are immutable, but the event allows its chunk field to be reassigned. Buffer insertion · Forwarding the event · Serializing the buffer
Minimal reproduction
Run from the Graphon repository root. The example uses the existing response-filter test graph and one non-final source chunk. EscapeText is a custom filter added for this reproduction. It consumes the same public filter API a host can use.
PYTHONPATH=.:src uv run python - <<'PY'
import json
from html import escape
from graphon.engine.filter import ResponseStreamFilter, filter_engine_events
from graphon.engine_events.graph import GraphRunStartedEvent
from graphon.engine_events.node import NodeRunStreamChunkEvent
from tests.engine.test_response_stream_filter import (
_context, _stream_chunk, _variable_response_graph,
)
class EscapeText:
def initialize(self, context):
pass
def on_event(self, event):
if isinstance(event, NodeRunStreamChunkEvent):
event.chunk = escape(event.chunk)
return [event]
def flush(self):
return []
selector = ["source", "text"]
response = ResponseStreamFilter()
events = filter_engine_events(
[GraphRunStartedEvent(), _stream_chunk("&", selector=selector, is_final=False)],
context=_context(_variable_response_graph(selector=selector)),
filters=[response, EscapeText()],
)
print("display:", [e.chunk for e in events if isinstance(e, NodeRunStreamChunkEvent)])
buffer = json.loads(response.dumps())["stream_buffers"][0]
print("checkpoint:", buffer["events"][0]["chunk"])
PY
Expected and actual behavior
The source emits &. A display filter should be able to produce & while the upstream response filter retains the & it observed. For a control, change just the assignment in EscapeText.on_event to event = event.model_copy(update={"chunk": escape(event.chunk)}).
| Downstream transformation | Displayed chunk | Chunk in the upstream checkpoint |
|---|---|---|
Assign to event.chunk |
& |
& |
| Return an updated copy | & |
& |
Verified both rows on Python 3.12.12 at main (b79228b) and on #395 (d4032bf). The checkpoint example works with a single reference on main. Replaying a reference makes the same effect visible in the reply on #395: for source text &a and template {{#llm.text#}}/{{#llm.text#}}, the custom in-place filter produced &a/&amp;a. Returning a copy produced &a/&a.
Proposed change
I propose making NodeRunStreamChunkEvent immutable from construction. A filter can forward the event it received or return a new event when it transforms the text, for example event.model_copy(update={"chunk": escape(event.chunk)}). An attempt to assign to event.chunk should fail at the point of assignment.
With this contract, ResponseStreamFilter can retain the source event for checkpointing and replay. In the example above, the downstream consumer receives & and the upstream checkpoint still contains &. This proposal can be handled independently of #395.
- Dominant language
- Python
- Stars
- 90
- Forks
- 47
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langgenius/graphon
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/graphon#443 ·
Maintainers usually reply within 2 days
-
Complete LLM results disappear from streamed answersPossibly taken @WH-2099 claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
langgenius/graphon#389 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
bug(utils): parse_json_markdown drops a valid payload when the text contains a backtickPossibly taken @WH-2099 claimed this 9 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
langgenius/graphon#380 · 1 assignee ·
Maintainers usually reply within 2 days
-
project#graphon
Difficulty 4/5 3-5 days Newbie friendliness 40/100
langgenius/graphon#442 ·
Maintainers usually reply within 2 days
-
project#graphon
Difficulty 5/5 Over a week Newbie friendliness 8/100
langgenius/graphon#436 · 3 comments ·
Maintainers usually reply within 2 days
All issues in langgenius/graphon
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
[BUG]: Management endpoints /v1/memory/stats and /v1/memory/counts bypass API key authenticationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
docling-project/docling-serve#788 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainers usually reply within 1 day
-
load_advbench() re-raises HTTPError as the bare class, so a failed download ends in a TypeErrorOpenneeds-triage
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Maintainers usually reply within 2 days