Skip to content

refactor(pcap): give TShark selection and version admission one owner - #3407

Merged
morluto merged 16 commits into
morluto:mainfrom
555aaditya:refactor/tshark-single-owner
Oct 22, 2026
Merged

morluto merged 16 commits into
morluto:mainfrom
555aaditya:refactor/tshark-single-owner

Conversation

@555aaditya

@555aaditya 555aaditya commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #3403, milestone 1. Share caller-selected TShark/Capinfos selection, version parsing and executable identity facts between pcap and packet-capture workflows, including server availability.

An absolute environment path is honored; an invalid relative value is refused. Without a configured value, selection uses an executable in an absolute PATH directory where the platform locator supports it. Both providers reuse the shared size/SHA owner and verify the selected binary before and after a run. Retained identity contains byte count/digest, not whole executable buffers.

Current inspect_pcap_client output includes resolved path, digest and verified/unresolved status for each tool. The advertised output schema requires these facts; historical retained Evidence is read through a separate compatibility schema that supplies null/unresolved for absent old fields. It never invents verified identity.

Executable-read cancellation and failed descriptor cleanup pass through ArtifactAnalysisResources, preserving the primary cancellation, cleanup observations and retry owner. Missing configured tools remain typed capability failures instead of unreadable output.

Validation

On pinned Node 24.18.0/npm 11.16.0, current focused schema/view/MCP/cross-platform tests passed 17 tests with 2 platform skips; npm run check:fast passed. Earlier focused configuration/provider sets passed 84 tests, with 25 host-gated skips.

The real Linux TShark/Capinfos lane 39682764813 passed on ancestor 4924706e, including focused Linux tests and verify-packet-capture.mjs. The later changes fix retained-Evidence compatibility, current fixtures and read-error mapping. The fresh exact-head real-provider run 39685186476 also passed on f2cffbdf, including Linux focused tests and verify-packet-capture.mjs. This is current-head Linux provider verification; Windows remains outside that proof.

Remaining coverage

Windows PATH/PATHEXT identity remains explicitly unresolved where the locator cannot establish an absolute binary. Packet-capture host support stays Linux-only. Shared Windows native bounds and CPU-ceiling alignment remain later #3403 work. This pass adds no target execution or mutation authority; provider commands inspect caller-selected capture files. Host TShark/Capinfos are unavailable locally.

Compatibility

Breaking change for inspect_pcap_* on Linux and macOS: with REA_TSHARK_COMMAND or REA_CAPINFOS_COMMAND unset, the tool must now be in an absolute PATH entry. Previously the bare name went to the process launcher, which also searched relative PATH entries. A setup whose TShark/Capinfos is reachable only through a relative PATH entry now fails with tshark_missing / capinfos_missing. Migration: put the tool in an absolute PATH directory or set the absolute REA_TSHARK_COMMAND / REA_CAPINFOS_COMMAND. Absolute environment paths, absolute PATH installs and Windows PATH/PATHEXT selection behave as before. inspect_packet_* previously accepted only an absolute REA_TSHARK_COMMAND, so it gains PATH installs and loses nothing.

Review follow-ups (merge of main at b8c1b45)

  • Resolved the import conflicts with main's parseAnalysisViewResult (pcapCaptureView.ts) and privateWorkspaceFailure (TsharkCaptureProvider.ts), keeping pcapEvidenceSchemas.
  • A missing selected tool now names its configured path again ("The selected tshark executable /nonexistent/tshark could not be found at its configured path."). This restores the public CLI refusal that tests/boundary/cli/pcapCli.test.ts checks.
  • New tests:
    • A 3.x TShark banner and a non-Wireshark banner through the packet provider. Each pins the capability-unavailable reason and that only the version probe ran.
    • The inspect_packet_capture session availability rule over MCP: PATH-only, absolute and relative REA_TSHARK_COMMAND, plus the no-absolute-PATH-entry case. The first three are Linux-gated.
  • main's new late-cancellation service fixture now has tool.selection_source.
  • On macOS arm64 with Node 26.5.0: npm run test:fast passed (13,966 passed, 23 skipped). The pcap/captures/MCP set passed (154 passed, 39 host-gated skipped). The pcap CLI boundary test passed with a fresh build, and npm run check:fast passed. I didn't run the Linux-gated availability cases or real TShark locally.

