From 26d20af48c1b0734c4b6074105a30db7c2188708 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 20 Mar 2026 20:58:32 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20address=20review=20=E2=80=94=20scratch?= =?UTF-8?q?=20file=20survives=20crash,=20cap=20read=20size,=20fix=20instru?= =?UTF-8?q?ction=20(#262)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove SCRATCH_FILE from action-agent cleanup() trap so it survives crashes - Change instruction to note contents already injected (avoid wasted tool call) - Cap scratch file read at 8KB via head -c 8192 - Move predictor scratch instruction after formula (consistent placement) - Remove redundant FINAL_PHASE re-reads in planner/predictor Co-Authored-By: Claude Opus 4.6 (1M context) --- action/action-agent.sh | 2 +- lib/formula-session.sh | 4 ++-- planner/planner-run.sh | 4 ++-- predictor/predictor-run.sh | 9 ++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/action/action-agent.sh b/action/action-agent.sh index cf51dd6..a1fd470 100644 --- a/action/action-agent.sh +++ b/action/action-agent.sh @@ -88,7 +88,7 @@ cleanup() { agent_kill_session "$SESSION_NAME" # Best-effort docker cleanup for containers started during this action (cd "${PROJECT_REPO_ROOT}" 2>/dev/null && docker compose down 2>/dev/null) || true - rm -f "$PHASE_FILE" "$IMPL_SUMMARY_FILE" "$PREFLIGHT_RESULT" "$SCRATCH_FILE" + rm -f "$PHASE_FILE" "$IMPL_SUMMARY_FILE" "$PREFLIGHT_RESULT" } trap cleanup EXIT diff --git a/lib/formula-session.sh b/lib/formula-session.sh index 58665e6..f09eec1 100644 --- a/lib/formula-session.sh +++ b/lib/formula-session.sh @@ -142,7 +142,7 @@ Periodically (every 10-15 tool calls), write a summary of: - What remains to do to: ${scratch_file} -If you find this file exists when you start, read it first — it is your previous context. +If this file existed at session start, its contents have already been injected into your prompt above. This file is ephemeral — not evidence or permanent memory, just a compaction survival mechanism. _SCRATCH_EOF_ } @@ -153,7 +153,7 @@ _SCRATCH_EOF_ read_scratch_context() { local scratch_file="$1" if [ -f "$scratch_file" ]; then - printf '## Previous context (from scratch file)\n%s\n' "$(cat "$scratch_file")" + printf '## Previous context (from scratch file)\n%s\n' "$(head -c 8192 "$scratch_file")" fi } diff --git a/planner/planner-run.sh b/planner/planner-run.sh index 65f6da9..3ddb6c7 100755 --- a/planner/planner-run.sh +++ b/planner/planner-run.sh @@ -85,7 +85,7 @@ export CLAUDE_MODEL="opus" run_formula_and_monitor "planner" # ── Cleanup scratch file on normal exit ────────────────────────────────── -FINAL_PHASE=$(read_phase "$PHASE_FILE") -if [ "$FINAL_PHASE" = "PHASE:done" ]; then +# FINAL_PHASE already set by run_formula_and_monitor +if [ "${FINAL_PHASE:-}" = "PHASE:done" ]; then rm -f "$SCRATCH_FILE" fi diff --git a/predictor/predictor-run.sh b/predictor/predictor-run.sh index cdb217d..2c43a4f 100755 --- a/predictor/predictor-run.sh +++ b/predictor/predictor-run.sh @@ -64,12 +64,11 @@ about CI health, issue staleness, agent status, and system conditions. ## Project context ${CONTEXT_BLOCK} -${SCRATCH_CONTEXT:+${SCRATCH_CONTEXT} -}${SCRATCH_INSTRUCTION} - +${SCRATCH_CONTEXT} ## Formula ${FORMULA_CONTENT} +${SCRATCH_INSTRUCTION} ${PROMPT_FOOTER}" # ── Run session ────────────────────────────────────────────────────────── @@ -77,7 +76,7 @@ export CLAUDE_MODEL="sonnet" run_formula_and_monitor "predictor" # ── Cleanup scratch file on normal exit ────────────────────────────────── -FINAL_PHASE=$(read_phase "$PHASE_FILE") -if [ "$FINAL_PHASE" = "PHASE:done" ]; then +# FINAL_PHASE already set by run_formula_and_monitor +if [ "${FINAL_PHASE:-}" = "PHASE:done" ]; then rm -f "$SCRATCH_FILE" fi