Skip to content

feat(git): coordinate snapshot generation across replicas#391

Merged
worstell merged 1 commit into
mainfrom
worstell/snapshot-generation-coordination
Jul 21, 2026
Merged

feat(git): coordinate snapshot generation across replicas#391
worstell merged 1 commit into
mainfrom
worstell/snapshot-generation-coordination

Conversation

@worstell

Copy link
Copy Markdown
Contributor

Every replica independently runs the periodic snapshot, mirror-snapshot, and LFS-snapshot jobs for each repository, so N replicas regenerate and re-upload the same artifact every interval. For large repositories an LFS snapshot generation takes ~20 minutes — multiplied across every replica, every interval. And because a new pod's schedule store is empty, every deploy triggers an immediate full regeneration on every replica at once.

This shares per-artifact generation state through the metadata store: before generating, a replica checks whether a peer completed a generation within the interval or holds an unexpired in-progress claim, and skips if so. Claims expire after 30 minutes so a crashed generator can't block peers. Periodic schedules get per-replica jitter so claims (which sync asynchronously) propagate before peers decide.

Coordination is advisory — the store is last-write-wins — so replicas deciding within the same sync window can still generate concurrently; that's rare with jitter, and a duplicate generation is wasteful but harmless. Without a metadata store configured, behavior is unchanged.

@worstell
worstell force-pushed the worstell/snapshot-generation-coordination branch 6 times, most recently from a63103d to 3f1ae69 Compare July 21, 2026 18:52
@worstell
worstell marked this pull request as ready for review July 21, 2026 19:14
@worstell
worstell requested a review from a team as a code owner July 21, 2026 19:14
@worstell
worstell requested review from joshfriend and removed request for a team July 21, 2026 19:14

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f1ae6936b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/strategy/git/snapshot.go Outdated
Every replica independently runs the periodic snapshot, mirror-snapshot,
and LFS-snapshot jobs for each repository, so N replicas regenerate and
re-upload the same artifact every interval. For large repositories an
LFS snapshot generation takes ~20 minutes, multiplied across every
replica, every interval — and because a new pod's schedule store is
empty, every deploy triggers an immediate full regeneration on every
replica at once.

Share per-artifact generation state through the metadata store: before
generating, a replica checks whether a peer completed a generation
within the interval or holds an unexpired in-progress claim, and skips
if so. Claims expire after 30 minutes so a crashed generator can't
block peers indefinitely. Steady-state ticks get per-replica jitter and
first runs after registration are spread over a few minutes, so claims
(which sync asynchronously) propagate before peers decide.

Coordination is advisory — the store is last-write-wins — so replicas
deciding within the same sync window can still generate concurrently;
that's rare with the spread, and a duplicate generation is wasteful but
harmless. Without a metadata store, behavior is unchanged.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019f85b8-d346-7243-961f-fbf2236a7f94
@worstell
worstell force-pushed the worstell/snapshot-generation-coordination branch from 3f1ae69 to 6416cc0 Compare July 21, 2026 19:29
@worstell
worstell requested a review from alecthomas July 21, 2026 22:07
}
}

// jitterInterval spreads replicas' periodic snapshot schedules apart so that

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Holy comments Batman

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we know you love your comments

@worstell
worstell merged commit e99b1d5 into main Jul 21, 2026
7 checks passed
@worstell
worstell deleted the worstell/snapshot-generation-coordination branch July 21, 2026 22:34
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.

2 participants