Skip to content

fix: don't fork the consolidation chain on duplicate report rows - #361

Merged
matthyx merged 1 commit into
kubescape:mainfrom
magic-peach:fix-consolidate-duplicate-report-rows
Aug 18, 2026
Merged

fix: don't fork the consolidation chain on duplicate report rows#361
matthyx merged 1 commit into
kubescape:mainfrom
magic-peach:fix-consolidate-duplicate-report-rows

Conversation

@magic-peach

Copy link
Copy Markdown
Contributor

Found via #352, filed off the node-agent#866 review discussion.

`consolidateContinuousTimeSeries` walks time series rows in reverse chronological order and links row `j` to row `i+1` when `j.PreviousReportTimestamp == (i+1).ReportTimestamp`. That's correct for real chain links, but two rows can also share the exact same `(previousReportTimestamp, reportTimestamp)` pair when a single logical report got split into two physical objects client-side (e.g. a chunk that came back over the queue's size limit and got resent as two halves). Neither row's timestamps chain to the other, so the walk treats them as a fork and `newTimeSeries` ends up with two rows for what should be one. `updateProfileStatus`'s completion check only fires when `len(newTimeSeries) == 1`, so the profile just... never completes.

Added a case that recognizes the duplicate-pair situation and treats it as one link instead of a fork.

Test: `TestConsolidateContinuousTimeSeries_DuplicateReportRowsCollapse`, fails on main (asserts 1 result, gets 2), passes with the fix. Ran the rest of the `Consolidate*` suite too, nothing regressed.

consolidateContinuousTimeSeries walks rows by matching j's
PreviousReportTimestamp against the next row's ReportTimestamp. Two
rows that instead share the exact same (previousReportTimestamp,
reportTimestamp) pair - same logical report, split into two physical
objects - don't match that check, so they get treated as a fork
instead of one link. The series never collapses to a single row, and
updateProfileStatus's completion check (len == 1) never fires.

Add a case for the duplicate-pair situation so those rows count as
one link instead of two.

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

Review available on request

  • 🔍 Trigger review

Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment @coderabbitai review to review the latest changes. For a full review, comment @coderabbitai full review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b540f204-a9ac-4d62-8597-8b505fbc2083


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@matthyx matthyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced the new switch in consolidateContinuousTimeSeries through several scenarios (dup pair alone, dup pair chained to a real predecessor, 3-way duplicate collapse, duplicate immediately followed by a genuine fork) — all collapse/link correctly, and the new case is mutually exclusive with the existing chain-link case so no regression to the normal walk.

Confirmed the dropped duplicate row doesn't lose data: mergeTimeSeriesData iterates the original unconsolidated slice (independent of consolidateContinuousTimeSeries), so both physical rows' TS profile blobs still get merged into the profile and both get queued for deletion via deleteTimeSeries; consolidateContinuousTimeSeries only decides what's written back as the surviving chain state.

Regression test fails on main / passes with the fix, matches the described bug precisely. No blockers — approving.

@matthyx
matthyx merged commit c87618e into kubescape:main Aug 18, 2026
7 checks passed
@matthyx matthyx moved this to To Archive in KS PRs tracking Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Archive

Development

Successfully merging this pull request may close these issues.

2 participants