diff --git a/.github/workflows/ailoop.yaml b/.github/workflows/ailoop.yaml index 2299ab0..37c6cc3 100644 --- a/.github/workflows/ailoop.yaml +++ b/.github/workflows/ailoop.yaml @@ -19,6 +19,7 @@ on: permissions: contents: write pull-requests: write + issues: write jobs: loop: @@ -67,6 +68,7 @@ jobs: - name: Run AI Fix timeout-minutes: 360 + continue-on-error: true id: ai_fix env: DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} @@ -83,19 +85,13 @@ jobs: name: attempts-log path: attempts.txt - - name: Push changes - if: always() && ${{ github.event.inputs.pr-on-fail }} - run: | - git checkout -b ${{ env.BRANCH }}-ai-fix-${{ env.SHORT_DATE }} - git push origin ${{ env.BRANCH }}-ai-fix-${{ env.SHORT_DATE }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Create PR + - name: Create PR or Issue if: always() && ${{ github.event.inputs.pr-on-fail }} uses: peter-evans/create-pull-request@v5 + env: + GH_TOKEN: ${{ secrets.PAT_TOKEN }} with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ env.GH_TOKEN }} commit-message: "AI Fix" title: "AI Fix for ${{ env.BRANCH }} (Attempts: ${{ env.MAX_ATTEMPTS }})" body: | diff --git a/scripts/ai-loop.sh b/scripts/ai-loop.sh index 21bd7ae..0cd06d5 100755 --- a/scripts/ai-loop.sh +++ b/scripts/ai-loop.sh @@ -13,19 +13,18 @@ BRANCH=${BRANCH:-tokenizer} success=0 for i in $(seq 1 $attempts); do - echo "=== Attempt $i/$attempts ===" | tee -a attempts.txt + echo "=== Attempt $i/$attempts ===" - # Run tests and print output to console, capture to temp file - cargo test -- --test accepts_model_from_config --test-threads=1 2>&1 | tee test_output.tmp - test_exit_code=${PIPESTATUS[0]} + # Run tests and print output to console + test_output=$(cargo test -- --test accepts_model_from_config --test-threads=1 2>&1) + test_exit_code=$? + echo "$test_output" >test_output.tmp - # Trim output to only include failures section - test_output=$(sed -n '/failures:/,/failures:/p' test_output.tmp | sed '1d; $d') - rm test_output.tmp - - # Append trimmed test results to attempts.txt - echo "$test_output" >>attempts.txt - echo -e "\n\n" >>attempts.txt + # Append last attempt to test output if it exists + if [ -f last_attempt.txt ]; then + echo "## Last time we tried this but we failed:" + cat last_attempt.txt >>test_output.tmp + fi # Exit loop if tests passed if [ $test_exit_code -eq 0 ]; then @@ -33,49 +32,33 @@ for i in $(seq 1 $attempts); do if [ "$GITHUB_ACTIONS" ]; then echo "ATTEMPTS=$i" >>$GITHUB_ENV fi + echo "Tests passed!!" break fi - # Create temp file for askds input and clean it up - askds_input=$(tail -c 250000 attempts.txt | sed 's/===/---/g') - echo "$askds_input" >askds_input.tmp - - # Run askds and stream output to both console and variable - echo "--- askds Output ---" | tee -a attempts.txt - - askds_output=$( - askds \ - --hide-ui \ - --fix \ - --auto-apply \ - --serialize="yek --max-size=100KB | cat" \ - --test-file-pattern='tests/*.rs' \ - --source-file-pattern='src/**/*.rs' \ - --system-prompt=./prompts/fix-tests.txt \ - --run="cat askds_input.tmp" 2>&1 | tee /dev/stderr - ) - askds_exit_code=$? - - if [ $askds_exit_code -ne 0 ]; then - echo "askds failed with exit code $askds_exit_code" >>attempts.txt - echo "askds failed. Guessing we ran out of context window. Trimming attempts.txt to last 30KB" - tail -c 30000 attempts.txt >attempts.tmp - mv attempts.tmp attempts.txt - continue - fi + # Run askds to fix the tests + askds \ + --hide-ui \ + --fix \ + --auto-apply \ + --serialize="yek --max-size=100KB | cat" \ + --test-file-pattern='tests/*.rs' \ + --source-file-pattern='src/**/*.rs' \ + --system-prompt=./prompts/fix-tests.txt \ + --run="cat test_output.tmp" || true - echo "$askds_output" >>attempts.txt - echo "--- End askds Output ---" >>attempts.txt - # Cleanup temp files - rm askds_input.tmp + rm last_attempt.txt + cargo fmt + cargo clippy --fix --allow-dirty # Commit changes if any if ! git diff --quiet; then git add . git commit -m "fix attempt $i (${BRANCH})" - echo "Applied fixes for ${BRANCH} tests" | tee -a attempts.txt + echo "Applied fixes for ${BRANCH} tests" else - echo "No changes in attempt $i" | tee -a attempts.txt + echo "No changes in attempt $i" + cp test_output.tmp last_attempt.txt continue fi done