fix: release completed SSH writer queue entries (#21150)

Co-authored-by: m4air <m4air@Mac.localdomain>
This commit is contained in:
OrcaWin
2026-09-17 20:12:25 -07:00
committed by GitHub
co-authored by m4air
parent ab331253a0
commit 14654d03cb
12 changed files with 1810 additions and 4 deletions
@@ -0,0 +1,54 @@
# Completed SSH writes retained behind a rolling backlog
The SSH multiplexer lane scheduler advanced its read index without clearing consumed entries. A lane that stayed nonempty retained every completed `WriterEntry`, its encoded buffer and its settlement callback. The writer had already released those entries from its byte and frame counters, so admission limits did not bound this consumed prefix. Fully draining the lane or disposing the multiplexer released it.
The fix clears the selected slot and compacts a consumed prefix after at least 1,024 selections when it occupies at least half the array. This follows the existing `RelayFrameBuffer` pattern. Lane ordering, fairness, admission limits, transport settlement and in-flight ownership are unchanged. `clear()` returns only remaining live entries.
## Actual caller and ownership
The ordinary-lane proof executes `writeToSshPtyWithSettlement``SshChannelMultiplexer.notifyWithSettlement``SshMultiplexerTransportWriter``SshMultiplexerWriterLaneScheduler`. `SshPtyProvider` exposes the same helper through its RPC operations. The control-lane proof uses the `git.responseAck` notification shape emitted by `requestGitStreamable`.
`ssh-relay-deploy-helpers.ts` connects transport writes and settlement callbacks to `channel.stdin.write`, and registers its `drain` event. A producer that keeps at least one queued entry behind repeated backpressure/drain cycles reaches the retained-prefix state. The proof exercises both a controlled callback/drain port and a real Node `Writable` with a deferred write callback and a synthetic 16 KiB high-water mark. No SSH connection, app, window or remote process is launched.
Selecting an entry transfers scheduler custody to the writer's in-flight set. Clearing its consumed queue slot does not complete the write. A separate control disposes with an in-flight and a queued write: their existing results remain `unverifiable` and `refused`, respectively. The native callback can still retain the in-flight buffer until that callback reference is released. Late and duplicate callbacks do not settle it twice.
## Results
Both captured runtimes produce the same counts: Node 26.6 and Electron 43.7 / Node 24.21. Each runs six scenarios before and after the fix.
| Scenario at the controlled pause | Original | Fixed |
| ----------------------------------------------------------------------- | ---------: | ------: |
| Ordinary lane: completed buffers and settlement callbacks retained | 2,048 each | 0 |
| Control lane: completed buffers and settlement callbacks retained | 2,048 each | 0 |
| Physical queue slots after those selections | 2,050 | 2 |
| Logical queued ordinary frames / bytes | 2 / 706 | 2 / 706 |
| Logical queued control frames / bytes | 2 / 184 | 2 / 184 |
| Real writable: retained written buffers, including one in flight | 128 | 1 |
| In-flight buffer retained after disposal while native callback is owned | 1 | 1 |
| Written buffers retained after complete drain or final callback release | 0 | 0 |
The real-writable scenario completes 128 writes, starts the 129th and keeps two further writes queued. The first write preceded the rolling backlog and is collectible in both variants; the original therefore retains 127 completed buffers plus the in-flight one. Its logical budget is three frames / 49,440 bytes in both variants. Empty slots below the compaction threshold are expected and do not retain those buffers.
The scenarios assert FIFO order, isolation of ordinary/control counters, full-drain and disposal cleanup. Five permanent lifetime regressions plus 26 existing tests pass. The original-source overlay fails the four rolling-backlog regressions and passes the other 27 tests. Existing tests cover control priority and starvation prevention, liveness bypass, synchronous drain, callback errors and duplicates, overflow, disposal, timeouts and slow-but-live transport handling. See `validation.json` for commands and full-publication quality checks.
## Reproduce
From the repository root after dependency installation:
```sh
ORCA_BACKGROUND_LAUNCH=1 node --expose-gc --max-old-space-size=192 docs/audits/ssh-writer-consumed-prefix/reproduce.cjs
```
For Electron, run the installed Electron executable with `ELECTRON_RUN_AS_NODE=1` and `ORCA_BACKGROUND_LAUNCH=1`, passing the same flags and script path. This is a Node-mode process with no UI. The runner has a 20-second deadline.
An optional final argument selects the report destination, for example `notes/ssh-writer-consumed-prefix/reviewer-node.json`. Without it, the runner refreshes the corresponding artifact `node-results.json` or `electron-results.json`.
`sources.cjs` reverses `fix.patch` in memory and verifies both original and fixed SHA-256 hashes. It also verifies all nine bundled source dependencies against the recorded hashes. No source file is rewritten. A synthetic CRLF read of the patch and source must reproduce identical canonical LF sources and hashes. `before.config.mjs` uses the same source loader for the original-source test overlay.
## Source compatibility and scope
`source-versions.json` records the exact scheduler baseline at the pre-fix audit commit, independent main `291b4ddd6f1c1af480169885e0fda7f9c78ff053`, and v1.4.198 `e0826956fcfc532f5a1e55b5e081f2e57e553c43`. These scheduler sources are byte-identical after LF normalization, so the same patch yields the same fixed hash. All nine bundled sources and three additional caller sources match independent main. The projected main change has no dependency on the other memory-audit fixes.
The v1.4.198 scheduler is identical, and its writer contains the same enqueue/select/release path. Seven of the twelve dependency/caller files differ from current source; this artifact does not claim to execute the packaged historical release.
Inputs and timing are controlled fixtures. Reachability counts establish the code-level retention mechanism; they do not measure affected-host RSS, model a reported growth rate, or establish that an incident had a continuously nonempty SSH write lane. Active pending writes, transport-owned callbacks and retained primitive sequence timestamps remain governed by their existing limits and lifecycles.
@@ -0,0 +1,24 @@
import { resolve } from 'node:path'
import { createRequire } from 'node:module'
import { defineConfig, mergeConfig } from 'vitest/config'
import baseConfig from '../../../config/vitest.config.ts'
const { loadSources } = createRequire(import.meta.url)(
resolve('docs/audits/ssh-writer-consumed-prefix/sources.cjs')
)
const { before } = loadSources()
export default mergeConfig(
baseConfig,
defineConfig({
plugins: [
{
name: 'ssh-scheduler-before-fix',
enforce: 'pre',
transform(_code, id) {
const source = before.get(resolve(id.split('?')[0]))
return source === undefined ? undefined : { code: source, map: null }
}
}
]
})
)
@@ -0,0 +1,382 @@
{
"runtime": {
"node": "24.21.0",
"acorn": "8.18.0",
"ada": "4.0.0",
"amaro": "1.1.11",
"ares": "1.34.8",
"brotli": "1.2.0",
"cldr": "48.0",
"icu": "78.2",
"llhttp": "9.4.3",
"merve": "1.2.2",
"modules": "148",
"napi": "10",
"nbytes": "0.1.4",
"ncrypto": "0.0.1",
"nghttp2": "1.70.0",
"nghttp3": "",
"ngtcp2": "",
"openssl": "0.0.0",
"simdjson": "4.6.7",
"simdutf": "7.7.0",
"sqlite": "3.53.4",
"tz": "2025c",
"undici": "7.29.1",
"unicode": "17.0",
"uv": "1.52.1",
"uvwasi": "0.0.23",
"v8": "15.0.245.31-electron.0",
"zlib": "1.3.2.1-motley",
"zstd": "1.6.0",
"electron": "43.7.0",
"chrome": "150.0.7871.250"
},
"sourceHashLineEndings": "canonical LF",
"crlfLoaderControl": {
"syntheticCrlfReads": 2,
"identicalSourcesAndHashes": true
},
"cases": [
{
"fixed": false,
"release": "drain",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": false,
"release": "dispose",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"fixed": false,
"release": "drain",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": false,
"release": "dispose",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"kind": "real-node-writable",
"fixed": false,
"writes": 129,
"accepted": 128,
"logicalFrames": 3,
"logicalBytes": 49440,
"physicalSlots": 130,
"retainedBuffers": 128
},
{
"kind": "in-flight-callback-ownership",
"fixed": false,
"retainedByNativeCallback": 1,
"afterNativeCallbackRelease": 0,
"pendingResult": {
"outcome": "unverifiable",
"reason": "transport_settlement_lost",
"bytesHandedToTransport": true
},
"queuedResult": {
"outcome": "refused",
"reason": "transport_rejected_before_handoff"
}
},
{
"fixed": true,
"release": "drain",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": true,
"release": "dispose",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"fixed": true,
"release": "drain",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": true,
"release": "dispose",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"kind": "real-node-writable",
"fixed": true,
"writes": 129,
"accepted": 128,
"logicalFrames": 3,
"logicalBytes": 49440,
"physicalSlots": 130,
"retainedBuffers": 1
},
{
"kind": "in-flight-callback-ownership",
"fixed": true,
"retainedByNativeCallback": 1,
"afterNativeCallbackRelease": 0,
"pendingResult": {
"outcome": "unverifiable",
"reason": "transport_settlement_lost",
"bytesHandedToTransport": true
},
"queuedResult": {
"outcome": "refused",
"reason": "transport_rejected_before_handoff"
}
}
],
"versions": [
{
"fixed": false,
"sourceHashes": {
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts": {
"before": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"after": "6173ddd6640a930d0fa586fed91c1adc0d865a33f81af9a1ed5a0817c08e90cc"
}
},
"bundleSha256": "aafe581371b67c00d50d96a0857257bee20fa317c2d8ce4ea1800e558c7a1b91",
"dependencies": [
{
"path": "src/shared/relay-frame-decoder-contract.ts",
"sha256": "f58279099fe4dbbdfde9e3e038a916ae077e71d8ac6aa871b59a64c6fbaeaad8"
},
{
"path": "src/shared/relay-frame-buffer.ts",
"sha256": "f89fcd33489894c34f79ba8fd5e5634487555a7c34fc8e7c054229ae1c20e0be"
},
{
"path": "src/shared/relay-frame-decoder.ts",
"sha256": "88c0ecbc06b93efe6733094b8c9e4509ab1cbd139f8cb3257e9fb74a0ed39194"
},
{
"path": "src/main/ssh/relay-protocol.ts",
"sha256": "644aa6f2087b5867d41006bfdcec78ffba693157a2912feb8f82b120f5647b34"
},
{
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"sha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50"
},
{
"path": "src/shared/pty-write-settlement.ts",
"sha256": "0726aba75f2ef127d41f47a0685fb42daab34fc139d5b9f727079aec88b702e6"
},
{
"path": "src/main/ssh/ssh-multiplexer-transport-writer.ts",
"sha256": "433a2cc400b5ed9743871ca03aac06d31a079ef23c42c2a2759f78967312d071"
},
{
"path": "src/main/ssh/ssh-channel-multiplexer.ts",
"sha256": "9ecd88963fec72901596bd25d2cb4c8666ef41d3c8a968242c6eef52095ee108"
},
{
"path": "src/main/providers/ssh-pty-write.ts",
"sha256": "357024da7dc5bf2df1dabd43f6f90146afa239d414e29f04b17f86a6351520ae"
}
]
},
{
"fixed": true,
"sourceHashes": {
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts": {
"before": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"after": "6173ddd6640a930d0fa586fed91c1adc0d865a33f81af9a1ed5a0817c08e90cc"
}
},
"bundleSha256": "8dad9c7df8842e01466d24e238ed08b8cfc642fbc3f0a6867ea2ec49058d2aa8",
"dependencies": [
{
"path": "src/shared/relay-frame-decoder-contract.ts",
"sha256": "f58279099fe4dbbdfde9e3e038a916ae077e71d8ac6aa871b59a64c6fbaeaad8"
},
{
"path": "src/shared/relay-frame-buffer.ts",
"sha256": "f89fcd33489894c34f79ba8fd5e5634487555a7c34fc8e7c054229ae1c20e0be"
},
{
"path": "src/shared/relay-frame-decoder.ts",
"sha256": "88c0ecbc06b93efe6733094b8c9e4509ab1cbd139f8cb3257e9fb74a0ed39194"
},
{
"path": "src/main/ssh/relay-protocol.ts",
"sha256": "644aa6f2087b5867d41006bfdcec78ffba693157a2912feb8f82b120f5647b34"
},
{
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"sha256": "6173ddd6640a930d0fa586fed91c1adc0d865a33f81af9a1ed5a0817c08e90cc"
},
{
"path": "src/shared/pty-write-settlement.ts",
"sha256": "0726aba75f2ef127d41f47a0685fb42daab34fc139d5b9f727079aec88b702e6"
},
{
"path": "src/main/ssh/ssh-multiplexer-transport-writer.ts",
"sha256": "433a2cc400b5ed9743871ca03aac06d31a079ef23c42c2a2759f78967312d071"
},
{
"path": "src/main/ssh/ssh-channel-multiplexer.ts",
"sha256": "9ecd88963fec72901596bd25d2cb4c8666ef41d3c8a968242c6eef52095ee108"
},
{
"path": "src/main/providers/ssh-pty-write.ts",
"sha256": "357024da7dc5bf2df1dabd43f6f90146afa239d414e29f04b17f86a6351520ae"
}
]
}
]
}
@@ -0,0 +1,18 @@
--- a/src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts
+++ b/src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts
@@ -6 +6 @@
- entries: T[]
+ entries: (T | undefined)[]
@@ -22,0 +23 @@
+ queue.entries[queue.head] = undefined
@@ -24,2 +25,5 @@
- if (queue.head === queue.entries.length) {
- queue.entries.length = 0
+ if (
+ queue.head === queue.entries.length ||
+ (queue.head >= 1024 && queue.head * 2 >= queue.entries.length)
+ ) {
+ queue.entries = queue.entries.slice(queue.head)
@@ -32 +36 @@
- const entries = queue.entries.slice(queue.head)
+ const entries = queue.entries.slice(queue.head).filter((entry): entry is T => entry !== undefined)
@@ -0,0 +1,381 @@
{
"runtime": {
"node": "26.6.0",
"acorn": "8.17.0",
"ada": "4.0.0",
"amaro": "1.1.11",
"ares": "1.34.8",
"brotli": "1.2.0",
"cldr": "48.0",
"icu": "78.3",
"libffi": "3.7.1",
"llhttp": "9.4.3",
"merve": "1.2.2",
"modules": "147",
"napi": "10",
"nbytes": "0.1.4",
"ncrypto": "0.0.1",
"nghttp2": "1.70.0",
"nghttp3": "",
"ngtcp2": "",
"openssl": "3.6.3",
"simdjson": "4.6.6",
"simdutf": "7.7.0",
"sqlite": "3.53.4",
"tz": "2026a",
"undici": "8.9.0",
"unicode": "17.0",
"uv": "1.52.1",
"uvwasi": "0.0.23",
"v8": "14.6.202.34-node.26",
"zlib": "1.2.12",
"zstd": "1.5.7"
},
"sourceHashLineEndings": "canonical LF",
"crlfLoaderControl": {
"syntheticCrlfReads": 2,
"identicalSourcesAndHashes": true
},
"cases": [
{
"fixed": false,
"release": "drain",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": false,
"release": "dispose",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"fixed": false,
"release": "drain",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": false,
"release": "dispose",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 2048,
"completedCallbacksAlive": 2048,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2050,
"head": 2048,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"kind": "real-node-writable",
"fixed": false,
"writes": 129,
"accepted": 128,
"logicalFrames": 3,
"logicalBytes": 49440,
"physicalSlots": 130,
"retainedBuffers": 128
},
{
"kind": "in-flight-callback-ownership",
"fixed": false,
"retainedByNativeCallback": 1,
"afterNativeCallbackRelease": 0,
"pendingResult": {
"outcome": "unverifiable",
"reason": "transport_settlement_lost",
"bytesHandedToTransport": true
},
"queuedResult": {
"outcome": "refused",
"reason": "transport_rejected_before_handoff"
}
},
{
"fixed": true,
"release": "drain",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": true,
"release": "dispose",
"laneName": "ordinary",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 706,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"fixed": true,
"release": "drain",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": false
}
},
{
"fixed": true,
"release": "dispose",
"laneName": "control",
"during": {
"completedWrites": 2049,
"accepted": 2049,
"completedBuffersAlive": 0,
"completedCallbacksAlive": 0,
"logicalFrames": 2,
"logicalBytes": 184,
"physicalSlots": 2,
"head": 0,
"liveQueued": 2,
"disposed": false
},
"after": {
"completedBuffersAlive": 0,
"physicalSlots": 0,
"logicalFrames": 0,
"logicalBytes": 0,
"disposed": true
}
},
{
"kind": "real-node-writable",
"fixed": true,
"writes": 129,
"accepted": 128,
"logicalFrames": 3,
"logicalBytes": 49440,
"physicalSlots": 130,
"retainedBuffers": 1
},
{
"kind": "in-flight-callback-ownership",
"fixed": true,
"retainedByNativeCallback": 1,
"afterNativeCallbackRelease": 0,
"pendingResult": {
"outcome": "unverifiable",
"reason": "transport_settlement_lost",
"bytesHandedToTransport": true
},
"queuedResult": {
"outcome": "refused",
"reason": "transport_rejected_before_handoff"
}
}
],
"versions": [
{
"fixed": false,
"sourceHashes": {
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts": {
"before": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"after": "6173ddd6640a930d0fa586fed91c1adc0d865a33f81af9a1ed5a0817c08e90cc"
}
},
"bundleSha256": "aafe581371b67c00d50d96a0857257bee20fa317c2d8ce4ea1800e558c7a1b91",
"dependencies": [
{
"path": "src/shared/relay-frame-decoder-contract.ts",
"sha256": "f58279099fe4dbbdfde9e3e038a916ae077e71d8ac6aa871b59a64c6fbaeaad8"
},
{
"path": "src/shared/relay-frame-buffer.ts",
"sha256": "f89fcd33489894c34f79ba8fd5e5634487555a7c34fc8e7c054229ae1c20e0be"
},
{
"path": "src/shared/relay-frame-decoder.ts",
"sha256": "88c0ecbc06b93efe6733094b8c9e4509ab1cbd139f8cb3257e9fb74a0ed39194"
},
{
"path": "src/main/ssh/relay-protocol.ts",
"sha256": "644aa6f2087b5867d41006bfdcec78ffba693157a2912feb8f82b120f5647b34"
},
{
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"sha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50"
},
{
"path": "src/shared/pty-write-settlement.ts",
"sha256": "0726aba75f2ef127d41f47a0685fb42daab34fc139d5b9f727079aec88b702e6"
},
{
"path": "src/main/ssh/ssh-multiplexer-transport-writer.ts",
"sha256": "433a2cc400b5ed9743871ca03aac06d31a079ef23c42c2a2759f78967312d071"
},
{
"path": "src/main/ssh/ssh-channel-multiplexer.ts",
"sha256": "9ecd88963fec72901596bd25d2cb4c8666ef41d3c8a968242c6eef52095ee108"
},
{
"path": "src/main/providers/ssh-pty-write.ts",
"sha256": "357024da7dc5bf2df1dabd43f6f90146afa239d414e29f04b17f86a6351520ae"
}
]
},
{
"fixed": true,
"sourceHashes": {
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts": {
"before": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"after": "6173ddd6640a930d0fa586fed91c1adc0d865a33f81af9a1ed5a0817c08e90cc"
}
},
"bundleSha256": "8dad9c7df8842e01466d24e238ed08b8cfc642fbc3f0a6867ea2ec49058d2aa8",
"dependencies": [
{
"path": "src/shared/relay-frame-decoder-contract.ts",
"sha256": "f58279099fe4dbbdfde9e3e038a916ae077e71d8ac6aa871b59a64c6fbaeaad8"
},
{
"path": "src/shared/relay-frame-buffer.ts",
"sha256": "f89fcd33489894c34f79ba8fd5e5634487555a7c34fc8e7c054229ae1c20e0be"
},
{
"path": "src/shared/relay-frame-decoder.ts",
"sha256": "88c0ecbc06b93efe6733094b8c9e4509ab1cbd139f8cb3257e9fb74a0ed39194"
},
{
"path": "src/main/ssh/relay-protocol.ts",
"sha256": "644aa6f2087b5867d41006bfdcec78ffba693157a2912feb8f82b120f5647b34"
},
{
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"sha256": "6173ddd6640a930d0fa586fed91c1adc0d865a33f81af9a1ed5a0817c08e90cc"
},
{
"path": "src/shared/pty-write-settlement.ts",
"sha256": "0726aba75f2ef127d41f47a0685fb42daab34fc139d5b9f727079aec88b702e6"
},
{
"path": "src/main/ssh/ssh-multiplexer-transport-writer.ts",
"sha256": "433a2cc400b5ed9743871ca03aac06d31a079ef23c42c2a2759f78967312d071"
},
{
"path": "src/main/ssh/ssh-channel-multiplexer.ts",
"sha256": "9ecd88963fec72901596bd25d2cb4c8666ef41d3c8a968242c6eef52095ee108"
},
{
"path": "src/main/providers/ssh-pty-write.ts",
"sha256": "357024da7dc5bf2df1dabd43f6f90146afa239d414e29f04b17f86a6351520ae"
}
]
}
]
}
@@ -0,0 +1,57 @@
const assert = require('node:assert/strict')
const { readFileSync, writeFileSync } = require('node:fs')
const path = require('node:path')
const { load, loadSources, canonicalLf } = require('./sources.cjs')
const { scenario, realWritableScenario, inFlightOwnership } = require('./scenario.cjs')
assert.equal(process.env.ORCA_BACKGROUND_LAUNCH, '1')
assert.equal(typeof global.gc, 'function')
function checkCrlfLoader() {
const normal = loadSources()
let syntheticCrlfReads = 0
const crlf = loadSources({
readText(file) {
syntheticCrlfReads++
return canonicalLf(readFileSync(file, 'utf8')).replace(/\n/g, '\r\n')
}
})
assert.equal(syntheticCrlfReads, 2)
assert.deepEqual(crlf.before, normal.before)
assert.deepEqual(crlf.after, normal.after)
assert.deepEqual(crlf.hashes, normal.hashes)
return { syntheticCrlfReads, identicalSourcesAndHashes: true }
}
async function main() {
const timer = setTimeout(() => {
process.stderr.write('deadline\n')
process.exit(2)
}, 20_000)
const output = {
runtime: process.versions,
sourceHashLineEndings: 'canonical LF',
crlfLoaderControl: checkCrlfLoader(),
cases: [],
versions: []
}
for (const fixed of [false, true]) {
const api = await load(fixed)
output.versions.push({ fixed, ...api.versions })
for (const lane of ['ordinary', 'control']) {
for (const release of ['drain', 'dispose']) {
output.cases.push(await scenario(api, fixed, release, lane))
}
}
output.cases.push(await realWritableScenario(api, fixed))
output.cases.push(await inFlightOwnership(api, fixed))
}
clearTimeout(timer)
const defaultName = process.versions.electron ? 'electron-results.json' : 'node-results.json'
const destination = process.argv[2]
? path.resolve(process.argv[2])
: path.join(__dirname, defaultName)
writeFileSync(destination, `${JSON.stringify(output, null, 2)}\n`)
process.stdout.write(`${JSON.stringify(output.cases, null, 2)}\n`)
}
main().catch((error) => {
process.stderr.write(`${error.stack}\n`)
process.exit(1)
})
@@ -0,0 +1,260 @@
const assert = require('node:assert/strict')
const { Writable } = require('node:stream')
const pause = () => new Promise((resolve) => setImmediate(resolve))
async function collect() {
for (let i = 0; i < 8; i++) {
await pause()
global.gc()
}
await pause()
}
async function scenario(api, fixed, release, laneName) {
let drain,
current,
writes = 0,
next = 0,
accepted = 0
const weak = [],
callbacks = []
const mux = new api.SshChannelMultiplexer({
supportsWriteSettlement: true,
write(bytes, settle) {
assert.equal(current, undefined)
const msg = JSON.parse(bytes.subarray(13).toString())
assert.equal(
laneName === 'ordinary' ? Number.parseInt(msg.params.data, 10) : msg.params.seq,
writes
)
weak.push(new WeakRef(bytes))
callbacks.push(new WeakRef([...mux.writer.inFlight][0].onSettled))
current = settle
writes++
return false
},
onDrain(fn) {
drain = fn
return () => {
drain = undefined
}
},
onData() {},
onClose() {},
pauseReads() {},
resumeReads() {},
close() {}
})
const enqueue = () => {
const id = next++
if (laneName === 'ordinary') {
const promise = api.writeToSshPtyWithSettlement(
mux,
'synthetic-pty',
`${id}:${'x'.repeat(256)}`
)
void promise.then((result) => {
if (result.outcome === 'accepted') {
accepted++
}
})
} else {
mux.notify('git.responseAck', { streamId: 1, seq: id })
}
}
const settle = () => {
assert.ok(current)
const cb = current
current = undefined
cb({ ok: true })
if (laneName === 'control') {
accepted++
}
}
enqueue()
enqueue()
enqueue()
settle()
for (let i = 0; i < 2048; i++) {
drain()
settle()
enqueue()
}
await collect()
const lane = mux.writer.scheduler[laneName]
const completedAlive = weak.reduce((n, w) => n + (w.deref() !== undefined), 0)
const during = {
completedWrites: writes,
accepted,
completedBuffersAlive: completedAlive,
completedCallbacksAlive: callbacks.reduce((n, w) => n + (w.deref() !== undefined), 0),
logicalFrames: mux.writer[`${laneName}Frames`],
logicalBytes: mux.writer[`${laneName}Bytes`],
physicalSlots: lane.entries.length,
head: lane.head,
liveQueued: lane.entries.length - lane.head,
disposed: mux.isDisposed()
}
assert.equal(during.liveQueued, 2)
assert.equal(during.logicalFrames, 2)
assert.equal(during.disposed, false)
assert.equal(accepted, writes)
assert.equal(completedAlive, fixed ? 0 : 2048)
assert.equal(during.completedCallbacksAlive, fixed ? 0 : 2048)
const sibling = laneName === 'ordinary' ? 'control' : 'ordinary'
assert.equal(mux.writer.scheduler[sibling].entries.length, 0)
assert.equal(mux.writer[`${sibling}Frames`], 0)
if (release === 'drain') {
drain()
settle()
drain()
settle()
} else {
mux.dispose()
}
await collect()
const after = {
completedBuffersAlive: weak.reduce((n, w) => n + (w.deref() !== undefined), 0),
physicalSlots: lane.entries.length,
logicalFrames: mux.writer[`${laneName}Frames`],
logicalBytes: mux.writer[`${laneName}Bytes`],
disposed: mux.isDisposed()
}
assert.equal(after.completedBuffersAlive, 0)
assert.equal(after.physicalSlots, 0)
assert.equal(after.logicalFrames, 0)
mux.dispose()
return { fixed, release, laneName, during, after }
}
async function realWritableScenario(api, fixed) {
let complete,
writes = 0,
accepted = 0
const weak = []
const sink = new Writable({
highWaterMark: 16 * 1024,
write(bytes, encoding, callback) {
assert.equal(complete, undefined)
assert.equal(
Number.parseInt(JSON.parse(bytes.subarray(13).toString()).params.data, 10),
writes
)
weak.push(new WeakRef(bytes))
writes++
complete = callback
}
})
const mux = new api.SshChannelMultiplexer({
supportsWriteSettlement: true,
write: (bytes, onSettled) =>
sink.write(bytes, (error) => onSettled(error ? { ok: false, error } : { ok: true })),
onDrain: (fn) => {
sink.on('drain', fn)
return () => sink.off('drain', fn)
},
onData() {},
onClose() {},
close() {}
})
let next = 0
const enqueue = () =>
void api
.writeToSshPtyWithSettlement(mux, 'synthetic-pty', `${next++}:${'x'.repeat(16 * 1024)}`)
.then((result) => {
if (result.outcome === 'accepted') {
accepted++
}
})
const completeWrite = async () => {
assert.ok(complete)
const cb = complete
complete = undefined
cb()
await pause()
}
enqueue()
enqueue()
enqueue()
for (let i = 0; i < 128; i++) {
await completeWrite()
enqueue()
}
await collect()
const retained = weak.reduce((n, w) => n + (w.deref() !== undefined), 0)
const result = {
kind: 'real-node-writable',
fixed,
writes,
accepted,
logicalFrames: mux.writer.ordinaryFrames,
logicalBytes: mux.writer.ordinaryBytes,
physicalSlots: mux.writer.scheduler.ordinary.entries.length,
retainedBuffers: retained
}
assert.equal(accepted, 128)
assert.equal(writes, 129)
assert.equal(result.logicalFrames, 3)
assert.equal(retained, fixed ? 1 : 128)
while (complete) {
await completeWrite()
}
await collect()
assert.equal(
weak.reduce((n, w) => n + (w.deref() !== undefined), 0),
0
)
assert.equal(mux.writer.scheduler.ordinary.entries.length, 0)
assert.equal(mux.writer.ordinaryFrames, 0)
mux.dispose()
sink.destroy()
return result
}
async function inFlightOwnership(api, fixed) {
let current, drain
const weak = []
const mux = new api.SshChannelMultiplexer({
supportsWriteSettlement: true,
write(bytes, fn) {
weak.push(new WeakRef(bytes))
current = fn
return false
},
onDrain(fn) {
drain = fn
return () => {
drain = undefined
}
},
onData() {},
onClose() {},
close() {}
})
const pending = api.writeToSshPtyWithSettlement(mux, 'synthetic-pty', 'in-flight')
const queued = api.writeToSshPtyWithSettlement(mux, 'synthetic-pty', 'queued')
mux.dispose()
const pendingResult = await pending,
queuedResult = await queued
assert.equal(pendingResult.outcome, 'unverifiable')
assert.equal(queuedResult.outcome, 'refused')
await collect()
const retainedByNativeCallback = weak.reduce((n, w) => n + (w.deref() !== undefined), 0)
assert.equal(retainedByNativeCallback, 1)
assert.equal(drain, undefined)
current({ ok: true })
current({ ok: false, error: new Error('synthetic late duplicate') })
current = undefined
await collect()
assert.equal(
weak.reduce((n, w) => n + (w.deref() !== undefined), 0),
0
)
return {
kind: 'in-flight-callback-ownership',
fixed,
retainedByNativeCallback,
afterNativeCallbackRelease: 0,
pendingResult,
queuedResult
}
}
module.exports = { scenario, realWritableScenario, inFlightOwnership }
@@ -0,0 +1,208 @@
{
"baselineHashes": {
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50"
},
"fixedHashes": {
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts": "6173ddd6640a930d0fa586fed91c1adc0d865a33f81af9a1ed5a0817c08e90cc"
},
"sourceHashLineEndings": "canonical LF",
"namedRefs": {
"2e83de3154c4ee1bbeea816734b892c34500a5cc": {
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"sha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"equalsBaseline": true
},
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"sha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"equalsBaseline": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"sha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"equalsBaseline": true
}
},
"provenance": [
{
"path": "src/shared/relay-frame-decoder-contract.ts",
"currentBaselineSha256": "f58279099fe4dbbdfde9e3e038a916ae077e71d8ac6aa871b59a64c6fbaeaad8",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "f58279099fe4dbbdfde9e3e038a916ae077e71d8ac6aa871b59a64c6fbaeaad8",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "f58279099fe4dbbdfde9e3e038a916ae077e71d8ac6aa871b59a64c6fbaeaad8",
"identical": true
}
},
"bundled": true
},
{
"path": "src/shared/relay-frame-buffer.ts",
"currentBaselineSha256": "f89fcd33489894c34f79ba8fd5e5634487555a7c34fc8e7c054229ae1c20e0be",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "f89fcd33489894c34f79ba8fd5e5634487555a7c34fc8e7c054229ae1c20e0be",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "4d40ca7cb812e0af6edf78340b017a150ce9529b71396e4c946358f4ed698f81",
"identical": false
}
},
"bundled": true
},
{
"path": "src/shared/relay-frame-decoder.ts",
"currentBaselineSha256": "88c0ecbc06b93efe6733094b8c9e4509ab1cbd139f8cb3257e9fb74a0ed39194",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "88c0ecbc06b93efe6733094b8c9e4509ab1cbd139f8cb3257e9fb74a0ed39194",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "88c0ecbc06b93efe6733094b8c9e4509ab1cbd139f8cb3257e9fb74a0ed39194",
"identical": true
}
},
"bundled": true
},
{
"path": "src/main/ssh/relay-protocol.ts",
"currentBaselineSha256": "644aa6f2087b5867d41006bfdcec78ffba693157a2912feb8f82b120f5647b34",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "644aa6f2087b5867d41006bfdcec78ffba693157a2912feb8f82b120f5647b34",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "644aa6f2087b5867d41006bfdcec78ffba693157a2912feb8f82b120f5647b34",
"identical": true
}
},
"bundled": true
},
{
"path": "src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"currentBaselineSha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "3e5fe7a1e3537505baf42869449193fc0448339d851254a49527ec2a1c7cbb50",
"identical": true
}
},
"bundled": true
},
{
"path": "src/shared/pty-write-settlement.ts",
"currentBaselineSha256": "0726aba75f2ef127d41f47a0685fb42daab34fc139d5b9f727079aec88b702e6",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "0726aba75f2ef127d41f47a0685fb42daab34fc139d5b9f727079aec88b702e6",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": null,
"identical": false
}
},
"bundled": true
},
{
"path": "src/main/ssh/ssh-multiplexer-transport-writer.ts",
"currentBaselineSha256": "433a2cc400b5ed9743871ca03aac06d31a079ef23c42c2a2759f78967312d071",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "433a2cc400b5ed9743871ca03aac06d31a079ef23c42c2a2759f78967312d071",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "4a73e2194f15ec0604802fe6810742f34930fc55e542458b6d8ab7344ee841a2",
"identical": false
}
},
"bundled": true
},
{
"path": "src/main/ssh/ssh-channel-multiplexer.ts",
"currentBaselineSha256": "9ecd88963fec72901596bd25d2cb4c8666ef41d3c8a968242c6eef52095ee108",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "9ecd88963fec72901596bd25d2cb4c8666ef41d3c8a968242c6eef52095ee108",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "480c722b27dd1ffb8c70bfca8fb3568294ff2777b7b02607548df93bb280f6ae",
"identical": false
}
},
"bundled": true
},
{
"path": "src/main/providers/ssh-pty-write.ts",
"currentBaselineSha256": "357024da7dc5bf2df1dabd43f6f90146afa239d414e29f04b17f86a6351520ae",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "357024da7dc5bf2df1dabd43f6f90146afa239d414e29f04b17f86a6351520ae",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "76c4994509a0de61052ceb984a8a9fa0f958bd6a87239ea8e95ff7702f242c67",
"identical": false
}
},
"bundled": true
},
{
"path": "src/main/ssh/ssh-relay-deploy-helpers.ts",
"currentBaselineSha256": "5452b8a441268a42abe09ae71ae64c5684e070a7469eed0b421ab4cd8e41abae",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "5452b8a441268a42abe09ae71ae64c5684e070a7469eed0b421ab4cd8e41abae",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "d9f42be19fb6c1a7921d2f0258f4b4dea814e0dd19f228616d1a2c4158a7c41e",
"identical": false
}
},
"bundled": false
},
{
"path": "src/main/ssh/ssh-git-response-stream-reader.ts",
"currentBaselineSha256": "8e3a2a5606f95ce1c70c1397ca5a807d90989074ea2be41497785c269381af0e",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "8e3a2a5606f95ce1c70c1397ca5a807d90989074ea2be41497785c269381af0e",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "8e3a2a5606f95ce1c70c1397ca5a807d90989074ea2be41497785c269381af0e",
"identical": true
}
},
"bundled": false
},
{
"path": "src/main/providers/ssh-pty-provider.ts",
"currentBaselineSha256": "7bf1a9e41b606dcfd73bd2a4aa9d9aa185b12f18f9beb027b640fe10cf360123",
"namedRefs": {
"291b4ddd6f1c1af480169885e0fda7f9c78ff053": {
"sha256": "7bf1a9e41b606dcfd73bd2a4aa9d9aa185b12f18f9beb027b640fe10cf360123",
"identical": true
},
"e0826956fcfc532f5a1e55b5e081f2e57e553c43": {
"sha256": "f37a0e8688544a79b35e2d2342282f215cd80928adb9da4824d185598fb8a6b6",
"identical": false
}
},
"bundled": false
}
]
}
@@ -0,0 +1,102 @@
const assert = require('node:assert/strict')
const { readFileSync } = require('node:fs')
const { createHash } = require('node:crypto')
const path = require('node:path')
const Module = require('node:module')
const esbuild = require('esbuild')
const { applyPatch, parsePatch, reversePatch } = require('diff')
const { resolve } = path
const root = resolve(__dirname, '../../..')
const canonicalLf = (text) => text.replace(/\r\n/g, '\n')
const read = (file) => canonicalLf(readFileSync(file, 'utf8'))
const sha = (value) => createHash('sha256').update(value).digest('hex')
const sourcePath = 'src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts'
function loadSources({ readText = (file) => readFileSync(file, 'utf8') } = {}) {
const root = resolve(__dirname, '../../..')
const expected = JSON.parse(readFileSync(resolve(__dirname, 'source-versions.json'), 'utf8'))
const parsed = parsePatch(canonicalLf(readText(resolve(__dirname, 'fix.patch'))))
const before = new Map()
const after = new Map()
const hashes = {}
assert.equal(parsed.length, 1)
for (const patch of parsed) {
const path = patch.newFileName.replace(/^b\//, '')
assert.ok(Object.hasOwn(expected.baselineHashes, path), `Unexpected patch path: ${path}`)
const absolute = resolve(root, path)
const current = canonicalLf(readText(absolute))
const baseline = applyPatch(current, reversePatch(patch))
assert.notEqual(baseline, false, `Source changed; review fix.patch: ${path}`)
const hash = (source) => createHash('sha256').update(source).digest('hex')
assert.equal(hash(baseline), expected.baselineHashes[path], `Baseline drift: ${path}`)
assert.equal(hash(current), expected.fixedHashes[path], `Fixed source drift: ${path}`)
before.set(absolute, baseline)
after.set(absolute, current)
hashes[path] = { before: hash(baseline), after: hash(current) }
}
return { root, before, after, hashes }
}
async function load(fixed) {
const { before, after, hashes } = loadSources()
const source = (fixed ? after : before).get(resolve(root, sourcePath))
const built = await esbuild.build({
stdin: {
contents:
"export { SshChannelMultiplexer } from './src/main/ssh/ssh-channel-multiplexer'; export { writeToSshPtyWithSettlement } from './src/main/providers/ssh-pty-write'",
resolveDir: root,
sourcefile: 'fixture.ts',
loader: 'ts'
},
bundle: true,
platform: 'node',
format: 'cjs',
write: false,
metafile: true,
plugins: [
{
name: 'scheduler-variant',
setup(builder) {
builder.onLoad({ filter: /ssh-multiplexer-writer-lane-scheduler\.ts$/ }, (args) => {
assert.equal(args.path, resolve(root, sourcePath))
return { contents: source, loader: 'ts' }
})
}
}
]
})
const filename = resolve(__dirname, 'in-memory.cjs')
const expected = JSON.parse(readFileSync(resolve(__dirname, 'source-versions.json'), 'utf8'))
const dependencies = Object.keys(built.metafile.inputs)
.filter((file) => file.startsWith('src/'))
.map((file) => ({
path: file,
sha256: sha(file === sourcePath ? source : read(resolve(root, file)))
}))
const baselineDependencies = new Map(
expected.provenance
.filter((entry) => entry.bundled)
.map((entry) => [entry.path, entry.currentBaselineSha256])
)
assert.equal(dependencies.length, baselineDependencies.size)
for (const dependency of dependencies) {
const expectedHash =
fixed && dependency.path === sourcePath
? expected.fixedHashes[sourcePath]
: baselineDependencies.get(dependency.path)
assert.equal(dependency.sha256, expectedHash, `Dependency drift: ${dependency.path}`)
}
const loaded = new Module(filename, module)
loaded.filename = filename
loaded.paths = Module._nodeModulePaths(__dirname)
loaded._compile(built.outputFiles[0].text, filename)
return {
...loaded.exports,
versions: {
sourceHashes: hashes,
bundleSha256: sha(built.outputFiles[0].contents),
dependencies
}
}
}
module.exports = { load, loadSources, canonicalLf }
@@ -0,0 +1,157 @@
{
"tests": {
"command": "ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/ssh/ssh-multiplexer-writer-retention.test.ts src/main/ssh/ssh-multiplexer-transport-writer.test.ts src/main/ssh/ssh-channel-multiplexer-backpressure.test.ts src/main/ssh/ssh-channel-multiplexer-saturation-wedge.test.ts src/main/providers/ssh-pty-write.test.ts",
"passed": 31,
"files": 5,
"newRegressionCases": 5,
"exitCode": 0
},
"baselineOverlay": {
"command": "ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config docs/audits/ssh-writer-consumed-prefix/before.config.mjs src/main/ssh/ssh-multiplexer-writer-retention.test.ts src/main/ssh/ssh-multiplexer-transport-writer.test.ts src/main/ssh/ssh-channel-multiplexer-backpressure.test.ts src/main/ssh/ssh-channel-multiplexer-saturation-wedge.test.ts src/main/providers/ssh-pty-write.test.ts",
"passed": 27,
"expectedFailed": 4,
"failures": "Ordinary/control rolling backlog, each with drain/dispose cleanup variant: 32 completed buffers remain reachable.",
"exitCode": 1
},
"typecheck": {
"command": "ORCA_BACKGROUND_LAUNCH=1 pnpm tc:node",
"exitCode": 0
},
"publicationQuality": {
"files": [
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"src/main/ssh/ssh-multiplexer-writer-retention.test.ts",
"docs/audits/ssh-writer-consumed-prefix/reproduce.cjs",
"docs/audits/ssh-writer-consumed-prefix/sources.cjs",
"docs/audits/ssh-writer-consumed-prefix/scenario.cjs",
"docs/audits/ssh-writer-consumed-prefix/before.config.mjs"
],
"scans": [
{
"label": "code quality",
"argv": [
"pnpm",
"exec",
"oxlint",
"--no-ignore",
"--deny-warnings",
"--report-unused-disable-directives-severity",
"warn",
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"src/main/ssh/ssh-multiplexer-writer-retention.test.ts",
"docs/audits/ssh-writer-consumed-prefix/reproduce.cjs",
"docs/audits/ssh-writer-consumed-prefix/sources.cjs",
"docs/audits/ssh-writer-consumed-prefix/scenario.cjs",
"docs/audits/ssh-writer-consumed-prefix/before.config.mjs"
],
"exitCode": 0
},
{
"label": "casting code quality",
"argv": [
"pnpm",
"exec",
"oxlint",
"--no-ignore",
"--deny-warnings",
"--config",
"config/oxlint-code-quality-casting.json",
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"src/main/ssh/ssh-multiplexer-writer-retention.test.ts",
"docs/audits/ssh-writer-consumed-prefix/reproduce.cjs",
"docs/audits/ssh-writer-consumed-prefix/sources.cjs",
"docs/audits/ssh-writer-consumed-prefix/scenario.cjs",
"docs/audits/ssh-writer-consumed-prefix/before.config.mjs"
],
"exitCode": 0
},
{
"label": "type-aware code quality",
"argv": [
"pnpm",
"exec",
"oxlint",
"--no-ignore",
"--deny-warnings",
"--type-aware",
"--config",
"config/oxlint-code-quality-type-aware.json",
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"src/main/ssh/ssh-multiplexer-writer-retention.test.ts",
"docs/audits/ssh-writer-consumed-prefix/reproduce.cjs",
"docs/audits/ssh-writer-consumed-prefix/sources.cjs",
"docs/audits/ssh-writer-consumed-prefix/scenario.cjs",
"docs/audits/ssh-writer-consumed-prefix/before.config.mjs"
],
"exitCode": 0
},
{
"label": "React Doctor",
"argv": [
"pnpm",
"exec",
"oxlint",
"--no-ignore",
"--deny-warnings",
"--config",
"config/oxlint-react-doctor.json",
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"src/main/ssh/ssh-multiplexer-writer-retention.test.ts",
"docs/audits/ssh-writer-consumed-prefix/reproduce.cjs",
"docs/audits/ssh-writer-consumed-prefix/sources.cjs",
"docs/audits/ssh-writer-consumed-prefix/scenario.cjs",
"docs/audits/ssh-writer-consumed-prefix/before.config.mjs"
],
"exitCode": 0
},
{
"label": "design system",
"argv": [
"pnpm",
"exec",
"oxlint",
"--no-ignore",
"--deny-warnings",
"--config",
"config/oxlint-design-system.json",
"src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts",
"src/main/ssh/ssh-multiplexer-writer-retention.test.ts",
"docs/audits/ssh-writer-consumed-prefix/reproduce.cjs",
"docs/audits/ssh-writer-consumed-prefix/sources.cjs",
"docs/audits/ssh-writer-consumed-prefix/scenario.cjs",
"docs/audits/ssh-writer-consumed-prefix/before.config.mjs"
],
"exitCode": 0
}
]
},
"changedQuality": {
"command": "ORCA_BACKGROUND_LAUNCH=1 ORCA_CODE_QUALITY_BASE=HEAD pnpm run check:code-quality:changed",
"exitCode": 0,
"note": "The five explicit-file scans above include every durable CJS/MJS file; the ordinary changed gate cannot see newly ignored artifacts before staging."
},
"proofs": {
"node": "ORCA_BACKGROUND_LAUNCH=1 node --expose-gc --max-old-space-size=192 docs/audits/ssh-writer-consumed-prefix/reproduce.cjs",
"electron": "Installed Electron executable with ELECTRON_RUN_AS_NODE=1 and ORCA_BACKGROUND_LAUNCH=1; same flags and script path.",
"exitCodes": [0, 0],
"beforeAfterCasesPerRuntime": 12,
"crlfLoaderControl": true,
"bundledSourceHashChecks": 9
},
"sourceParity": {
"identicalNamedSchedulerBaselines": 3,
"independentMainIdenticalBundledAndCallerSources": 12,
"historicalIdenticalBundledAndCallerSources": 5,
"historicalProvenanceSources": 12,
"historicalExecutableReplay": false
},
"format": "All 12 promoted TS/CJS/MJS/MD/JSON paths checked with oxfmt stdin mode, excluding fix.patch.",
"gitDiffCheckExitCode": 0,
"publicationWhitespace": {
"commandTemplate": "git diff --no-index --check <empty-file> <promoted-path>",
"files": 12,
"expectedExitCode": 1,
"diagnostics": 0,
"note": "Each complete file is checked, including ignored new artifacts. Exit 1 only reports its content differs from an empty file; no whitespace diagnostics. fix.patch uses zero-context hunks."
}
}
@@ -3,7 +3,7 @@ import type { MultiplexerWriterLane } from './ssh-multiplexer-transport-writer'
const CONTROL_WRITES_BEFORE_ORDINARY = 4
type LaneQueue<T> = {
entries: T[]
entries: (T | undefined)[]
head: number
}
@@ -20,16 +20,20 @@ function shift<T>(queue: LaneQueue<T>): T | undefined {
if (entry === undefined) {
return undefined
}
queue.entries[queue.head] = undefined
queue.head += 1
if (queue.head === queue.entries.length) {
queue.entries.length = 0
if (
queue.head === queue.entries.length ||
(queue.head >= 1024 && queue.head * 2 >= queue.entries.length)
) {
queue.entries = queue.entries.slice(queue.head)
queue.head = 0
}
return entry
}
function clear<T>(queue: LaneQueue<T>): T[] {
const entries = queue.entries.slice(queue.head)
const entries = queue.entries.slice(queue.head).filter((entry): entry is T => entry !== undefined)
queue.entries.length = 0
queue.head = 0
return entries
@@ -0,0 +1,159 @@
import { describe, expect, it } from 'vitest'
import {
SshMultiplexerTransportWriter,
type MultiplexerTransportWriteResult,
type MultiplexerWriterLane
} from './ssh-multiplexer-transport-writer'
async function collect(): Promise<void> {
if (!('gc' in globalThis) || typeof globalThis.gc !== 'function') {
throw new Error('The test runner must enable --expose-gc')
}
for (let round = 0; round < 6; round += 1) {
await new Promise<void>((resolve) => setImmediate(resolve))
globalThis.gc()
}
}
function harness() {
let drain: (() => void) | undefined
let nativeCallback: ((result: MultiplexerTransportWriteResult) => void) | undefined
const buffers: WeakRef<Buffer>[] = []
const receipts: WeakRef<{ index: number }>[] = []
const writes: number[] = []
const settlements: { index: number; outcome: string }[] = []
const writer = new SshMultiplexerTransportWriter(
{
supportsWriteSettlement: true,
write: (bytes, onSettled) => {
expect(nativeCallback).toBeUndefined()
nativeCallback = onSettled
writes.push(bytes.readUInt32BE())
return false
},
onDrain: (listener) => {
drain = listener
return () => {
drain = undefined
}
},
onData: () => {},
onClose: () => {}
},
(error) => {
throw error
}
)
return {
writer,
buffers,
receipts,
writes,
settlements,
enqueue(index: number, lane: MultiplexerWriterLane): void {
const data = Buffer.alloc(32)
data.writeUInt32BE(index)
const receipt = { index }
buffers.push(new WeakRef(data))
receipts.push(new WeakRef(receipt))
expect(
writer.enqueue(data, lane, (result) => {
settlements.push({ index: receipt.index, outcome: result.outcome })
})
).toBe(true)
},
drain(): void {
if (!drain) {
throw new Error('Missing drain listener')
}
drain()
},
complete(): void {
const callback = nativeCallback
nativeCallback = undefined
if (!callback) {
throw new Error('Missing native write')
}
callback({ ok: true })
},
duplicateCompletion(): void {
nativeCallback?.({ ok: true })
nativeCallback?.({ ok: false, error: new Error('Late duplicate failure') })
}
}
}
describe('SSH writer completed entry lifetime', () => {
for (const lane of ['ordinary', 'control'] as const) {
it.each(['drain', 'dispose'] as const)(
`releases completed ${lane} entries during a rolling backlog, then %s`,
async (release) => {
const state = harness()
try {
state.enqueue(0, lane)
state.enqueue(1, lane)
state.enqueue(2, lane)
state.complete()
for (let index = 0; index < 32; index += 1) {
state.drain()
state.complete()
state.enqueue(index + 3, lane)
}
await collect()
expect(state.buffers.slice(0, 33).filter((ref) => ref.deref())).toHaveLength(0)
expect(state.receipts.slice(0, 33).filter((ref) => ref.deref())).toHaveLength(0)
expect(state.buffers.slice(33).filter((ref) => ref.deref())).toHaveLength(2)
expect(state.receipts.slice(33).filter((ref) => ref.deref())).toHaveLength(2)
expect(state.writes).toEqual(Array.from({ length: 33 }, (_, index) => index))
expect(state.settlements).toEqual(
state.writes.map((index) => ({ index, outcome: 'accepted' }))
)
if (release === 'drain') {
state.drain()
state.complete()
state.drain()
state.complete()
} else {
state.writer.dispose()
}
await collect()
expect(state.buffers.filter((ref) => ref.deref())).toHaveLength(0)
expect(state.receipts.filter((ref) => ref.deref())).toHaveLength(0)
expect(state.settlements).toHaveLength(35)
expect(state.settlements.slice(33).map((result) => result.outcome)).toEqual(
release === 'drain' ? ['accepted', 'accepted'] : ['refused', 'refused']
)
} finally {
state.writer.dispose()
}
}
)
}
it('preserves in-flight callback ownership and one settlement across disposal', async () => {
const state = harness()
try {
state.enqueue(0, 'ordinary')
state.enqueue(1, 'ordinary')
state.writer.dispose()
await collect()
expect(state.buffers[0]?.deref()).toBeDefined()
expect(state.receipts[0]?.deref()).toBeDefined()
expect(state.buffers[1]?.deref()).toBeUndefined()
expect(state.receipts[1]?.deref()).toBeUndefined()
expect(state.settlements).toEqual([
{ index: 1, outcome: 'refused' },
{ index: 0, outcome: 'unverifiable' }
])
state.duplicateCompletion()
state.complete()
await collect()
expect(state.buffers.filter((ref) => ref.deref())).toHaveLength(0)
expect(state.receipts.filter((ref) => ref.deref())).toHaveLength(0)
expect(state.settlements).toHaveLength(2)
} finally {
state.writer.dispose()
}
})
})