Skip to content

fix(javascript): match resource release methods to the acquired handle - #7773

Merged
morluto merged 3 commits into
morluto:mainfrom
XiaoBinGan:fix/resource-release-family
Oct 29, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
XiaoBinGan:fix/resource-release-family

Conversation

@XiaoBinGan

Copy link
Copy Markdown
Contributor

Summary

Every acquisition family admitted every release method, so h.close(), h.destroy() and h.end() each resolved as a complete release of whatever the binding held. Node exposes a different subset per acquisition, and the other pairs throw at the call site.

Measured on Node 24.22.1:

acquisition value release members
fs.openSync number none
fs.open (callback) undefined none
fs.createReadStream ReadStream close, destroy (end is the byte-offset field)
fs.createWriteStream WriteStream close, destroy, end
fs/promises.open FileHandle close
net.connect Connection destroy, end
tls.connect TLSSocket destroy, end

Problem and expected behavior

RELEASE_METHODS in src/domain/javascript/javascriptSemanticResources.ts was family-blind, so a member call on any single-acquisition binding became resolution: "complete" and was projected as releases / resolved. Six pairings refute that — Node throws at the call site, so the resource is never released while the lifecycle is reported as covered:

fs.openSync(...) + fd.close()            TypeError: fd.close is not a function
fs.open(...cb) + fd.close()              returns undefined; nothing to close
createReadStream(...) + stream.end()     stream.end is a number (byte offset, Infinity)
fs/promises.open(...) + handle.destroy() TypeError: fh.destroy is not a function
net.connect(...) + socket.close()        net.Socket.prototype has no close
tls.connect(...) + socket.close()        TLSSocket has no close

fs.closeSync(fd)/fs.close(fd), the descriptor's real release, is not a member call and was not modelled at all, so the descriptor lifecycle was wrong in both directions.

tls.createConnection is not a Node export either: 'createConnection' in require('node:tls') is false and the ESM import does not link (SyntaxError: does not provide an export named 'createConnection'). The acquisition was therefore fabricated for a module that does not load. net.createConnection === net.connect, so only the tls entry was wrong.

Change and scope

Carry the builtin specifier with each acquisition candidate, list the release methods each specifier/method pair actually exposes, and emit no release when the pair is not one of them. A release stays complete only when the binding held exactly one acquisition and that acquisition admitted the method. Drop createConnection from the tls entry.

Three files: the resource methods table, the resource collector, and a new test.

Contract and boundary impact

  • Semantic owner and earliest changed stage: JavaScript semantic resources (collectJavaScriptSemanticResources).
  • CLI and MCP/tool-catalog contract: no tool, schema, or catalog change. The emitted releases facts become accurate for these pairings.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: the analysis no longer claims a teardown that throws, and no longer invents an acquisition for a non-export.
  • Generated metadata, package, or installation impact: none; tsc --noEmit and oxfmt --check pass.

Expected effects:

  • Read existing files or captured data.
  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests: javascriptSemanticAnalysis.release_families.test.ts adds 10 cases. The seven rejected rows fail on unmodified main and pass here; the three accepted rows keep resolution: "complete", so the filter is pure narrowing.
  • Reproduction: the Node table above is the literal output of running each pair. Full --project domain is 8858 passed.
  • Remaining gaps: only the seven pairings tabulated were run against Node. An unlisted specifier/method pair admits no release, so an acquisition added later without a table entry emits acquisitions only.

Validation performed

Compatibility, safety, and release

No breaking change. The change narrows an overstated claim; no public contract, CLI output shape, or IR type changes.

Author readiness

Human owner: @XiaoBinGan

  • 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.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Every acquisition family admitted every release method, so `h.close()`,
`h.destroy()` and `h.end()` each resolved as a complete release of whatever the
binding held. Node exposes a different subset per acquisition, and the rejected
pairs throw at the call site instead.

Measured on Node 24.22.1:

| acquisition | value | release members |
| --- | --- | --- |
| `fs.openSync` | number | none |
| `fs.open` (callback) | undefined | none |
| `fs.createReadStream` | ReadStream | `close`, `destroy` (`end` is the byte-offset field) |
| `fs.createWriteStream` | WriteStream | `close`, `destroy`, `end` |
| `fs/promises.open` | FileHandle | `close` |
| `net.connect` | Socket | `destroy`, `end` |
| `tls.connect` | TLSSocket | `destroy`, `end` |

So `fs.openSync(...)` + `fd.close()`, `createReadStream(...)` + `.end()`,
`net.connect(...)` + `.close()` and the FileHandle cases emitted a `releases` /
`resolved` fact for a call that throws.

Carry the specifier with each acquisition candidate, list the release methods
each pair actually has, and emit no release when the pair is not one of them. A
release stays `complete` only when the binding held exactly one acquisition and
that acquisition admitted the method.

`tls.createConnection` is not a Node export at all: `'createConnection' in
require('node:tls')` is false and the ESM import does not link. Drop it from the
table so a `tls.createConnection` call yields no acquisition.
@XiaoBinGan XiaoBinGan changed the title fix(javascript):-match-resource-release-methods-to-the-acquired-handle fix(javascript): match resource release methods to the acquired handle Oct 28, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-10-28T16:07:37.297945Z fcdd7a2 New commits
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains.

Summary

The PR matches release methods to the acquired Node resource and removes the unsupported tls.createConnection acquisition.

  • JavaScript resource analysis matches releases to the acquired handle.

Reviews (2) · Last reviewed commit: "fix(javascript): cover a mixed-family bi..." · Reviewed by Greptile

…ease

greptile asked for the mixed-family case: a binding that can hold either a
FileHandle or a socket, then calls close(). The FileHandle is the only linked
acquisition and the release stays partial.

That case also showed the `candidates.length === 1` guard was dead: an
acquisition of another family is not in `linked`, so `holdsOnlyAcquisitions`
already returns false for it and the release already stayed partial without the
guard. Removing the guard and keeping the test means the behaviour is now pinned
by a test rather than by two overlapping conditions.
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Addressed in fcdd7a249.

Two mixed-family cases are now in the table, both expecting { method, linked: 1, resolution: "partial" }:

  • a FileHandle or a net.Socket, released with close() — only the FileHandle is linked;
  • a ReadStream or a WriteStream, released with end() — only the WriteStream admits it.

Writing the first one also showed the candidates.length === 1 guard greptile pointed at was dead: the socket acquisition is not in linked, so holdsOnlyAcquisitions already returns false for it and the release already stayed partial with the guard removed. I verified that by deleting the guard and re-running: the new test passes either way, because the guard and holdsOnlyAcquisitions were covering the same condition.

So rather than keep two overlapping conditions, the guard is gone and the behaviour is pinned by the test instead. --project domain is 8860 passed.

@morluto
morluto merged commit b7442c1 into morluto:main Oct 29, 2026
41 checks passed
@morluto morluto added area: build Build, CI, packaging, and publishing bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build, CI, packaging, and publishing bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants