# Agent9 Workspace Batch Upload

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "agent9-workspace-batch-upload-2026-08-24",
  "problems": [
    {
      "problemId": "agent9-first-turn-workspace-upload-latency",
      "summary": "A new Agent9 Session received 31 small Auto-oncall workspace files through separate HTTP and Drive9 writes, consuming 7.86 seconds before the first Turn request.",
      "status": "optimized_verified",
      "applicability": "Agent9-backed Auto-oncall Agent Sessions with a non-empty initial text workspace.",
      "issueKeys": [],
      "sourceRefs": ["agent9-session:sess_f1147f5da91746378a58e425bb5ffe15#problem:first-turn-workspace-upload-latency"],
      "signalTextIncludesAny": [
        "agent9 first turn workspace upload latency",
        "separate session file uploads before turn"
      ],
      "observedThrough": "2026-08-24",
      "effectiveAt": "2026-08-24T08:59:00Z",
      "verifiedAt": "2026-08-24T09:30:25Z",
      "attemptedAction": "Create one bounded Agent9 Session batch-upload route backed by Drive9 fs:batch-write and use it only for a new AOS Agent9 Session's initial workspace sync.",
      "evidenceUrl": "https://internal.us-west-2.agent.mem9.ai/api/sessions/sess_29cbaff2c0a545bea7fd3a139e375d47"
    }
  ]
}
-->

- Optimization ID: `agent9-workspace-batch-upload-2026-08-24`
- Owner: Agent9 Session file transport and the Auto-oncall Agent9 adapter
- Source: Agent9 Session `sess_f1147f5da91746378a58e425bb5ffe15`
- Implementation status: deployed
- Effective status: `optimized_verified`

## Bounded problem

The measured first Router Session uploaded 31 small text files individually before
creating its first Turn. That synchronization consumed 7.86 seconds even though
the payload was small. This record owns only initial Session workspace transport;
it does not change role prompts, evidence handoffs, provider execution, diagnosis,
timeouts, or publication behavior.

## Candidate change

- Add one authenticated Session batch-upload endpoint with the existing per-file,
  path, count, and aggregate-byte boundaries.
- Provision the Session Drive and resolve its owner write key once.
- Reuse Drive9's existing create-only `fs:batch-write` operation.
- Use the batch route only for a newly created Agent9 Session. Keep the existing
  incremental overwrite route for resumed Sessions and later Turns.

## Verification evidence

Read-only run `a64e970a-c16f-410e-ad27-824c8012ba13` created Router Session
`sess_29cbaff2c0a545bea7fd3a139e375d47`. It uploaded the 114,179-byte initial
workspace with exactly one `/files/batch` request in 4.335 seconds, versus the
7.86-second 31-request baseline. The first Router Turn then completed normally.

## Unresolved gaps

- The remaining 4-second batch latency is Drive provisioning plus one bounded
  Drive9 batch write; this record does not claim it is zero-cost.

## Next validation action

Keep the batch route for new Sessions and the per-file overwrite path for resumed
Sessions; investigate further only if first-Turn transport again becomes material.
