Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 71a92b39f8d21ffb73a7d0db193d5f3d93db5411
parent 15584ab0a88ad252a574204a5cad152fcfd5ee0c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 14:52:50 -0500

network exits: a startup probe, the probe tested, a SOCKS error counted as a proxy failure

A minute after an editor boot with an enabled exit, each proxy is asked to answer (no
destination; the echo URL only when set) and one line per exit goes to the server log.
Below the idle gate, not on the e2e server.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/networkExits.ts | 27+++++++++++++++++++++++++++
Mcommon/ytdlp/networkExitListing.test.ts | 33+++++++++++++++++++++++++++++++++
Mcommon/ytdlp/runYtdlp.ts | 6+++---
Meditor/instrumentation.ts | 14++++++++++++++
4 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/common/controller/networkExits.ts b/common/controller/networkExits.ts @@ -559,6 +559,33 @@ export async function networkReport( }; } +// THE STARTUP PROBE: once, a minute after the editor boots, when an exit is +// enabled — each proxy asked to answer (no destination) and, only when +// network.echoUrl is set, the echo fetched through it. One line per exit in +// the server log; the answers land in probe.json for `get network`. Never +// throws; armed below the idle gate (editor/instrumentation.ts). +export function startupNetworkProbe(opts: { log: (line: string) => void; delayMs?: number; paths?: Paths }): void { + const t = setTimeout(() => { + void (async () => { + try { + const network = settingsNetwork(); + if (!network?.exits.some((e) => e.enabled)) return; + const { getPaths } = await import("../lib/paths"); + const probe = await probeNetworkExits(opts.paths ?? getPaths(), network); + for (const [id, p] of Object.entries(probe.exits)) { + opts.log( + `network exit "${id}": ${p.reachable ? "answers" : `unreachable — ${p.reason ?? "?"}`}` + + (p.address ? `, shows ${p.address}` : p.echoError ? `, echo failed — ${p.echoError}` : ""), + ); + } + } catch (e) { + opts.log(`network exits: the startup probe failed — ${(e as Error).message}`); + } + })(); + }, opts.delayMs ?? 60_000); + t.unref?.(); +} + // What the listing needs to send a request through an exit, read once per // listing: the pool (for the all-rest check) and the routable kinds. export function listingPool(network: NetworkSettings | undefined, platform: string): string[] | null { diff --git a/common/ytdlp/networkExitListing.test.ts b/common/ytdlp/networkExitListing.test.ts @@ -329,3 +329,36 @@ test("pacing is per platform: two exits make the same starts per hour as one", a assert.equal(two, one); assert.equal(one, 29); }); + +test("the probe: each proxy answers or not; the echo URL is fetched only when set", async () => { + const { startEchoServer } = await import("../testing/fakeProxy"); + const echo = await startEchoServer("198.51.100.23\n"); + const routed = await startFakeSocks5({ route: (host, port) => (host === "echo.exit.test" ? { host: "127.0.0.1", port } : null) }); + try { + const dead = `socks5h://user-a:${SECRET}@127.0.0.1:${await closedPort()}`; + const exits = [ + { id: "exit-a", label: "A", proxy: `socks5h://127.0.0.1:${routed.port}`, enabled: true }, + { id: "exit-dead", label: "D", proxy: dead, enabled: true }, + { id: "exit-off", label: "O", proxy: dead, enabled: false }, + ]; + const net = { exits, platforms: {}, jars: {}, echoUrl: "" }; + const quiet = await NE.probeNetworkExits(getPaths(), net); + assert.equal(echo.hits(), 0, "no echo URL, no request"); + assert.equal(quiet.exits["exit-a"]!.reachable, true); + assert.equal(quiet.exits["exit-dead"]!.reachable, false); + assert.equal(quiet.exits["exit-off"], undefined); + const loud = await NE.probeNetworkExits(getPaths(), { ...net, echoUrl: `http://echo.exit.test:${echo.port}/` }); + assert.equal(loud.exits["exit-a"]!.address, "198.51.100.23"); + assert.equal(echo.hits(), 1); + assert.ok(!readFileSync(path.join(ROOT, ".network", "probe.json"), "utf8").includes(SECRET)); + // The startup probe logs one line per enabled exit, no secret. + settings({ exits, platforms: {} }); + const lines: string[] = []; + NE.startupNetworkProbe({ log: (l) => lines.push(l), delayMs: 0, paths: getPaths() }); + for (let i = 0; i < 100 && lines.length < 2; i++) await new Promise((r) => setTimeout(r, 20)); + assert.deepEqual(lines.map((l) => l.split(":")[0]).sort(), ['network exit "exit-a"', 'network exit "exit-dead"']); + assert.ok(lines.every((l) => !l.includes(SECRET))); + } finally { + await Promise.all([echo.close(), routed.close()]); + } +}); diff --git a/common/ytdlp/runYtdlp.ts b/common/ytdlp/runYtdlp.ts @@ -582,8 +582,8 @@ async function enumeratePlaylistUrls( // THE LISTING, ROUTED (lane network-exits). `exit` is the network exit it went // through, or null when the platform has no network policy — and then the // request is today's, byte for byte: same argv, same echo, same handling -// (spawnListing with no `via`). Under a policy, routeListing decides direct or -// an exit (controller/networkExits.ts) and spawnListing carries it. +// (spawnListing with no `via`). Under a policy, resolveListingRoute decides +// direct or an exit (controller/networkExits.ts) and spawnListing carries it. async function enumeratePlaylistListing( opts: RunYtdlpOpts, root: string, @@ -773,7 +773,7 @@ async function listingFailedVia( ): Promise<void> { const rateLimited = classifyDownloadFailure(stderr, undefined) === "rate_limit"; const botCheck = isBotCheck(stderr); - const proxyFailed = via.exit !== DIRECT_EXIT && /proxy/i.test(stderr); + const proxyFailed = via.exit !== DIRECT_EXIT && /proxy|socks/i.test(stderr); await countNetworkUse(opts.paths, via.platform, via.exit, { ...(rateLimited ? { rateLimits: 1 } : {}), ...(botCheck ? { botChecks: 1 } : {}), diff --git a/editor/instrumentation.ts b/editor/instrumentation.ts @@ -364,6 +364,20 @@ export async function register() { } } + // NETWORK EXITS' STARTUP PROBE (lane network-exits): a minute after boot, + // when an exit is enabled, each proxy is asked to answer (no destination; + // the echo URL only when the operator set one). Below the idle gate — it + // connects out — and not on the e2e test server. + // See common/controller/networkExits.ts. + if (process.env.E2E_TEST_ROUTES !== "1") { + try { + const { startupNetworkProbe } = await import("yt-dlp-transcript-common/controller/networkExits"); + startupNetworkProbe({ log: (line) => console.log(line) }); + } catch { + /* a probe that fails to arm must not block server readiness */ + } + } + // THE RECURRING REPORTS (umtool R5): the report-schedule lane — a scan now // and every minute, ONE report-tick job per due schedule, held by its pause // gate. Below the idle gate: a tick is generation work.