Skip to content

[Fix] Keep a closed maintenance from returning to an open status - #131

Merged
Aloento merged 2 commits into
mainfrom
fix/issue-121-maintenance-closed-status
Dec 1, 2026
Merged

Aloento merged 2 commits into
mainfrom
fix/issue-121-maintenance-closed-status

Conversation

@Aloento

@Aloento Aloento commented Dec 1, 2026

Copy link
Copy Markdown
Member

A maintenance always carries an end date, so checkPatchData could not tell a finished event from an open one: a completed or cancelled maintenance could be patched to planned or in_progress while the stored end date stayed in the past, and the checker then reopened it. Reject non-terminal statuses once the stored maintenance is completed or cancelled; completed ↔ cancelled remains allowed and the incident and info branches are unchanged.

Verified with go build ./... && go vet ./... && go test ./internal/....

Closes #121

@Aloento Aloento self-assigned this Dec 1, 2026

@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

Small, targeted fix: checkPatchData now rejects a PATCH that would move a maintenance that is already completed or cancelled back to a non-terminal status (planned/in_progress/…), which previously slipped through because a maintenance always carries an end date so the checker couldn't distinguish a finished event from an open one. New error ErrIncidentPatchClosedMaintenanceStatus added, completed ↔ cancelled still allowed, incident/info branches untouched. Tests added, CI green (build, go-test, go-test-acc, golangci-lint, CodeQL all pass).

Findings

No correctness, security, or build-blocking issues found. The change is correct and well tested.

Suggestions / open questions (non-blocking)

  1. Possible redundancy with the existing maintenance transition validation — internal/api/v2/v2.go:1279-1284 adds the terminal-status guard inside checkPatchData (called at ~2244), while there is already a maintenance status-transition conflict check around internal/api/v2/v2.go:2137-2156 that raises ErrMaintenanceStatusTransitionConflict. The two guards now overlap for the closed→open case, and they return different error codes depending on which runs first. This works, but it's worth confirming the intended error/HTTP status is consistent for the client. Consider whether one of these is the canonical enforcement point and the other can be consolidated, or at least documented, so the API surface stays predictable.

  2. Scope of "non-terminal" — the new check blocks planned and in_progress (and, since only completed/cancelled are allowed through, implicitly pending_review/reviewed too). That appears intentional given the PR description, but it's worth a quick sanity check that pending_review/reviewed are also legitimately closed for a completed/cancelled maintenance, so the guard isn't wider than intended.

Notes (verified)

  • The guard is placed after the type/status validation (line ~1241), so incoming.Status is already guaranteed to be a valid maintenance status when the new branch runs; no nil/zero-value edge case is introduced.
  • The completed → cancelled and cancelled → cancelled paths correctly fall through, matching the added test table (internal/api/v2/v2_test.go:250-306).

Verdict: approve — no changes required to merge; the two suggestions above are worth a quick follow-up but do not block.

@Aloento
Aloento merged commit f7807de into main Dec 1, 2026
13 checks passed
@Aloento
Aloento deleted the fix/issue-121-maintenance-closed-status branch December 1, 2026 10:56
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.

[api] Check maintenance invariants on the merged state

1 participant