Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .github/workflows/ailoop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
permissions:
contents: write
pull-requests: write
issues: write

jobs:
loop:
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Comment on lines +92 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using both GH_TOKEN and token with the same PAT value is redundant. One environment variable is sufficient.

commit-message: "AI Fix"
title: "AI Fix for ${{ env.BRANCH }} (Attempts: ${{ env.MAX_ATTEMPTS }})"
body: |
Expand Down
71 changes: 27 additions & 44 deletions scripts/ai-loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,52 @@ 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
success=1
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: rm last_attempt.txt will fail if file doesn't exist - should use rm -f

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
Expand Down
Loading