-
Notifications
You must be signed in to change notification settings - Fork 0
Fix illustration pipeline: poll background job token to display generated images in UI #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1359,29 +1359,103 @@ $(function () { | |||
| $gallery.removeClass("d-none"); | ||||
| } | ||||
|
|
||||
| // Poll the illustration job token until it reaches a terminal state, | ||||
| // then fetch the full payload and render the images. | ||||
| function _pollIllustrationJob(illustToken, _errorRetries) { | ||||
| var retries = _errorRetries || 0; | ||||
| $.ajax({ | ||||
| url: "/progress/" + illustToken, | ||||
| method: "GET", | ||||
| success: function (data) { | ||||
| if (data.status === "done") { | ||||
| // Job finished – fetch the full payload to get the illustrations array. | ||||
| $.ajax({ | ||||
| url: "/progress/" + illustToken + "/full", | ||||
| method: "GET", | ||||
| success: function (full) { | ||||
| renderIllustrations(full.illustrations || []); | ||||
| }, | ||||
| error: function () { | ||||
| renderIllustrations([]); | ||||
| }, | ||||
| complete: function () { | ||||
| $("#illustrations-spinner").addClass("d-none"); | ||||
| $("#illustrations-spinner-label").addClass("d-none").text(""); | ||||
| _enableExportButtons(); | ||||
|
Comment on lines
+1372
to
+1384
|
||||
| }, | ||||
| }); | ||||
| } else if (data.status === "error") { | ||||
| showAlert( | ||||
| data.error || | ||||
| "Illustration generation failed. The AI service may be rate-limited — wait a few minutes and try again." | ||||
| ); | ||||
| $("#illustrations-spinner").addClass("d-none"); | ||||
| $("#illustrations-spinner-label").addClass("d-none").text(""); | ||||
| _enableExportButtons(); | ||||
| } else { | ||||
| // Still running – update the spinner label and keep polling. | ||||
| var stepText = data.step || "Generating\u2026"; | ||||
| var current = data.current || 0; | ||||
| var total = data.total || 0; | ||||
| var label = total > 0 | ||||
| ? stepText + " (" + current + "/" + total + ")" | ||||
| : stepText; | ||||
| $("#illustrations-spinner-label").text(label); | ||||
| setTimeout(function () { | ||||
| _pollIllustrationJob(illustToken, 0); | ||||
| }, 3000); | ||||
| } | ||||
| }, | ||||
| error: function () { | ||||
| // Retry on transient network errors, up to 10 attempts. | ||||
| if (retries < 10) { | ||||
| setTimeout(function () { | ||||
| _pollIllustrationJob(illustToken, retries + 1); | ||||
| }, 5000); | ||||
| } else { | ||||
| showAlert( | ||||
| "Lost connection to the server while waiting for illustrations. Please check your connection and try again." | ||||
| ); | ||||
| $("#illustrations-spinner").addClass("d-none"); | ||||
| $("#illustrations-spinner-label").addClass("d-none").text(""); | ||||
| _enableExportButtons(); | ||||
| } | ||||
|
Comment on lines
+1409
to
+1422
|
||||
| }, | ||||
| }); | ||||
| } | ||||
|
|
||||
| $("#btn-generate-illustrations").on("click", function () { | ||||
| clearAlerts(); | ||||
| var $btn = $(this); | ||||
|
||||
| var $btn = $(this); |
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial POST to /generate_illustrations no longer has any timeout. That route should return quickly with an illustration_token; without a timeout a stalled request can leave the UI stuck in “Starting…”. Consider adding a short timeout (and treating timeouts like other transient errors) since the long-running work is now done via polling.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -439,6 +439,7 @@ <h6 class="fw-semibold mb-3"><i class="bi bi-pencil-square me-2"></i>Revise Indi | |||||
| <h6 class="text-muted mb-2">Illustrations</h6> | ||||||
| <button class="btn btn-outline-primary" id="btn-generate-illustrations"> | ||||||
| <span class="spinner-border spinner-border-sm d-none me-2" id="illustrations-spinner"></span> | ||||||
| <span id="illustrations-spinner-label" class="d-none me-1"></span> | ||||||
|
||||||
| <span id="illustrations-spinner-label" class="d-none me-1"></span> | |
| <span id="illustrations-spinner-label" class="d-none me-1" aria-live="polite" role="status"></span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The polling GET requests don’t set a timeout. If a /progress/ request hangs (e.g., stalled connection), neither the success nor error callback will fire, so polling stops and the spinner/export buttons never recover. Add a reasonable timeout for the lightweight poll (and handle timeout in the error path) so the UI can continue retrying or fail gracefully.