Skip to content

fix(javascript): use Windows private-runtime write for source-transfer - #8765

Closed
BeqaKs wants to merge 1 commit into
morluto:mainfrom
BeqaKs:fix/javascript-windows-source-transfer-eperm
Closed

BeqaKs wants to merge 1 commit into
morluto:mainfrom
BeqaKs:fix/javascript-windows-source-transfer-eperm

Conversation

@BeqaKs

@BeqaKs BeqaKs commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #8658. Parent JavaScriptAnalysisWorker source-transfer used Node exclusive writeFile (wx, mode 0600) inside the worker-owned Windows private runtime root; that path-based create can fail with EPERM. Write through the existing native private-runtime owner instead, matching the Ghidra runtime-file pattern.

Problem and expected behavior

After the worker handshake, the parent stages ${id}.source under the private runtime root before sending the request frame. On Windows that root uses a protected DACL and a retained directory handle. Path-based exclusive create is the wrong write boundary there and can fail with EPERM, aborting analysis at source-transfer.

Expected: source-transfer succeeds on Windows by creating the temp source file through windowsPrivateRuntime.writeFile (runtime_write), without weakening the private DACL. POSIX keeps exclusive owner-only wx create.

Change and scope

  • Add writeJavaScriptAnalysisSourceTransfer at the owning write boundary.
  • On win32, call windowsPrivateRuntime(dirname).writeFile(basename, source) (same owner pattern as writeGhidraRuntimeFile).
  • On POSIX, keep writeFile with flag: "wx", mode: 0o600, and the deadline signal.
  • Focused tests cover the Windows native path (including that a mocked path-create EPERM is never consulted), cancellation before the Windows write, POSIX exclusive create, and POSIX EPERM propagation.

Intentionally not included: AppContainer DACL / package-SID policy (still open under #5225 / the clarifying questions on #8658); worker-side .static.json / transfer-record writes; WebBundle source staging.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: JavaScriptAnalysisWorker parent source-transfer write into OwnedWorkerRuntime / PrivateRuntimeRoot; consumers still read ${id}.source by the same relative name.
  • Contribution scope fit and linked maintainer decision: ordinary fix within the existing Windows private-runtime write boundary; not applicable (no new AppContainer authority).
  • CLI and MCP/tool-catalog contract: none
  • Provider, bridge, target-format, or platform compatibility: Windows JavaScript analysis source-transfer uses native private-runtime write; POSIX unchanged
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): reuses admitted WindowsPrivateRuntime lease; no new cleanup owner
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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

For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.

Boundary: producer ownership / projection at the private-runtime write boundary (Windows native vs POSIX exclusive create). Lifecycle: cancellation before Windows write is covered; full worker cleanup lifecycle unchanged.

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 test:focused -- src/javascript/analysis/JavaScriptAnalysisSourceTransfer.test.ts — 4 passed
  • npm run format:check — passed
  • npm run check:fast (pre-push) — typecheck and lint passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: not run; Windows behavior inferred from the existing private-runtime write owner and focused mocks
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: continues to use the protected private-runtime DACL via native runtime_write; does not add AppContainer package ACE or weaken owner-only POSIX mode 0600

Author readiness

Human owner: @BeqaKs

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

