fix(generation): repair invalid model output - #313
Merged
Conversation
This was referenced Sep 1, 2026
Collaborator
Author
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Sep 1, 2026
anandpant
force-pushed
the
gen/gen-repair-loop
branch
2 times, most recently
from
September 1, 2026 03:41
0f395b2 to
388d06d
Compare
anandpant
force-pushed
the
gen/gen-mindmap-nested
branch
from
September 1, 2026 18:38
47cc19f to
c35165e
Compare
anandpant
force-pushed
the
gen/gen-repair-loop
branch
3 times, most recently
from
September 1, 2026 18:52
d811c8b to
cc8206f
Compare
anandpant
force-pushed
the
gen/gen-mindmap-nested
branch
from
September 1, 2026 18:52
c35165e to
779498f
Compare
anandpant
force-pushed
the
gen/gen-repair-loop
branch
from
September 1, 2026 19:27
cc8206f to
e71a8ae
Compare
anandpant
force-pushed
the
gen/gen-mindmap-nested
branch
from
September 1, 2026 19:27
779498f to
308fe6e
Compare
anandpant
force-pushed
the
gen/gen-repair-loop
branch
from
September 1, 2026 20:15
e71a8ae to
135f329
Compare
anandpant
force-pushed
the
gen/gen-mindmap-nested
branch
from
September 1, 2026 20:15
308fe6e to
0cac637
Compare
anandpant
force-pushed
the
gen/gen-repair-loop
branch
from
September 1, 2026 21:01
135f329 to
237076a
Compare
Merge activity
|
## Scope
- Add a configurable semantic repair budget with `maxRepairAttempts: 2` by default, allowing one more semantic repair when the first repair introduces a different violation class.
- Repair invalid JSON/IR with the prior output plus all validator diagnostics; regenerate truncated output fresh.
- Promote `flowchart.start_has_incoming` and `flowchart.self_loop`, including their validator hints, at the top of repair requests. Start-node failures reroute to the first process after start; self-loops reroute to an earlier distinct process or decision node.
- Preserve the original malformed candidate and its text/raw/error/usage when a repair call fails or returns invalid output; enrich it with both attempts' diagnostics.
- Catch typed repair-call failures while allowing interruption to propagate, and always record `sketchi_generation_repairs{outcome="failed"}` for failed repair calls.
- Classify truncation from only the latest model response so a truncated regeneration that is still invalid proceeds to semantic repair.
- Preserve every existing node and label except the minimal edit required by reported diagnostics, and restate the original diagram type, scenario, parsed minimum node count, required node labels, and required branch labels on every repair call.
- Keep transport retries and timeouts around each model call, normalize empty optional edge labels, and extract the first complete JSON object when a model appends trailing output.
- Bypass Cloudflare AI Gateway cache in fresh mode with `cf-aig-skip-cache: true`.
## Expected latency tradeoff
- Each provider attempt has a 30-second timeout and up to two transient retries with 250 ms and 500 ms backoff, so one exhausted model call can take up to 90.75 seconds.
- A malformed initial response can trigger two complete repair calls, making the configured generation-policy ceiling 272.25 seconds before outer request overhead. Requests above 120 seconds are therefore expected in the worst repair/retry cases; the added latency is the tradeoff for recovering when a repair introduces a new violation such as dropping below a requested minimum node count.
- The deployed probe permits 302.25 seconds: the full 272.25-second policy budget plus a 30-second margin.
## Proof
- `pnpm nx test diagram-generation --skip-nx-cache` - 37/37 passed at `237076a`.
- `pnpm nx run-many -t typecheck,test,build --skip-nx-cache` - passed at `237076a`.
- `pnpm nx build-storybook diagram-ui --skip-nx-cache` - passed at `237076a`.
- Added typed repair-failure preservation, invalid-repair original-candidate preservation, interruption propagation, failed repair metric, latest-response truncation classification, priority start-node and self-loop correction, preserve-content/hard-requirement repair instructions, repair-introduced minimum violation recovery, cache bypass, requested-cycle, minimum-count, diagnostic-composition, and repair-success fixtures.
This is PR 5 of 6 in the generation-reliability stack.
graphite-app
Bot
force-pushed
the
gen/gen-mindmap-nested
branch
from
September 1, 2026 21:27
0cac637 to
f014afc
Compare
graphite-app
Bot
force-pushed
the
gen/gen-repair-loop
branch
from
September 1, 2026 21:28
237076a to
9f64991
Compare
Contributor
Sketchi Icons PreviewStatus:
Preview Worker cleanup has completed. |
Contributor
Sketchi Web PreviewStatus:
Preview Worker cleanup has completed. |
Contributor
Sketchi Playground / Studio PreviewStatus:
Preview Worker cleanup has completed. |
Contributor
Sketchi Eval Harness PreviewStatus:
Preview Worker cleanup has completed. |
Contributor
Sketchi Excalidraw Workspace PreviewStatus:
Preview Worker cleanup has completed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Scope
maxRepairAttempts: 2by default, allowing one more semantic repair when the first repair introduces a different violation class.flowchart.start_has_incomingandflowchart.self_loop, including their validator hints, at the top of repair requests. Start-node failures reroute to the first process after start; self-loops reroute to an earlier distinct process or decision node.sketchi_generation_repairs{outcome="failed"}for failed repair calls.cf-aig-skip-cache: true.Expected latency tradeoff
Proof
pnpm nx test diagram-generation --skip-nx-cache- 37/37 passed at237076a.pnpm nx run-many -t typecheck,test,build --skip-nx-cache- passed at237076a.pnpm nx build-storybook diagram-ui --skip-nx-cache- passed at237076a.This is PR 5 of 6 in the generation-reliability stack.