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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ RFC or claim formal D2. This checkpoint starts no cohort, soak or promotion.
The dated checkpoints below retain source-specific implementation and validation
history; instructions to remove still-live writers describe those baselines.

The bounded NoKV helper transport repair preserves complete JSON-lines replies
when process exit precedes stdout drain. Existing requests finish from buffered
replies; new requests to an exited helper are refused. Real subprocess tests
cover read, CAS publication, typed open refusal and incomplete replies. This
qualifies the source transport boundary, not a live NoKV SDK stack, installed
adoption, provider promotion or D2/D3.

## Historical 1.x implementation context

Dated records through 2026-10-12 follow; they retain their original source boundaries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
或晋升。下方具名 checkpoint 保留当时实现和验证历史;“仍活跃 writer 待删除”描述
对应旧基线。

有界 NoKV helper 传输修复保留进程退出早于 stdout 排空时的完整 JSON-lines 回复。
已有请求从缓冲回复完成;向已退出 helper 发起的新请求被拒绝。真实子进程测试覆盖
读取、CAS 发布、带类型的 open 拒绝及不完整回复。这验证源码传输边界,不认证
真实 NoKV SDK 栈、安装采用、provider 晋升或 D2/D3。

## 历史 1.x 实现背景

下方保留截至 2026-10-12 的具名历史记录及各自原源码边界。
Expand Down
11 changes: 9 additions & 2 deletions loopx/control_plane/coordination/nokv_jsonl_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,16 @@ export class NoKVJsonLinesTransport implements NoKVBlobTransport {
// escape the provider boundary.
this.child.stderr.on("data", () => {});
this.child.stdin.on("error", () => {
if (!this.closing) this.failUnavailable("NoKV helper stdin failed");
if (!this.closing && this.child.exitCode === null && this.child.signalCode === null) {
this.failUnavailable("NoKV helper stdin failed");
}
});
this.child.on("error", () => {
this.failUnavailable("NoKV helper failed to start");
});
this.child.on("exit", (code, signal) => {
// Process exit precedes stdio drain. A complete publication reply still
// buffered in stdout must settle its request before disconnection does.
this.child.on("close", (code, signal) => {
if (this.closing && this.pending.size === 0) return;
this.failUnavailable(
`NoKV helper disconnected (code=${String(code)}, signal=${String(signal)})`,
Expand Down Expand Up @@ -280,6 +284,9 @@ export class NoKVJsonLinesTransport implements NoKVBlobTransport {

private async exchange(operation: string, values: JsonObject): Promise<JsonObject> {
if (this.terminalError) throw this.terminalError;
if (this.child.exitCode !== null || this.child.signalCode !== null) {
throw new NoKVTransportUnavailableError("NoKV helper disconnected");
}
if (this.closing) {
throw new NoKVTransportUnavailableError("NoKV helper transport is closed");
}
Expand Down
87 changes: 87 additions & 0 deletions tests/control_plane_ts/nokv_stdout_drain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import assert from "node:assert/strict";
import {spawn, type ChildProcessWithoutNullStreams} from "node:child_process";
import {once} from "node:events";
import test from "node:test";
import {fileURLToPath} from "node:url";

import {NoKVHelperOpenRefusedError, NoKVJsonLinesTransport} from "../../loopx/control_plane/coordination/nokv_jsonl_transport.ts";
import {NoKVTransportUnavailableError} from "../../loopx/control_plane/coordination/nokv_authority_store.ts";
import {resolveTestPython} from "../../scripts/test-python.mjs";

const helperPath = fileURLToPath(new URL("../fixtures/nokv_jsonl_fake_helper.py", import.meta.url));

for (const operation of ["read", "publish"] as const) {
test(`a completed NoKV ${operation} reply survives process exit before stdout drain`, {timeout: 10_000}, async t => {
let helper: ChildProcessWithoutNullStreams | undefined;
const transport = await NoKVJsonLinesTransport.open({
argv: [resolveTestPython(), helperPath, "reply_then_exit"],
config: {},
process_factory(command, args, options) {
helper = spawn(command, args, {...options, stdio: ["pipe", "pipe", "pipe"]});
return helper;
},
});
t.after(async () => {helper?.stdout.resume(); await transport.close();});
assert.ok(helper);
// Hold pipe delivery while the real helper writes its complete reply and
// exits. Node flushes unread stdio after publishing the process exit event.
helper.stdout.pause();
const order: string[] = [];
let refusedAfterExit: Promise<void> | undefined;
helper.once("exit", () => {
order.push("exit");
refusedAfterExit = assert.rejects(
transport.storeIdentity("authority-workbench"), NoKVTransportUnavailableError,
);
});
helper.stdout.on("data", () => {order.push("stdout");});
const closed = once(helper, "close");
const response = operation === "read"
? transport.readBlob("authority-workbench", "metadata/head.json")
: transport.casPublishBlob({
workbench: "authority-workbench", path: "metadata/head.json",
expected_generation: null, expected_workspace_incarnation_id: "a".repeat(32),
bytes: Buffer.from("committed payload"), operation_id: "b".repeat(32),
artifact_revision_id: "c".repeat(32),
});
const outcome = await response.then(result => ({result}), error => ({error}));
await closed;
await refusedAfterExit;
assert.equal(order[0], "exit");
assert.ok(order.includes("stdout"), "the completed helper reply must reach the pipe reader");
assert.deepEqual(outcome, {result: operation === "read"
? {status: "missing"} : {status: "applied", generation: 1}});
await assert.rejects(transport.readBlob("authority-workbench", "metadata/head.json"), /disconnected/);
});
}

test("a complete NoKV open refusal retains its typed reason after helper exit", {timeout: 10_000}, async () => {
let closed: Promise<unknown> | undefined;
await assert.rejects(NoKVJsonLinesTransport.open({
argv: [resolveTestPython(), helperPath, "refuse_then_exit"],
config: {},
process_factory(command, args, options) {
const helper = spawn(command, args, {...options, stdio: ["pipe", "pipe", "pipe"]});
helper.stdout.pause();
closed = once(helper, "close");
return helper;
},
}), error => {
assert.ok(error instanceof NoKVHelperOpenRefusedError);
assert.equal(error.reasonCode, "nokv_sdk_capability_mismatch");
return true;
});
await closed;
});

test("an unterminated NoKV reply remains unavailable after stdout drain", {timeout: 10_000}, async t => {
const transport = await NoKVJsonLinesTransport.open({
argv: [resolveTestPython(), helperPath, "partial_then_exit"], config: {},
});
t.after(async () => {await transport.close();});
await assert.rejects(transport.readBlob("authority-workbench", "metadata/head.json"), error => {
assert.ok(error instanceof NoKVTransportUnavailableError);
assert.match(error.message, /code=17/);
return true;
});
});
16 changes: 16 additions & 0 deletions tests/fixtures/nokv_jsonl_fake_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def emit(value: object) -> None:


first = json.loads(sys.stdin.readline())
if mode == "refuse_then_exit":
emit(
{
"request_id": first["request_id"],
"status": "failed",
"reason_code": "nokv_sdk_capability_mismatch",
"reason": "required SDK publication fence is unavailable",
}
)
raise SystemExit(17)
emit({"request_id": first["request_id"], "status": "ready"})

for line in sys.stdin:
Expand All @@ -27,6 +37,10 @@ def emit(value: object) -> None:
sys.stderr.write("provider-private-diagnostic=must-not-escape\n")
sys.stderr.flush()
raise SystemExit(17)
if mode == "partial_then_exit":
sys.stdout.write(json.dumps({"request_id": request_id, "status": "missing"}))
sys.stdout.flush()
raise SystemExit(17)
if mode == "invalid":
emit({"request_id": request_id, "status": "loaded", "generation": True})
continue
Expand Down Expand Up @@ -82,3 +96,5 @@ def emit(value: object) -> None:
"reason": "unknown operation",
}
)
if mode == "reply_then_exit":
raise SystemExit(17)
Loading