Parent JavaScriptAnalysisWorker path-created the temp .source file with
exclusive writeFile inside the private runtime root; on Windows that can
fail with EPERM. Match the Ghidra runtime-file owner and write through
windowsPrivateRuntime instead.

Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

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 ✅ Completed 2026-11-03T09:40:36.381380Z 41023ea 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41023ea331

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const platform = options.platform ?? process.platform;
options.signal?.throwIfAborted();
if (platform === "win32") {
windowsPrivateRuntime(win32.dirname(path)).writeFile(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Release the source handle before per-job deletion

On Windows, runtime_write retains this file's handle in WindowsPrivateRuntime.immutableFiles; the handle allows only FILE_SHARE_READ and remains open until the runtime closes, so the per-job rm at the end of JavaScriptAnalysisWorker.analyze() cannot delete the source file. Every otherwise successful analysis is therefore converted into a cleanup error and the runtime is retained; use an owner operation that permits per-job removal or defer cleanup until the native runtime closes.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The change affects source staging in the JavaScript analysis workflow on Windows.

Fix the Windows source-file cleanup and blocking write before merging.

Findings

  1. P1 Source handles block cleanup ▶
  2. P1 Source writes freeze the server ▶
Fix with agent prompt
### Issue 1
src/javascript/analysis/JavaScriptAnalysisSourceTransfer.ts:25-28
The Windows write keeps the source file open until the entire runtime closes. That handle allows only `FILE_SHARE_READ`, so the existing per-source `rm` cannot delete it. `analyze()` then turns an otherwise successful result into a cleanup error and marks the worker unavailable for reuse.

Add an owner-controlled way to remove each completed source without weakening the private file protections. Cover writing through per-source cleanup in a Windows test.

### Issue 2
src/javascript/analysis/JavaScriptAnalysisSourceTransfer.ts:24-29
The Windows branch replaces an asynchronous, abort-aware write with a synchronous native write and `FlushFileBuffers`. If a large source or slow temporary storage makes this take a long time, the parent thread stays blocked. The deadline timer, caller cancellation, and other server requests cannot run until the disk operation finishes.

Use an asynchronous native write that preserves ownership and accepts cancellation. Checking the signal only before the write does not preserve the previous behavior.

---

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

Summary

The PR routes Windows JavaScript source transfer through the existing private-runtime owner. POSIX keeps exclusive owner-only file creation.

  • JavaScript analysis stages source through the Windows private runtime.

Acknowledged scope exclusions from BeqaKs: AppContainer package-SID policy remains deferred; worker-side .static.json and transfer-record writes, and WebBundle staging, are intentionally excluded. Real Windows and AppContainer coverage is explicitly unverified.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Parent source transfer] --> B{Platform}
  B -->|Windows| C[Native write and flush]
  C --> D[Retain immutable source handle]
  D --> E[Worker analyzes source]
  E --> F[Parent removes per-source files]
  F --> G[Retained handle blocks deletion]
  G --> H[Cleanup error replaces result]
  B -->|POSIX| I[Async exclusive write with signal]
Loading

Reviews (1) · Last reviewed commit: "fix(javascript): use Windows private-run..." · Reviewed by Greptile

Comment on lines +25 to +28
windowsPrivateRuntime(win32.dirname(path)).writeFile(
win32.basename(path),
source,
);

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.

P1 Source handles block cleanup

The Windows write keeps the source file open until the entire runtime closes. That handle allows only FILE_SHARE_READ, so the existing per-source rm cannot delete it. analyze() then turns an otherwise successful result into a cleanup error and marks the worker unavailable for reuse.

Add an owner-controlled way to remove each completed source without weakening the private file protections. Cover writing through per-source cleanup in a Windows test.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/javascript/analysis/JavaScriptAnalysisSourceTransfer.ts
Line: 25-28

Comment:
**Source handles block cleanup**

The Windows write keeps the source file open until the entire runtime closes. That handle allows only `FILE_SHARE_READ`, so the existing per-source `rm` cannot delete it. `analyze()` then turns an otherwise successful result into a cleanup error and marks the worker unavailable for reuse.

Add an owner-controlled way to remove each completed source without weakening the private file protections. Cover writing through per-source cleanup in a Windows test.

---

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

Comment on lines +24 to +29
if (platform === "win32") {
windowsPrivateRuntime(win32.dirname(path)).writeFile(
win32.basename(path),
source,
);
return;

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.

P1 Source writes freeze the server

The Windows branch replaces an asynchronous, abort-aware write with a synchronous native write and FlushFileBuffers. If a large source or slow temporary storage makes this take a long time, the parent thread stays blocked. The deadline timer, caller cancellation, and other server requests cannot run until the disk operation finishes.

Use an asynchronous native write that preserves ownership and accepts cancellation. Checking the signal only before the write does not preserve the previous behavior.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/javascript/analysis/JavaScriptAnalysisSourceTransfer.ts
Line: 24-29

Comment:
**Source writes freeze the server**

The Windows branch replaces an asynchronous, abort-aware write with a synchronous native write and `FlushFileBuffers`. If a large source or slow temporary storage makes this take a long time, the parent thread stays blocked. The deadline timer, caller cancellation, and other server requests cannot run until the disk operation finishes.

Use an asynchronous native write that preserves ownership and accepts cancellation. Checking the signal only before the write does not preserve the previous behavior.

---

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

@BeqaKs

BeqaKs commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Closing: Greptile 3/5 with unresolved P1s that make this unsafe to merge as written.

  1. Windows runtime_write keeps the source file handle open (FILE_SHARE_READ only) until the private runtime closes, so per-job rm after a successful analysis fails and converts success into cleanup failure / retained runtime.
  2. The Windows path uses a synchronous native write + FlushFileBuffers, which can block the parent (deadlines, cancellation, other requests) on large sources.

Needs an async, abort-aware write that still permits per-source cleanup without weakening private-runtime protections—and Windows AppContainer verification we do not have here. Happy to revisit with that design.

@BeqaKs BeqaKs closed this Nov 3, 2026
@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: JavaScript analysis fails during parent source-transfer with EPERM

2 participants