Skip to content

[Fix] Preserve the incident interval when extracting components - #136

Merged
Aloento merged 1 commit into
mainfrom
fix/issue-111-extraction-interval
Dec 1, 2026
Merged

Aloento merged 1 commit into
mainfrom
fix/issue-111-extraction-interval

Conversation

@Aloento

@Aloento Aloento commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

ExtractComponentsToNewIncident created the new incident at the extraction time, so the downtime the moved components had already accumulated was dropped from both incidents, and a closed source also lost its end date.

The new incident now inherits the source start date and, for a closed source, its end date, taken from the row re-read inside the transaction. The moved from/to statuses keep the extraction timestamp.

Verified with go test ./internal/... -count 1 and the go-test-acc job, which runs go test ./tests/... -count 1 against Postgres and covers extraction from open and closed incidents.

Closes #111

ExtractComponentsToNewIncident started the new incident at the extraction time, so the downtime the moved components had already spent in the source incident was dropped from both. Closed-incident extraction additionally lost the recorded end date.

The new incident now inherits the source start date and, when the source is closed, its end date, both taken from the row re-read inside the transaction. The moved from/to statuses keep the extraction timestamp: they are audit records, not the outage interval.

@ecosquad-autoreview ecosquad-autoreview Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

The fix is sound. Previously ExtractComponentsToNewIncident (internal/db/db.go:971) created the new incident with StartDate = now and EndDate = nil, silently dropping the downtime the moved components had already accumulated. The new code moves the construction of inc inside the transaction and inherits StartDate (and EndDate for a closed source) from the re-read incOld row, while appendExtractionStatuses (db.go:1048) still stamps the "moved from/to" statuses with timeNow — matching the stated intent. Taking the interval from the in-transaction re-read (not the caller's copy) is the right choice, consistent with the existing fresh-read semantics tested by TestExtractComponentsUsesFreshIncidentState.

The two new DB tests (tests/extract_tx_test.go:181, :251) cover the open and closed source cases, check both in-memory and stored rows, and use microsecond truncation to match Postgres timestamp precision. Test helpers (incidentStatusWithText, incidentComponentIDs, newProbeComponent, tableCount) all exist.

Findings

Suggestion

  • internal/db/db.go (~line 1004): startDate := *incOld.StartDate dereferences unconditionally. If a row could ever exist with a NULL start_date, this panics inside the transaction. If the ent schema guarantees non-null (which the existing ordering/filter code suggests), this is fine as-is — otherwise add a guard that returns an error when incOld.StartDate == nil.
  • Closed-source extraction: the new incident is created closed (inherited EndDate in the past) but with Status: event.OutDatedSystem (i.e. "ongoing"), which was the pre-existing behavior for status. Now that the end date is inherited, a "ongoing" incident with a past end date is more visible. Consider whether extracting from a closed incident should instead reuse the source's status.

Note

  • Verification: the PR description states the ./tests DB-backed suite could not be executed locally (needs Docker), so the new interval tests have not actually run yet. CI (go-test, go-test-acc, build) was still queued at review time — please make sure the acceptance suite passes on CI before merging.

Verdict

No correctness, security or data-loss issues found in the change. Approving; the two suggestions above are optional.

@Aloento
Aloento merged commit 2bbec66 into main Dec 1, 2026
15 checks passed
@Aloento
Aloento deleted the fix/issue-111-extraction-interval branch December 1, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[db] Component extraction must preserve the original incident interval

1 participant