The prior fix (sinceSeconds window anchored to lastLogReceivedAt) still
caused duplicates: on reconnect, the K8s API re-streams N seconds of
already-seen content and those bytes were forwarded to onLog verbatim.
New approach:
- First stream attempt: emit chunks to onLog in real-time as before.
- Reconnect attempts: buffer all incoming chunks rather than emitting
immediately, then call findNewLogContent() to strip any prefix of the
buffered data that overlaps with content already sent, and forward only
the genuinely new suffix.
- findNewLogContent uses the KMP failure-function algorithm (O(N)) to
find the longest prefix of the reconnect data that matches a suffix of
the accumulated content, guaranteeing correct deduplication even for
large sinceSeconds windows or rapidly repeated lines.
Co-Authored-By: Paperclip <noreply@paperclip.ing>