feat: enhanced token probe with diagnostics - tests Azure and GitHub endpoints, logs token source

This commit is contained in:
Alex Verkhovsky 2025-12-03 06:50:39 -07:00
parent 40d64c8b69
commit b50675d667
1 changed files with 72 additions and 61 deletions

View File

@ -155,20 +155,39 @@ jobs:
steps: steps:
- name: Probe token limits - name: Probe token limits
env: env:
GITHUB_TOKEN: ${{ secrets.COPILOT_PAT || secrets.GITHUB_TOKEN }} AUTH_TOKEN: ${{ secrets.COPILOT_PAT }}
FALLBACK_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Try Azure endpoint (Gemini's suggestion) - deprecated Oct 2025 but may have different limits
LLM_ENDPOINT_AZURE: "https://models.inference.ai.azure.com/chat/completions"
LLM_ENDPOINT_GITHUB: "https://models.github.ai/inference/chat/completions"
run: | run: |
echo "=== Token Limit Probe ===" echo "=== Token Limit Probe ==="
echo "Testing progressively larger payloads to find the ceiling"
# Diagnostic: which token are we using?
if [ -n "$AUTH_TOKEN" ]; then
echo "Using: COPILOT_PAT (length: ${#AUTH_TOKEN} chars)"
TOKEN="$AUTH_TOKEN"
else
echo "Using: GITHUB_TOKEN (fallback)"
TOKEN="$FALLBACK_TOKEN"
fi
# Test both endpoints
for ENDPOINT_NAME in "AZURE" "GITHUB"; do
if [ "$ENDPOINT_NAME" = "AZURE" ]; then
ENDPOINT="$LLM_ENDPOINT_AZURE"
else
ENDPOINT="$LLM_ENDPOINT_GITHUB"
fi
echo ""
echo "=== Testing $ENDPOINT_NAME endpoint ==="
echo "URL: $ENDPOINT"
echo "Model: gpt-4o"
echo "" echo ""
# Test sizes in characters (roughly 4 chars per token) # Test sizes in characters (roughly 4 chars per token)
SIZES=(2000 4000 8000 16000 32000 64000) SIZES=(2000 4000 8000 16000 32000 64000 128000)
# Generate filler text (lorem ipsum style)
generate_filler() {
local size=$1
python3 -c "print(('The quick brown fox jumps over the lazy dog. ' * ($size // 45 + 1))[:$size])"
}
echo "| Size (chars) | ~Tokens | HTTP Status | Result |" echo "| Size (chars) | ~Tokens | HTTP Status | Result |"
echo "|--------------|---------|-------------|--------|" echo "|--------------|---------|-------------|--------|"
@ -176,18 +195,17 @@ jobs:
for SIZE in "${SIZES[@]}"; do for SIZE in "${SIZES[@]}"; do
APPROX_TOKENS=$((SIZE / 4)) APPROX_TOKENS=$((SIZE / 4))
# Generate payload of specified size # Generate filler
FILLER=$(generate_filler $SIZE) FILLER=$(python3 -c "print(('The quick brown fox jumps over the lazy dog. ' * ($SIZE // 45 + 1))[:$SIZE])")
PROMPT="Respond with exactly one word: 'received'. Here is padding text to test token limits: $FILLER" PROMPT="Respond with exactly one word: 'received'. Here is padding text to test token limits: $FILLER"
PROMPT_ESCAPED=$(echo "$PROMPT" | jq -Rs .) PROMPT_ESCAPED=$(echo "$PROMPT" | jq -Rs .)
# Call the LLM RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$ENDPOINT" \
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$LLM_ENDPOINT" \ -H "Authorization: Bearer $TOKEN" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{ -d "{
\"model\": \"$LLM_MODEL\", \"model\": \"gpt-4o\",
\"messages\": [ \"messages\": [
{\"role\": \"user\", \"content\": $PROMPT_ESCAPED} {\"role\": \"user\", \"content\": $PROMPT_ESCAPED}
], ],
@ -200,32 +218,25 @@ jobs:
if [ "$HTTP_CODE" = "200" ]; then if [ "$HTTP_CODE" = "200" ]; then
RESULT="OK" RESULT="OK"
else else
# Extract error message if present
ERROR_MSG=$(echo "$BODY" | jq -r '.error.message // .message // "Unknown error"' 2>/dev/null | head -c 50) ERROR_MSG=$(echo "$BODY" | jq -r '.error.message // .message // "Unknown error"' 2>/dev/null | head -c 50)
RESULT="FAIL: $ERROR_MSG" RESULT="FAIL: $ERROR_MSG"
# Log full error for debugging
echo "" echo ""
echo "::warning::Failed at ${SIZE} chars (~${APPROX_TOKENS} tokens)" echo "::warning::Failed at ${SIZE} chars (~${APPROX_TOKENS} tokens) on $ENDPOINT_NAME"
echo "Full error response:" echo "Full error: $BODY"
echo "$BODY" | jq . 2>/dev/null || echo "$BODY"
echo "" echo ""
fi fi
echo "| $SIZE | ~$APPROX_TOKENS | $HTTP_CODE | $RESULT |" echo "| $SIZE | ~$APPROX_TOKENS | $HTTP_CODE | $RESULT |"
# Stop probing after first failure to avoid hammering the API
if [ "$HTTP_CODE" != "200" ]; then if [ "$HTTP_CODE" != "200" ]; then
echo "" echo ""
echo "=== Ceiling Found ===" echo "=== $ENDPOINT_NAME Ceiling: ~$((SIZE / 8)) tokens ==="
echo "Last successful size: $((SIZE / 2)) chars (~$((SIZE / 8)) tokens)"
echo "First failure at: $SIZE chars (~$APPROX_TOKENS tokens)"
break break
fi fi
# Small delay to avoid rate limiting
sleep 1 sleep 1
done done
done
echo "" echo ""
echo "=== Probe Complete ===" echo "=== Probe Complete ==="