Conversation
…ough stderr The parent treats a missing protocol file as 'protocol response was missing', but the broker's swallow-and-reap catch hid the underlying write error (ENOSPC, EACCES, ...). The broker now emits a bounded stderr marker before reaping itself, and the parent captures a 4KB stderr tail and retries the protocol read for 200ms (5x50ms) to tolerate tmpfs/AV races where close edges ahead of the file write. Classified as protocol_write_failed. Fixes CodebuffAI#1359
|
Good bug hunt — collapsing every broker write failure into the same generic Two things need attention before this is portable as-is:
Right instinct, but these two points change the risk profile of the change enough that a maintainer will want them resolved or explained before porting. Please also open with what specific input caused the validator to reject a legitimate path — that's the actual root cause worth fixing. |
|
Thanks for the review — both points are addressed in the latest push. 1. Group reaping on the write-failure path You were right that the explicit reap disappeared. It was not a leak — the
2. The raw-env fallback Agreed, and it is gone. What I did instead was harden the comparison where a legitimate rejection was actually plausible:
|
Return reapOwnProcessGroup() directly from the protocol write failure path so a failed write never outlives a successful one, and flush the stderr marker through a bounded wait before the group is killed. On POSIX process.stderr is an async pipe, so the previous fire-and-forget write could lose the failure reason to the immediate SIGKILL. Remove protocolWriteTargets(): the raw-environment fallback skipped temp-directory validation, and its rejection case could not be reproduced because the broker inherits the parent environment. Compare the protocol directory after resolving symlinks, fold case on Windows, and cover both spellings plus the reaping path with tests.
f2b85a7 to
920580d
Compare
Summary
The parent CLI treats a missing broker protocol file as
terminal command broker protocol response was missing, but the broker's swallow-and-reapcatchhid the root cause (e.g.ENOSPC,EACCES) — every failure looked identical on Windows.Changes
[freebuff-broker] protocol write failed: <err>) before the normal cleanup reap, instead of vanishing silently.PROTOCOL_READ_ATTEMPTS=5×PROTOCOL_READ_RETRY_MS=50) to tolerate filesystems/AV whereclosecan edge ahead of the one-shot file write.protocol_write_failedcode; the classifier checks the stderr marker before the genericprotocol_missingbranch. The missing-protocol error message now includesBroker stderr: <tail>when available.writeProtocolfalls back from the validated env path to the raw env path when validation rejects a broken environment, so a valid response is never lost to over-strictness.Tests
normalizes failuresnow assertsprotocol_write_failedclassification via the stderr marker.explains a missing protocol response with the broker stderr reason(helper writes marker to stderr + exits 1 → parent reportsprotocol_write_failedwith the stderr reason).tolerates a protocol file written just after the helper exits(delayed write race → read retry succeeds).windows-terminal-healthtests still pass.Fixes #1359