Skip to content

fix(api): revert approval to pending when resume fails to start - #6384

Open
lorenzozanee wants to merge 1 commit into
Agenta-AI:mainfrom
lorenzozanee:fix/approval-resume-failure-5592
Open

fix(api): revert approval to pending when resume fails to start#6384
lorenzozanee wants to merge 1 commit into
Agenta-AI:mainfrom
lorenzozanee:fix/approval-resume-failure-5592

Conversation

@lorenzozanee

@lorenzozanee lorenzozanee commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Answering a parked approval marks the row as responded before the resumed run is known to have started. When the workflow service returns 500 or the enqueue fails, the approval is lost — the run never starts and there is no way to retry.

This change reverts the row to pending with the error stored in resolution and returns 502 so the approval remains actionable and the failure is visible. For the async worker path, the revert happens only on the final retry to avoid races with concurrent retries. Also fixes watch publishing to emit pending on revert.

Fixes #5592.

Testing

Verified locally

  • pytest oss/tests/pytest/unit/sessions/test_respond_interaction_resume_failure.py — 4 new tests (inline invoke, dispatcher, kiq enqueue failure, and success path)
  • pytest oss/tests/pytest/unit/sessions/test_respond_interaction_enqueue.py — 3 existing tests still pass
  • ruff format / ruff check — clean

Added or updated tests

  • api/oss/tests/pytest/unit/sessions/test_respond_interaction_resume_failure.py — covers three enqueue paths reverting to pending with 502 and the success path staying responded.

QA follow-up

  • Park an agent on a tool needing approval, make the resumed run fail to start, POST the approval — expect 502 and row stays pending with resolution.error.
  • Verify normal approval flow (playground and out-of-band) still moves to responded/resolved.

Demo

API-only fix — approval resume failure is backend behavior. Screenshot of the new regression tests passing locally and the 502 revert behavior:

approval revert demo

test evidence

https://github.com/user-attachments/assets/demo-approval-revert.mp4

Checklist

  • Demo shows the real app running this branch (not a mock-up or recreated UI), or is marked N/A
  • Relevant tests pass locally
  • Relevant linting and formatting pass locally
  • I have signed the CLA, or I will sign it when the bot prompts me

Answering a pending approval currently marks the row as responded
before the detached workflow run is known to have started. If the
workflow service returns 500 or the enqueue fails, the approval is
consumed and the human has no way to retry, with no visible error on
the row.

Revert the interaction to pending with the error recorded in
resolution and surface a 502 so the caller knows the run never
started. For the async worker path, revert only on the final retry
so concurrent retries cannot double-enqueue.

Closes Agenta-AI#5592
@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@lorenzozanee is attempting to deploy a commit to the agenta projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

✅ Thanks @lorenzozanee! This PR now meets the contribution requirements and has been reopened. A maintainer will review it soon.

@github-actions github-actions Bot added the incomplete-pr PR is missing required template sections or a demo recording label Aug 31, 2026
@github-actions github-actions Bot closed this Aug 31, 2026
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot removed the incomplete-pr PR is missing required template sections or a demo recording label Aug 31, 2026
@github-actions github-actions Bot reopened this Aug 31, 2026

@mmabrouk mmabrouk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the pr. i found one issue that needs a change before qa.

request=invoke_request,
)
except Exception as exc: # noqa: BLE001 — revert answered gate so retry stays possible
err = str(exc)[:500] or exc.__class__.__name__

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception text is not safe to return or persist here. WorkflowDetachedStartFailed includes up to 500 bytes of the runner's raw response body (workflows/service.py:734-737), and this value is copied into both resolution.error and the HTTP 502 detail. A failed resume can therefore expose internal response data to the project user and retain it in the interaction row. Log the original exception server-side, but store and return a stable sanitized message, with a support ID if needed. Apply the same sanitization in interactions_worker.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(bug) Answering an approval consumes it even when the resumed run never starts

3 participants