Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7547 fix(ci): prune the Go build cache to the run's entries and deflake telegram lease tests (#8624)

Bohan Jiang6dbcc257df06
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 27e427835f..3597b7347b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -282,6 +282,14 @@ jobs:
# release, an entry built on the old one must not be restored. setup-go
# keys on ImageOS for the same reason (actions/setup-go#368).
#
+ # A rolling entry only grows on its own: each save is the restored entry
+ # plus this commit's objects, and Go trims only what has sat unused for
+ # five days, so the entry carried every recent main commit's race objects.
+ # It reached 3.5 GB in ten days, and restoring and saving it cost more than
+ # the compile it saved (MUL-7547). Before saving, the job therefore drops
+ # every entry this run did not use, leaving the next run the objects of the
+ # tree it is most likely to build.
+ #
# This job is the only writer of either entry. backend-agent-tests restores
# both, but it downloads just pkg/agent's slice of the module graph and
# finishes first, so letting it save would repeat the first-writer-wins
@@ -365,6 +373,14 @@ jobs:
key: ${{ steps.gocache.outputs.prefix }}${{ github.sha }}
restore-keys: ${{ steps.gocache.outputs.prefix }}
+ # Go refreshes a cache entry's mtime when it uses it, but only once that
+ # mtime is an hour old. So after the run, an entry no newer than an hour
+ # before the first compile is one this run did not use. The prune step
+ # before the save compares against this marker.
+ - name: Mark Go build cache epoch
+ id: goepoch
+ run: touch -d '-1 hour' "$RUNNER_TEMP/go-build-epoch"
+
- name: Build
run: cd server && go build -race ./...
@@ -387,6 +403,17 @@ jobs:
# pkg/agent runs on its own runner: backend-agent-tests below.
run: bash scripts/test-go.sh --race --only regular
+ # Go's own trim (cmd/go/internal/cache) with this run as the window
+ # instead of five days: only `-a`/`-d` entries, and an executable entry
+ # is a directory, so it goes whole. See the job comment.
+ - name: Prune Go build cache to this run's entries
+ if: ${{ !cancelled() && github.event_name == 'push' && steps.goepoch.outcome == 'success' }}
+ run: |
+ du -sh ~/.cache/go-build
+ find ~/.cache/go-build -mindepth 2 -maxdepth 2 \( -name '*-a' -o -name '*-d' \) \
+ ! -newer "$RUNNER_TEMP/go-build-epoch" -exec rm -rf {} +
+ du -sh ~/.cache/go-build
+
# Publishes from main only; see the job comment. `!cancelled()` so a red
# main still refreshes the objects for the next run, and the key step's
# outcome so a run that never reached Go does not save an empty entry
diff --git a/server/internal/integrations/telegram/outbound_delivery_boundaries_test.go b/server/internal/integrations/telegram/outbound_delivery_boundaries_test.go
index 3ef240ddd2..0fd0fc912c 100644
--- a/server/internal/integrations/telegram/outbound_delivery_boundaries_test.go
+++ b/server/internal/integrations/telegram/outbound_delivery_boundaries_test.go
@@ -139,7 +139,7 @@ func TestReview8545PostgresAbandonedInFlightDoesNotBlockForever(t *testing.T) {
o, q, c, e := review8545Setup(t, bot)
// Expiry is decided by database time, which the test clock cannot move, so
// the lease is shortened and really waited out.
- o.leaseTTL = 100 * time.Millisecond
+ o.leaseTTL = testLeaseTTL
ctx := context.Background()
target, err := o.resolveTarget(ctx, e, false)
if err != nil {
@@ -158,7 +158,7 @@ func TestReview8545PostgresAbandonedInFlightDoesNotBlockForever(t *testing.T) {
}
// The owner process dies after claiming: it never records an outcome and
// never releases the turn. Only the lease expiring can free it.
- time.Sleep(150 * time.Millisecond)
+ time.Sleep(testLeaseLapse)
c.advance(24 * time.Hour)
_ = q
reply := &terminalReply{event: e}
@@ -310,16 +310,16 @@ func TestReview8545PostgresStaleStreamCannotOverwriteSettledAnswer(t *testing.T)
q := &review8545PauseStreamRead{review8545Queries: base, entered: make(chan struct{}), release: make(chan struct{})}
q.pause.Store(true)
a.q = q
- a.leaseTTL = 100 * time.Millisecond
+ a.leaseTTL = testLeaseTTL
b := review8545Second(a)
- b.leaseTTL = 100 * time.Millisecond
+ b.leaseTTL = testLeaseTTL
done := make(chan struct{})
go func() { defer close(done); a.handleTaskMessage(telegramPartialEvent(e.TaskID, " stale tail")) }()
defer func() { close(q.release); <-done }()
<-q.entered
// The paused frame still owns the turn; the final answer takes over only
// once that lease expires.
- time.Sleep(150 * time.Millisecond)
+ time.Sleep(testLeaseLapse)
b.enqueueTerminalReply(e)
auditDrain(t, b, c, e.ChatSessionID)
q.release <- struct{}{}
@@ -445,7 +445,7 @@ func TestReview8545PostgresSettledElsewhereReleasesLocalState(t *testing.T) {
func TestReview8545PostgresFailureNoticeWaitsForALiveLease(t *testing.T) {
bot := &auditBot{}
a, _, c, e := review8545Setup(t, bot)
- a.leaseTTL = 100 * time.Millisecond
+ a.leaseTTL = testLeaseTTL
a.handleTaskMessage(telegramPartialEvent(e.TaskID, "streamed reply"))
ctx := context.Background()
@@ -463,10 +463,10 @@ func TestReview8545PostgresFailureNoticeWaitsForALiveLease(t *testing.T) {
}
b := review8545Second(a)
- b.leaseTTL = 100 * time.Millisecond
+ b.leaseTTL = testLeaseTTL
b.handleTaskFailed(events.Event{TaskID: e.TaskID, ChatSessionID: e.ChatSessionID,
Payload: map[string]any{"retry_pending": false}})
- time.Sleep(150 * time.Millisecond)
+ time.Sleep(testLeaseLapse)
auditDrain(t, b, c, e.ChatSessionID)
review8545MessageCount(t, bot, 1)
@@ -517,7 +517,7 @@ func TestReview8545PostgresSupersededAttemptCannotCloseTheTurn(t *testing.T) {
func TestReview8545PostgresFailureNoticeStopsAfterLosingTheLease(t *testing.T) {
bot := &auditBot{failFirstEdit: true}
o, _, c, e := review8545Setup(t, bot)
- o.leaseTTL = 100 * time.Millisecond
+ o.leaseTTL = testLeaseTTL
o.handleTaskMessage(telegramPartialEvent(e.TaskID, "streamed reply"))
o.handleTaskFailed(events.Event{TaskID: e.TaskID, ChatSessionID: e.ChatSessionID,
Payload: map[string]any{"retry_pending": false}})
@@ -544,8 +544,8 @@ func TestReview8545PostgresFailureNoticeStopsAfterLosingTheLease(t *testing.T) {
// Another replica takes the turn over while this one waits.
other := review8545Second(o)
- other.leaseTTL = 100 * time.Millisecond
- time.Sleep(150 * time.Millisecond)
+ other.leaseTTL = testLeaseTTL
+ time.Sleep(testLeaseLapse)
target, err := other.resolveTarget(context.Background(), e, false)
if err != nil {
t.Fatal(err)
diff --git a/server/internal/integrations/telegram/outbound_delivery_contract_test.go b/server/internal/integrations/telegram/outbound_delivery_contract_test.go
index 86fdfe5af0..bafa5d9df0 100644
--- a/server/internal/integrations/telegram/outbound_delivery_contract_test.go
+++ b/server/internal/integrations/telegram/outbound_delivery_contract_test.go
@@ -91,6 +91,17 @@ func (a *auditBot) wantOne(t *testing.T) {
}
}
+// Lease expiry is database time, which auditClock cannot move, so cases that
+// exercise a takeover shorten the lease and really wait it out. The lease also
+// sizes every provider call's budget (a third of it, see callContext), and that
+// budget covers real Postgres writes: the 33ms a 100ms lease left timed out a
+// send claim on a slow -race CI runner and failed the case (MUL-7547).
+const (
+ testLeaseTTL = 600 * time.Millisecond
+ // testLeaseLapse outlasts testLeaseTTL, so any lease taken before it has expired.
+ testLeaseLapse = testLeaseTTL + 150*time.Millisecond
+)
+
type auditClock struct{ nanos atomic.Int64 }
func (c *auditClock) now() time.Time { return time.Unix(0, c.nanos.Load()) }
@@ -389,7 +400,7 @@ func TestAuditReplayAfterInterruptionBetweenChunks(t *testing.T) {
// The interrupted process never releases its lease — it stops existing.
// Expiry is what frees the turn, and expiry is database time, so the test
// shortens the lease and really waits for it.
- a.leaseTTL = 100 * time.Millisecond
+ a.leaseTTL = testLeaseTTL
e := telegramTestEventFor(3, 2, strings.Repeat("A", maxMessageUnits)+"tail")
a.enqueueTerminalReply(e)
reply := a.terminalSessions[e.ChatSessionID].queue[0]
@@ -407,10 +418,10 @@ func TestAuditReplayAfterInterruptionBetweenChunks(t *testing.T) {
}
// Simulate losing process memory before the next chunk. A replay-capable
// caller delivers the same completion against the same durable database.
- time.Sleep(150 * time.Millisecond)
+ time.Sleep(testLeaseLapse)
b := NewOutbound(q, nil, srv.URL, srv.Client(), nil)
b.now = c.now
- b.leaseTTL = 100 * time.Millisecond
+ b.leaseTTL = testLeaseTTL
b.enqueueTerminalReply(e)
auditDrain(t, b, c, e.ChatSessionID)
bot.mu.Lock()