Repository navigation
fix(harness): make MsgContext.canonicalKey injective for routing - #3535
hermanrous wants to merge 2 commits into
Conversation
canonicalKey() joined the routing components with an unescaped separator, so two different contexts could produce the same session key and share one gateway session. Escaping % and | keeps keys without reserved characters unchanged. Refs agentscope-ai#3534
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Thanks — the Two small suggestions:
Minor: components containing |
Addresses review feedback on agentscope-ai#3535. An extra key containing '=' could still forge a collision: {"a": "b=c"} and {"a=b": "c"} both produced "c|x:a=b=c". Extra keys are now escaped for '=' as well, while values stay untouched. The canonical key format is also pinned with a golden assertion because the key derives persisted gateway session ids, plus a case covering every escape.
|
Both points are implemented in e72a07b.
The description now notes the compatibility effect: a component containing Local checks: |
|
[P1] The new encoding can reuse a different conversation's pre-upgrade session key. The escaping fixes collisions within the new format, but old and new key spaces overlap. For example, with channel
Please isolate the new encoding from persisted legacy keys (or provide a migration that establishes ownership) and add a regression that creates the first conversation under the legacy encoding, upgrades, then routes the second conversation. Document the migration behavior alongside the unchanged ordinary-character keys. Reviewed head: |
Problem
MsgContext#canonicalKey()builds the gateway routing key by joining the components with a bare|and never escaping that separator inside a component, so the key is not injective:extrakeys and values are joined the same way and can forge structural fragments too.Impact
The canonical key is the gateway session key — it derives the session id, keys the per-session turn gate and the session -> key wake-up map. A collision routes two different conversations to the same gateway session, so one group/room can see another conversation's state.
Fix
Escape
%(first) and|in each component before appending. A component without reserved characters keeps its old key, so existing session mappings are unaffected;HarnessGatewaySessionIdTestandSessionIdUtilsTeststill pass.Tests
New
MsgContextCanonicalKeyTestfails onmain(expected: not equal but was: <chatui|g:team|r:room-1>) and passes with the fix. The gateway test set (10 classes, 40 tests, includingHarnessGatewaySessionIdTest) is green;spotless:checkpasses.Compatibility
Components without reserved characters keep exactly the same key, so existing session mappings are unaffected. A component containing
%or|, or an extra key containing=, moves to a new key (and a new gateway session id) after this change — that is inherent to making the key injective.Fixes #3534