fix(approvals): poll with originating context, not empty result.raw#5
Merged
Conversation
CoreAdapter.handle_approval read workflow_id/run_id/activity_id from result.raw, but Core's evaluate response never echoes them, so a configured ApprovalPoller polled with empty IDs. Thread the originating ActivityContext into handle_approval(result, context=None) — the async lifecycle path builds it from the event, the async hook path passes the span-resolved context — preferring it over result.raw, which is kept as a backward-compatible fallback. Call sites pass context only when the adapter signature accepts it (adapter_accepts_context, the same inspection already used for on_completed_hook_result), so adapters defined as handle_approval(self, result) keep working. The sync hook path was already correct. Mirrors the openbox-sdk-ts base SDK fix.
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.
Problem
CoreAdapter.handle_approvalreadworkflow_id/run_id/activity_idfromresult.raw, but Core's public evaluate response(
GovernanceVerdictPublicResponse) never echoes them. So with a realApprovalPollerconfigured (HITL),POST /api/v1/governance/approvalwaspolled with empty IDs — Core could never match the pending approval, and
the poll rejected/timed out.
Reachable only when a poller is wired; the default no-poller adapter rejects
outright (fail-safe), which is why it stayed latent. The same root cause
exists in the
openbox-sdk-tsbase SDK and is fixed there too.Fix
Thread the originating context into the approval seam, mirroring
on_completed_hook_result(result, context):handle_approval(result, context=None)— optionalActivityContext;CoreAdapterprefers it and keepsresult.rawas a backward-compat fallback.workflow_id/run_idfrom the payload;activity_idfrom the envelope).and is unchanged.
Backward compatibility
Call sites pass
contextonly when the adapter's signature accepts it, viaadapter_accepts_context— the same signature-inspection already used foron_completed_hook_result. Adapters defined ashandle_approval(self, result)keep working unchanged.
Tests
+3 tests in
test_runtime_delegation.py: polls with context IDs whenresult.rawis empty, raw fallback without context, and the lifecyclethreading the event context.
ruff: cleanmypy: at the pre-existing baseline (no new errors)