Return the longest existing record whose msg_hashes is a (non-strict) prefix of the incoming msg_hashes — equal-length matches included so repeated single-shot prompts collapse into the same session, mirroring v1's content-equality semantics.
(self, msg_hashes: tuple[str, ...])
| 76 | self._evict_expired(now) |
| 77 | |
| 78 | def find_prefix_match(self, msg_hashes: tuple[str, ...]) -> _SessionRecord | None: |
| 79 | """Return the longest existing record whose msg_hashes is a (non-strict) |
| 80 | prefix of the incoming msg_hashes — equal-length matches included so |
| 81 | repeated single-shot prompts collapse into the same session, mirroring |
| 82 | v1's content-equality semantics.""" |
| 83 | best: _SessionRecord | None = None |
| 84 | n = len(msg_hashes) |
| 85 | for rec in self._records.values(): |
| 86 | m = len(rec.msg_hashes) |
| 87 | if m > n: |
| 88 | continue |
| 89 | if msg_hashes[:m] == rec.msg_hashes: |
| 90 | if best is None or m > len(best.msg_hashes): |
| 91 | best = rec |
| 92 | return best |
| 93 | |
| 94 | def upsert(self, record: _SessionRecord) -> None: |
| 95 | # Move-to-end on touch (LRU). |
no outgoing calls
no test coverage detected