Skip to main content
← Back to list
01Issue
BugShippedSwamp CLIPublic
Assigneeszack

Relationships

#4469 A method run writing thousands of resources reports 'Invalid string length' after succeeding, and runs out of heap past ~4,200

Opened by mtaylor · 11/6/2026· Shipped 11/6/2026

Description

An extension method that writes many resources in one run (ctx.writeResource in a loop, one resource per item) fails in two ways once the run is large, although the method itself keeps its memory flat (it reads, builds and writes one item at a time and holds nothing between items):

  1. The run reports failure after everything is written. swamp behavior run <model> <method> --json ends with {"error": "Method execution failed: Invalid string length"}, yet every resource was written, and swamp report get @swamp/method-summary --model <model> --json for the same run says succeeded, producing N resources. A caller (a workflow step, a script checking the exit status) sees a failed run that actually succeeded.
  2. The swamp process runs out of heap partway. Fatal JavaScript out of memory: Ineffective mark-compacts near heap limit, after about 4,200 resources of 50 to 300 KB each; the resources written before the crash stay, and no later ones (nor the method's final summary resource) are written. DENO_V8_FLAGS=--max-old-space-size=16384 made no difference. The only way through was splitting the input across several runs.

What was run

One method, mineClics on a local extension model, writing one resource per input file plus one summary resource at the end. Resource sizes are about 50 to 300 KB (a JSON profile per network device). Results per run:

Resources written Total input Outcome
1,008 0.4 GB succeeded
about 1,200 each (three runs) about 0.5 GB each written, then "Invalid string length"
about 1,200 (a fourth run, same input folder) about 0.5 GB succeeded
4,074 1.5 GB written, then "Invalid string length"
6,314 0.8 GB written, then "Invalid string length"
4,213 of about 4,900 2.0 GB heap out of memory partway

So the failure doesn't follow the resource count alone: runs of about 1,200 resources both succeeded and failed, which suggests the size of what the run accumulates (resource contents, or the run's output) rather than the number of handles.

Expected

A method that streams its writes keeps swamp's memory bounded too, and a run whose method succeeded and whose resources were all written reports success, with the same result --json and the method-summary report give.

Steps to reproduce

  1. An extension model method that loops for (const item of items) handles.push(await ctx.writeResource("spec", name-${i}, bigObject)), with about 4,000 objects of about 200 KB each, and returns { dataHandles: handles }.
  2. swamp behavior run <instance> <method> --json.
  3. The run ends with "Invalid string length" (or, larger, a heap out-of-memory crash) after the writes; swamp report get @swamp/method-summary says it succeeded.

Environment

  • swamp 20261103.172234.0-sha.b94358f0
  • Windows 11 Pro (10.0.26300), Git Bash
  • local filesystem datastore
02Bog Flow
✓OPEN✓TRIAGED✓IN PROGRESS✓SHIPPED+ 1 MOREASSIGNED+ 14 MOREREVIEW+ 20 MOREPR_LINKED+ 2 MORESESSION_SUMMARIZED

Shipped

11/6/2026, 8:05:38 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
zack assigned zack11/6/2026, 3:00:24 PM
Editable. Press Enter to edit.

zack commented 11/6/2026, 8:05:39 PM

Thanks @mtaylor for reporting this! We shipped: Bound how much resource content a single method run keeps in memory and puts in its result. A per-method-run attribute budget (64 MiB of serialized JSON) limits handle.attributes and the --json method result, which marks artifacts past the cap attributesOmitted instead of embedding their contents. Under the cap nothing changes. This removes the false Invalid string length failure after a succeeded run and the handle retention that grows the heap. The workflow run path is tracked in swamp-club#4477.. The fix has been merged and a release is on its way. We appreciate your contribution to swamp.

Sign in to post a ripple.