AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase05_FinalRepairPrompt.txt

PHASE 05 FINAL REPAIR PROMPT - FIX THE EXECUTE-MODE NOAA FAILURE-STREAK GUARD PRECEDENCE
 
Goal:
Fix the final remaining Phase 05 test failure by restoring the correct precedence between the NOAA repeated-failure terminal guard and the generic weather clarification path. The latest output shows the weather extraction fix is working, but execution still falls through to the generic clarification message instead of returning the required `NOAA_FORECAST_FAILURE_STREAK_GUARD` marker.
 
Inputs:
- AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase05_WeatherRoutingHardening_Implementation.txt
- AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase05_WeatherRoutingHardening_Strict.txt
- LogsAndExports/Logs/TechAgentMarkdown/TechAgent_20260905_230006_36688.md
- LogsAndExports/Logs/TechAgentMarkdown/TechAgent_20260905_232133_36688.md
 
Problem statement:
- The weather routing hardening is mostly complete: the ZIP extraction assertion passes, the build passes, and the weather-specific logic remains provenance-aware.
- One exact remaining outage remains:
  - `AgentOrchestratorTests.RunAsync_ExecuteMode_RepeatedFailingNoaaCallsWithVaryingArgs_TriggersFailureStreakGuard`
- The current execute-mode path returns the generic weather clarification message:
  - `I could not verify a sufficiently confident...`
- The expected result is the explicit failure-streak guard marker:
  - `NOAA_FORECAST_FAILURE_STREAK_GUARD`
- The latest output also indicates the attempted repair removed a premature loop-continue path and preserved the existing guard marker, but the guard still does not win over the generic clarification route. The bug is now narrowed to execute-mode state propagation and guard precedence.
 
Required code work:
- Trace the execute-mode flow that decides between the NOAA repeated-failure guard and the generic weather clarification response.
- Restore precedence so the NOAA failure-streak guard wins when repeated NOAA requests fail with varying arguments and the guard threshold is reached.
- Keep the generic clarification path only for low-confidence or insufficiently proven weather requests, not for explicitly triggered repeated-failure guards.
- Preserve the existing ZIP provenance, confidence threshold, margin gate, explicit user-ZIP behavior, authorization, and clarification logic.
- Do not weaken weather safety gates or execution safety rules.
 
Implementation constraints:
- Keep this repair narrow and specific to the final failing guard precedence issue.
- Do not broaden into unrelated weather enhancement work or unrelated orchestrator changes.
- Do not relax confidence gating, provenance requirements, or authorization checks to satisfy the test.
- Do not reintroduce the generic clarification fallback before the failure-streak guard has been evaluated.
 
Minimum tests to add/update:
- Fix and pass the exact failing assertion:
  - `AgentOrchestratorTests.RunAsync_ExecuteMode_RepeatedFailingNoaaCallsWithVaryingArgs_TriggersFailureStreakGuard`
- Keep the existing weather-routing regression coverage green.
- If a small guard-specific regression test is needed, add only the precise test that covers the precedence bug.
 
Validation commands:
- dotnet build src/TechToolbox.Agent/TechToolbox.Agent.csproj -c Release
- dotnet test src/TechToolbox.Agent/Tests/TechToolbox.Agent.Tests.csproj -c Release --filter "Orchestrator|Weather|NOAA|ZIP|Search|Routing|Strict"
 
Deliverable:
Return changed files, the corrected execute-mode precedence logic, the final guard behavior, and proof that the NOAA failure-streak assertion passes without weakening the weather-routing safeguards.
 
Step budget (hard limits):
1) Discovery: <= 6 read/search tool calls.
2) Edits: <= 8 file edits total.
3) Validation: 1 build + 1 targeted test run; allow up to 2 repair cycles if failures are phase-related.
4) Stop once acceptance criteria pass.
 
Loop guards:
- If the fix expands beyond the execute-mode guard precedence issue, stop and keep the patch narrow.
- If the generic weather clarification still wins over the failure-streak guard, stop and restore the precedence ordering.
- If confidence, provenance, or authorization gates are weakened to satisfy the test, stop and restore the original safety logic.
- If the guard still does not return `NOAA_FORECAST_FAILURE_STREAK_GUARD`, stop and trace the exact state propagation path instead of broadening weather logic.
 
Fallback behavior:
- Fallback A: repair the execute-mode state/decision precedence so the failure-streak guard is evaluated before generic clarification fallback.
- Fallback B: if the issue is in the message wiring or terminal guard propagation, fix that wiring only and keep the rest of the weather logic unchanged.
- Fallback C: after two failed repair cycles, emit FAILED_VALIDATION with the exact failing assertion and the current guard precedence path.
 
Acceptance criteria:
- The exact failing assertion passes.
- The execute-mode result includes `NOAA_FORECAST_FAILURE_STREAK_GUARD` for repeated NOAA failures with varying arguments.
- Weather provenance, confidence gates, and user-ZIP handling remain intact.
- The general orchestrator safety rules remain unchanged.
 
Output results in markdown using this structure:
1) Summary
2) Files changed
3) Weather routing and failure-guard notes
4) Tests added/updated
5) Validation results
6) Step-budget report (planned vs actual counts)