Skip to content

feat(container): Phase 2 (DO-native) + short idle teardown - #122

Merged
MathurAditya724 merged 1 commit into
mainfrom
feat/phase2-container-lifecycle
Aug 5, 2026
Merged

MathurAditya724 merged 1 commit into
mainfrom
feat/phase2-container-lifecycle

Conversation

@MathurAditya724

Copy link
Copy Markdown
Member

Summary

Answers the lifecycle question: delete the container when work is done, and resume prior context on the next event. We get this by moving to the intended Phase 2 topology instead of hand-rolling a fragile in-container session restore.

  • Phase 2 (DO-native): FLUE_NATIVE=1 + thin container image (./container/Dockerfile). The agent brain and full conversation now live in the FlueJaredAgent Durable Object; the container is a disposable git/gh sandbox.
  • Short idle teardown: sleepAfter 2h → 10m, centralized in SANDBOX_SLEEP_AFTER. In Phase 2 the container is only active during DO exec() calls, so this is an idle-safe teardown — it never fires mid-work (each exec resets the timer), and conversation survives in the DO regardless.
  • Resume on next event: because the DO persists the conversation, the next webhook resumes context and the thin path re-clones the repo into a fresh sandbox. No D1→container restore needed (D1 stays a dashboard mirror).

Why not a manual sandbox.destroy() on "done"?

Arming a hard destroy from the agent-finish hook would need a reentrant self-call into the same DO (deadlock-prone) or a timer that can't tell whether the agent is still mid-work. sleepAfter is the platform-native, idle-aware teardown and composes cleanly with DO persistence.

Trade-off (intentional, agreed)

Lore only runs in-container (Phase 1). In Phase 2, model traffic goes direct to OpenRouter until a standalone Lore gateway is deployed (LORE_GATEWAY_URL). Follow-up: stand up a standalone Lore service.

Rollback

Instant: set FLUE_NATIVE=0 and flip the image back to Dockerfile.phase1, then redeploy.

Test plan

  • biome + tsc + vitest (54 passing)
  • Deployed to jared.getsentry.workers.dev (Version 77aab56e)
  • Live validation on getsentry/cli#1365: dispatch → DO brain → activate_skill + gh/bash tool exec in the thin sandbox → correct SKIPPED decision; history synced from the DO to D1; no exceptions in logs.
  • Observe a full ~10m idle teardown → next-event resume in production (mechanism verified in code; DO persistence is a platform guarantee).

Made with Cursor

Flip FLUE_NATIVE=1 and the container to the thin Dockerfile so the agent
brain and conversation live in the FlueJaredAgent Durable Object. The
container becomes a disposable git/gh sandbox that Cloudflare tears down
~10m after its last exec (sleepAfter 2h -> 10m, centralized in
SANDBOX_SLEEP_AFTER). Because the DO persists the conversation, the next
event resumes context and re-clones the repo into a fresh sandbox — so we
get delete-when-idle + resume-on-next-event without a fragile in-container
session restore.

Trade-off: Lore only runs in-container (Phase 1). In Phase 2 model traffic
goes direct to OpenRouter until a standalone Lore gateway is deployed
(LORE_GATEWAY_URL). Instant rollback: set FLUE_NATIVE=0 and flip the image
back to Dockerfile.phase1.

Validated live on getsentry/cli#1365: dispatch -> DO -> skills + gh/bash
tool exec in the thin sandbox -> correct SKIPPED decision, history synced
from the DO to D1, no exceptions.

Co-authored-by: Cursor <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 5, 2026 •

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 e609a7c Aug 05 2026, 04:57 PM

@MathurAditya724
MathurAditya724 enabled auto-merge (squash) August 5, 2026 16:56
@MathurAditya724
MathurAditya724 merged commit b9740d3 into main Aug 5, 2026
14 of 16 checks passed
@MathurAditya724
MathurAditya724 deleted the feat/phase2-container-lifecycle branch August 5, 2026 16:57
// set back to "0" and flip the container image to Dockerfile.phase1.
// Note: Lore runs in-container (Phase 1 only) — in Phase 2 model traffic goes
// direct to OpenRouter until a standalone Lore gateway (LORE_GATEWAY_URL) is set.
"FLUE_NATIVE": "1",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Phase 2 still writes provider API keys into the disposable untrusted sandbox

With FLUE_NATIVE=1 the container is a thin git/gh sandbox, but ensureSandboxReady's thin path still writes OPENROUTER_API_KEY, ANTHROPIC_API_KEY, and OPENAI_API_KEY to /tmp/flue-env.sh where no Phase 2 process needs them and the agent executes commands driven by untrusted webhook/repo content — skip writing provider keys when thinSandbox is set.

Evidence
  • This line sets FLUE_NATIVE: "1", so isFlueNative() in apps/server/src/lib/github/dispatch.ts and the check in apps/server/src/routes/webhooks/sentry.ts:318 pass thinSandbox: true to ensureSandboxReady.
  • The thin branch of ensureSandboxReady (apps/server/src/lib/containers/dispatch.ts) calls writeEnvFile, which unconditionally writes OPENROUTER_API_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY, and SENTRY_DSN to /tmp/flue-env.sh; the keys are passed in from env.OPENROUTER_API_KEY etc. at both call sites.
  • In Phase 2 no container process consumes that file for model traffic: the agent brain runs in the FlueJaredAgent DO and model calls resolve the Worker-side OPENROUTER_API_KEY (apps/server/src/lib/lore/provider.ts, agents/models.ts).
  • The sandbox is an untrusted execution environment: it clones repos from dispatched webhook events and the DO agent runs arbitrary exec() in it via cloudflareSandbox (agents/jared.ts); prompts embed the raw webhook payload (formatEventPrompt). session-ingest-token.ts explicitly refuses to write the shared internal token into sandboxes because "they execute untrusted repo code," but the provider keys are still written.
  • A prompt-injection or malicious repo script executed by the agent can read /tmp/flue-env.sh and exfiltrate the keys over the sandbox's network access (used for git clone / gh / reporter POSTs), enabling paid LLM API abuse.

Identified by Warden · security-review · 8NN-UZS

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