Author readiness

Human owner: @555aaditya

  • 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.

Maintainer blocker verification

The shared selection/version boundary now also owns executable identity projection and same-run size/SHA checks for both packet-capture and pcap consumers. It retains compact byte-count/digest facts rather than whole executable buffers between calls. Absolute configured paths remain caller-selected; invalid relative environment paths fail rather than silently selecting PATH. Windows PATH/PATHEXT resolution remains explicitly unresolved where the locator cannot establish an absolute binary identity.

On Node 24.18.0/npm 11.16.0, the latest focused configuration/pcap/capture set passed 84 tests, with 25 platform-gated skips; npm run check:fast passed. TShark/Capinfos are unavailable locally. An exact-head hosted real-provider workflow has been requested separately; queued execution is not provider proof. Existing file-only analysis authority suffices for this correction; no new target execution/injection capability is added.

The pcap and packet-capture families wrapped the same caller-supplied
TShark with diverging rules. inspect_pcap_* accepted an absolute
REA_TSHARK_COMMAND or tshark from PATH, while inspect_packet_* and the
server availability policy required an absolute REA_TSHARK_COMMAND and
parsed the version banner with a separate regex.

PcapConfiguration now owns the rule: selectWiresharkTool selects an
absolute environment path or the bare name on PATH and refuses relative
values; locateWiresharkTool resolves a PATH selection to the first
absolute PATH entry holding an executable file; parseWiresharkVersion
admits Wireshark 4.x banners for both providers. TsharkCaptureProvider
and the session availability policy consume these facts instead of
reinterpreting REA_TSHARK_COMMAND, so all four tools accept and refuse
the same configurations. inspect_packet_* still resolves, hashes and
rechecks the located executable, and records selection_source in its
tool Evidence.

Host support and resource bounds are unchanged; unifying them is the
next milestone in morluto#3403.

Refs morluto#3403
@555aaditya
555aaditya marked this pull request as ready for review October 14, 2026 10:47
@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 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; the remaining cleanup finding is fixed.

Summary

The PR shares TShark selection, version checks, and executable identity checks across pcap and packet-capture tools.

  • Packet and pcap inspections now select and check Wireshark tools the same way.
  • Pcap results now show the resolved identity of each tool.
  • Packet-capture session status follows the shared TShark lookup.
  • Pcap failures keep executable-read and probe cleanup details attached.

Reviews (12) · Last reviewed commit: "fix(pcap): keep a failed executable re-r..." · Reviewed by Greptile

Comment thread src/pcap/PcapConfiguration.ts Outdated
resolvePcapTools still returned bare tool names for PATH selections, so
the operating system could run a tool from a relative PATH entry while
the packet tools skipped that entry and selected a different install.

On POSIX hosts, resolve PATH selections through locateWiresharkTool and
run that absolute executable, failing with the existing tshark_missing or
capinfos_missing code when no absolute PATH entry holds the tool. Both
selections are validated before PATH is consulted, so a relative
environment value still reports its own configuration error. Windows
keeps PATH/PATHEXT resolution in the process launcher.

Refs morluto#3403
@555aaditya

Copy link
Copy Markdown
Contributor Author

@morluto @baron if you could review this please
Thanks!

Resolve the node:fs/promises import conflict in pcapProviderCrossPlatform.test.ts by importing open, symlink and writeFile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Merged latest main into this branch (a22adc7) to clear the merge conflict. No force-push; your commits are untouched.

