Skip to content

perf(runtime): bound Cattle artifact restore latency and memory #563

Description

@Yevanchen

Context

PR #559 restores the latest ready artifacts when a recycled Cattle Session gets a fresh workspace. The current path restores files serially: each R2 object is fully buffered as a Uint8Array, base64-encoded, and then written through the Sandbox RPC.

This prioritizes correctness, but large files increase Worker peak memory and encoding/GC pressure, while many files add cold-start latency linearly. This is a follow-up optimization, not a blocker for #559.

Related: #559, #387, langgenius/mosoo-agent-driver#117

Goal

Measure and reduce artifact rehydration latency and Worker memory without weakening Session isolation, latest-per-source-path selection, audit history, original paths, or fail-closed handling for missing objects.

Scope

  • Add observability for artifact count, total bytes, largest file, R2 read time, encoding/write time, end-to-end restore time, and failures.
  • Establish a repeatable baseline for 1/10/50/100 files with mixed sizes, including p50/p95 and peak memory.
  • Based on measurements, evaluate the smallest safe improvement: bounded concurrency, fewer byte/base64 copies, or streaming if supported by the Sandbox API.
  • Define safe per-file and per-restore byte limits with an actionable error; do not introduce unbounded concurrency.

Acceptance criteria

  • A repeatable benchmark or integration test compares before/after behavior.
  • Restore latency no longer grows strictly through fully serial file processing, or measurements justify a different optimization.
  • Peak memory has a documented bound and all artifacts are never buffered simultaneously.
  • Existing Cattle continuation, cross-Session isolation, latest-version, and missing-object tests remain green.
  • Production rollout and rollback signals identify whether time is spent in R2 read, encoding, or Sandbox write.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions