From 167bcc4ce5cb01ab4c9e0a993f295c02813b5586 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Sun, 23 Aug 2026 07:02:36 +0200 Subject: [PATCH] =?UTF-8?q?fix(SAC=5FLSTM=5FBot):=20MA=20history=20self-tr?= =?UTF-8?q?uncation=20=E2=80=94=20read=20before=20>=20redirect;=20campaign?= =?UTF-8?q?=20v2=20attempt-3=20prep=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $(cat f) inside a command redirected to f saw the already-truncated file, so every eval cycle wiped ma_history_*.txt back to one leading-space value and degraded the composite best-gate to last-cycle mean. Read is hoisted into its own statement; unquoted expansion + tail -n keeps exactly the last MA_WINDOW values. Verified: fresh/5+/6+ cycle edges reproduce sliding window. --- SAC_LSTM_Bot/sac_train.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/SAC_LSTM_Bot/sac_train.sh b/SAC_LSTM_Bot/sac_train.sh index 83f7331..a3096ca 100755 --- a/SAC_LSTM_Bot/sac_train.sh +++ b/SAC_LSTM_Bot/sac_train.sh @@ -119,8 +119,16 @@ eval_checkpoint() { wr=$(( 100 * wins / rounds )) echo ">>> [eval] win rate: $wins/$rounds ($wr%) vs $opp" cat "$otmp" >> "$tmp"; rm -f "$otmp" - # Per-opponent history: append this cycle's win rate, keep last MA_WINDOW. - printf '%s\n' "$(cat "$(ma_hist_file "$opp")" 2>/dev/null)" "$wr" \ + # Per-opponent history: append this cycle's win rate, keep last MA_WINDOW + # values on one line. Read FIRST, separately: `$(cat f)` inside a command + # redirected `> f` executes against the already-truncated file (bash sets + # up the redirect before running the substitution) — every cycle wiped the + # history back to a single leading-space value (#60). $hist is UNQUOTED on + # purpose: word-splitting turns the stored line into one value per line so + # tail keeps the last MA_WINDOW values. + local hist + hist="$(cat "$(ma_hist_file "$opp")" 2>/dev/null)" + printf '%s\n' $hist "$wr" \ | tail -n "$MA_WINDOW" | tr '\n' ' ' > "$(ma_hist_file "$opp")" done mv "$tmp" "$EVAL_LOG_FILE"