refactor(acp): land PR #199 audit fixes
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
Reviewer fanout (ponytail/security/general) over #199 found no behavior defects. Apply the accepted non-behavioral findings: - requestOutcome helper dedups the two outcome tasks; the two discarded wedge tasks drop their unread do/catch scaffolding - awaitBounded doc names its real bound (window is green-world only; the RED-world watchdog is the fake's /bin/sleep 30 exit) - send() gains a ponytail ceiling comment: queued sends are unbounded and a send racing close() writes onto a closed handle (benign, probe-verified) — bounded by the model's sequential sends; guard if a looping caller appears - request() doc notes a timed-out request's bytes may still land on the wire (late replies dropped, ids never reused) Suite 697/697 green post-change; format+lint clean.
This commit is contained in:
1 parent
ce21057586
commit
9ccfe83ec0
2 files changed
+46
-41
No files matched your search
@@ -157,6 +157,10 @@ final nonisolated class ACPEngineClient: @unchecked Sendable {
|
||||
/// Send a JSON-RPC request and await its matching response result.
|
||||
/// A request that gets no answer within `timeout` fails — a hung engine
|
||||
/// must surface as an error (→ restart prompt), never an eternal await.
|
||||
/// brief-27: a timed-out request's bytes may still reach the engine once
|
||||
/// the child unblocks (the deadline fails the caller, never dequeues the
|
||||
/// write) — phantom engine work only: ids are never reused and the
|
||||
/// response path drops unknown ids, so a late reply can never misroute.
|
||||
/// (No default arguments: the only caller is EngineHost, which rides the
|
||||
/// seam — `EngineTransport.request`'s convenience owns the default shape.)
|
||||
func request(_ method: String, params: JSONValue?, timeout: TimeInterval) async throws -> JSONValue? {
|
||||
@@ -261,6 +265,13 @@ final nonisolated class ACPEngineClient: @unchecked Sendable {
|
||||
/// brief-27: the write runs on the WRITER queue, never the state queue —
|
||||
/// a blocked write here starves no deadline and no teardown.
|
||||
private func send(_ data: Data) {
|
||||
// ponytail: queued sends are unbounded, and a send racing close() writes
|
||||
// onto a closed handle (benign — write throws a catchable CocoaError 512
|
||||
// that try? swallows; probe-verified by two independent reviewers).
|
||||
// Bounded today by MentorSessionModel's sequential-send discipline (a
|
||||
// request is awaited before the next; worst case one prompt + one
|
||||
// cancel). Add a closed/depth guard here if a looping or
|
||||
// non-MainActor caller ever appears.
|
||||
writerQueue.async {
|
||||
var framed = Data(data)
|
||||
framed.append(0x0A)
|
||||
|
||||
@@ -222,11 +222,14 @@ struct EngineSmokeTests {
|
||||
|
||||
// MARK: - brief-27 backpressure smokes (blocked-writer regression rig)
|
||||
|
||||
/// brief-27: bounded await for operations that HANG on the unfixed
|
||||
/// transport (the RED shape) — nil when the task hasn't finished inside
|
||||
/// `window` seconds. One deadline per call (the house rule). The losing
|
||||
/// leg is cancelled; the task itself keeps running and settles at the
|
||||
/// test's teardown (SIGKILL of the rig child unblocks the writer).
|
||||
/// brief-27: await an operation that may HANG on the unfixed transport
|
||||
/// (the RED shape) and report what it answered — nil when the window leg
|
||||
/// won. One deadline per call (the house rule). The bound is `window`
|
||||
/// only in the green world: withTaskGroup awaits stragglers at scope
|
||||
/// exit and `await task.value` is cancellation-blind, so a HUNG task
|
||||
/// holds this helper until IT settles — the real RED-world watchdog is
|
||||
/// the fake's `exec /bin/sleep 30` exit (~30 s, inside the rail's 60 s
|
||||
/// per-test timeout). Keep the fake's sleep short.
|
||||
@MainActor
|
||||
private func awaitBounded<T: Sendable>(_ task: Task<T, Never>, window: TimeInterval) async -> T? {
|
||||
await withTaskGroup(of: T?.self) { group in
|
||||
@@ -241,6 +244,22 @@ struct EngineSmokeTests {
|
||||
}
|
||||
}
|
||||
|
||||
/// brief-27: run one request on a task and string-encode its outcome
|
||||
/// ("returned" or the error) — the observable the pins match on.
|
||||
@MainActor
|
||||
private func requestOutcome(
|
||||
_ client: ACPEngineClient, method: String, params: JSONValue?, timeout: TimeInterval,
|
||||
) -> Task<String, Never> {
|
||||
Task<String, Never> {
|
||||
do {
|
||||
_ = try await client.request(method, params: params, timeout: timeout)
|
||||
return "returned"
|
||||
} catch {
|
||||
return String(describing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// brief-27: the blocked-writer rig — a real ACPEngineClient over the
|
||||
/// zsh fake in `neverRead` mode, which execs /bin/sleep without ever
|
||||
/// reading stdin (the finding's inert non-reading child; no real
|
||||
@@ -273,14 +292,7 @@ struct EngineSmokeTests {
|
||||
kill(pid, SIGKILL) // settle the blocked pipe FIRST — close's boundedness is the next smoke's pin, not this one's
|
||||
client.close()
|
||||
}
|
||||
let outcome = Task<String, Never> {
|
||||
do {
|
||||
_ = try await client.request("session/prompt", params: blockedWriterPayload, timeout: 0.5)
|
||||
return "returned"
|
||||
} catch {
|
||||
return String(describing: error)
|
||||
}
|
||||
}
|
||||
let outcome = requestOutcome(client, method: "session/prompt", params: blockedWriterPayload, timeout: 0.5)
|
||||
let result = await awaitBounded(outcome, window: 5)
|
||||
#expect(
|
||||
result?.contains("timed out") == true,
|
||||
@@ -303,29 +315,17 @@ struct EngineSmokeTests {
|
||||
kill(pid, SIGKILL)
|
||||
client.close()
|
||||
}
|
||||
_ = Task<String, Never> {
|
||||
do {
|
||||
_ = try await client.request("session/prompt", params: blockedWriterPayload, timeout: 8)
|
||||
} catch {
|
||||
return String(describing: error)
|
||||
}
|
||||
return "returned"
|
||||
}
|
||||
// Wedge the writer: the oversized prompt fills the pipe (outcome unobserved).
|
||||
Task { _ = try? await client.request("session/prompt", params: blockedWriterPayload, timeout: 8) }
|
||||
// Let the oversized write reach the pipe and wedge the writer first.
|
||||
try await Task.sleep(nanoseconds: 200_000_000)
|
||||
client.notify("session/cancel", params: .object(["sessionId": .string("sess-1")]))
|
||||
let second = Task<String, Never> {
|
||||
do {
|
||||
_ = try await client.request(
|
||||
"session/new",
|
||||
params: .object(["cwd": .string("/tmp"), "mcpServers": .array([])]),
|
||||
timeout: 0.5,
|
||||
)
|
||||
return "returned"
|
||||
} catch {
|
||||
return String(describing: error)
|
||||
}
|
||||
}
|
||||
let second = requestOutcome(
|
||||
client,
|
||||
method: "session/new",
|
||||
params: .object(["cwd": .string("/tmp"), "mcpServers": .array([])]),
|
||||
timeout: 0.5,
|
||||
)
|
||||
let result = await awaitBounded(second, window: 5)
|
||||
#expect(
|
||||
result?.contains("timed out") == true,
|
||||
@@ -345,14 +345,8 @@ struct EngineSmokeTests {
|
||||
kill(pid, SIGKILL)
|
||||
client.close()
|
||||
}
|
||||
_ = Task<String, Never> {
|
||||
do {
|
||||
_ = try await client.request("session/prompt", params: blockedWriterPayload, timeout: 8)
|
||||
} catch {
|
||||
return String(describing: error)
|
||||
}
|
||||
return "returned"
|
||||
}
|
||||
// Wedge the writer: the oversized prompt fills the pipe (outcome unobserved).
|
||||
Task { _ = try? await client.request("session/prompt", params: blockedWriterPayload, timeout: 8) }
|
||||
// The write is in the pipe and the writer wedged before close runs.
|
||||
try await Task.sleep(nanoseconds: 200_000_000)
|
||||
let closeTask = Task<Void, Never> { client.close() }
|
||||
|
||||
Reference in new issue
Block a user