release: stamp app pointers to the millisecond so signers rarely wait
Every signer waits until its stamp is strictly after the head it replaces. At whole seconds that cost a back-to-back promote up to a second (promote door median 993 ms against a 900 ms ceiling) and ran the authorize simulation past CI's 15 minute timeout. App pointers are now stamped to the millisecond; the strict ordering rule and the box floors are unchanged. System pointers keep whole seconds and their wait (waitPastSystemStamp). The digest straggler check compares a pointer's stamp at the marker's whole-second resolution, as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+122
−20
internal/release/digests.go+5 −1internal/release/release.go+45 −14internal/release/stampgrain_test.go+67 −0internal/release/systempointer.go+4 −4internal/release/systempublication.go+1 −1
diff --git a/internal/release/digests.go b/internal/release/digests.go| index d5c79893c..3e0c03d53 100644 |
| --- a/internal/release/digests.go |
| +++ b/internal/release/digests.go |
| @@ -173,7 +173,11 @@ func DigestStateOf(p *ChannelPointer, marker *DigestMarker) ChannelDigestState { |
| st.HistoryMissing++ |
| } |
| } |
| - st.Straggler = marker != nil && !st.HeadDigest && p.PromotedAt.After(marker.At) |
| + // The marker is stamped to the second and a pointer to the millisecond |
| + // (pointerStampGrain), so the pointer's stamp is compared at the |
| + // marker's resolution: a pointer signed in the second the marker went on |
| + // is not after it, as when both were whole seconds. |
| + st.Straggler = marker != nil && !st.HeadDigest && p.PromotedAt.Truncate(time.Second).After(marker.At) |
| return st |
| } |
diff --git a/internal/release/release.go b/internal/release/release.go| index 41d386894..20041aacc 100644 |
| --- a/internal/release/release.go |
| +++ b/internal/release/release.go |
| @@ -539,7 +539,7 @@ func signPointer(sg Signer, p *ChannelPointer) ([]byte, error) { |
| return nil, err |
| } |
| p.Schema = 1 |
| - p.PromotedAt = time.Now().UTC().Truncate(time.Second) |
| + p.PromotedAt = time.Now().UTC().Truncate(pointerStampGrain) |
| // Optional on READ (old pointers), required on WRITE: nothing signed from |
| // here on may be an unbound pointer, or the binding is a convention. |
| if !ValidAccount(p.Account) { |
| @@ -1101,29 +1101,60 @@ func (sg Signer) claimRawPromote(ctx context.Context, s Store, acct, app, channe |
| return err |
| } |
| -// waitPastPromotedAt returns once the stamp signPointer (or |
| -// signSystemPointer) would produce (now, truncated to the second) is |
| -// strictly after prev, waiting into the next second if it must. Every |
| -// signer of an app or system pointer calls it with the stamp of the head it |
| -// replaces, so a channel's stamps strictly increase and a box's floor needs |
| -// no other ordering. The wait is bounded at 2 s: a prev further ahead than |
| -// that is clock skew, and it refuses rather than write a stamp that is not |
| -// newer, so skew between two publishers fails loudly here instead of every |
| -// box refusing the later write as a replay. |
| +// pointerStampGrain is the resolution of an app channel pointer's |
| +// promoted_at (signPointer). Every signer waits until its stamp is strictly |
| +// after the head it replaces (waitPastPromotedAt), and at whole seconds that |
| +// cost a write following another on the same channel up to a second (a |
| +// promote median of 993 ms against a 600 ms budget, and a 400-seed |
| +// simulation past CI's timeout). At a millisecond the same rule waits at |
| +// most a millisecond. The wire is unchanged: promoted_at was always an |
| +// RFC 3339 time, which every reader parses with its fraction, and every |
| +// floor (the box's channel watermark, the failure book, refusals) keeps |
| +// time.Time. Pointers signed before carry whole seconds, and a later stamp |
| +// in the same second is still strictly after them. |
| +const pointerStampGrain = time.Millisecond |
| + |
| +// systemStampGrain is the resolution of a system pointer's promoted_at |
| +// (signSystemPointer). System writes are rare and their stamps travel |
| +// through more box records (install requests, results, the floor), so they |
| +// stay at whole seconds and their signers may wait into the next one. |
| +const systemStampGrain = time.Second |
| + |
| +// waitPastPromotedAt returns once the stamp signPointer would produce (now, |
| +// truncated to pointerStampGrain) is strictly after prev. Every signer of an |
| +// app pointer calls it with the stamp of the head it replaces, so a |
| +// channel's stamps strictly increase and a box's floor needs no other |
| +// ordering. |
| func waitPastPromotedAt(ctx context.Context, channel string, prev time.Time) error { |
| - if time.Now().UTC().Truncate(time.Second).After(prev) { |
| + return waitPastStamp(ctx, channel, prev, pointerStampGrain) |
| +} |
| + |
| +// waitPastSystemStamp is waitPastPromotedAt for a system pointer, whose |
| +// stamp signSystemPointer truncates to systemStampGrain. |
| +func waitPastSystemStamp(ctx context.Context, channel string, prev time.Time) error { |
| + return waitPastStamp(ctx, channel, prev, systemStampGrain) |
| +} |
| + |
| +// waitPastStamp returns once now, truncated to grain, is strictly after |
| +// prev, waiting into the next grain if it must; it waits only when prev is |
| +// not yet in the past at that grain. The wait is bounded at 2 s: a prev |
| +// further ahead than that is clock skew, and it refuses rather than write a |
| +// stamp that is not newer, so skew between two publishers fails loudly here |
| +// instead of every box refusing the later write as a replay. |
| +func waitPastStamp(ctx context.Context, channel string, prev time.Time, grain time.Duration) error { |
| + if time.Now().UTC().Truncate(grain).After(prev) { |
| return nil |
| } |
| - t := time.NewTimer(min(time.Until(prev.Add(time.Second)), 2*time.Second)) |
| + t := time.NewTimer(min(time.Until(prev.Truncate(grain).Add(grain)), 2*time.Second)) |
| select { |
| case <-ctx.Done(): |
| t.Stop() |
| return ctx.Err() |
| case <-t.C: |
| } |
| - if !time.Now().UTC().Truncate(time.Second).After(prev) { |
| + if !time.Now().UTC().Truncate(grain).After(prev) { |
| return fmt.Errorf("%s was last written at %s, ahead of this clock; nothing was written", |
| - channel, prev.Format(time.RFC3339)) |
| + channel, prev.Format(time.RFC3339Nano)) |
| } |
| return nil |
| } |
diff --git a/internal/release/stampgrain_test.go b/internal/release/stampgrain_test.go| new file mode 100644 |
| index 000000000..43f5f213c |
| --- /dev/null |
| +++ b/internal/release/stampgrain_test.go |
| @@ -0,0 +1,67 @@ |
| +package release |
| + |
| +import ( |
| + "context" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// CI fix for the release chain: every signer waits until its stamp is |
| +// strictly after the head it replaces. At whole-second stamps that cost a |
| +// write following another on the same channel up to a second, every time |
| +// (the promote door's median went from about 500 ms to 993 ms, and the |
| +// authorize simulation ran past CI's 15 minute timeout). An app pointer is |
| +// stamped to the millisecond, so the rule still holds and the wait is at |
| +// most a millisecond. |
| + |
| +// Two promotes of one channel back to back: the second is stamped strictly |
| +// after the first (the floor's ordering rule), and not pushed into the next |
| +// whole second to get there. |
| +func TestBackToBackPromotesAreOrderedWithoutWaitingASecond(t *testing.T) { |
| + s := NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + priv, pub := testKeys(t) |
| + shipRelease(t, s, "bab", "shop", "v1", adoptPlatform, []byte("v1")) |
| + shipRelease(t, s, "bab", "shop", "v2", adoptPlatform, []byte("v2")) |
| + if err := Promote(ctx, s, priv, "bab", "shop", "canary/x", "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + first, err := Channel(ctx, s, pub, "bab", "shop", "canary/x") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := Promote(ctx, s, priv, "bab", "shop", "canary/x", "v2"); err != nil { |
| + t.Fatal(err) |
| + } |
| + second, err := Channel(ctx, s, pub, "bab", "shop", "canary/x") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !second.PromotedAt.After(first.PromotedAt) { |
| + t.Fatalf("the second promote is stamped %s, not after the first's %s", second.PromotedAt, first.PromotedAt) |
| + } |
| + if gap := second.PromotedAt.Sub(first.PromotedAt); gap >= time.Second { |
| + t.Errorf("the second promote is stamped %s after the first: it waited into the next second", gap) |
| + } |
| +} |
| + |
| +// A head stamped earlier in this very second, as every pointer signed |
| +// before the millisecond stamp is, is already in the past: the next signer |
| +// does not wait for the second to turn. |
| +func TestWaitPastPromotedAtDoesNotWaitForAStampAlreadyPast(t *testing.T) { |
| + prev := time.Now().UTC().Truncate(pointerStampGrain).Add(-pointerStampGrain) |
| + start := time.Now() |
| + if err := waitPastPromotedAt(context.Background(), "stable", prev); err != nil { |
| + t.Fatal(err) |
| + } |
| + if took := time.Since(start); took >= 500*time.Millisecond { |
| + t.Errorf("waited %s past a stamp a millisecond old", took) |
| + } |
| + // The system pointer keeps whole seconds, and its rule with them: a |
| + // stamp in the current second is not yet past. |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + cancel() |
| + if err := waitPastSystemStamp(ctx, "stable", time.Now().UTC().Add(time.Second).Truncate(systemStampGrain)); err == nil { |
| + t.Error("a system stamp in the next second was treated as past") |
| + } |
| +} |
diff --git a/internal/release/systempointer.go b/internal/release/systempointer.go| index c3b5ab8f9..809eb4d47 100644 |
| --- a/internal/release/systempointer.go |
| +++ b/internal/release/systempointer.go |
| @@ -205,7 +205,7 @@ func signSystemPointer(sg Signer, p *SystemPointer) ([]byte, error) { |
| return nil, errors.New("system pointer: signed by a scoped key — the platform takes the root key only") |
| } |
| p.Schema = 1 |
| - p.PromotedAt = time.Now().UTC().Truncate(time.Second) |
| + p.PromotedAt = time.Now().UTC().Truncate(systemStampGrain) |
| if err := validateSystemPointer(p, p.Component, p.Channel); err != nil { |
| return nil, err |
| } |
| @@ -332,8 +332,8 @@ func PrepareSystemPromotion(ctx context.Context, s Store, sg Signer, component, |
| return SystemPublication{}, err |
| } |
| // Strictly after the pointer it replaces, a cancellation included |
| - // (waitPastPromotedAt): a box's replay floor admits only a newer stamp. |
| - if err := waitPastPromotedAt(ctx, channel, old.PromotedAt); err != nil { |
| + // (waitPastSystemStamp): a box's replay floor admits only a newer stamp. |
| + if err := waitPastSystemStamp(ctx, channel, old.PromotedAt); err != nil { |
| return SystemPublication{}, fmt.Errorf("system promote: %w", err) |
| } |
| } |
| @@ -398,7 +398,7 @@ func PrepareSystemRollback(ctx context.Context, s Store, sg Signer, component, c |
| if len(old.History) == 0 { |
| return SystemPublication{}, ErrNoSystemHistory |
| } |
| - if err := waitPastPromotedAt(ctx, channel, old.PromotedAt); err != nil { |
| + if err := waitPastSystemStamp(ctx, channel, old.PromotedAt); err != nil { |
| return SystemPublication{}, fmt.Errorf("system rollback: %w", err) |
| } |
| next := &SystemPointer{ActivationID: id, |
diff --git a/internal/release/systempublication.go b/internal/release/systempublication.go| index d09480417..0e6039222 100644 |
| --- a/internal/release/systempublication.go |
| +++ b/internal/release/systempublication.go |
| @@ -88,7 +88,7 @@ func CancelSystemPublication(ctx context.Context, s Store, sg Signer, p SystemPu |
| // admits only a strictly later stamp, or the exact pointer it admitted, so |
| // a fence carrying Before's own stamp would be a second pointer at that |
| // stamp. It takes After's stamp, which the preparer put strictly after |
| -// Before's (waitPastPromotedAt); After and the fence both replace Before |
| +// Before's (waitPastSystemStamp); After and the fence both replace Before |
| // under its ETag, so at most one of them is ever a head. The stamp comes |
| // from the kept After rather than the clock, and the signature is |
| // deterministic, so a retry signs the same bytes and recognises its own |