Commit d6cddb9
committed
fix: drain _seen_logs drift on hit path and pin FIFO by key identity
Two Copilot review follow-ups on #1717:
- ``_mark_seen`` returned early on cache hits, so a drift-overshoot
left behind by concurrent inserts (FT or sync-multi-instance
callers racing the ``len < cap`` check) only drained on the next
miss. A workload that's mostly hits after a contention burst could
keep the dict permanently above the cap. Add a drift-drain ``while``
inside the hit branch, gated on ``len > _MAX_SEEN_LOGS`` so
steady-state-at-cap hits remain a single ``len`` + compare past the
membership check. The shared pop+race-tolerant idiom factors out
into a small ``_evict_oldest`` helper invoked only when the
outer ``while`` predicate is true, so the hot-path cost is
unchanged. Pin the behaviour with
``test_mark_seen_drains_drift_on_hit_path``.
- ``tests/test_protocol.py::test_seen_logs_is_bounded`` asserted
FIFO eviction via substring matches on the exception text
(``"'1.2.3.4', 0)" in k``). That tied the test to the current
``IncomingDecodeError`` message format, so a future normalization
of dedup-key shape (as discussed on #1714) would break the test
without changing the bounded/eviction behaviour. Snapshot the
actual key the parser inserted per port via
``next(reversed(_seen_logs))`` and assert FIFO by key identity.
Also pin ``len(set(keys_per_port)) == _MAX_SEEN_LOGS + overflow``
so a regression that dropped ``self.source`` from the exception
text (collapsing all calls to one dedup key) still fails the
test rather than silently passing — preserving the per-port-
unique-key check from the prior Kōan review.1 parent d3598be commit d6cddb9
3 files changed
Lines changed: 71 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
46 | 63 | | |
47 | 64 | | |
48 | 65 | | |
| |||
53 | 70 | | |
54 | 71 | | |
55 | 72 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
65 | 79 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
76 | 89 | | |
77 | 90 | | |
78 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
129 | 150 | | |
130 | 151 | | |
131 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
973 | 973 | | |
974 | 974 | | |
975 | 975 | | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
976 | 982 | | |
977 | 983 | | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
| 984 | + | |
| 985 | + | |
982 | 986 | | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
987 | 997 | | |
988 | 998 | | |
989 | 999 | | |
| |||
0 commit comments