Skip to content
Merged
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
65 changes: 65 additions & 0 deletions .github/workflows/ci-e2e-dsh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: e2e-dsh-plugin-lane

# #2170 measure 3: the dsh plugin lane (anthropic wire, x-bili-plugin:dsh
# headers, fork/title-gen side traffic) is the surface where the #2156/#2157/
# #2164 regression chain lived. This lane runs every dsh/fork/side-shaped
# suite in one named place so a lane regression is visible on the PR as its
# own red check, not buried in the general test matrix. Zero tokens: all
# upstreams are in-process mocks.
on:
pull_request:
paths:
- "src/server.ts"
- "src/server/**"
- "src/session.ts"
- "src/plugin.ts"
- "tests/*fork*.test.ts"
- "tests/*side*.test.ts"
- "tests/*dsh*.test.ts"
- ".github/workflows/ci-e2e-dsh.yml"
workflow_dispatch:

concurrency:
group: e2e-dsh-plugin-lane-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
e2e-dsh-plugin-lane:
name: dsh plugin lane (fork adoption + side-request isolation + lane truth tables)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm

- name: Install deps
run: npm ci

# tsx resolves `acp-kernel` to its built dist (kernel/ is a workspace
# package) — same prerequisite as the main test matrix.
- name: Build kernel
run: npm --prefix kernel run build

- name: Run dsh plugin lane suites (sequential — concurrent runs flake on shared XDG dirs)
run: |
set -euo pipefail
for f in \
side-lane-truth-table \
side-lane-invariants \
fork-side-request-lane \
side-request-isolation \
fix-1075-side-request \
dsh-persona-fingerprint \
plugin-fork \
fork-adoption \
fork-ccr-adoption \
fork-nudge-trigger \
truncation-fork \
preflight-fork-estimate; do
echo "=== tests/$f.test.ts ==="
node --import tsx --test "tests/$f.test.ts"
done
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,40 @@ jobs:
with:
node-version: 22
- run: node tools/gen-config-docs.mjs check-coverage

# #2170 lane guard: the side-lane decision (#388 passthrough — src/server/
# side-request.ts + the lane region of src/server.ts) is regression-critical
# (the #2156/#2157/#2164 chain). Changing it without touching its dedicated
# suites has silently shipped regressions before; this job makes the pairing
# mechanical: lane logic moves ⇔ a side-lane suite moves with it.
lane-guard:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Side-lane test discipline (#2170)
run: |
set -euo pipefail
LANE_SUITE_RE='tests/(fork-side-request-lane|side-lane-truth-table|side-lane-invariants|side-request-isolation)\.test\.ts'
# Lane logic = src/server/side-request.ts, or lane-symbol lines in src/server.ts.
LANE_DIFF=""
if git diff origin/master...HEAD -- src/server/side-request.ts | grep -qE '^[+-]'; then
LANE_DIFF="src/server/side-request.ts"
fi
if git diff origin/master...HEAD -- src/server.ts | grep -Eq '^[+-].*(demotedSide|sideIntent|sideRequestLike|demoteGate|resolveSideLane|SIDE_REQUEST_MAX_TOKENS|isSideRequest|stripLeakedBiliTools|side request|side passthrough|sidePassthrough|side-lane)'; then
LANE_DIFF="${LANE_DIFF:+$LANE_DIFF, }src/server.ts (lane symbols)"
fi
if [[ -z "$LANE_DIFF" ]]; then
echo "✓ no side-lane logic changes"
exit 0
fi
echo "side-lane logic changed: $LANE_DIFF"
if git diff --name-only origin/master...HEAD | grep -Eq "$LANE_SUITE_RE"; then
echo "✓ side-lane suites updated alongside lane logic"
exit 0
fi
echo "::error::Side-lane logic changed without updating any dedicated side-lane suite ($LANE_SUITE_RE)."
echo "The lane gates are truth-table-pinned (tests/side-lane-truth-table.test.ts) and behavior-pinned (tests/side-lane-invariants.test.ts, fork-side-request-lane, side-request-isolation) — a gate edit must land with the suite edit. See #2170."
exit 1
58 changes: 51 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
} from "acp-kernel/wire";
import { responsesToCoreWithToolImages as responsesToCore, patchResponsesInputWithToolImages as patchResponsesInput, mergeAdjacentConfigurationUpdates } from "./responses-tool-output.js";
import { reconcileFoldCoverage, noteSystemPromptFingerprint, resolveFoldReconcileMode } from "./fold-reconcile.js";
import { diagnoseSuccessWithoutUsage, getSession, hasProcessedState, listSessions, peekSession, type PendingRetrieval, type Session, initSessions, markDirty, flushAllSessions, acquireInFlight, releaseInFlight, totalInFlight, withSessionLock, markNativeCompactionBoundary, reconcileNativeCompactionBoundary, snapshotMessages, applyCompactionArchive, detectUnannouncedHistoryRewrite, markCompactionBoundary, storeEffectiveConfig, foldCoverage, REWRITE_MIN_INCOMING_TOTAL } from "./session.js";
import { diagnoseSuccessWithoutUsage, getSession, hasProcessedState, listSessions, peekSession, type PendingRetrieval, type Session, initSessions, markDirty, flushAllSessions, acquireInFlight, releaseInFlight, totalInFlight, withSessionLock, markNativeCompactionBoundary, reconcileNativeCompactionBoundary, snapshotMessages, applyCompactionArchive, detectUnannouncedHistoryRewrite, markCompactionBoundary, storeEffectiveConfig, foldCoverage, splitSessionWarnings, REWRITE_MIN_INCOMING_TOTAL } from "./session.js";
import { detectStaleInstall } from "./update.js";
import { getAdvisoryState, cannotResolveTarget } from "./advisory.js";
import { PACKAGE_NAME, VERSION } from "./version.js";
Expand Down Expand Up @@ -152,7 +152,7 @@ import { buildForwardHeaders, connectionNamedHeaders, NO_IDENTITY_MESSAGE, RESPO
import { installWebSocketBridge } from "./ws-bridge.js";
import { codexResponsesCodec, responsesCodec } from "./responses-ws.js";
import { currentFetchTransport } from "./fetch-transport.js";
import { hasLeakedBiliToolsOnly, isSideRequest, outputBudgetField, restoreOutputBudget, SIDE_REQUEST_MAX_TOKENS, sideRequestGuard, stripLeakedBiliTools } from "./server/side-request.js";
import { demoteGate, hasLeakedBiliToolsOnly, isSideRequest, outputBudgetField, resolveSideLane, restoreOutputBudget, SIDE_REQUEST_MAX_TOKENS, sideRequestGuard, stripLeakedBiliTools } from "./server/side-request.js";
import { dshCompactionRefusal, isDshCompactionCall } from "./server/dsh-compaction-guard.js";
import { clampOutgoingOutput, countSystemAndToolsTokens, emergencyNudge, estimateInputTokens, estimateWireOverhead, projectThinkingMass } from "./server/budget.js";
import { awaitDrain, bufferToStream, dumpStreamToFile, pipeThrough, readStreamToBuffer } from "./server/stream-io.js";
Expand Down Expand Up @@ -1270,6 +1270,8 @@ function adminTrustedHostnames(bindHost: string): Set<string> {
// #924: one-time-per-model log for the output-budget fallback (request carries
// no budget → configured/registry max output) — same pattern as windowSourceLogged.
const headroomFallbackLogged = new Set<string>();
// #2170 split-session canary: one log line per conversation base per process.
const splitWarnedBases = new Set<string>();

// #2096: dedupe the post-reservation effective-window line per model|value —
// the reserved window varies per request (max_tokens), so key on both.
Expand Down Expand Up @@ -2297,6 +2299,20 @@ async function handle(
? (anthropicIdentity?.value ?? anthropicSignal)
: undefined;
const personaForked = rawPersonaIdentity !== undefined && conversation !== rawPersonaIdentity;
// #2170 measure 4: stamp sessions deliberately namespaced onto a
// `|sub:` key — #970 claude subagents, #1916/#1307/#1314 dsh persona-
// fork reviews, codex/claude-over-Responses instructions personas —
// so the split-session canary can tell a DESIGNED split from the
// #2165 drift shape (see splitSessionWarnings in src/session.ts).
// personaForked covers the anthropic/openai wires; the responses wire
// needs its own check (codexTurn keys verbatim and must not count).
const designNamespaced = personaForked
|| (protocol === "responses"
&& codexTurn === undefined
&& instructionsFingerprintApplies(req.headers)
&& !sideRequestLike
&& responsesIdentity !== undefined
&& conversation !== responsesIdentity.value);
// The session ID is the client-provided conversation value VERBATIM —
// no hash, no protocol/credential/upstream dimensions (#286): those
// are all mutable mid-conversation (bearer rotation, relay switching,
Expand Down Expand Up @@ -2433,6 +2449,7 @@ async function handle(
? bodyIdentity.value
: clientConversationHeader(req.headers);
const session = getSession(sessionId, { protocol, upstreamOrigin, label: clientLabel ?? (anonAffinity ? "prefix-affinity" : undefined) });
if (designNamespaced && session.metadata.personaNamespace !== true) session.metadata.personaNamespace = true;
let publicForkPrefix = false;
if (!countTokens && !responsesCompact && session.metadata.publicForkReceipt !== undefined) {
acquireInFlight(session);
Expand Down Expand Up @@ -2789,9 +2806,12 @@ async function handle(
// are identified by the #1699 persona header instead).
const wsLaneEnvelope = req.headers["x-bili-ws-lane"] !== undefined;
const requestAgent = pluginRequestAgentHeader(req.headers);
// #2170 measure 1: the gate conjuncts live in side-request.ts as the
// pure, truth-table-tested demoteGate(); the two request-body effects
// stay here and stay lazy — detectAcpArtifacts only runs when the cheap
// gate holds, the strip only when the artifact scan came back clean.
// Explicit main intent and a verified public-fork prefix each veto heuristic demotion.
const demotedSide = !countTokens && !responsesCompact && protocol !== null && pluginMode
&& requestAgent !== "main" && !wsLaneEnvelope && !publicForkPrefix
const demotedSide = demoteGate({ countTokens, responsesCompact, protocol, pluginMode, requestAgent, wsLaneEnvelope, publicForkPrefix })
&& detectAcpArtifacts(bodyBuffer, parsed) === null
&& stripLeakedBiliTools(parsed);
// #546: restore a client-shrunk output budget BEFORE the side gate so a
Expand Down Expand Up @@ -2867,7 +2887,10 @@ async function handle(
// header) can false-positive it — only intent-certain side
// identification (declared side agent, or a tool-less tiny budget)
// diverts under a receipt.
if (!countTokens && !responsesCompact && protocol !== null && (demotedSide || sideIntent)) {
// #2170 measure 1: the decision itself is resolveSideLane() (pure,
// truth-table-tested); demotedSide ⊆ lane==="side" by construction.
const sideLane = resolveSideLane({ countTokens, responsesCompact, protocol, stripApplied: demotedSide, sideIntent, requestAgent });
if (sideLane.lane === "side") {
// #554: the passthrough below skips EVERY input-side guard by design
// (#388) — a full-history side request over the window is a
// guaranteed upstream 400 (and title-gen/probe clients re-issue it,
Expand Down Expand Up @@ -2898,7 +2921,7 @@ async function handle(
logRequestCost(log, session.id, inboundMsgs, inboundBytes, reqT0);
return;
}
const sideReason = demotedSide ? "leaked bili tools stripped (#1897)" : requestAgent !== undefined ? `agent=${requestAgent}` : `max_tokens<=${SIDE_REQUEST_MAX_TOKENS}`;
const sideReason = sideLane.reason;
log("info", `[${session.id}] side request (${sideReason}) → passthrough + tag strip only, kernel state untouched`);
// #1897: a demoted request was mutated (tools stripped) — re-serialize
// the parsed body so the leak is actually gone from the wire.
Expand Down Expand Up @@ -2926,6 +2949,20 @@ async function handle(
await forward(req, res, opts, sideBody, sidePrepared, core, reqConfig, log, route, instanceId, affinity);
return;
}
// #2170 measure 4 (runtime canary): every legitimately side-shaped
// LANE-ELIGIBLE request returned inside the lane above. count_tokens,
// /responses/compact and session-less (protocol-less) requests are
// deliberately NOT lane-eligible — they route to their own handling
// below, so they are excluded here (ework review finding B). If a
// lane-eligible side-intent or demoted request reaches the full
// pipeline anyway, the lane contract is broken (the #2157/#2164
// regression class: side traffic touching kernel state). Count it on
// the session and say it loudly — with the pure resolveSideLane()
// this is unreachable by construction; any future drift trips it.
if (!countTokens && !responsesCompact && protocol !== null && (sideIntent || demotedSide)) {
session.metadata.sideEffectLeaks = (typeof session.metadata.sideEffectLeaks === "number" ? session.metadata.sideEffectLeaks : 0) + 1;
log("warn", `[${session.id}] SIDE-EFFECT LEAK (#2170 canary): ${sideLane.reason} request entered the full pipeline — expected the #388 side passthrough; kernel state pollution likely (cf. #2156/#2164)`);
}
// #987: the window is NEVER learned from traffic — no self-heal read
// here. Only the one-shot emergency shrink (armed on the overflow
// itself) reacts to a wrong declared window.
Expand Down Expand Up @@ -7627,7 +7664,14 @@ async function sendStatus(res: http.ServerResponse, opts: ProxyOptions): Promise
// fs hiccup: report running state only, never fail the status endpoint
}
res.writeHead(200, { "content-type": "application/json" });
res.end(JSON.stringify({ version: VERSION, diskVersion, stale, autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), inFlight: totalInFlight(), conflicts: summarizeConflicts(listSessions()) }, null, 2));
const splitWarnings = splitSessionWarnings(listSessions());
for (const w of splitWarnings) {
if (!splitWarnedBases.has(w.base)) {
splitWarnedBases.add(w.base);
loggerLog("warn", `split-session canary (#2170): conversation ${w.base} has live traffic under multiple session keys (design persona forks are excluded): ${w.sessions.map((s) => `${s.id} (requests=${s.requests})`).join("; ")}. For a non-persona host this is the #2165 failure shape (stolen anchor / never-compressing split) — investigate if unexpected.`);
}
}
res.end(JSON.stringify({ version: VERSION, diskVersion, stale, autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), inFlight: totalInFlight(), splitSessions: splitWarnings, conflicts: summarizeConflicts(listSessions()) }, null, 2));
}

async function sendOverview(res: http.ServerResponse, opts: ProxyOptions): Promise<void> {
Expand Down
53 changes: 53 additions & 0 deletions src/server/side-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,59 @@ export function isSideRequest(parsed: unknown, requestAgent?: string): boolean {
return typeof raw === "number" && raw > 0 && raw <= SIDE_REQUEST_MAX_TOKENS;
}

// #2170 measure 1: the two lane gates extracted from src/server.ts so they have
// ONE home and an exhaustive truth-table test. They are PURE — the two effects
// that guard demotion (detectAcpArtifacts' full-history re-encode and the
// stripLeakedBiliTools mutation) stay in the caller and MUST stay lazily
// evaluated after demoteGate (never hoisted — see the sideRequestLike note in
// src/server.ts: the artifact scan may only run for the all-bili subset).
export interface DemoteGateSignals {
countTokens: boolean;
responsesCompact: boolean;
protocol: WireProtocol | null;
pluginMode: boolean;
requestAgent: string | undefined;
wsLaneEnvelope: boolean;
publicForkPrefix: boolean;
}
// Heuristic demotion eligibility — every conjunct is cheap (no request-body
// scan). `publicForkPrefix` deliberately vetoes: a public-fork child's EARLY
// mainline turns (raw inherited prefix, no artifacts yet, no agent header)
// false-positive the leak-shape heuristic; once anchored, the fork's side
// requests enter the lane via `sideIntent` instead (which resolves without
// any fork input — the #2164 fix).
export function demoteGate(s: DemoteGateSignals): boolean {
return !s.countTokens && !s.responsesCompact && s.protocol !== null && s.pluginMode
&& s.requestAgent !== "main" && !s.wsLaneEnvelope && !s.publicForkPrefix;
}

export interface SideLaneSignals {
countTokens: boolean;
responsesCompact: boolean;
protocol: WireProtocol | null;
// stripLeakedBiliTools() ran and stripped (only ever true when demoteGate
// held and detectAcpArtifacts returned null — the caller's short-circuit).
stripApplied: boolean;
sideIntent: boolean;
requestAgent: string | undefined;
}
export type SideLaneDecision = { lane: "side" | "main"; demoted: boolean; reason: string };
// The #388 lane decision. `demoted` ⊆ `lane === "side"`. No fork input can
// reach here: intent-certain side requests ride the lane under a fork receipt
// (#2164) — that property is structural (there is no fork field to consult).
export function resolveSideLane(s: SideLaneSignals): SideLaneDecision {
if (s.countTokens || s.responsesCompact || s.protocol === null) {
return { lane: "main", demoted: false, reason: "not a model turn" };
}
if (s.stripApplied) {
return { lane: "side", demoted: true, reason: "leaked bili tools stripped (#1897)" };
}
if (s.sideIntent) {
return { lane: "side", demoted: false, reason: s.requestAgent !== undefined ? `agent=${s.requestAgent}` : `max_tokens<=${SIDE_REQUEST_MAX_TOKENS}` };
}
return { lane: "main", demoted: false, reason: "main turn" };
}

// #1897: hosts like omp register bili's ACP tools as first-class extension tools
// and include them in EVERY model request — including side requests (title-gen),
// which carry no host action tools of their own. The title request defeats both
Expand Down
Loading
Loading