Skip to content

[agentic-token-optimizer] Contribution Check: fix E002 safe-output collision and orchestration retry loops #42289

Description

@github-actions

Target Workflow

Contribution Check (contribution-check.md) — selected as the highest-AIC workflow in the 7-day window (587.8 AIC, 100% failure rate in window) that has not been optimized in the last 14 days.

Analysis Period

2026-06-22 → 2026-06-29 (daily snapshots) + last 30 GitHub Actions runs via API.

Cost Profile

Metric Value
Runs analyzed 30 (from GitHub API, last ~8 days)
Failure rate 4/30 (13.3%)
Failed run AIC 587.8 (run §28378357077)
Avg AIC — successful runs ~152.8 (from 2026-06-23 snapshot, 2 runs)
AIC overhead per failure event ~435 (587.8 − 152.8)
Avg successful run duration ~16 min (17 observed, max 22 min)
Failed run duration 28.4 min (1703 s, near 30-min timeout)
GitHub API calls (failed run) 21
Raw tokens / turns Not available in dataset

Failure breakdown:

  • 2 infrastructure failures (MCP gateway ECONNRESET, runs 28313489959 and 28307653871) — not addressable by prompt changes
  • 2 partial-execution failures (runs 28378357077 and 28211424614) — E002 safe-output collision, addressable

Ranked Recommendations

1. Enforce exclusive MCP-path for safe-outputs — ~29 AIC/run

The main orchestrator emitted safe-output calls through the safeoutputs bash CLI and through the MCP safe-output tools in the same run. When the CLI consumed the create_issue slot (max: 1), subsequent MCP create_issue calls returned E002: create_issue limit reached — 1 of 1 already used this run. The agent then retried the entire orchestration loop three more times.

Action: Add to the workflow prompt (before Step 1):

"Use only the MCP safe-output tools (create_issue, add_labels, add_comment) for safe-output calls. Do not emit safe outputs via the safeoutputs bash CLI. Never pipe JSON to safeoutputs create_issue . or similar."

Evidence: Run §28378357077 — step summary shows E002 twice; the JSONL was written via CLI path (line 1 contains the correct report), but the MCP tool attempts at id:8 and id:13 both failed because the CLI had already consumed the slot. Run §28211424614 shows the same partial_execution pattern across 4 harness retries.


2. Add E002 recovery guard to cap orchestration retries — ~15 AIC/run

When E002 occurred (14:23:05), the agent misread it as "report was created in an earlier run" and continued looping, repeating the full report-compilation cycle at 14:23:59, 14:29:29, 14:29:37, and 14:33:54. Each loop consumed ~100 additional AIC.

Action: Add to the Completion Gate section:

"If create_issue returns an E002 error, the issue slot was already consumed earlier in this run — the report was created. Do not retry create_issue. Do not re-run the evaluation loop. Proceed directly to add_comment and add_labels calls with the PRs already evaluated, then finish."

Evidence: Agent log text from run §28378357077: "The create_issue limit is already used (report was created in the earlier run)." — incorrect attribution led to three extra loop cycles totalling ~290 AIC of wasted work.


3. Enforce safe-output ordering: create_issue before add_labels — ~5 AIC/run

At 14:19:36 the agent called safeoutputs add_labels . < '{"item_number":"#aw_summary",...}' before create_issue had recorded the aw_summary temporary ID. Although the JSONL order was correct at ingestion time, the out-of-order CLI calls are fragile and were repeated three times after E002 errors (each emitting the same add_labels payload).

Action: Add to Step 3:

"Call create_issue first and wait for its successful response containing temporary_id. Only after you receive that response, emit add_labels with item_number: \"#aw_summary\". Never reference #aw_summary before create_issue has returned a successful result."

References: §28378357077add_labels #aw_summary appeared at 14:19:36 and was duplicated at 14:23:59, 14:29:37, 14:33:54.


4. Remove safe-output schema probing — ~5 AIC/run

At 14:19:16, before any safe-output call, the agent ran:

safeoutputs create_issue --help && safeoutputs add_labels --help

Both schemas are already injected into the system prompt. This probing step wastes 2 turns (~5 AIC) on every run.

Action: Add to the workflow prompt (or directly to the Important section):

"Do not probe safe-output tool schemas with --help commands or test invocations. All tool signatures are already in your system prompt."


5. Fix invalid fields parameter on create_issue — 0 AIC (correctness only)

The agent emitted "fields": {"close-older-issues": true} inside the create_issue payload. The fields property must be an array of {name, value} pairs for custom project fields; close-older-issues is a workflow YAML configuration option, not a create_issue field. This triggered a validation warning:

Line 1: create_issue 'fields' must be an array

Action: Add to Step 2:

"Do not include a fields property in the create_issue payload unless setting custom project fields (arrays of {\"name\": \"...\", \"value\": \"...\"} pairs). The close-older-issues behaviour is configured in the workflow YAML and must not be passed as a field."


Total Estimated AIC Savings

Recommendation Estimated savings/run
1. Exclusive MCP path ~29 AIC
2. E002 recovery guard ~15 AIC
3. Ordering gate ~5 AIC
4. Remove --help probes ~5 AIC
5. Fix fields param 0 AIC
Total (conservative) ~40 AIC/run

Caveats

  • AIC for successful runs is derived from the 2026-06-23 daily snapshot (2 runs, avg 152.8); no raw token data is available for this workflow.
  • The 40 AIC/run savings estimate is weighted across all runs (including the ~7% that hit the E002 bug and the ~93% that succeed normally).
  • Infrastructure failures (MCP gateway ECONNRESET) account for 2 of the 4 observed failures and are not addressable by prompt changes.
  • Recommendations 1 and 2 together eliminate the same failure event; individual savings overlap — combined expected impact is ~40 AIC/run, not 44.
Run history (last 30)
Run ID Date Conclusion Duration
28378357077 2026-06-29 14:11 failure (E002) 28.4 min
28364835480 2026-06-29 10:14 success 19.7 min
28352794909 2026-06-29 06:22 success 15.8 min
28343127321 2026-06-29 01:32 success 17.5 min
28336118520 2026-06-28 21:11 success 22.8 min
28329817229 2026-06-28 17:12 success 16.5 min
28323414333 2026-06-28 13:14 success 21.3 min
28318355232 2026-06-28 09:48 success 19.1 min
28313489959 2026-06-28 06:13 failure (infra) 9.8 min
28307653871 2026-06-28 01:30 failure (infra) 25.9 min
28211424614 2026-06-26 01:32 failure (E002) ~25 min

Generated by Agentic Workflow AIC Usage Optimizer · 158.5 AIC · ⊞ 7.2K ·

  • expires on Jul 6, 2026, 8:26 AM UTC-08:00

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions