Skip to content

fix(cloud-agent-next): avoid OOM by downloading snapshot in sandbox#908

Merged
eshurakov merged 4 commits intomainfrom
worktree-session-ingest-streaming-consumer
Mar 9, 2026
Merged

fix(cloud-agent-next): avoid OOM by downloading snapshot in sandbox#908
eshurakov merged 4 commits intomainfrom
worktree-session-ingest-streaming-consumer

Conversation

@iscekic
Copy link
Copy Markdown
Contributor

@iscekic iscekic commented Mar 7, 2026

Summary

  • Move snapshot download from worker memory to sandbox via curl — the full JSON never materializes in the 128MB worker
  • Replace worker-side diff extraction (extractDiffsFromMessages) and application (applySessionDiff) with a sandbox-side Node script that reads, deduplicates, and applies diffs directly on disk
  • Refactor restoreSessionSnapshot to accept a file path (curl writes directly) instead of a string payload
  • Remove resolve and zod imports that were only used by deleted methods

Depends on PR #884 which adds the streaming /api/session/:id/export endpoint.

Test plan

  • All 601 existing tests pass (updated 4 cold-start tests for new exec-based flow)
  • Typecheck passes
  • Integration test: cold-start resume with real session to verify curl download + kilo import + diff application

@iscekic iscekic self-assigned this Mar 7, 2026
@iscekic iscekic requested a review from eshurakov March 7, 2026 00:42
Comment thread cloud-agent-next/src/session-service.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 7, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (7 files)
  • cloud-agent-next/Dockerfile
  • cloud-agent-next/Dockerfile.dev
  • cloud-agent-next/src/session-service.ts
  • cloud-agent-next/src/session-service.test.ts
  • cloud-agent-next/wrapper/build.ts
  • cloud-agent-next/wrapper/src/restore-session.ts
  • cloud-agent-next/wrapper/src/restore-session.test.ts

Comment thread cloud-agent-next/src/session-service.ts Outdated
Comment thread cloud-agent-next/src/session-service.ts Outdated
Comment thread cloud-agent-next/src/session-service.ts Outdated
Comment thread cloud-agent-next/src/session-service.ts Outdated
Comment thread cloud-agent-next/src/session-service.test.ts Outdated
Base automatically changed from worktree-session-ingest-streaming to main March 9, 2026 10:23
@eshurakov eshurakov force-pushed the worktree-session-ingest-streaming-consumer branch from 59157bf to cd36c93 Compare March 9, 2026 14:28
Comment thread cloud-agent-next/wrapper/src/restore-session.ts
Comment thread cloud-agent-next/wrapper/src/restore-session.ts
Comment thread cloud-agent-next/wrapper/src/restore-session.ts Outdated
Comment thread cloud-agent-next/wrapper/src/restore-session.test.ts Outdated
Comment thread cloud-agent-next/wrapper/src/restore-session.ts
…andbox to avoid worker OOM

Offload snapshot fetching to curl inside the sandbox and parse/apply
diffs via a jq subprocess so the full snapshot payload never enters
worker memory. Consolidates the cold-start restore into a single
sandbox script, adds proper error handling for fetch timeouts and
malformed diffs, and constrains the autocommit tooltip width.
@eshurakov eshurakov force-pushed the worktree-session-ingest-streaming-consumer branch from 9e6a16e to ee6efcd Compare March 9, 2026 20:11
Comment thread cloud-agent-next/wrapper/src/restore-session.ts
Comment thread cloud-agent-next/wrapper/src/restore-session.ts
- Make path traversal test deterministic by using a tmpDir-relative
  target instead of /etc/passwd which exists on Linux runners
- Surface non-ENOENT unlinkSync errors instead of silently swallowing
  them; only treat missing files as non-fatal during delete diffs
@eshurakov eshurakov merged commit 0ccb095 into main Mar 9, 2026
18 checks passed
@eshurakov eshurakov deleted the worktree-session-ingest-streaming-consumer branch March 9, 2026 20:43
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.

3 participants