fix: preserve TextMentionTermination.sources across serialization round-trip - #7933
Humphrey (HumphreySun98) wants to merge 1 commit into
Conversation
…nd-trip `TextMentionTermination` accepts a `sources` argument that restricts which message sources are checked, but `TextMentionTerminationConfig` only stored `text`, and `_to_config`/`_from_config` only serialized/restored `text`. As a result, a condition configured with `sources` silently lost that restriction after a `dump_component()` / `load_component()` round-trip and then fired on any source — a behavior change on save/load. The sibling `SourceMatchTermination` already round-trips its `sources` field correctly. Add `sources` to the config model and serialize/restore it in `_to_config`/`_from_config`, with a regression test covering both the sources-restricted and unrestricted cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ErenAta16 (ErenAta16)
left a comment
There was a problem hiding this comment.
Ran the round-trip test — passes for both the sources-restricted and unrestricted cases. Worth noting this brings TextMentionTermination in line with SourceMatchTermination, which the PR description says already round-trips sources correctly — so this was an inconsistency between two conceptually similar termination conditions rather than a one-off oversight, which matches what I'd expect from how these config classes tend to drift when a field gets added to the runtime class but not mirrored into _to_config/_from_config.
|
Closing and immediately reopening to re-create the expired CI workflow runs (explanation follows). |
|
Explanation for the reopen above: the workflow runs created when this PR opened in July had expired (GitHub expires unapproved fork runs after 30 days) and been purged, so the PR carried zero runs. There was therefore nothing for a maintainer to approve, and the 18 required status checks could never have reported. Reopening at the same commit re-created them, with no commits changed and nothing force-pushed. This PR now has 7 runs in |
Why are these changes needed?
TextMentionTerminationaccepts asourcesargument that restricts whichmessage sources are checked for the termination text:
However
TextMentionTerminationConfigonly storedtext, and_to_config/_from_configonly serialized/restoredtext. So a conditionconfigured with
sourcessilently loses that restriction after a declarativedump_component()/load_component()round-trip, and the reloaded conditionthen fires on any source (including
useror other agents) — a behaviorchange on save/load.
The sibling
SourceMatchTerminationalready round-trips itssourcesfieldcorrectly (and the existing declarative test asserts it), which makes this an
inconsistency rather than an intentional omission.
This PR adds
sourcestoTextMentionTerminationConfigand serializes/restoresit in
_to_config/_from_config, with a regression test covering both thesources-restricted and unrestricted cases.
Related issue number
N/A — found during review. Fixes a serialization round-trip data loss;
SourceMatchTerminationis the correct reference behavior.Related PRs
sourcesto the config and round-trips it). I did not find it before opening this one. Differences are minor: fix: preserve TextMentionTermination sources in config #7837 normalizessourcesto a list in__init__, this PR does so in_to_config, and this PR's test also covers the unrestricted (sources=None) case. Either fixes the bug; happy for maintainers to merge whichever and close the other.Checks
ruff,mypy, and the relevantpytestlocally).