Fix-with-agent misdiagnoses a backend/infra run failure as a graph bug, destroys a correct workflow, then dead-loops
Summary
When a workflow run fails for a backend/infra reason (not a wiring problem), the "Fix with agent" repair turn (mode=Repair) treats it as a graph-wiring bug: it restructures a correct graph into a broken one, produces inconsistent intermediate graphs that the author-gate correctly rejects, and then dead-loops on repeated edit_workflow failures and gives up with no proposal.
Problem
Observed run (live)
A file-attachment workflow was built correctly as a 6-node native chain:
trigger -> research(agent) -> build_html(code_executor) -> upload_file(oh:storage_upload_file) -> get_link(oh:storage_get_link) -> send(GMAIL_SEND_EMAIL)
The run reached upload_file and failed with a pure backend error (unrelated to the graph):
tool_call `oh:storage_upload_file` failed: File upload failed: Backend returned 500 Internal Server Error
for POST_MULTIPART .../agent-integrations/file-storage/files: The specified bucket does not exist
(steps: research success, build_html success, upload_file error.)
What "Fix with agent" did
mode=Repair then:
- Tore out the
upload_fileandget_linknodes, collapsing the correct 6-node chain back to a broken 4-node shape (trigger -> research -> build_html -> send). - Left
send.attachmentbound to=nodes.get_link.item.json.urlwhileget_linkno longer existed, so the author-gate correctly rejected the dangling reference:required-arg resolvability check: arg resolved null in sandbox - rejecting node=send field=attachment expression==nodes.get_link.item.json.url - Looped on
edit_workflow(4xError), hit the middleware halt (repeated tool failure - halting run ... tool=edit_workflow step=8), and endedtrail_off=true has_proposal=false- i.e. it gave up with no fix.
Root cause
The repair turn does not distinguish a backend/infra failure ("the specified bucket does not exist", a 500 from the file-storage service) from a graph-wiring failure (a null-resolved binding, a wrong slug). A backend 500 means "the graph is fine, the environment is broken" - the correct repair is to surface that and NOT touch the graph. Instead the agent assumes the wiring is wrong, restructures a correct graph, and destroys it.
Impact
- A correct, working workflow is degraded into a broken one by the repair flow whenever the backend has a transient/infra failure.
- The repair then dead-loops and delivers no proposal, so the user is left worse off than before clicking "Fix with agent".
- The graph the repair produced (4 nodes, no upload/link) cannot ever attach a file even after the backend recovers.
Steps to reproduce
- Build a workflow whose run fails for a backend reason (e.g.
oh:storage_upload_filewhen the file-storage bucket is misconfigured - see #5174). - Run it; it fails at the upload step with the backend 500.
- Click "Fix with agent".
- Observe: it restructures the (correct) graph, the gate rejects inconsistent intermediates,
edit_workflowloops, and the turn ends with no proposal (trail_off).
Environment: desktop dev build, current file-attachment branch (#5148). The gate carve-out and native-tool handling in #5148 are working correctly here - the initial build was correct and the run failed loudly at the right node; this issue is strictly about the repair turn's misdiagnosis.
Solution (suspected)
The repair flow needs to classify the run's failure before acting:
- A tool_call failure whose error is a provider/backend transport error (5xx, "bucket does not exist", connection/timeouts) is not a graph bug. Surface it to the user as a backend/infra failure and do not restructure the graph. (The core already classifies budget-exhausted errors as
kind="budget"and skips them - a similarkind="backend"/"infra"classification for run failures could gate the repair.) - Only a genuine wiring/validation failure (null-resolved required arg, unreal slug, dangling reference) should trigger a graph edit.
- Independently, the repair should not collapse a correct native file chain back to an in-agent shape - but the primary fix is the diagnosis gate above.
Acceptance criteria
- [ ] No graph destruction on backend failure - a run that fails with a backend/infra error (e.g. storage 500) does not cause "Fix with agent" to restructure or degrade a correct graph.
- [ ] Actionable message - the repair surfaces the backend failure ("the file-storage backend returned an error; your workflow is fine") instead of silently mangling the graph.
- [ ] No dead-loop - the repair turn either proposes a real fix or clearly explains the backend failure; it does not exhaust
edit_workflowretries andtrail_offwith no proposal. - [ ] Regression coverage - a test that a backend-class run error does not trigger a graph edit.
Related
- #5148 - the file-attachment PR; its gate carve-out + native-tool handling are working (the initial build was correct and the failure was surfaced loudly). This issue is about the repair turn only.
- #5174 - the storage bucket 500 that triggered this scenario. With the bucket provisioned the run succeeds and no repair is invoked, but the misdiagnosis remains latent for any future backend failure.
Verified — unfixed on main (6be58a9ab), and the root cause is visible in the repair brief itself
The diagnosis in this issue is correct. The repair turn has no way to express "the graph is fine, the environment is broken" — the brief it is handed structurally demands a graph change.
The brief is rendered server-side from BuilderRequest (flows/ops_part_10.rs:310-314), and builder_prompt resolves to the vendored copilot (flows/agents/workflow_builder/mod.rs:22 — pub use tinyflows_copilot::builder as builder_prompt). The Repair arm is vendor/tinyflows/crates/tinyflows-copilot/src/builder.rs:190-232:
BuildMode::Repair => {
let mut parts = vec![
DIRECTIVE_PROPOSE.to_string(),
String::new(),
format!(
"A run of this workflow failed (run id: {run_id}). Read the run with get_flow_run, \
diagnose why it failed, and propose a fix."
),
];
…
parts.push("Return the full corrected proposal.".to_string());
with (builder.rs:95-96):
const DIRECTIVE_PROPOSE: &str = "Design a tinyflows automation and return a workflow proposal for me to review. \
Do not save, enable, or run anything.";
So the turn opens with "Design a tinyflows automation and return a workflow proposal" and closes with "Return the full corrected proposal." — the only success condition offered is a changed graph. Nothing in the brief mentions that a run can fail for reasons outside the graph, and there is no permitted outcome of the form "no change needed; the failure is upstream."
That fully explains the observed run. Handed a correct 6-node chain and a backend 500 (The specified bucket does not exist), an agent required to return a corrected proposal has nothing to correct except the wiring — so it removes upload_file and get_link, leaves send.attachment bound to =nodes.get_link.item.json.url, and the author-gate correctly rejects the dangling reference. The edit_workflow dead-loop and trail_off=true has_proposal=false follow from being unable to satisfy an unsatisfiable instruction.
No classification exists. grep -rIn "bucket does not exist\|is_infra\|backend_failure" across the flows tree returns nothing; there is no infra-vs-wiring discrimination anywhere on the repair path. The inputs to make it are all present and already passed to the agent — run_id (flows_schema_part_01.rs:507-511), the run-level error string (:513-517), and failing_node_ids — they are simply never used to decide whether a graph change is the right answer.
The fix has two halves, and the second is the one that actually stops the damage
1. Classify the failure. A step that fails with an upstream HTTP 5xx from a service call is categorically different from a null-resolved binding or a bad slug. The run record already distinguishes them: in the reported run, research and build_html are success and upload_file is error carrying a backend 500. A correct graph that reached step 3 of 6 and died on an upstream error is strong evidence against a wiring fault — the first two nodes resolving proves the chain upstream of the failure is wired.
2. Give the repair turn a permitted "no change" outcome. This is the load-bearing part. Even with perfect classification, an agent told "Return the full corrected proposal" will still return a mutated graph, because that is the only shape of answer the brief accepts. The Repair arm needs an explicit alternative — return the graph unchanged with an explanation naming the infra fault — and DIRECTIVE_PROPOSE is the wrong directive to open a repair with, since it says "Design a tinyflows automation" to an agent whose job is to decide whether anything needs designing at all.
Concretely: a DIRECTIVE_REPAIR distinct from DIRECTIVE_PROPOSE, stating that a run can fail for environment reasons and that leaving a correct graph untouched is a valid and preferred outcome when the error is not a wiring fault.
Worth noting the change is in vendor/tinyflows, not this repo, so the fix is a tinyflows change plus a submodule bump — the same shape as any other copilot-prompt change.
Two things to add to the issue
- The damage is worse than "no fix delivered." The issue notes the repaired graph can never attach a file even after the backend recovers, which is right — but the sharper framing is that clicking "Fix with agent" on a transient infra failure destroys a working workflow, and the user has no indication that is what happened. Whatever lands should probably also be defensive about replacing a graph whose failing step is not itself implicated.
- Related infra dependency: the reported trigger (
oh:storage_upload_file→ "The specified bucket does not exist") is #5174. That is a separate bug, but it is the thing that makes this one reachable in normal use.
Leaving open.