Skip to content

Commit 67ade9d

Browse files
luisleo526claude
andcommitted
run_json: reserve the report channel, so strategy output on fd 1 cannot corrupt a report
The harness printed the report or a typed failure on fd 1, but the strategy library it loads runs in the same process and could write to fd 1 as well: one native printf corrupted a successful report. - The host saves the caller's stdout as a private report descriptor before it parses arguments or loads any strategy, redirects native fd 1 to stderr, and writes the report and every typed failure through the saved descriptor. Failed-report discard now discards that descriptor. - A publication guard shared by the main handler and the cleanup keeps a fault after a published result or failure from printing a second document; the exit status stays nonzero and the late diagnostic goes to stderr. - FD sink mode keeps the native NDJSON stream on its caller-supplied stream. A sink or phase descriptor, or the arena slot, that collides with the report channel is refused with the existing run_request_invalid failure. - docker/entrypoint.sh sends ordinary transpile, compile and bind subprocess output to diagnostics; the explicit transpile-only mode keeps stdout. - The documentation states the limit: the loaded library inherits the saved descriptor, so this isolates ordinary native writes and is not a security boundary. - tests/test_run_json_stdout.py with tests/test_run_json_stdout_strategy.cpp loads a stub strategy that writes a marker to fd 1 through the real harness: clean runs print exactly the expected report with the marker only on stderr, a failing run prints exactly one failure document, a fault after publication prints no second document, and colliding descriptors are refused. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 482b000 commit 67ade9d

8 files changed

Lines changed: 689 additions & 48 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ diagnostics keys, described below.
147147
up, not 5, different from any phase descriptor); a refusal ends the run with
148148
the usual entrypoint status. With the variable unset nothing changes.
149149

150+
### Isolated report channel
151+
152+
- The JSON host reserves the caller's stdout before parsing or loading a
153+
strategy, redirects native fd 1 to stderr, and writes the report and typed
154+
failures through the saved descriptor. FD sink records stay on their
155+
caller-supplied stream, and descriptor collisions with the report channel,
156+
phase channel, or arena slot use the existing `run_request_invalid` failure.
157+
The loaded strategy remains in the same process and inherits the saved
158+
descriptor, so this isolates ordinary native fd 1 output without creating a
159+
security boundary.
160+
150161
### CI and release process
151162

152163
- **Light jobs on a pinned hosted image.** The light, secret-free CI jobs run

‎docker/entrypoint.sh‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ if [[ -f "${PINE}" ]]; then
187187
echo "[pineforge] transpiling strategy.pine ..." >&2
188188
if [[ "${SELECTED}" == "true" ]]; then
189189
INVENTORY_IN="${WORK}/request_feed_inventory.source.json"
190-
run_transpile_with_inventory "${PINE}" "${GEN}" "${INVENTORY_IN}" # set -e aborts (exit 5)
190+
run_transpile_with_inventory "${PINE}" "${GEN}" "${INVENTORY_IN}" >&2 # set -e aborts (exit 5)
191191
else
192-
run_transpile "${PINE}" "${GEN}" # set -e aborts (exit 5) on failure
192+
run_transpile "${PINE}" "${GEN}" >&2 # set -e aborts (exit 5) on failure
193193
fi
194194
SRC="${GEN}"
195195
TRANSPILED=true
@@ -201,7 +201,7 @@ elif [[ -f "${SRC_CPP}" ]]; then
201201
# Freeze the caller's bytes once into the private work dir (GEN). From here g++, the
202202
# binder and run_json.py's --generated-cpp all use that one file, so the caller's
203203
# mutable file is read only here. A failed copy ends the run before compile and run.
204-
cp -- "${SRC_CPP}" "${GEN}" \
204+
cp -- "${SRC_CPP}" "${GEN}" >&2 \
205205
|| { echo "[pineforge] cannot snapshot strategy.cpp into the work dir" >&2; exit 3; }
206206
SRC="${GEN}"
207207
fi
@@ -229,7 +229,7 @@ g++ -std=c++17 -O2 -ffp-contract=off -fPIC -shared \
229229
-I/usr/include/eigen3 \
230230
"${SRC}" \
231231
-Wl,--whole-archive "${PREFIX}/lib/libpineforge.a" -Wl,--no-whole-archive \
232-
-o "${SO}" \
232+
-o "${SO}" >&2 \
233233
|| { echo "[pineforge] compile failed" >&2; exit 3; }
234234

235235
# --- Selected path: bind the inventory to the C++ and library just built. ---
@@ -246,7 +246,7 @@ if [[ "${SELECTED}" == "true" ]]; then
246246
--inventory "${INVENTORY_IN}" \
247247
--cpp "${SRC}" \
248248
--so "${SO}" \
249-
--out "${BOUND_INVENTORY}" \
249+
--out "${BOUND_INVENTORY}" >&2 \
250250
|| { echo "[pineforge] request-feed inventory binding failed" >&2; exit 3; }
251251
else
252252
echo "[pineforge] no request-feed inventory for this strategy.cpp; none is passed on" >&2

0 commit comments

Comments
 (0)