Skip to content

fix(agent): stop handoff checkpoint uploads failing on large repos#3393

Merged
tatoalo merged 1 commit into
mainfrom
posthog-code/fix-handoff-checkpoint-uploads
Jul 14, 2026
Merged

fix(agent): stop handoff checkpoint uploads failing on large repos#3393
tatoalo merged 1 commit into
mainfrom
posthog-code/fix-handoff-checkpoint-uploads

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Cloud sessions that end without local handoff state (the normal case: a sandbox stopped by SIGTERM) build their handoff git pack with no exclusion baseline, so git pack-objects packs everything reachable from HEAD, the entire repo snapshot. The pack is then shipped base64-encoded inside a JSON API body. On large repos (e.g. posthog/posthog, ~100 MB packed, ~134 MB after base64) the request exceeds API body limits and fails with 413 Payload Too Large, so the final checkpoint is lost and cold resumes cannot restore the session's branch, index, and uncommitted changes.

This was latent since checkpoints landed (#1665) and became visible once sandbox cleanup started gracefully stopping the agent server (PostHog/posthog#70086), which exercises the final-checkpoint capture on every cloud teardown.

Changes

  • reduce default handoff pack size by excluding objects already present in the upstream tracking branch (or the remote default branch when needed), so packs contain only session-created objects while the apply flow restores the baseline automatically
  • upload handoff artifacts through the backend's presigned upload flow, avoiding base64 overhead and API size limits. Keep the existing inline upload as a fallback, ensuring checkpoints only reference artifacts successfully attached by the backend and maintaining compatibility with legacy artifacts
  • gracefully handle oversized artifacts by skipping uploads above the server limits with a warning. If a required artifact cannot be uploaded, discard the checkpoint instead of creating one that cannot be restored

@trunk-io

trunk-io Bot commented Jul 13, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 74c0a84.

@tatoalo tatoalo self-assigned this Jul 13, 2026
@tatoalo tatoalo marked this pull request as ready for review July 13, 2026 14:20
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 13, 2026
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): stop handoff checkpoint uplo..." | Re-trigger Greptile

Comment thread packages/agent/src/handoff-checkpoint.ts
Comment thread packages/agent/src/handoff-checkpoint.ts Outdated
Comment thread packages/git/src/handoff.ts Outdated

@stamphog stamphog 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.

Technically sound fix with good fallback logic and test coverage, but it's a complex change (523 lines) to critical agent handoff infrastructure — new API endpoint calls, a data-encoding detection heuristic, and a git-pack exclusion change — with zero reviews. Higher-risk changes with no reviews should get a human sign-off.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 13, 2026
Cloud sessions that end without local handoff state packed every object
reachable from HEAD (the entire repo snapshot for a fresh sandbox clone),
then shipped it base64-encoded inside a JSON API body. On large repos the
request exceeded API body limits and the final checkpoint was lost with a
413, so cold resumes could not restore the session's git state.

- default the pack baseline to the branch's upstream tracking ref (which
  the apply side fetches before unpacking), falling back to the remote
  default branch that any fresh clone already contains, so packs only
  carry session-created objects
- upload checkpoint artifacts via the presigned prepare/finalize direct
  upload flow, storing raw bytes instead of base64 text; keep the inline
  JSON upload as a fallback (also used when finalize does not confirm the
  artifact) and sniff pack/index magic bytes on download so legacy
  base64-at-rest artifacts still apply
- cap artifact and inline upload sizes with clear warnings, and discard
  the checkpoint instead of publishing one whose required artifacts never
  reached storage
@tatoalo tatoalo force-pushed the posthog-code/fix-handoff-checkpoint-uploads branch from 8222db1 to 74c0a84 Compare July 13, 2026 14:28
@tatoalo tatoalo requested a review from a team July 13, 2026 14:33
@tatoalo tatoalo merged commit 0cbc64f into main Jul 14, 2026
26 checks passed
@tatoalo tatoalo deleted the posthog-code/fix-handoff-checkpoint-uploads branch July 14, 2026 13:24
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