Skip to content

forget_replaced_streams matches a selector prefix, so it drops unrelated nested streams #443

Backlog

Description

@Luckyou-d

Problem

_TemplateStream.forget_replaced_streams filters the wrong part of its keys:

def forget_replaced_streams(self, selector: Sequence[str]) -> None:
    for key in list(self.latest_streams):
        if key[:2] == tuple(selector):
            del self.latest_streams[key]

latest_streams is keyed by the selector itself (self.latest_streams[selector] = ..., template_stream.py:182), not by a longer tuple - source_streams is the one keyed (execution_id, retry_index, selector). So the [:2] slice belongs to the other dict.

Two consequences, and the second one is the harmful one:

  • for a two-part selector the comparison is selector[:2] == selector, which is true - so the intended entry is dropped, by accident;
  • for a selector of three or more parts, ("a", "b", "c")[:2] == ("a", "b") is also true, so replacing a.b also forgets the entry of the unrelated nested stream a.b.c.

FrameSession._replace_values calls this for every variable it sees replaced, so whenever a graph has both a.b and a.b.c as streaming selectors, a replacement on the former takes the latter's pinned stream away with it.

Reproduced directly against _TemplateStream (no engine needed): append one stream per selector, call forget_replaced_streams(("source", "text")), and both entries are gone where only the flat one should be.

Expected

Only the entry whose key equals the selector is dropped; a nested selector keeps its pinned stream.

Fix

Compare the whole key. PR to follow with a regression test.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions