SHS serve co-process (NDJSON) + env-var contract#4
Merged
Conversation
Replace the popen-per-stuck-branch query path with one long-lived
`kofta-shs serve` co-process streamed over a pipe (one NDJSON request
line -> one JSON-array response line). A persistent process is what
lets the Python side accumulate cost across the whole campaign and
flush it on exit via --cost-out.
Adopt the KOFTA_SHS=1 boolean + KOFTA_SHS_{BIN,MODEL,CACHE,COST,BUDGET,
NOSLICE} env contract (replacing the merged command-string design),
matching shs/campaign.example.json. Broken pipe / read failure disables
the seam gracefully; shutdown via atexit closes stdin so serve dumps
cost even under a timeout-driven SIGTERM. Fix kofta-shs shebang to
/usr/bin/env python3 so KOFTA_SHS_BIN is execvp-resolvable, and point
the docker smoke test at the new contract.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
popen-per-stuck-branchkofta-shs querypath with one long-livedkofta-shs serveco-process, streamed over a pipe: one NDJSON request line (verified branch facts) → one JSON-array response line (candidate strings). A persistent process is what lets the Python side accumulate cost across the whole campaign and flush it on exit via--cost-out— the prerequisite for per-campaign cost accounting.KOFTA_SHS=1boolean +KOFTA_SHS_{BIN,MODEL,CACHE,COST,BUDGET,NOSLICE}env-var contract, replacing the merged command-string design. This matchesshs/campaign.example.json, which already used these vars.SIGPIPEis ignored and detected viawrite()/getline()return values instead. Shutdown viaatexitcloses the co-process stdin soservesees EOF and dumps--cost-outeven under atimeout-drivenSIGTERM(AFL's stop path exits cleanly throughexit(0)).kofta-shsshebang#!python3→#!/usr/bin/env python3soKOFTA_SHS_BINisexecvp-resolvable.docker/run-smoke.shat the new contract (KOFTA_SHS=1 KOFTA_SHS_BIN=… KOFTA_SHS_CACHE=… KOFTA_SHS_COST=…) and print the resultingshs_cost.json; fix./afl-fuzz→./kofta-fuzzinshs/campaign.example.jsonand addKOFTA_SHS_BIN.Test plan
afl-fuzz.ccompiles cleanly in both default and-DKOFTA_DEBUGbuilds (only the pre-existing macOS-onlymemfd_createincompatibility remains; Linux CI builds it).kofta-shs serve --mockverified end-to-end via the new shebang: NDJSON request →["kofta_magic"]response →shs_cost.jsondumped on EOF.source_sliceyields[]from the mock client (nothing to echo).KOFTA_DEBUG) on Ubuntu.docker/smoke.sh) — blocked locally by KOFTA's x86_64-only argv-leak asm under arm64 emulation, orthogonal to this change.🤖 Generated with Claude Code