Repository navigation
perf(dispatch): resolve a run's authority once before launch - #1469
Open
MTG-Thomas wants to merge 2 commits into
Open
MTG-Thomas wants to merge 2 commits into
MTG-Thomas wants to merge 2 commits into
Conversation
The workflow consumer minted a run's claims credentials, which loads the run's authority inside the minter's read-only snapshot, and then opened a second session to load the same authority again only to read the run user and provenance. Claims credentials now carry the authority they were minted from, and the consumer reuses it. A legacy-format token is signed without reading the authority, so that route still loads it as before. load_run_user also read the user's row twice: once for identity kind and active state, then again inside build_authorization_context. It now reads the row once and builds the context from it. The promoter test that simulated a deletion between those two reads now simulates the user being gone when the recheck reads them, the only window left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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 And Result
Before a workflow run reaches its worker, the consumer reads the run's authority twice and the run's user row twice:
issue_run_credentialsmints claims from the run'sRuntimeAuthorityin a read-only snapshot, then the consumer opens another session and loads the same authority again for provenance.load_run_userreads theusersrow for identity/active state, thenbuild_authorization_contextreads the same row again.Each statement is cheap in Postgres (0.01-0.05 ms), but they run one after another on the dispatch path at about 1-1.5 ms per round trip.
Now:
IssuedAccessToken.authority,RunCredentials.authority), and the consumer reuses it. Legacy-format tokens are signed without reading the authority, so that route still loads it, as before.load_run_userreads the user row once and passes it to the newauthorization_context_for_user_row;build_authorization_contextkeeps its signature and delegates to it.Provenance is still read in its own short session, so transactions per run are unchanged. No protocol, schema, settings, DTO or UI change.
One promoter test simulated the initiator being deleted between the two user-row reads. That window no longer exists, so the test now covers an initiator already gone when it is read (
test_an_initiator_deleted_before_the_recheck_fails_that_row_only).Measurements
Sync
POST /api/workflows/executeagainst a remote worker, one request in flight, alternating builds (before, fix, before, fix), spans exported to a local sink. Illustrative numbers from one host:Contribution Basis And Tracking
Actual use: our production instance runs tens of thousands of short, mostly webhook-driven workflow executions a day, and per-run dispatch overhead is a large share of its CPU. We found these repeated reads while tracing dispatch with the OpenTelemetry work discussed in #1386. No issue was filed for this change; happy to open one if you prefer to track it there.
Verification
usersreads; no authority carried on credentials) and pass with the change../test.sh tests/unit/authorization tests/unit/jobs/consumers tests/unit/jobs/schedulers/test_deferred_execution_promoter.py tests/unit/services/test_access_check_policies.py tests/unit/services/test_access_check_writer.py tests/unit/core/test_execution_policy_authority.py tests/unit/services/test_legacy_broker_drain.py: 866 passed../test.sh tests/e2e/api/test_executions.py tests/e2e/api/test_access_check_attribution.py tests/e2e/api/test_agent_workflow_tool_execution.py tests/e2e/platform/test_workflow_conversion.py: 29 passed../test.sh quality api: pyright 0 errors; Ruff passed../test.sh pr-preflighton the rebased head: repository checks, lint/types, 13,444 backend unit tests and 663 client test files passed. The local CodeQL step did not run (no CodeQL CLI on this host); CI runs it.Product Updates
Omit: routine performance repair, with canonical disposition in
product-updates/dispositions/pr-1469.json, following current authoring policy.🤖 Generated with Claude Code