Skip to content

Commit 7694635

Browse files
committed
Fix all Slack notifications and improve diff truncation detection
- Fix all Slack notification steps to use JSON file approach (avoid shell quoting) - Extract task/requester from event payload using jq instead of direct substitution - Prevents 'Admin to SlackONOS: command not found' errors - Improve diff truncation detection to catch small incomplete diffs - Better error messages for truncated diffs with troubleshooting suggestions - Detects mid-file-path truncation (+++ b/p) even for small diffs
1 parent 22d948d commit 7694635

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

.github/agent/agent.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,11 +1050,16 @@ if (validationResult.errors.length > 0 || diff.match(/\+\+\+ b\/[^\n]*$/m)) {
10501050
console.warn(`[AGENT] Diff length: ${diffLength} characters`);
10511051
console.warn(`[AGENT] Last 5 lines:\n${lastLines}`);
10521052

1053-
// Try to detect if this is a token limit issue
1054-
if (diffLength > 7000 && diff.match(/\+\+\+ b\/[^\n]*$/m)) {
1055-
const errorMsg = `Diff appears to be truncated (likely hit token limit). The AI model may have generated an incomplete diff.\n\nErrors:\n${validationResult.errors.join('\n')}\n\nDiff preview (last 500 chars):\n\`\`\`\n${diff.substring(Math.max(0, diffLength - 500))}\n\`\`\`\n\nSuggestion: Try breaking the task into smaller parts or increase max_tokens.`;
1053+
// Try to detect if this is a token limit or truncation issue
1054+
// Check for incomplete +++ b/ lines (truncated file paths)
1055+
const incompletePathMatch = diff.match(/\+\+\+ b\/[^\n]{1,10}$/m);
1056+
if (incompletePathMatch || (diffLength > 7000 && diff.match(/\+\+\+ b\/[^\n]*$/m))) {
1057+
const truncationReason = incompletePathMatch
1058+
? "Diff appears to be truncated mid-file-path (model stopped generating)"
1059+
: "Diff appears to be truncated (likely hit token limit)";
1060+
const errorMsg = `${truncationReason}. The AI model may have generated an incomplete diff.\n\nErrors:\n${validationResult.errors.join('\n')}\n\nDiff preview (last 500 chars):\n\`\`\`\n${diff.substring(Math.max(0, diffLength - 500))}\n\`\`\`\n\nPossible causes:\n- Model hit output token limit (check max_tokens setting)\n- Low API credits causing early termination\n- Input context too large, leaving insufficient room for output\n- Model stopped generating for other reasons\n\nSuggestions:\n- Check Anthropic account credits\n- Reduce input context size (fewer files)\n- Break task into smaller parts\n- Verify max_tokens is sufficient (currently 180K)`;
10561061
const errorDetails = formatErrorDetails(new Error(errorMsg), { diff: diff.substring(Math.max(0, diffLength - 1000)), files: validationResult.stats.filesChanged });
1057-
await handleError(new Error(errorMsg), "Incomplete Diff (Token Limit?)", { diff: diff.substring(Math.max(0, diffLength - 1000)), errorDetails });
1062+
await handleError(new Error(errorMsg), "Incomplete Diff (Truncated)", { diff: diff.substring(Math.max(0, diffLength - 1000)), errorDetails });
10581063
// handleError calls process.exit(1), so we never reach here
10591064
}
10601065
}

.github/workflows/aicode-agent.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ jobs:
7676
- name: Notify Slack on agent failure
7777
if: steps.agent.outcome != 'success'
7878
run: |
79-
# Use jq to safely construct JSON payload
80-
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
81-
REQUESTER="${{ github.event.client_payload.requester }}"
79+
# Write event payload to JSON file to avoid shell quoting issues
80+
echo '${{ toJSON(github.event.client_payload) }}' > /tmp/event_payload.json
81+
82+
# Extract values using jq (handles all escaping automatically)
83+
TASK=$(jq -r '.task // .original_task // "Unknown task"' /tmp/event_payload.json)
84+
REQUESTER=$(jq -r '.requester // "unknown"' /tmp/event_payload.json)
8285
RUN_ID="${{ github.run_id }}"
8386
8487
PAYLOAD=$(jq -n \
@@ -199,10 +202,14 @@ jobs:
199202
- name: Notify Slack on success
200203
if: steps.agent.outcome == 'success' && steps.tests.outcome == 'success' && steps.secrets-check.outcome == 'success'
201204
run: |
205+
# Write event payload to JSON file to avoid shell quoting issues
206+
echo '${{ toJSON(github.event.client_payload) }}' > /tmp/event_payload.json
207+
208+
# Extract values using jq (handles all escaping automatically)
202209
CHANGED_FILES="${{ steps.changed-files.outputs.files }}"
203-
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
204-
ORIGINAL_TASK="${{ github.event.client_payload.original_task || 'N/A' }}"
205-
REQUESTER="${{ github.event.client_payload.requester }}"
210+
TASK=$(jq -r '.task // .original_task // "Unknown task"' /tmp/event_payload.json)
211+
ORIGINAL_TASK=$(jq -r '.original_task // .task // "N/A"' /tmp/event_payload.json)
212+
REQUESTER=$(jq -r '.requester // "unknown"' /tmp/event_payload.json)
206213
PR_NUMBER="${{ steps.cpr.outputs.pull-request-number }}"
207214
RUN_ID="${{ github.run_id }}"
208215
@@ -241,8 +248,12 @@ jobs:
241248
- name: Notify Slack on validation failure
242249
if: steps.agent.outcome == 'success' && steps.secrets-check.outcome != 'success'
243250
run: |
244-
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
245-
REQUESTER="${{ github.event.client_payload.requester }}"
251+
# Write event payload to JSON file to avoid shell quoting issues
252+
echo '${{ toJSON(github.event.client_payload) }}' > /tmp/event_payload.json
253+
254+
# Extract values using jq (handles all escaping automatically)
255+
TASK=$(jq -r '.task // .original_task // "Unknown task"' /tmp/event_payload.json)
256+
REQUESTER=$(jq -r '.requester // "unknown"' /tmp/event_payload.json)
246257
RUN_ID="${{ github.run_id }}"
247258
248259
PAYLOAD=$(jq -n \
@@ -277,8 +288,12 @@ jobs:
277288
- name: Notify Slack on test failure
278289
if: steps.agent.outcome == 'success' && steps.secrets-check.outcome == 'success' && steps.tests.outcome != 'success'
279290
run: |
280-
TASK="${{ github.event.client_payload.task || github.event.client_payload.original_task }}"
281-
REQUESTER="${{ github.event.client_payload.requester }}"
291+
# Write event payload to JSON file to avoid shell quoting issues
292+
echo '${{ toJSON(github.event.client_payload) }}' > /tmp/event_payload.json
293+
294+
# Extract values using jq (handles all escaping automatically)
295+
TASK=$(jq -r '.task // .original_task // "Unknown task"' /tmp/event_payload.json)
296+
REQUESTER=$(jq -r '.requester // "unknown"' /tmp/event_payload.json)
282297
RUN_ID="${{ github.run_id }}"
283298
284299
PAYLOAD=$(jq -n \

0 commit comments

Comments
 (0)