From fe5fa5912a59c646647ea66654c3e28f91520ac8 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Fri, 30 Oct 2026 23:28:45 +0800 Subject: [PATCH 1/2] agent: one-lane guard for dsh; thick lifecycle stays local, documented (#5241 phase 1, PR-1d) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Final slice of the approved phase-1 plan. dsh does NOT migrate onto the shared native-attach.ts lifecycle — closing the loop on the plan's "dsh's extras go through spec hooks" with what the code actually shows: dsh's verifyAttachAndRecover is a thicker state machine, not a parameterization of the thin one. #3616 world-generation checks sit at different points per branch (landings check giveUpSeq; the spawn landing checks ONLY the gen — register), #3544 rotation emits client events before any staleness check, and the register — not the env — is dsh's publish surface. Branch-hook transposition would spread one coherent state machine across two files with subtly mismatched check points. What dsh DOES adopt from the shared module: armNativeLane("dsh") at its arm point (apply() — the plugin lifecycle owns the lane; re-activation of the same lane stays legal), making the one-lane-per-process contract explicit on all four lanes. Both files now cross-reference the deliberate thin/thick split so nobody "finishes" the migration by accident. The divergence stays frozen by issue3544 (20/20) and the phase-0 stakes (3/3, untouched). --- src/agent/dsh-native.ts | 23 ++++++++++++++++++++++- src/agent/native-attach.ts | 18 +++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/agent/dsh-native.ts b/src/agent/dsh-native.ts index daecb744c2..9d3d851902 100644 --- a/src/agent/dsh-native.ts +++ b/src/agent/dsh-native.ts @@ -63,6 +63,7 @@ import { decodeRequestBody } from "../content-encoding.js"; import { dshContextTabEnabled, dshContextTabLabel, limitsDecodedBytes } from "../knobs.js"; import { MIN_ASSUMED_WINDOW_TOKENS } from "../util.js"; import { markNativeHost, nativeAttachOrigin, nativeBootstrapGate, nativeProxyScriptPath, proxyEnvOrigin, singleFlight } from "./native-bootstrap.js"; +import { armNativeLane } from "./native-attach.js"; import { bodyOverWindowDetail as sharedBodyOverWindowDetail, getDeclaredModelEndpoints, installNativeFetchIntercept, liveStateSlotEffect, noteRoutedOrigin, observeRoutedOrigin, routedBiliModelUrl, setDeclaredModelEndpoints, type GateVerdict, type NativeInterceptState } from "./native-intercept.js"; import { matchModelEndpoint, loadDeclaredModelEndpoints } from "../model-endpoints.js"; import { runOutsideFetchChain } from "./fetch-chain/index.js"; @@ -771,7 +772,22 @@ export function _setSpawnForTest(fn?: () => Promise): void { * or undefined when nothing came up (register left base-less; maybeRetry * keeps re-probing through the respawn hook). Exported for tests, like the * omp/pi/opencode lanes' twins: the pinned-attach version decision (#3544) is - * driven hermetically against a version-controllable resident. */ + * driven hermetically against a version-controllable resident. + * + * #5241 phase 1 (PR-1d) — deliberate split, do not "finish" the migration: + * pi/omp/opencode ride the shared thin lifecycle in native-attach.ts; THIS + * lane keeps its own function. The thick variant is not a parameterization + * of the thin one: #3616 world-generation checks sit at different points per + * branch (landings check giveUpSeq, the spawn landing checks ONLY the gen — + * #983/#1783 self-heal requires a late spawn landing to re-base a given-up + * register), #3544 rotation emits client events before any staleness check, + * and the register — not the env — is dsh's publish surface. Branch-hook + * transposition would spread one coherent state machine across two files + * with subtly mismatched check points. What IS shared: the armNativeLane + * guard above, the #1365 precedence chain (explicit > routed > planned — + * kept in lockstep by the phase-0 stakes), and the probe/wait primitives. + * The divergence is frozen by tests/issue3544-stale-proxy-rotation.test.ts + * and tests/contract-v2-stake-verify-attach.test.ts. */ export async function verifyAttachAndRecover(attachOrigin: string): Promise { const seqAtEntry = register.giveUpSeq; // #3616: capture this flight's world — an apply() re-arm (or a test reset) @@ -1894,6 +1910,11 @@ async function maybeRecallBeforeSend(ctx: PluginContext, url: string, init: Requ export async function apply(ctx: PluginContext): Promise { const plan = planNativeDsh(process.env); if (plan.mode === "off") return; + // #5241 phase 1: one native lane per process — a second, different lane + // would overwrite this lane's BILLION_CONTEXT_PROXY and fetch intercept + // (see native-attach.ts). dsh's arm point is this apply(): the plugin + // lifecycle owns the lane, and re-activation (same lane) stays legal. + armNativeLane("dsh"); // #3616: a fresh activation is a fresh origin world — in-flight recoveries // from the previous world are superseded here (their late landings must not // write this world's register/state). Off-mode arms nothing and bumps diff --git a/src/agent/native-attach.ts b/src/agent/native-attach.ts index 97d64778fc..9c704d0d73 100644 --- a/src/agent/native-attach.ts +++ b/src/agent/native-attach.ts @@ -1,14 +1,22 @@ // Shared attach/recovery lifecycle for the native host lanes (#5241 phase 1). // // Transplanted verbatim from pi-native.ts (PR-1a): pi/omp/opencode carried -// near-identical copies of this function — dsh carries a thicker variant — so -// every fix had to be applied four times and the same bug class kept -// reappearing on lane after lane (port pinning #926→#4566→#5127, cold-start -// tools #4134→#4998→#5001→#4641; see umbrella #5241). One lane migrates per -// PR; each lane's answers are frozen by the phase-0 stakes +// near-identical copies of this function, so every fix had to be applied +// three times and the same bug class kept reappearing on lane after lane +// (port pinning #926→#4566→#5127, cold-start tools #4134→#4998→#5001→#4641; +// see umbrella #5241). One lane migrates per PR; each lane's answers are +// frozen by the phase-0 stakes // (tests/contract-v2-stake-verify-attach.test.ts) — a change here that changes // any lane's observable behavior must update those stakes in the same PR, by // design. +// +// PR-1d deliberately did NOT migrate dsh onto this implementation: dsh's +// verify is a thicker state machine (stale-resident rotation #3544, +// world-generation flight guards #3616, register-based publishing) whose +// per-branch check points do not transpose onto branch hooks — see the +// verifyAttachAndRecover doc comment in dsh-native.ts. dsh shares the +// armNativeLane guard, the #1365 precedence chain and the probe/wait +// primitives; its flow stays lane-local by decision, not by neglect. import { nativeAttachOrigin, singleFlight } from "./native-bootstrap.js"; import { observeRoutedOrigin, type NativeInterceptState } from "./native-intercept.js"; From 81fb1dc910f83f413aacee1607e26a3221af64a3 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sat, 31 Oct 2026 01:39:10 +0800 Subject: [PATCH 2/2] docs: name the dsh guard's arm point in the split comment (review follow-up, #5241 PR-1d) --- src/agent/dsh-native.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/agent/dsh-native.ts b/src/agent/dsh-native.ts index 9d3d851902..b1cc51b55f 100644 --- a/src/agent/dsh-native.ts +++ b/src/agent/dsh-native.ts @@ -784,8 +784,9 @@ export function _setSpawnForTest(fn?: () => Promise): void { * and the register — not the env — is dsh's publish surface. Branch-hook * transposition would spread one coherent state machine across two files * with subtly mismatched check points. What IS shared: the armNativeLane - * guard above, the #1365 precedence chain (explicit > routed > planned — - * kept in lockstep by the phase-0 stakes), and the probe/wait primitives. + * guard (armed in apply()), the #1365 precedence chain (explicit > routed + * > planned — kept in lockstep by the phase-0 stakes), and the probe/wait + * primitives. * The divergence is frozen by tests/issue3544-stale-proxy-rotation.test.ts * and tests/contract-v2-stake-verify-attach.test.ts. */ export async function verifyAttachAndRecover(attachOrigin: string): Promise {