Skip to content

fix(agent): re-clone + re-auth thin sandbox on DO-initiated turns - #123

Merged
MathurAditya724 merged 1 commit into
mainfrom
fix/do-sandbox-prep
Aug 5, 2026
Merged

MathurAditya724 merged 1 commit into
mainfrom
fix/do-sandbox-prep

Conversation

@MathurAditya724

Copy link
Copy Markdown
Member

Summary

Follow-up to #122 (Phase 2 / DO-native + 10m idle teardown). Closes a correctness gap surfaced in review: DO-initiated turns can run against an empty, unauthenticated container.

On a webhook event the Worker runs ensureSandboxReady (clone + GH auth) before dispatch. But two paths reach the FlueJaredAgent Durable Object without that prep:

  • Scheduled follow-ups — the auto-merge/fix-ci skills call the DO's scheduleFollowUp for the remaining quiet period (~10 min), which now lands right when the container has been torn down by the 10m idle window.
  • Post-teardown resumes / long tool-less reasoning gaps.

In those cases the thin container respins empty (no /workspace/repo, gh unauthenticated) and git/gh fail.

Fix

Add a useAgentStart hook in Jared() that ensures the thin sandbox is prepped before the model's first turn:

  • Derive owner/repo from the entity key (looked up in agent_sessions by the conversation id, since toAgentInstanceId is lossy).
  • Mint a fresh installation token (getRepoInstallationToken).
  • Reuse ensureSandboxReady(thinSandbox) to clone + re-auth.

Idempotent and best-effort (never throws into the turn). Webhook (user) turns with an existing clone are skipped; non-user deliveries force a re-prep so the ~1h GitHub token is also refreshed for long-delayed follow-ups. Not mirrored to container/flue (Phase 1 in-container Flue already owns the repo).

Test plan

  • Unit test for repo derivation (parseOwnerRepo)
  • biome + tsc + vitest (58 passing) + vite build (bundles cleanly into the DO)
  • Deployed (jared.getsentry.workers.dev, Version 14cb364b) and re-validated on getsentry/cli#1365: normal webhook turn unaffected (skills + gh/bash → correct decision), no prep errors / exceptions in logs, hook correctly no-ops on already-prepped turns.
  • Observe an actual scheduled auto-merge follow-up after teardown re-clone in prod (mechanism unit-tested + reuses proven ensureSandboxReady).

Made with Cursor

Webhook turns are prepped by the Worker (ensureSandboxReady) before dispatch,
but DO-initiated turns bypass that path: scheduled auto-merge/fix-ci follow-ups
(via scheduleFollowUp) and post-teardown resumes reach the FlueJaredAgent DO
with a possibly-empty container. With the 10m idle teardown, the auto-merge
quiet period (~10m) lands right when the container is gone, so git/gh would run
against an empty, unauthenticated sandbox.

Add a useAgentStart hook that ensures the thin sandbox is prepped before the
model's first turn: derive owner/repo from the entity key (agent_sessions row
keyed by the conversation id), mint a fresh installation token, and reuse
ensureSandboxReady(thinSandbox) to clone + re-auth. Idempotent and best-effort
(never throws into the turn). Webhook ('user') turns with an existing clone are
skipped; non-user deliveries force a re-prep so the ~1h GitHub token is also
refreshed for long-delayed follow-ups.

Not mirrored to container/flue (Phase 1 in-container Flue already owns the repo).
Validated live on getsentry/cli#1365: normal turn unaffected, no prep errors.

Co-authored-by: Cursor <[email protected]>
@MathurAditya724
MathurAditya724 enabled auto-merge (squash) August 5, 2026 18:47
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
jared 02bdbf6 Aug 05 2026, 06:47 PM

@MathurAditya724
MathurAditya724 merged commit 396b565 into main Aug 5, 2026
16 of 18 checks passed
@MathurAditya724
MathurAditya724 deleted the fix/do-sandbox-prep branch August 5, 2026 18:48
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.

1 participant