What changed and why

  • tests/boundary/pcap/pcapProviderCrossPlatform.test.ts: the only conflict was the node:fs/promises import. Your branch added symlink and main added open, so the import now has open, symlink, writeFile. Nothing else needed manual resolution.

Validation (local macOS, merged head)

  • tsc --noEmit: clean
  • npm run test:focused on all src/pcap, tests/boundary/pcap and tests/boundary/captures tests: 9 files passed, 123 tests passed. 35 tests skipped because TShark/capinfos are not installed on this machine (pcapProvider, pcapRetainedView, captureDescriptorCleanup, resourceLimits). CI's TShark lanes cover those.
  • check:fast, format:check, docs:check, metadata:check: pass

The pre-commit oxlint --fix touched two files this PR does not change; keep them identical to main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Follow-up: 658c29b restores main's copies of src/domain/flutter/flutterBuildAnalysis.ts and src/server/http/NodeHttpRequestOwner.ts. The local pre-commit oxlint --fix hook reformatted them while committing the merge. This PR does not touch them, so they now match main exactly.

@CassieFox23 CassieFox23 left a comment

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.

TL;DR: The change gives TShark selection one owner, and the shape is sound. Three things need work before merge. The PR body says no earlier setup breaks, but one now fails. A 3.x banner has no test. The new availability rule has no test either.

Findings

Should fix

  • The body says old setups all still work. The diff shows one that does not. resolvePcapTools now skips relative PATH entries. It throws tshark_missing or capinfos_missing when no absolute entry holds the tool. The new test with PATH: "relative-only" shows this. Before, the bare name went to the process launcher. From the diff alone, a setup with the tool only in a relative PATH entry now fails for inspect_pcap_*. This may be the right rule. Please list it under breaking changes in the body. See PcapConfiguration.ts.
  • With a 3.x banner, parseWiresharkVersion throws. The error is PcapConfigurationFailure. It returns null for a non-Wireshark banner or empty output. The old regex gave one plain Error for both cases. The catch at L401 sends it down the generic failure path, which reports the error's own message. So a 3.x banner now gets different wording. No test in the diff sends a 3.x banner through the packet provider. Please add one. See TsharkCaptureProvider.ts.
  • The new tsharkLocatable rule changes what the session reports. It affects which tools show as available. The body says PATH-only installs now show as available. No test in the diff covers this rule. Please cover a PATH-only install, an absolute REA_TSHARK_COMMAND and a relative one. See createServer.ts.

Nit

  • The locate test has a local const relative. It hides the relative from node:path. It is also an absolute path to a directory the test never creates. A new name would be clearer. See PcapConfiguration.test.ts.
  • docs/pcap-analysis.md: The edited paragraph now has one very long line. It joins the Windows sentence to "Client inspection reads no capture file." Please rewrap it.

Looks good

  • One rule selects the tool. One rule locates it. They replace three copies. Both tools are checked before PATH is read. A relative environment value is refused, not looked up. See PcapConfiguration.ts.
  • The cross-provider test compares tshark with the packet rule. They pick the same absolute file, even with a relative decoy ahead of it. See PcapConfiguration.test.ts.
  • The resolve and hash flow is kept. selection_source is added, with tests for both the environment and path cases. See TsharkCaptureProvider.ts.
  • The tool text and the docs move together. It covers the capability fix text. See captureToolContracts.ts.

Not run

  • No build and no tests. This is a read-only review of the diff against main.

Thanks, 555aaditya, for pulling three separate reads of REA_TSHARK_COMMAND into one owner. You also added a test that checks the tools pick the same executable.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • Head / base: 658c29b / d0067ba

🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

Comment thread src/domain/pcap/pcapAnalysis.ts
Comment thread src/pcap/PcapProvider.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

morluto and others added 7 commits October 22, 2026 05:52
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.
Address review follow-ups on the shared TShark owner:

