Skip to content

fix(pcap): report workspace allocation failures by their system cause - #6229

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/6123-pcap-workspace-allocation-errors
Oct 22, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/6123-pcap-workspace-allocation-errors

Conversation

@kaoru0822-kitauji

@kaoru0822-kitauji kaoru0822-kitauji commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

What broke: inspect_pcap_capture reported any failure to allocate or write its private workspace, including real ENOTDIR/EACCES from mkdtemp, as resource_constraint / resource: "file-size" with reported_limits: null and worker file-size advice. The errno and failing path were lost. Flutter's owned snapshot storage had the same errno-blind mapping.
Fix: One shared owner, src/process/privateWorkspaceFailure.ts, classifies private-workspace filesystem failures. ENOSPC/EDQUOT/EFBIG stay file-size resource constraints, now with their system code and path. All other failures become a provider workspace failure (execution_failure) with stage, workspace path, failing path, system code and recovery that fits the cause. Pcap, Flutter, TShark and sigrok all use it, and the duplicate TShark/sigrok copies are removed.
Risk: Low. No schema change. Pcap and Flutter workspace failures that are not about storage move from resource_constraint to execution_failure with diagnostics. TShark/sigrok keep their classification and gain path plus cause-specific remediation.

Summary

Fixes #6123.

Before this change, PcapSnapshot.create turned every allocation failure except the privacy-capability one into a file-size resource constraint. PcapSnapshot.capture did the same for writes inside the workspace (Owned capture snapshot I/O failed). A denied or non-directory temporary parent was therefore reported as an exceeded size allowance, with no errno and no path. Now a workspace failure keeps its system cause, its failing path and cause-specific recovery. Real size refusals are still reported as size limits.

Problem and expected behavior

Smallest trigger: run inspect_pcap_capture with the pcap workspace parent set to a regular file (ENOTDIR) or to a mode-0500 directory (EACCES). This violates the AnalysisResourceConstraintError contract, which means a measured resource limit or a bounded admission refusal. A permission denial or a bad path does not establish either. Expected: a workspace-preparation failure that preserves system_code and the path and points recovery at the temporary parent. Genuine storage exhaustion keeps its cause and gets storage-specific recovery.

Change and scope

  • src/process/privateWorkspaceFailure.ts (new) is the single owner of private-workspace filesystem failure projection:
    • ENOSPC/EDQUOT produce AnalysisResourceConstraintError("file-size"). reported_limits carries {workspace_path, path, system_code} and the remediation says to free disk space or quota.
    • EFBIG produces the same constraint and keeps the default worker file-size recovery.
    • EMFILE/ENFILE produce ProviderAdapterError whose remediation says to close files or raise the open-file limit.
    • Any other errno, or a cause with no errno, produces ProviderAdapterError. Its diagnostics hold {stage: "workspace", workspace_path, path, system_code, reason} and its remediation covers TMPDIR existence, permission and writability.
    • path is the errno's own coordinate when one exists (for example the mkdtemp template) and otherwise the workspace path.
  • src/pcap/PcapSnapshot.ts: allocation failures and snapshot workspace writes (mkdir of the configuration directory, the wx open, write, chmod) use the shared owner. The privacy-capability path (PrivateRuntimeRootUnavailableError) and source-read handling are unchanged.
  • src/flutter/FlutterBuildProvider.ts: the errno branch of mapOwnedIoFailure uses the shared owner. It previously mapped every errno, EACCES included, to file-size. mapOwnedIoFailure now receives the owned root (null only before mkdtemp succeeds). Package-reader system errors propagate to the request owner, which maps them against snapshot.root, so failures with no errno path still name their workspace.
  • src/captures/TsharkCaptureProvider.ts and src/signals/SigrokRecordingProvider.ts: their identical inline workspace classification is replaced by the shared owner.
  • Sweep: I checked every other "file-size" producer. They are real size guards or SIGXFSZ projections. Other PrivateRuntimeRoot.create callers (firmware, apktool, lldb, kuna, ida, and others) do not project allocation errors as size limits.
  • Not included: no new public error type or resource kind, and no change to how PrivateRuntimeRoot allocates.

Contribution scope: not applicable. This is an ordinary fix within existing boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: privateWorkspaceFailure (src/process), at workspace allocation and owned-snapshot writes.

  • Contribution scope fit and linked maintainer decision: not applicable (ordinary fix).

  • CLI and MCP/tool-catalog contract: no schema change. Error projections for non-storage workspace failures change from resource_constraint to execution_failure and now include details.diagnostics.

  • Provider, bridge, target-format, or platform compatibility: pcap, Flutter, TShark and sigrok. No platform behavior change.

  • Evidence, artifact, provenance, or reconstruction contract: none. The failure happens before any capture bytes are read.

  • Target selection, authority, upstream behavior, and cleanup details: unchanged. A partially prepared pcap workspace is still removed; the new test covers this.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

(This is what the existing tools already do. This PR adds no new effects.)

Evidence and regression coverage

  • Tests added or updated:

    • tests/boundary/mcp/pcapWorkspaceAllocation.test.ts (new) runs through the production MCP server, PcapProvider and the POSIX tool stubs. Native admission is simulated so macOS reaches allocation, as in the issue. It covers:
      • real ENOTDIR and real EACCES from mkdtemp;
      • a writable-parent control, which reaches invalid_request;
      • simulated ENOSPC/EDQUOT (resource constraint plus storage recovery);
      • simulated EMFILE/ENFILE (descriptor recovery);
      • simulated EROFS;
      • a real EACCES on the configuration directory inside an allocated workspace, checking workspace_path, the failing path and that the partial workspace is removed;
      • a counterexample: a sparse capture one byte over the 2 GiB snapshot allowance is still resource_constraint / file-size with max_capture_bytes.
    • src/process/privateWorkspaceFailure.test.ts (new): EFBIG keeps the file-size recovery, and errno without a path, an error without errno, and a non-Error value all fall back to the workspace coordinate.
    • tests/boundary/filesystem/flutterBuildProvider.test.ts: owned-storage ENOSPC stays resource_constraint, and EACCES/EPERM/EIO become workspace execution_failure with system_code. Each case also asserts workspace_path and path: null for the root stage and the rea-flutter-* root otherwise. 7 of the 8 cases fail without the root threading.
  • Base reproduction: on base 34fd7bdf7, the issue's focused test reproduced the bug verbatim. ENOTDIR and EACCES both projected as resource_constraint / file-size / reported_limits: null with no errno, and the normal-parent control returned invalid_request. With only src/pcap/PcapSnapshot.ts reverted, 8 of the 10 new MCP tests fail. The 2 that still pass are the control and the size-limit counterexample.

  • User-visible MCP output (fixed, real EACCES from mkdtemp):

    {"code":"execution_failure","category":"execution_failure","message":"Cannot prepare the private analysis workspace (EACCES): EACCES: permission denied, mkdtemp '<fixture-root>/parent/rea-pcap-Gq5FCR'","retryable":false,"remediation":{"action":"Review details.diagnostics.system_code and details.diagnostics.path. Make the host temporary directory (TMPDIR) an existing directory this user can create files in on a writable filesystem, then retry."},"details":{"provider_id":"pcap","operation":"inspect_pcap_capture","diagnostics":{"stage":"workspace","workspace_path":null,"path":"<fixture-root>/parent/rea-pcap-Gq5FCR","system_code":"EACCES","reason":"EACCES: permission denied, mkdtemp '<fixture-root>/parent/rea-pcap-Gq5FCR'"}}}
  • Remaining proof gaps:

    • ENOSPC, EDQUOT, EMFILE, ENFILE and EROFS were simulated as thrown errno errors, not produced by a full disk or exhausted descriptors.
    • No real Wireshark, and no native Linux/Windows run; native admission was simulated on macOS.
    • The Linux-only pcap, TShark and sigrok suites were skipped locally on macOS and rely on CI.
  • 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

All runs were on macOS arm64 as a non-root user.

  • Issue repro test (temporary file, base code): reproduced, with both cases projected as file-size.
  • vitest run tests/boundary/mcp/pcapWorkspaceAllocation.test.ts: 10 passed. With the pcap fix reverted: 8 failed, 2 passed.
  • vitest run across the Flutter provider, tests/boundary/{captures,signals,pcap}, the pcap and packet-capture MCP tests, the artifact process boundary tests and the new unit test: 262 passed and 44 skipped, the skips being Linux-only suites.
  • npm run check:fast: passed.
  • npm run format:check: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A caller that keyed on resource_constraint for a non-storage pcap or Flutter workspace failure now gets execution_failure with details.diagnostics.system_code.
  • Real Hopper/Ghidra, browser, or OS coverage: real macOS filesystem ENOTDIR/EACCES only. No real Wireshark.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: diagnostics expose only the local temporary path and errno text that the provider itself chose. No caller input bytes are included.

Author readiness

Human owner: @kaoru0822-kitauji

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • 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.

🤖 Generated with Claude Code

Pcap workspace allocation and snapshot writes mapped every filesystem
error, including ENOTDIR and EACCES from mkdtemp, to a file-size resource
constraint with null limits and worker file-size advice. Flutter's owned
snapshot storage had the same errno-blind mapping, while TShark and sigrok
carried duplicate copies of the correct split.

Move the private-workspace failure projection into one shared owner:
ENOSPC/EDQUOT/EFBIG stay file-size resource constraints with their system
code and path; descriptor exhaustion and every other failure become
provider workspace failures carrying stage, workspace path, failing path,
system code and cause-specific recovery.

Fixes #6123

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added bug Something isn't working track:bugs Small-bug loop track PRs labels Oct 22, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-22T02:45:55.517944Z
We couldn’t complete this review. Comment @codex review to try again.
eb23efc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a non-blocking Windows test matcher issue.

Findings

  1. P2 Windows tests reject correct paths ▶
Fix with agent prompt
### Issue 1
tests/boundary/filesystem/flutterBuildProvider.test.ts:327
The new matcher requires `/` before `rea-flutter-`, but Windows workspace paths use `\`. Running this suite on Windows now fails all seven cases after workspace allocation, even when the provider returns the correct location. Accept either separator, or compare the final directory name with `basename`.

```suggestion
        : (expect.stringMatching(/[\\/]rea-flutter-[^\\/]+$/u) as unknown);
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR puts workspace failure reporting in one shared helper.

  • Workspace failures report their system cause instead of a guessed size limit.

No new security issue was established. GitHub status and possible replacement PRs could not be checked because GitHub authentication was unavailable. Tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Workspace allocation or file error] --> B[privateWorkspaceFailure]
  B --> C{System code}
  C -->|ENOSPC or EDQUOT| D[File-size constraint with storage advice]
  C -->|EFBIG| E[File-size constraint with file-size advice]
  C -->|Other| F[Provider failure with workspace details]
  G[Flutter package error] --> H[execute catch with snapshot root]
  H --> B
Loading

Reviews (2) · Last reviewed commit: "fix(flutter): locate owned storage failu..." · Reviewed by Greptile

Comment thread src/flutter/FlutterBuildProvider.ts Resolved
mapOwnedIoFailure always passed a null workspace path, so a descriptor
write or read failure without its own errno path lost every location.
Thread the owned root through: allocation keeps null (no workspace yet),
snapshot failures use the allocated root, and package-reader system
errors propagate to the request owner, which maps them against the
snapshot root instead of mapping early without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
const workspace =
stage === "root"
? null
: (expect.stringMatching(/\/rea-flutter-[^/]+$/u) as unknown);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Windows tests reject correct paths

The new matcher requires / before rea-flutter-, but Windows workspace paths use \. Running this suite on Windows now fails all seven cases after workspace allocation, even when the provider returns the correct location. Accept either separator, or compare the final directory name with basename.

Suggested change
: (expect.stringMatching(/\/rea-flutter-[^/]+$/u) as unknown);
: (expect.stringMatching(/[\\/]rea-flutter-[^\\/]+$/u) as unknown);
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/boundary/filesystem/flutterBuildProvider.test.ts
Line: 327

Comment:
**Windows tests reject correct paths**

The new matcher requires `/` before `rea-flutter-`, but Windows workspace paths use `\`. Running this suite on Windows now fails all seven cases after workspace allocation, even when the provider returns the correct location. Accept either separator, or compare the final directory name with `basename`.

```suggestion
        : (expect.stringMatching(/[\\/]rea-flutter-[^\\/]+$/u) as unknown);
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit b4f9f0d into main Oct 22, 2026
43 of 44 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/6123-pcap-workspace-allocation-errors branch October 22, 2026 04:19
555aaditya added a commit to 555aaditya/rea that referenced this pull request Oct 22, 2026
Resolve import conflicts with main's retained-result validation helper
(b8c1b45) and workspace-failure mapping (morluto#6229): pcapCaptureView keeps
the historical-Evidence compatibility schema (pcapEvidenceSchemas) and
parses it through main's parseAnalysisViewResult; TsharkCaptureProvider
keeps both the shared Wireshark identity imports and
privateWorkspaceFailure.
@morluto morluto added the provider: pcap Analysis provider / engine: pcap label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: pcap Analysis provider / engine: pcap track:bugs Small-bug loop track PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Pcap workspace allocation errors masquerade as file-size limits

2 participants