Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/agent/dsh-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -771,7 +772,23 @@ export function _setSpawnForTest(fn?: () => Promise<string | undefined>): 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 (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<string | undefined> {
const seqAtEntry = register.giveUpSeq;
// #3616: capture this flight's world — an apply() re-arm (or a test reset)
Expand Down Expand Up @@ -1894,6 +1911,11 @@ async function maybeRecallBeforeSend(ctx: PluginContext, url: string, init: Requ
export async function apply(ctx: PluginContext): Promise<void> {
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
Expand Down
18 changes: 13 additions & 5 deletions src/agent/native-attach.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Loading