Skip to content

fix(artifacts): interrupt ZIP extraction under backpressure - #594

Merged
morluto merged 2 commits into
morluto:mainfrom
rudycelekli:campaign/rea-zip-backpressure-abort-20261005
Oct 5, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
rudycelekli:campaign/rea-zip-backpressure-abort-20261005

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 5, 2026 •

Copy link
Copy Markdown

Summary

Cancel ZIP extraction promptly when an unread consumer applies backpressure.

No issue is linked: this is a newly reproduced correctness defect found while reviewing current upstream; the regression and affected production seam are included for review.

Problem and expected behavior

Opening a large stored ZIP entry and aborting after its readable buffer fills leaves the producer waiting for drain. A caller cancellation must close the stream and release the producer.

Change and scope

Connect the caller signal and stream close to the extraction controller and make the drain wait abortable. Preserve the typed cancelled adapter failure.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ZipArtifactReader.extractStream, producer drain wait.
  • CLI and MCP/tool-catalog contract: existing operations and schemas remain compatible; Artifact extraction returns a cancelled failure and releases the stream instead of retaining an unread producer.
  • Provider, bridge, target-format, or platform compatibility: ZIP extraction on supported Node hosts.
  • Evidence, artifact, provenance, or reconstruction contract: existing source identity and explicit incomplete/unsupported evidence remain preserved.
  • Process execution, authorization, cleanup, or containment impact: Caller abort and consumer close release the extraction work and remove the abort listener.
  • Generated metadata (docs/product-catalog.json), package, or installation impact: no metadata or dependency changes required.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/providers/native/zipBackpressureCancellation.test.ts.
  • Base reproduction or other evidence: Executed real filesystem and zip.js boundary test: upstream leaves the stream undestroyed; fixed stream is destroyed and emits ArtifactReaderFailure(reason=cancelled). Affected base is ebb4c45.
  • User-visible CLI/MCP output: Artifact extraction returns a cancelled failure and releases the stream instead of retaining an unread producer.
  • Remaining proof gaps: No real Hopper/Ghidra session was needed or run.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check:pr — passed
  • npm run check:ci — passed
  • npm run verify:package — passed
  • npm pack --dry-run — passed

Focused regression and reproduction commands ran with the outcomes described above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: No real Hopper/Ghidra session was needed or run.
  • Package or release metadata impact: no version, dependency, generated catalog or installation changes.
  • Security, privacy, process, or containment review: Caller abort and consumer close release the extraction work and remove the abort listener. Final diff contains source and regression tests; local fixtures, binaries, caches and logs are excluded.

Review checklist

  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

AI assistance was used to investigate, implement, and test this change. Commits are signed and include a DCO sign-off.

Review clarification

The caller-abort path is reproduced through real ZIP backpressure. The sole production caller, ArtifactExtraction, fully drains the reader; the consumer-close branch is defensive cleanup. The abort callback destroys the output with its typed cancelled failure before aborting the internal controller. Abort listeners dispatch synchronously, and zip.js cannot settle getData inside that dispatch. Successful stream close also aborts the controller after extraction completion, which is currently benign.

@morluto

morluto commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Reviewed against ebb4c45 and locally executed. Approve.

Verification

Check Result
Base reproduction (revert only ZipArtifactReader.ts) 1 failed — expected false to be true, i.e. the stream is left undestroyed
Branch test 1 passed
signal is a real getData option in the pinned @zip.js/zip.js confirmed — index.d.ts:1476, "The AbortSignal instance used to cancel the decompression"
--project boundary tests/boundary/providers/native 16 files, 50 tests passed
tsc --noEmit / prettier --check / oxlint clean

The fix is correctly targeted

I confirmed the hang is where you say it is. output.write() returning false makes once(output, "drain") the only thing standing between the zip.js producer and completion; AbortSignal cannot reach into that events.once call, so the caller's abort fired, abortIfNeeded threw inside write/onprogress, the stream errored — and the producer stayed parked on a drain that could never arrive. Bridging both the caller signal and stream close into an internal AbortController, and feeding that to both once(..., { signal }) and getData({ signal }), releases both sides. The listener bookkeeping is correct too: once: true on the abort listener, removal on close, no leak when either fires first.

Two things I particularly like: passing controller.signal to getData as well, so decompression actually stops rather than just the handoff; and preserving ArtifactReaderFailure(reason=cancelled) rather than degrading to a raw abort error, so ArtifactExtraction's existing typed-failure handling still works.

Non-blocking notes

  • The typed failure depends on listener ordering. The consumer sees ArtifactReaderFailure("cancelled", …) only because onAbort destroys output before zip.js can observe the signal and reject with its own AbortError. That ordering does hold — AbortSignal listeners dispatch synchronously, and getData cannot settle inside the dispatch — so this is deterministic, not a race. But it is the only thing preserving the typed failure and nothing pins it. A test that lets getData reject first would document the dependency explicitly. Worth a line of comment at minimum.
  • close is overloaded. output.once("close", …) fires on the normal success path too, after output.end(). Aborting then is benign today because getData has already resolved, but semantically "close" is now both "consumer went away" and "extraction finished". A short comment would help.
  • Scope of the close path. The consumer-close half of this fix has no production caller today: the only caller of reader.open is ArtifactExtraction.ts:144, which always fully drains via output.write. The caller-abort half — the one your reproduction exercises — is real and does occur in production. Worth stating that split in the body so the close branch is not read as a currently-reachable bug fix.

Test quality

Using a real 2 MiB stored entry and the real filesystem is the right call — a WritableStream mock could not have reproduced this, and the test needs genuine backpressure to mean anything. The finally block that resumes and destroys the stalled stream, with the comment explaining it is there so a failing run also cleans up, is a nice touch that keeps the regression honest in both directions.

Merge

Independent of the other five PRs. No conflicts.

@rudycelekli

Copy link
Copy Markdown
Author

Thanks for verifying the production backpressure case and listener ordering. I clarified the body: caller abort is the reproduced production path, while consumer-close handling is defensive for the current fully-draining caller. The typed output failure is established before the shared controller is aborted; normal close runs after producer completion. The suggested inline comments and additional ordering control remain recorded as non-blocking follow-up notes.

@morluto
morluto merged commit 50f7e81 into morluto:main Oct 5, 2026
19 checks passed
@morluto

morluto commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks, @rudycelekli, for your work on “fix(artifacts): interrupt ZIP extraction under backpressure.” I appreciate your contribution to REA.

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
)

Cancel ZIP extraction promptly when an unread consumer applies backpressure, releasing the producer instead of leaving it parked on a drain that can never arrive.
@morluto morluto added bug Something isn't working area: evidence Evidence, artifacts, and reconstruction labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants