Reject GitHub PR effects after cancellation - #151
Conversation
|
Hourly maintenance: review routing was not applied because the head commit's combined status is still |
There was a problem hiding this comment.
The fix is correct and the new regression test covers both affected paths precisely.
SQL changes (src/runtime/postgres.ts)
registerGitHubPullRequestEffect — The added predicate AND execution.state IN ('PROVISIONING','RUNNING') is placed correctly in the locked-row query that gates the entire registration path. After requestExecutionCancellation is called on a PROVISIONING or RUNNING execution the execution transitions to CANCEL_REQUESTED (the deferred path — no immediate CANCELLED for active workers). The lease on the attempt is still technically valid at that point, but CANCEL_REQUESTED is not in the allowed set, so the query returns zero rows and the "Execution effect capability is not current" error is thrown before any INSERT can reach the effects table. That is exactly the right behavior.
reportGitHubPullRequestEffect — The new JOIN dispatch_executions … AND execution.state IN ('PROVISIONING','RUNNING') is structurally symmetric with the registration guard. The effect row is only locked and read when the execution is in an active state, so a cancelled (or cancel-requested) execution cannot have its already-registered effect reported after the fact. The FOR UPDATE OF effect lock scope is unchanged — only the effect row is exclusively locked, not the execution, which is consistent with the rest of the method.
Test coverage (test/e2e/supplied-wake-context-persistence.test.ts)
The new test exercises two independent sub-scenarios using separate executions:
-
Registration blocked after cancellation — Calls
requestExecutionCancellationwhile the execution is inPROVISIONING(freshly claimed, never transitioned toRUNNING). This producesCANCEL_REQUESTED, leaving the lease valid but the execution state disqualified. Then asserts both the thrown error and that zero effect rows were written. Clean. -
Reporting blocked after cancellation — Registers the effect successfully (correct: execution is still
PROVISIONINGat that point), then cancels, then attempts to report. Asserts the "capability is invalid" error and that the effect row remains inREGISTEREDstate with all PR fields null. The effect row cleanup (DELETE) is performed at the end. Clean.
Both executions are already in a cancelled/cancel-requested terminal state by the time the test ends, so no dangling state is left in the database.
CI
All 331 unit tests pass, both typechecks (typecheck and typecheck:test) are clean, pnpm audit --prod --audit-level high reports no vulnerabilities, and all required checks (CI, Dependency Review, CodeQL) are green.
Summary
Testing
corepack pnpm typecheckcorepack pnpm typecheck:testcorepack pnpm test:e2e -- test/e2e/supplied-wake-context-persistence.test.ts(blocked: no container runtime; the configured suite also ran all e2e tests and failed where Docker/Helm are required)Fixes #150