Skip to content

Add idempotency_token to job_runs resource#5882

Open
radakam wants to merge 6 commits into
mainfrom
job-runs-idempotency-wait-for-completion
Open

Add idempotency_token to job_runs resource#5882
radakam wants to merge 6 commits into
mainfrom
job-runs-idempotency-wait-for-completion

Conversation

@radakam

@radakam radakam commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Changes

Extends the experimental (direct-engine) job_runs resource with:

  • Wait for completionWaitAfterCreate polls until the run reaches a terminal state (TERMINATED/SKIPPED); only INTERNAL_ERROR fails the deploy, other result states surface as readable state.
  • Readable output fields — the run's output (state, run_id, run_page_url, ...) is exposed so downstream resources can reference e.g. ${resources.job_runs.<name>.state.result_state}.
  • Idempotent retries — an idempotency_token (SHA-256 of the RunNow request) is computed automatically and sent on run-now, so a retried deploy reuses the existing run instead of starting a duplicate. A user-set idempotency_token is rejected with a clear validation error.

Also hardens the shared direct-engine CRUD test so WaitAfterCreate's result is compared against a fresh read taken after the wait (a run legitimately transitions RUNNING → TERMINATED).

Why

Triggering a job during bundle deploy previously required scripts outside the bundle, and re-running a run without waiting left output fields unavailable to dependent resources and risked duplicate runs on retry. This makes job_runs deployments reliable and composable (Milestone 2: idempotency + wait for completion).

Tests

  • Unit: idempotency-token stability/determinism, preset-token override, and validation rejection.
  • Acceptance:
    • idempotent_recreate — retry mid-run (with and without a recorded run id); asserts run-now fires with one shared token and no duplicate run is created.
    • wait_output — downstream job reads the run's resolved result_state; redeploy is a no-op (no perpetual drift).

@radakam radakam temporarily deployed to test-trigger-is July 9, 2026 14:20 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 9, 2026 14:20 — with GitHub Actions Inactive
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: 7faf08b

Run: 29327359653

Env 🟨​KNOWN 🔄​flaky 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
💚​ aws linux 4 4 230 1089 5:53
💚​ aws windows 4 4 232 1087 7:23
💚​ aws-ucws linux 4 4 316 1006 9:43
💚​ aws-ucws windows 4 4 318 1004 9:32
🟨​ azure linux 1 1 4 230 1088 9:28
🟨​ azure windows 3 2 1 4 230 1086 10:42
💚​ azure-ucws linux 4 4 318 1003 8:39
💚​ azure-ucws windows 4 4 320 1001 8:08
💚​ gcp linux 4 4 229 1090 5:10
💚​ gcp windows 4 4 231 1088 7:20
10 interesting tests: 4 SKIP, 3 KNOWN, 2 flaky, 1 RECOVERED
Test Name aws linux aws windows aws-ucws linux aws-ucws windows azure linux azure windows azure-ucws linux azure-ucws windows gcp linux gcp windows
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/recreate/embedding_dimension 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🔄​ TestAccept/selftest/record_cloud/pipeline-crud/DATABRICKS_BUNDLE_ENGINE=direct ✅​p ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p ✅​p
🔄​ TestAccept/selftest/record_cloud/pipeline-crud/DATABRICKS_BUNDLE_ENGINE=terraform ✅​p ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p ✅​p
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestFetchRepositoryInfoAPI_FromRepo 💚​R 💚​R 💚​R 💚​R 🟨​K 🟨​K 💚​R 💚​R 💚​R 💚​R
🟨​ TestFetchRepositoryInfoAPI_FromRepo/root 💚​R 💚​R 💚​R 💚​R 🟨​K 💚​R 💚​R 💚​R 💚​R
🟨​ TestFetchRepositoryInfoAPI_FromRepo/subdir 💚​R 💚​R 💚​R 💚​R 🟨​K 💚​R 💚​R 💚​R 💚​R
Top 10 slowest tests (at least 2 minutes):
duration env testname
6:30 aws-ucws windows TestAccept
6:14 gcp windows TestAccept
6:10 aws windows TestAccept
6:07 azure-ucws windows TestAccept
2:57 azure linux TestAccept
2:56 gcp linux TestAccept
2:51 aws linux TestAccept
2:50 aws-ucws linux TestAccept
2:49 azure-ucws linux TestAccept
2:30 aws-ucws windows TestAccept/bundle/deploy/mlops-stacks/DATABRICKS_BUNDLE_ENGINE=terraform

