Second root Answer omits LLM text already streamed by the first Answer

Open
#435 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start from the repro script in the issue or run tests/engine/test_response_stream_filter.py around lines 1366-1405, then inspect src/graphon/engine/filter/builtin/response_stream/template_stream.py near lines 394-419 where the filter tracks its read position per selector. Trace how the closed llm.text cursor is reused by the second Answer. Done means the concatenated NodeRunStreamChunkEvent chunks read first:value|next:value while the second Answer's saved output remains next:value.

Written by the indexing model from the issue text.

Description

project#graphon

AI disclosure — Codex (gpt-6.2-astra) helped draft and verify this report. I reviewed the underlying behavior and am responsible for the report.

Description

When two root Answer nodes each reference {{#llm.text#}} once, the second Answer saves the full text but its streamed reply omits the LLM output. This reproduces on main (2e8b664) and on #395 (02e7e19).

Minimal reproduction

  1. Connect four nodes in sequence: Start → LLM → First Answer → Second Answer. Give the LLM node the ID llm and have it stream the text value.
  2. Set the first Answer template to first:{{#llm.text#}}| and the second to next:{{#llm.text#}}.
  3. Run the graph with ResponseStreamFilter and concatenate the emitted NodeRunStreamChunkEvent.chunk strings.
Expected Actual
Streamed text first:value|next:value first:value|next:
Second Answer's saved answer output next:value next:value
Runnable example with an in-process model stub

Run from the Graphon repository root with the development dependencies installed. The script uses the existing Slim LLM example graph and supplies one model token locally.

PYTHONPATH=.:src uv run python - <<'PY'
from pathlib import Path
from unittest.mock import patch

import yaml
from graphon.dsl import loads
from graphon.engine.filter import (
    EngineEventFilterContext, ResponseStreamFilter, filter_engine_events,
)
from graphon.engine_events.node import NodeRunStreamChunkEvent
from graphon.model_runtime.entities.llm_entities import LLMResultChunk, LLMResultChunkDelta
from graphon.model_runtime.entities.message_entities import AssistantPromptMessage
from tests.helpers.workflow_events import FakeSlimLLM

dsl = yaml.safe_load(Path("examples/slim_llm/graph.yml").read_text())
graph = dsl["graph"]
first = next(node for node in graph["nodes"] if node["id"] == "answer")
first["data"]["answer"] = "first:{{#llm.text#}}|"
graph["nodes"].append({
    "id": "second", "data": {"type": "answer", "answer": "next:{{#llm.text#}}"},
})
graph["edges"].append({"source": "answer", "target": "second"})

token = LLMResultChunk(
    model="gpt-4o-mini",
    delta=LLMResultChunkDelta(index=0, message=AssistantPromptMessage(content="value")),
)
credentials = {"model_credentials": [{"vendor": "openai", "values": {"openai_api_key": "unused"}}]}
with (
    patch("graphon.dsl.node_factory.SlimLLM", FakeSlimLLM),
    patch.object(FakeSlimLLM, "invoke_llm", return_value=iter([token])),
):
    engine = loads(yaml.safe_dump(dsl), credentials=credentials, start_inputs={"query": "test"})
    events = filter_engine_events(
        engine.run(),
        context=EngineEventFilterContext.from_engine(engine),
        filters=[ResponseStreamFilter()],
    )
    text = "".join(event.chunk for event in events if isinstance(event, NodeRunStreamChunkEvent))

print("Stream:", repr(text))
print("Second Answer:", repr(engine.runtime_state.variable_pool.get(["second", "answer"]).value))
PY

The root response filter stores its read position per selector. After the first Answer consumes the closed llm.text stream, the second Answer sees the same exhausted cursor and advances past its placeholder. The existing filter test also records the single-reference second reply ending at next:. Filter implementation · Existing test

Tracked separately as a non-blocking follow-up to #395.

Dominant language
Python
Stars
90
Forks
47
Avg merge
3d 23h
Merged PRs (30d)
19

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from langgenius/graphon

All issues in langgenius/graphon

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.