Repository navigation
fix(weixin): bound _known_users to recent peers - #24826
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The cap fixes linked issue #24825 at the cause: the set had no eviction. Every rider is required by the blocking AUTOSDE rule What this change shipsInventory (7 items) — 3 justifiedIntent: stop an open-policy Weixin bot from using more memory for every new person who ever messages it. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 5c1b81e Description read[DESCRIPTION-READ] 5d95f99e79f06f36b31f4714a9c0f93ef46a84156481c10c21020946a97f4c83 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the LRU cap removes a leak with no ceiling, and the only readers of the evicted entries are routes for sending to recent peers, which a peer gets back by writing again. Notes
[DESIGN-REVIEWED] 5c1b81e Description read[DESCRIPTION-READ] 6101bedfeb63eca1e5e900d86f8df18b70dddcf6f7ab08dd6c0beff1288815e0 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. Notes:
[OPUS-REVIEWED] 5c1b81e |
0d409b5 to
305c74d
Compare
|
Thanks — both notes were accurate and are addressed in
|
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
305c74d to
2713e26
Compare
|
Addressed in GPT 6.1 (blocking) — evicted recipients indistinguishable from never-configured. The eviction is inherent to bounding a learned-peer cache, but it was silent, which is the real gap. Added a Opus notes:
|
2713e26 to
25913ca
Compare
|
Addressed in GPT 6.1 (blocking) — peer-count cap does not bound retained identifier sizes. Fair: a count cap alone leaves per-id bytes unbounded. Added a named This also tightens the base-branch |
25913ca to
ee98b25
Compare
|
Reworked in
Net diff is now the count-cap LRU + read-site |
ee98b25 to
71622e8
Compare
71622e8 to
bbdae6e
Compare
|
Addressed in GPT 6.1 (blocking) — eviction loses truncation provenance (
This reconciles the earlier First Principles note that flagged a bare counter as "zero consumers": the counter now feeds the snapshot and the refusal, which is precisely the consumer the rule mandates. Tests pin the once-per-snapshot disclosure, the refusal, and that no sentinel appears before the cap is reached. |
bbdae6e to
dd40573
Compare
|
Both blocking findings fixed in
|
WeixinTransport._known_users recorded one entry per distinct inbound DM peer and evicted nothing. Under the supported dm_policy="open" config the transport serves any DM, so the key space is every user who ever messaged the bot and the set grew for the life of the gateway process -- a slow leak with no ceiling. Make it an OrderedDict LRU bounded by a named KNOWN_USERS_CAP (512): on receive, record the peer newest-last and pop the oldest over the cap. The two read sites that advertise recent peers as proactive-send targets wrap it in set(). may_send_to already consults _allowed alone, so an evicted peer loses nothing and is re-admitted the moment it writes again. The sibling wecom transport bounds its _warm_chats peer LRU to the same value.
dd40573 to
5c1b81e
Compare
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (4 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: bounds the Weixin recent-peer set to an LRU of 512 short ids and discloses the truncation; may_send_to still reads the allowlist alone; with tests. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/messaging.md.
Problem / Motivation
Goal: Stop
WeixinTransport._known_usersfrom growing without bound for the life of the gateway.src/kiro_crew/weixin/transport.pyrecords one entry per distinct inbound DMpeer in
receive()and evicts none of them — no TTL, no cap, no removal on anypath, unlike the
_seendedup map beside it. Under the supporteddm_policy="open"config the transport serves any DM, so the key space is everyuser who ever messaged the bot and the set grows for the process's lifetime.
Why it matters
A long-lived open-policy iLink bot reachable by many users accumulates ~100 B of
never-freed memory per distinct peer, indefinitely. It is a slow leak rather than
an outage, but it has no ceiling and the retained entries are not load-bearing:
may_send_to()consults_allowedalone, so the set only advertises recent peersas proactive-send targets.
Not a goal
wecom/transport.py's sibling_warm_chatsset has the same shape; it istracked and fixed separately, not here.
What changed (motivation → approach → change)
Observed symptom:
_known_userssize grows 1:1 with distinct senders and neverdecreases. Root cause: it is a plain
setwith an unconditional.add()inreceive()and no eviction. Change: make it anOrderedDict[str, None]LRUbounded by a named
KNOWN_USERS_CAP(512). On receive, the peer is recordednewest-last (
move_to_end) and the oldest entries over the cap are dropped(
popitem(last=False)). The two read sites wrap it inset(). Becausemay_send_to()consults_allowedalone, eviction never changes authorization;an evicted peer only drops out of the advertised proactive-send targets until it
writes again, which re-admits it.
So the per-entry key size stays bounded too, a pathologically long
from_user_id(over
MAX_RETAINED_USER_ID_LEN, 256) is NOT remembered in the LRU — but themessage is still served, so no DM is ever dropped. This is a retention ceiling, not a claim about the real iLink id length, so it
neither rejects nor truncates anything. Per the
a-bound-bounds-every-field-it-retainsreview rule, the overflow is COUNTED (_known_users_evicted) and said out loud once perconfigured_targets()snapshot (an unavailableknown_users_truncatedsentinel that is never a send target and never an inferred owner), and the unresolved-target refusal past the cap carries its own SEL reason so a truncated tail is not mistaken for peers that were never configured.messaging.mdis updated to describe all of this.Backwards compatibility
Compatible:
_known_usersis a private instance attribute; its externalbehaviour (which identities
configured_targets()/resolve_configured_target()advertise, and
may_send_to()'s decisions) is unchanged for any realistic peercount, and only differs beyond 512 distinct recent peers, where it now bounds
instead of growing.
Removes nothing: no documented capability, record, key or public function is
removed, hidden, renamed or tightened; the only behavioural change is that the
in-memory recent-peer list stops past 512 entries instead of growing forever.
Tests
test/test_weixin_transport_known_users.pydrives the realreceive()entry point and locks in: the set stays<= KNOWN_USERS_CAPafter 1,000 distinct senders (newest kept, oldest evicted); an evicted peer that writes again is re-admitted; churning the LRU past the cap never changesmay_send_to()(it consults_allowedalone); an over-longfrom_user_idis still dispatched but not retained (boundary inclusive at the ceiling); and the overflow is disclosed exactly once per snapshot plus in the refusal, with no sentinel before the cap is reached.test/test_channel_transport_outbound_authz.pyis updated to seed the LRU by its new type.Proof: PROVEN test/test_weixin_transport_known_users.py::test_known_users_is_bounded_under_many_distinct_senders, test/test_weixin_transport_known_users.py::test_an_evicted_peer_is_re_admitted_when_it_writes_again (head dd40573)
Manual verification
N/A — unit coverage drives the real
receive()path and exercises the bound,eviction and authorization behaviours directly.
Related Issues
Closes #24825
Sibling sweep
Swept:
git grep -nE "self\._(known_users|warm_chats)\b" -- src/Sibling: src/kiro_crew/wecom/transport.py:_warm_chats -- tracked in a separate PR -- same unbounded-peer-set shape under wecom.allow_all_users; fixed there to keep this diff single-file in production code
Sibling: src/kiro_crew/weixin/transport.py:_known_users -- changed here
Pattern harvest
Not generalizable: this is one unbounded learned-peer set; the gateway's other
long-lived maps already carry a cap, TTL, LRU or live-set prune, so there is no
recurring un-bounded-collection class a rule would catch here.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)