Skip to content

Commit 5ef7617

Browse files
fix(covenantsigner): correctly distinguish single vs both unparseable timestamps
The earlier tiebreaker fix incorrectly entered the "both unparseable" branch when only the candidate had an invalid timestamp. Parse both timestamps explicitly to distinguish three cases: only candidate bad (keep existing), only existing bad (replace), both bad (lexicographic tiebreak).
1 parent 054e261 commit 5ef7617

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

pkg/covenantsigner/store.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,38 @@ func (s *Store) load() error {
260260
// candidate's timestamp is valid, the failure is on
261261
// the existing job -- replace it. Otherwise skip the
262262
// candidate.
263-
if _, parseErr := time.Parse(time.RFC3339Nano, job.UpdatedAt); parseErr != nil {
263+
_, existingParseErr := time.Parse(time.RFC3339Nano, existing.UpdatedAt)
264+
_, candidateParseErr := time.Parse(time.RFC3339Nano, job.UpdatedAt)
265+
266+
switch {
267+
case candidateParseErr != nil && existingParseErr == nil:
268+
// Only the candidate is unparseable; keep existing.
269+
logger.Warnf(
270+
"skipping job [%s] with invalid timestamp on duplicate route key [%s/%s] (keeping [%s]): [%v]",
271+
job.RequestID,
272+
job.Route,
273+
job.RouteRequestID,
274+
existing.RequestID,
275+
err,
276+
)
277+
continue
278+
case candidateParseErr == nil && existingParseErr != nil:
279+
// Only the existing is unparseable; replace with candidate.
280+
logger.Warnf(
281+
"replacing job [%s] with invalid timestamp on duplicate route key [%s/%s]: [%v]",
282+
existing.RequestID,
283+
job.Route,
284+
job.RouteRequestID,
285+
err,
286+
)
287+
default:
264288
// Both timestamps are unparseable. Use
265289
// lexicographic RequestID as a deterministic
266-
// tiebreaker so the outcome does not depend on
267-
// file iteration order.
290+
// tiebreaker so the outcome does not depend
291+
// on file iteration order.
268292
if existing.RequestID <= job.RequestID {
269293
logger.Warnf(
270-
"skipping job [%s] with invalid timestamp on duplicate route key [%s/%s] (keeping [%s]): [%v]",
294+
"skipping job [%s] on duplicate route key [%s/%s] (keeping [%s], lexicographic tiebreak): [%v]",
271295
job.RequestID,
272296
job.Route,
273297
job.RouteRequestID,
@@ -277,15 +301,7 @@ func (s *Store) load() error {
277301
continue
278302
}
279303
logger.Warnf(
280-
"replacing job [%s] with invalid timestamp on duplicate route key [%s/%s] (both unparseable, lexicographic tiebreak): [%v]",
281-
existing.RequestID,
282-
job.Route,
283-
job.RouteRequestID,
284-
err,
285-
)
286-
} else {
287-
logger.Warnf(
288-
"replacing job [%s] with invalid timestamp on duplicate route key [%s/%s]: [%v]",
304+
"replacing job [%s] on duplicate route key [%s/%s] (lexicographic tiebreak): [%v]",
289305
existing.RequestID,
290306
job.Route,
291307
job.RouteRequestID,

0 commit comments

Comments
 (0)