- Send a 3.x TShark banner and a non-Wireshark banner through the packet
  provider, pinning the capability-unavailable reason for each and that
  only the version probe ran before refusal.
- Cover the session availability rule for inspect_packet_capture over
  MCP: a PATH-only install and an absolute REA_TSHARK_COMMAND are
  available on Linux, a relative REA_TSHARK_COMMAND is refused even when
  PATH holds TShark, and no absolute PATH entry reports provider_missing.
- Rename the locator test's missing absolute PATH entry so it no longer
  shadows node:path relative.

Refs morluto#3403
Resolving the selected executable before launch replaced the runner's
"Cannot run selected tool <path>" refusal with a message that kept the
configured path only in diagnostics, so the public CLI no longer told the
caller which REA_TSHARK_COMMAND or REA_CAPINFOS_COMMAND value to fix and
the pcap CLI boundary test failed. Include the configured command in the
capability-unavailable message and assert it there.

Refs morluto#3403
… source

The service fixture added on main in 719d56e predates the required tool.selection_source field, so its report failed output validation before reaching the late-cancellation path the test covers.

Refs morluto#3403
@555aaditya

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review, @CassieFox23! I addressed it in 1915d2ee2..5fa4bdd44, which also merges current main to clear the conflicts.

Should fix

  • Relative PATH entries are a breaking change. You're right. I added a Compatibility section to the description that names it, with the tshark_missing / capinfos_missing result and the migration (an absolute PATH directory or an absolute REA_*_COMMAND).
  • 3.x banner through the packet provider. Added refuses an unadmitted version banner before dissection in captureProvider.test.ts. It sends a 3.x banner and a non-Wireshark banner, pins each capability-unavailable reason, and asserts that only the version probe ran.
  • Availability rule. Added tests/boundary/mcp/packetCaptureAvailability.test.ts. It reads inspect_packet_capture availability from binary_session for a PATH-only install, an absolute REA_TSHARK_COMMAND, and a relative one (refused even when PATH holds TShark), plus a PATH with no absolute entry. The first three are Linux-gated, because the server enables the default packet tools only on Linux.

Nits

  • Renamed the locator test's relative to missingDirectory, so it no longer shadows node:path's relative.
  • The long docs/pcap-analysis.md line was already rewrapped in morluto's later commits.

While merging, I also found that resolving the executable before launch had dropped the configured path from the missing-tool message, which broke pcapCli.test.ts. The message names the path again. I also added selection_source to a service fixture main added today. npm run test:fast, the pcap/captures/MCP set and check:fast pass locally.

Comment thread src/pcap/PcapProvider.ts
When a tool probe returned with its owned process still awaiting cleanup,
a failed post-run executable re-read or identity check threw before run()
reported that cleanup. Probes have no snapshot to carry it, so callers
saw an ordinary error with cleanupIncomplete false while the provider
kept the process and refused the next request.

After the command returns, combine such a failure with the probe's
ProviderCleanupError (cancellation and other command failures keep their
own cleanup outcome). Classify request failures through one
analysisFailure owner shared by run() and executeAdmitted(), and let the
availability probe rethrow any cleanup-incomplete failure instead of
reporting the tool unavailable.

Refs morluto#3403
Comment thread src/pcap/PcapProvider.ts Outdated
…robe's

The combined post-run failure was bound only to the probe's pending
process cleanup. When the executable re-read had also failed to close its
file, the classified failure owned that cleanup, but the combined error's
live cleanupResources omitted the file and could clear cleanupIncomplete
once the process stopped. Bind both the classified failure and the probe
cleanup as dependencies.

Refs morluto#3403
@CassieFox23

Copy link
Copy Markdown
Contributor

Thanks, 555aaditya, for the quick round. At 48dd89e I read the code and ran no tests. All five items from my review are fixed:

I did not review the cleanup changes added since.

🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@morluto
morluto merged commit 92a9591 into morluto:main Oct 22, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants