Skip to content

Upsert memory: max-legal batches allocate ~2-3x body size simultaneously; concurrency uncapped #17

Description

@Coriou

Found by adversarial audit @ 261d00b, confirmed with corrected magnitude (original 14x/~400MB claim refuted down).

Mechanism: upsert.ts:120 retains the raw c.req.json() graph through the awaited write phase; Zod parse builds a second copy; vectors.map eagerly allocates per-vector Float32Array+Buffer+base64+JSON metadata all held by writes until the unchunked Promise.all (upsert.ts:170-191). Net ≈2-3× body peak per request (parsed doubles 8B/value + Float32 4B + base64 5.33B vs JSON text). bodyLimit bounds size, not concurrency: N parallel max-batches scale linearly.

Fix direction: drop the body reference before heavy work, dispatch EVALs in bounded chunks (e.g. 128) so encoded payloads become garbage promptly, optionally a global concurrent-write semaphore.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions