Skip to content

refactor(application): make remaining AnalysisViewService helpers async - #14759

Open
Plastic-time wants to merge 3 commits into
morluto:mainfrom
Plastic-time:rrfz/async-analysis-view-helpers
Open

Plastic-time wants to merge 3 commits into
morluto:mainfrom
Plastic-time:rrfz/async-analysis-view-helpers

Conversation

@Plastic-time

@Plastic-time Plastic-time commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses #14112

Implement Option 1 of #14112 as a draft PR for maintainer review: convert the remaining synchronous view-projection helpers (resolveArtifactComparisonEvidence and deriveEnvironmentState / prepareServedState) to async, switch environmentBuild.ts to dynamic import, and remove the unused static summarizeRetainedAnalysis import left in FridaInstrumentationService.ts. Together these remove all four remaining static AnalysisViewService imports in src/application/ (emptying and deleting scripts/verify/baselines/static-analysis-view-import.json), so dist/cli-runtime/ has zero static imports of the AnalysisViewService chunk.

Problem and expected behavior

  • Prior behavior: ArtifactComparisonEvidence.ts, environmentState.ts, environmentBuild.ts, and FridaInstrumentationService.ts statically imported AnalysisViewService.js. In the bundled CLI (dist/cli-runtime/), four chunks (artifactCommands, fridaCommands, environmentState, application__environment__environmentBuild) statically imported AnalysisViewService-*.js, causing commands such as inspect-artifact, non-summary compare-artifacts, and frida-devices --help to load AnalysisViewService even when no view projection occurred.
  • Expected behavior: All four application modules defer AnalysisViewService to await import("../analysisView/AnalysisViewService.js") on the branch that actually projects or summarizes a view. CLI/MCP behavior and output contracts are unchanged; dist/cli-runtime/ emits zero static imports of AnalysisViewService-*.js, and scripts/verify/baselines/static-analysis-view-import.json is retired.

Change and scope

  • Artifact comparison:
    • Allowed EvidenceFileRecordResolver (src/application/analysisView/evidenceFileSource.ts) and EvidenceSourceResolutionOptions.resolveEvidence (src/application/EvidenceInputResolver.ts) to return Result | Promise<Result> (their callers readEvidenceFileSource and resolveEvidenceSource are already async) and preserved post-await abort checks when a caller cancels mid-resolution.
    • Made resolveArtifactComparisonEvidence async in src/application/artifacts/ArtifactComparisonEvidence.ts, preserving post-await cancellation handling, and moved inspectAnalysisViewValidated behind await import("../analysisView/AnalysisViewService.js") right before summary reprojection so non-summary inventories and early validation failures never load AnalysisViewService.
  • Environment state / bundle / compare / build:
    • Made deriveEnvironmentState and prepareServedState async in src/application/environment/environmentState.ts, dynamically importing AnalysisViewService after parseEvidenceFile succeeds.
    • Updated EnvironmentBundleOptions.served and planEnvironmentBundle (src/application/environment/environmentBundle.ts) and compareEnvironment (src/application/environment/environmentCompare.ts) to async, preserving name-validation-before-state-derivation ordering.
    • Switched src/application/environment/environmentBuild.ts to dynamically import inspectAnalysisView on the already-async build path and await prepareServedState / planEnvironmentBundle.
    • Updated src/application/environment/environmentExport.ts and src/cli/environmentCommands.ts (including a post-await cancellation check in loadServeInputs).
  • Frida cleanup:
    • Removed the leftover unused static import { summarizeRetainedAnalysis } from "../analysisView/AnalysisViewService.js" in src/application/frida/FridaInstrumentationService.ts (line 297 already dynamically imports it on the summary branch).
  • Guard baseline & tests:
    • Removed scripts/verify/baselines/static-analysis-view-import.json via architecture-guards.mjs --shrink-baselines (zero remaining copies across 3155 source files) and updated the guard comment/message in scripts/verify/architecture-guards.mjs.
    • Updated affected unit tests and tests/fixtures/environmentServe.ts to await the async helpers, added an async resolveSelected cancellation regression test in src/application/analysisView/evidenceFileSource.test.ts, and added AnalysisViewService deferral assertions in tests/boundary/cli/cliStartupImports.test.ts.
  • Out of scope:

Follow the contribution scope.
#14112 carries the design label with two open options (Option 1: async-ify both helpers; Option 2: accept the current composition). This draft PR implements Option 1 so maintainers can inspect the actual diff and bundle effect; CLI/MCP user contracts are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ArtifactComparisonEvidence.ts, environmentState.ts, environmentBuild.ts, and FridaInstrumentationService.ts retain their existing ownership while deferring AnalysisViewService loading to dynamic import(). No duplicated ownership introduced; the stale static import in FridaInstrumentationService.ts and the retired guard baseline file are removed.
  • Contribution scope fit and linked maintainer decision: Pending maintainer decision on [Refactor] Decide async conversion for the two synchronous view-projection helpers blocking the AnalysisView chunk split #14112 (design label; Option 1 vs Option 2). This draft PR provides a concrete Option 1 implementation for evaluation.
  • CLI and MCP/tool-catalog contract: Unchanged; no CLI flags, MCP schemas, or Evidence formats change.
  • Provider, bridge, target-format, or platform compatibility: Portable JS/Node module loading only; no platform-specific behavior.
  • Evidence, artifact, provenance, or reconstruction contract: Unchanged; identical Evidence records, digests, and error projections.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): Not applicable (no new processes, files, or external side effects).
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: None.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • tests/boundary/cli/cliStartupImports.test.ts: extended single-command startup check to cover environment-serve, environment-compare, environment-export, and environment-build; added defers AnalysisViewService for artifact inspection, non-summary comparison, Frida, and environment modules verifying --help for inspect-artifact, compare-artifacts, frida-devices, real runs of inspect-artifact and non-summary evidence-file compare-artifacts, and importing compiled environmentState.js and environmentBuild.js do not resolve analysis-view-service.
    • src/application/analysisView/evidenceFileSource.test.ts: added regression test confirming cancellation during an async resolveSelected callback returns AnalysisCancelledError with the caller's abort cause.
    • Updated async call sites in tests/fixtures/environmentServe.ts, src/application/artifacts/ArtifactComparisonEvidence.test.ts, src/application/environment/environmentState.test.ts, src/application/environment/environmentBundle.test.ts, src/application/environment/environmentScenario.test.ts, src/application/environment/environmentCompare.test.ts, src/application/environment/environmentCompareBody.test.ts, src/application/environment/environmentCompareBulk.test.ts, and src/application/environment/environmentCompareIdsIntegration.test.ts.
  • Base reproduction or other evidence:
    • Bundle inspection of dist/cli-runtime/ on clean base 402771122 vs this branch: static imports of AnalysisViewService-*.js dropped from 4 (application__environment__environmentBuild, artifactCommands, environmentState, fridaCommands) to 0.
    • Clean-base A/B check on 402771122: the new defers AnalysisViewService test failed on base (inspect-artifact and compare-artifacts --help resolved analysis-view-service) and passes on this branch.
  • User-visible CLI/MCP output (if applicable): Unchanged functional output; reduced module resolution on one-shot CLI commands.
  • Remaining proof gaps:
    • Executed on Windows x64 (Node v24.22.1); Ubuntu Linux CI runs the full portable suite.
    • Pre-existing Windows-only test quirks observed identically on base 402771122 and this branch: environmentBuild.test.ts:165 quotes backslashed Windows temp paths in the next hint ('E:\...') and cliStartupImports.test.ts analyze-javascript-application exits 1 under Windows temp paths.

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:fast (after merging origin/main da129c00a: typecheck, lint, and verify:architecture-guards across 3,163 source files) — passed
  • npm run build:cached — passed (compile, bundle-runtime, artifacts:skills; 0 static AnalysisViewService-* imports in dist/cli-runtime/)
  • npm run verify:module-boundaries — passed (4875 source files checked)
  • npm run verify:test-discovery — passed (3932 test files discovered exactly once)
  • npm run format:check — passed (8952 files)
  • npm run test:focused -- src/application/artifacts/ArtifactComparisonEvidence.test.ts src/application/artifacts/ArtifactComparisonPathSources.test.ts src/application/environment/environmentState.test.ts src/application/environment/environmentBundle.test.ts src/application/environment/environmentBuild.test.ts src/application/environment/environmentCompare.test.ts src/application/environment/environmentCompareBody.test.ts src/application/environment/environmentCompareBulk.test.ts src/application/environment/environmentCompareIdsIntegration.test.ts src/application/environment/environmentScenario.test.ts src/application/environment/environmentExport.test.ts src/application/analysisView/evidenceFileSource.test.ts src/application/frida/FridaInstrumentationService.test.ts — 12/13 files passed cleanly; 1 pre-existing Windows path-quoting mismatch in environmentBuild.test.ts:165 (sameTree byte-for-byte check passed)
  • npx --no-install vitest run --project cli-boundary tests/boundary/cli/cliStartupImports.test.ts -t "Bundled heavy startup controls" — passed (3/3 tests)
  • Clean-base A/B check on 402771122 (defers AnalysisViewService) — confirmed failed on base, passes on branch

Compatibility, safety, and release

  • Breaking changes or migration steps: None for CLI/MCP users (internal TypeScript helper signatures in src/application/ changed from synchronous to Promise-returning, matching [Refactor] Decide async conversion for the two synchronous view-projection helpers blocking the AnalysisView chunk split #14112 Option 1).
  • Real Hopper/Ghidra, browser, or OS coverage: Not applicable (pure JS/TS module composition refactor; tested on Windows x64, CI covers Ubuntu).
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: No new process spawning, filesystem writes, or trust boundary changes; cancellation checks preserved across the new await points in evidenceFileSource.ts, ArtifactComparisonEvidence.ts, and loadServeInputs.

Author readiness

Human owner: @Plastic-time

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

Author checklist (completed by the PR author before requesting review)

  • 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.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

Remove the last four static AnalysisViewService imports in
src/application/ so the AnalysisViewService chunk is loaded dynamically
only when view projection is actually needed:

- Make resolveArtifactComparisonEvidence async in
  ArtifactComparisonEvidence.ts, allow async record/source resolvers in
  evidenceFileSource.ts and EvidenceInputResolver.ts (preserving
  post-await cancellation checks), and dynamically import
  AnalysisViewService only when reprojecting an inspect_analysis_view
  summary.
- Make deriveEnvironmentState, prepareServedState,
  planEnvironmentBundle, and compareEnvironment async and dynamically
  import AnalysisViewService inside deriveEnvironmentState and
  environmentBuild.ts; await them in environmentExport.ts and
  src/cli/environmentCommands.ts (preserving cancellation checks).
- Remove the leftover unused static summarizeRetainedAnalysis import in
  FridaInstrumentationService.ts (line 297 already loads it dynamically).
- Remove the now-empty static-analysis-view-import.json architecture
  guard baseline, update the guard comment/message in
  scripts/verify/architecture-guards.mjs, and add async cancellation and
  startup-import regression coverage.

Addresses morluto#14112
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The reviewed changes appear safe to merge.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Low impact] The reviewed changes appear safe to merge.

Summary

Defers AnalysisViewService loading until an application helper needs to project a view.

  • Application commands load AnalysisViewService only when a view projection is needed.

No actionable correctness or security issues were found. Tests were not run during this review. Supersession status could not be confirmed because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Application helper] --> B{View needed?}
  B -->|No| C[Return without loading view service]
  B -->|Yes| D[Check source and prerequisites]
  D --> E[Await dynamic import]
  E --> F[Project view]
  F --> G[Caller awaits result]
  G --> H[Check cancellation before next side effect]
Loading

Reviews (2) · Last reviewed commit: "refactor(application): check cancellatio..." · Reviewed by Greptile

@Plastic-time
Plastic-time marked this pull request as ready for review November 26, 2026 15:50
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T15:50:23.717299Z
We couldn’t complete this review. Comment @codex review to try again.
6b1f66c Draft marked ready
ℹ️ 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.

This branch has not been deployed

No deployments
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.

1 participant