@radakam radakam temporarily deployed to test-trigger-is July 10, 2026 09:31 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 10, 2026 09:31 — with GitHub Actions Inactive
@radakam radakam force-pushed the job-runs-idempotency-wait-for-completion branch from acf313b to 3a5ea16 Compare July 13, 2026 09:13
@radakam radakam temporarily deployed to test-trigger-is July 13, 2026 09:13 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 13, 2026 09:13 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 08:30 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 08:30 — with GitHub Actions Inactive
radakam added 4 commits July 14, 2026 12:07
Job runs now send an automatic idempotency_token on run-now so a retried
deployment reuses the existing run instead of triggering a duplicate. The
token is the hex SHA-256 of the RunNow request (job_id cleared of the token
itself), computed in DoCreate on a copy so it is never persisted to state.

A user-set idempotency_token is rejected at validation time, and the local
testserver now deduplicates run-now by token so the behavior is covered by
tests.
Covers the idempotency token end-to-end: deploy triggers a run, the run is
dropped from local state (keeping the job so job_id and the derived token stay
stable), and a redeploy re-issues run-now. The backend dedupes on the token and
returns the existing run, so no duplicate is created.

Drop the DoCreate-level TestJobRunIdempotentCreate since the acceptance test now
covers that path end-to-end; the token helper's unit tests remain.
Pick up GOOSOnPR fields added by the acceptance harness on main (#5876,
#5879), which restrict OS-independent bundle tests to Linux on PRs.
Add WaitAfterCreate to the job_runs direct-engine resource: it polls
until the run reaches a terminal state and returns the run's output
fields (state, run_id, run_page_url, ...) so downstream resources can
read e.g. ${resources.job_runs.x.state.result_state}. A FAILED result
is surfaced as readable state rather than failing the deploy; only
INTERNAL_ERROR fails it.

Add the wait_output acceptance test (a downstream job reads result_state,
and a redeploy stays a no-op so the resolved value doesn't churn), and
extend idempotent_recreate to cover both mid-run retry paths: a lost run
id (token dedupes run-now) and a recorded run id (retry is a no-op).
Regenerate the redeploy golden, which now shows the run TERMINATED.
@radakam radakam force-pushed the job-runs-idempotency-wait-for-completion branch from 51dca78 to 66ca15a Compare July 14, 2026 10:07
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 10:07 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 10:07 — with GitHub Actions Inactive
Add a changelog fragment for the idempotency + wait-for-completion work.

The shared CRUD harness compared WaitAfterCreate's result against the read
taken right after DoCreate. A job run transitions RUNNING -> TERMINATED while
we wait, so compare against a fresh read taken after the wait instead, mirroring
how DoUpdate is already validated.
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 10:10 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 10:10 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 11:00 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is July 14, 2026 11:00 — with GitHub Actions Inactive
@radakam radakam requested a review from denik July 14, 2026 11:52
@radakam radakam marked this pull request as ready for review July 14, 2026 11:52
@github-actions

Copy link
Copy Markdown
Contributor

Approval status: pending

/acceptance/bundle/ - needs approval

15 files changed
Suggested: @denik
Also eligible: @pietern, @shreyas-goenka, @janniklasrose, @andrewnester, @anton-107, @lennartkats-db

/bundle/ - needs approval

6 files changed
Suggested: @denik
Also eligible: @pietern, @shreyas-goenka, @janniklasrose, @andrewnester, @anton-107, @lennartkats-db

General files (require maintainer)

Files: .nextchanges/bundles/job-runs-idempotency-wait.md, libs/testserver/fake_workspace.go, libs/testserver/jobs.go
Based on git history:

  • @denik -- recent work in libs/testserver/, bundle/direct/dresources/, bundle/config/validate/

Any maintainer (@andrewnester, @anton-107, @denik, @pietern, @shreyas-goenka, @simonfaltum, @renaudhartert-db, @janniklasrose, @lennartkats-db) can approve all areas.
See OWNERS for ownership rules.

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.

2 participants