fix(plan-phase): recover safely from quota exhaustion
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# Agent Recovery and Stage Timing
|
||||
|
||||
Initialize once before the first planning agent is dispatched:
|
||||
|
||||
```bash
|
||||
PLAN_PHASE_STARTED_AT=$(date +%s)
|
||||
PLAN_PHASE_STAGE_STARTED_AT=$PLAN_PHASE_STARTED_AT
|
||||
PLAN_PHASE_BASELINE_SUMMARIES=$(gsd_run query find-phase "${phase_number}" | jq -r '.summary_count // 0')
|
||||
|
||||
gsd_plan_stage_start() {
|
||||
PLAN_PHASE_STAGE="$1"
|
||||
PLAN_PHASE_STAGE_STARTED_AT=$(date +%s)
|
||||
echo "◆ Stage ${PLAN_PHASE_STAGE} started"
|
||||
}
|
||||
|
||||
gsd_plan_stage_end() {
|
||||
_now=$(date +%s)
|
||||
echo "◆ Stage ${PLAN_PHASE_STAGE:-unknown}: $((_now - PLAN_PHASE_STAGE_STARTED_AT))s (${1:-complete}); plan-phase total: $((_now - PLAN_PHASE_STARTED_AT))s"
|
||||
}
|
||||
|
||||
gsd_plan_external_execution_started() {
|
||||
_current_summaries=$(gsd_run query find-phase "${phase_number}" | jq -r '.summary_count // 0')
|
||||
[ "$_current_summaries" -gt "$PLAN_PHASE_BASELINE_SUMMARIES" ]
|
||||
}
|
||||
|
||||
gsd_plan_classify_return() {
|
||||
gsd_run query agent.classify-failure -- "$1"
|
||||
}
|
||||
```
|
||||
|
||||
Call `gsd_plan_stage_start <planner|checker|revision>` immediately before each corresponding
|
||||
Agent dispatch. Call `gsd_plan_stage_end <marker|stalled|quota-exceeded|unrecognized>` exactly
|
||||
once when that dispatch ends, before retrying, stopping, or moving on. This exposes elapsed time
|
||||
even when an agent fails or exhausts quota.
|
||||
|
||||
Before every retry or revision dispatch, call `gsd_plan_external_execution_started`. If it
|
||||
succeeds, stop this stale planning run immediately: another session produced a new SUMMARY.md
|
||||
since this run started. Report baseline/current counts and direct the user to `/gsd:progress`.
|
||||
|
||||
For every empty, truncated, errored, or unrecognized Agent return, read the complete return body
|
||||
(for a background agent, read its bound `{outputFile}`), then run:
|
||||
|
||||
```bash
|
||||
PLAN_AGENT_FAILURE=$(gsd_plan_classify_return "$AGENT_RETURN_BODY")
|
||||
PLAN_AGENT_FAILURE_CLASS=$(printf '%s' "$PLAN_AGENT_FAILURE" | jq -r '.class // "unknown-failure"')
|
||||
```
|
||||
|
||||
If the class is `quota-exceeded`, call `gsd_plan_stage_end quota-exceeded`, show `sentinel` and
|
||||
`retryAfterSeconds` when present, and stop cleanly. Never offer or perform an immediate retry.
|
||||
Preserve PLAN.md files and tell the user to rerun `/gsd:plan-phase {PHASE}` after reset; step 6
|
||||
offers verification of existing plans. Non-quota failures continue to the existing fallback.
|
||||
Reference in New Issue
Block a user