Skip to content

fix(batchrouter): preserve prior LastJobStatus error on drain - #6958

Merged
achettyiitr merged 2 commits into
release/1.75.xfrom
fix.batch_rt_worker_draining
May 15, 2026
Merged

achettyiitr merged 2 commits into
release/1.75.xfrom
fix.batch_rt_worker_draining

Conversation

@achettyiitr

@achettyiitr achettyiitr commented May 14, 2026 •

Copy link
Copy Markdown
Member

Description

When a job is drained in the batch router's scheduleJobs (job expired, source not found, destination disabled, etc.), the ErrorResponse written to job_status was synthesized from an empty {} with just {"reason": "<drain reason>"}, e.g.

{ "reason": "job expired" }

Any upstream error from the previous delivery attempt that lived on job.LastJobStatus.ErrorResponse — fields like error, response, firstAttemptedAt — was clobbered, so by the time a job reached status Aborted with code 410 we'd lost all the context about why it had been failing.

Change

In router/batchrouter/worker.go, base the drained status's ErrorResponse on job.LastJobStatus.ErrorResponse instead of []byte("{}"). routerutils.EnhanceJSON then merges the new reason field into the existing object rather than replacing it.

-                ErrorResponse: routerutils.EnhanceJSON([]byte(`{}`), "reason", finalReason),
+                errResponse := routerutils.EnhanceJSON(job.LastJobStatus.ErrorResponse, "reason", finalReason)
+                ErrorResponse: errResponse,

After the fix, a drained job's ErrorResponse carries the prior upstream context alongside the drain reason:

{
  "error": "500 internal server error",
  "response": "upstream timed out",
  "firstAttemptedAt": "2024-01-01T00:00:00.000Z",
  "reason": "job expired"
}

ErrorCode stays 410 and JobState stays Aborted — no change to drain semantics, only what we surface to debuggers and downstream reporting.

Tests

New file router/batchrouter/worker_test.go with TestScheduleJobsDrainBranch covering three cases against a real scheduleJobs call (mocked jobsDB, fake drainer):

  1. preserves prior LastJobStatus error fields and stamps the drain reason — the bug-fix path. A job with a prior {"error":"…","response":"…","firstAttemptedAt":"…"} is drained; asserts all three fields survive and reason is stamped on top.
  2. synthesizes reason when LastJobStatus has no prior error response — first-attempt jobs (empty LastJobStatus.ErrorResponse) still end up with {"reason":"job expired"}. No regression on the existing behavior.
  3. uses source_not_found reason when the job's source is missing from the destination — the second branch of the same drain condition (!sourceFound) also benefits from the fix; the prior error is preserved alongside reason: "source_not_found".

Linear Ticket

  • Resolves INT-6358, INT-6356, INT-6349.

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

When a job is drained in batchrouter's scheduleJobs (job expired, source
not found, etc.) the ErrorResponse was synthesized from an empty {} with
just the drain reason, clobbering any prior upstream error fields from
LastJobStatus.ErrorResponse. Base the synthesized response on
job.LastJobStatus.ErrorResponse so error/response/firstAttemptedAt are
preserved alongside the new reason.
@achettyiitr
achettyiitr changed the base branch from master to release/1.75.x May 14, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves debuggability of batch router drained jobs by preserving any existing upstream error context in job.LastJobStatus.ErrorResponse and augmenting it with the drain reason, instead of overwriting the payload with a fresh {}.

Changes:

  • Update scheduleJobs drain-path status construction to base ErrorResponse on job.LastJobStatus.ErrorResponse and stamp reason onto it.
  • Add focused unit tests that execute the real scheduleJobs drain branch end-to-end (with mocked jobsDB) to validate preservation and stamping behavior across multiple drain scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
router/batchrouter/worker.go Preserve existing LastJobStatus.ErrorResponse when draining and merge in the drain reason.
router/batchrouter/worker_test.go Add coverage for drain-path behavior, including preservation of prior fields and correct drain reason selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ktgowtham ktgowtham left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tests are failing.

🔒 Scanned for secrets using gitleaks 8.29.1
@codecov

codecov Bot commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.06%. Comparing base (369f730) to head (7e3d154).

Additional details and impacted files
@@                Coverage Diff                 @@
##           release/1.75.x    #6958      +/-   ##
==================================================
- Coverage           80.14%   80.06%   -0.08%     
==================================================
  Files                 565      565              
  Lines               63671    63672       +1     
==================================================
- Hits                51026    50982      -44     
- Misses               9635     9674      +39     
- Partials             3010     3016       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@achettyiitr
achettyiitr merged commit eaabb87 into release/1.75.x May 15, 2026
106 of 109 checks passed
@achettyiitr
achettyiitr deleted the fix.batch_rt_worker_draining branch May 15, 2026 05:58
achettyiitr pushed a commit that referenced this pull request May 15, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.75.1](v1.75.0...v1.75.1)
(2026-05-15)


### Bug Fixes

* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([eaabb87](eaabb87))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
achettyiitr added a commit that referenced this pull request May 15, 2026
# Description

Syncing patch release v1.75.1 to main branch

**↓↓ Please review and edit commit overrides before merging ↓↓**

BEGIN_COMMIT_OVERRIDE
fix(batchrouter): preserve prior LastJobStatus error on drain (#6958)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Akash Chetty <[email protected]>
Co-authored-by: Akash <[email protected]>
Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
achettyiitr added a commit that referenced this pull request May 19, 2026
# Description

Syncing patch release v1.75.2 to main branch

**↓↓ Please review and edit commit overrides before merging ↓↓**

BEGIN_COMMIT_OVERRIDE
fix(batchrouter): preserve prior LastJobStatus error on drain (#6958)
fix: clickhouse quarter partition type (#6965)
fix: snowpipe streaming bulk status offset (#6966)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Akash Chetty <[email protected]>
Co-authored-by: Akash <[email protected]>
Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
mihir20 pushed a commit that referenced this pull request May 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.76.0-rc.1](v1.75.0...v1.76.0-rc.1)
(2026-05-25)


### Features

* per-workspace PyT routing + cold-start handling
([#6978](#6978))
([d81e175](d81e175))
* periodic cleanup of rsources shared db tables
([#6945](#6945))
([ed0dfe7](ed0dfe7))


### Bug Fixes

* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([af31e62](af31e62))
* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([193f797](193f797))
* clickhouse quarter partition type
([#6965](#6965))
([af31e62](af31e62))
* continuous backend config cache cause postgres disk bloat
([#6983](#6983))
([f45aa06](f45aa06))
* ignore failed messages when source job run id exists
([#6981](#6981))
([045fdc0](045fdc0))
* server getting stuck during startup while initializing rsources
([#6943](#6943))
([62791fa](62791fa))
* snowpipe streaming bulk status offset
([#6966](#6966))
([af31e62](af31e62))


### Miscellaneous

* **ci:** workflow cleanup (SEC-284)
([#6949](#6949))
([516ba5b](516ba5b))
* **deps:** bump actions/upload-artifact from 7.0.0 to 7.0.1
([#6892](#6892))
([866f04d](866f04d))
* **deps:** bump aws-actions/amazon-ecr-login from 2.0.1 to 2.1.4
([#6956](#6956))
([89f1168](89f1168))
* **deps:** bump docker/login-action from 4.0.0 to 4.1.0
([#6881](#6881))
([5bca875](5bca875))
* **deps:** bump rudderlabs/build-scan-push-action from 1.8.2 to 2.2.0
([#6955](#6955))
([78cc895](78cc895))
* **deps:** bump step-security/harden-runner from 2.16.0 to 2.19.1
([#6957](#6957))
([cc5b578](cc5b578))
* **jobsdb:** disable no results cache state filter optimization
([#6964](#6964))
([c20dad2](c20dad2))
* **jobsdb:** release dsList read lock early during store
([#6963](#6963))
([a172404](a172404))
* pyt contracts for ipc and multi threading
([#6942](#6942))
([d570865](d570865))
* remove unused sed deletion method from GZIPLocalFileHandler
([#6974](#6974))
([d788760](d788760))
* replace deprecated WithCredentialsJSON with WithAuthCredentialsJSON
([#6986](#6986))
([8395174](8395174))
* sync release v1.75.0 to main branch
([#6954](#6954))
([f16fe93](f16fe93))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
mihir20 pushed a commit that referenced this pull request May 26, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.76.0](v1.75.0...v1.76.0)
(2026-05-25)


### Features

* per-workspace PyT routing + cold-start handling
([#6978](#6978))
([d81e175](d81e175))
* periodic cleanup of rsources shared db tables
([#6945](#6945))
([ed0dfe7](ed0dfe7))


### Bug Fixes

* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([af31e62](af31e62))
* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([193f797](193f797))
* clickhouse quarter partition type
([#6965](#6965))
([af31e62](af31e62))
* continuous backend config cache cause postgres disk bloat
([#6983](#6983))
([f45aa06](f45aa06))
* ignore failed messages when source job run id exists
([#6981](#6981))
([045fdc0](045fdc0))
* server getting stuck during startup while initializing rsources
([#6943](#6943))
([62791fa](62791fa))
* snowpipe streaming bulk status offset
([#6966](#6966))
([af31e62](af31e62))


### Miscellaneous

* **ci:** workflow cleanup (SEC-284)
([#6949](#6949))
([516ba5b](516ba5b))
* **deps:** bump actions/upload-artifact from 7.0.0 to 7.0.1
([#6892](#6892))
([866f04d](866f04d))
* **deps:** bump aws-actions/amazon-ecr-login from 2.0.1 to 2.1.4
([#6956](#6956))
([89f1168](89f1168))
* **deps:** bump docker/login-action from 4.0.0 to 4.1.0
([#6881](#6881))
([5bca875](5bca875))
* **deps:** bump rudderlabs/build-scan-push-action from 1.8.2 to 2.2.0
([#6955](#6955))
([78cc895](78cc895))
* **deps:** bump step-security/harden-runner from 2.16.0 to 2.19.1
([#6957](#6957))
([cc5b578](cc5b578))
* **jobsdb:** disable no results cache state filter optimization
([#6964](#6964))
([c20dad2](c20dad2))
* **jobsdb:** release dsList read lock early during store
([#6963](#6963))
([a172404](a172404))
* pyt contracts for ipc and multi threading
([#6942](#6942))
([d570865](d570865))
* remove unused sed deletion method from GZIPLocalFileHandler
([#6974](#6974))
([d788760](d788760))
* replace deprecated WithCredentialsJSON with WithAuthCredentialsJSON
([#6986](#6986))
([8395174](8395174))
* sync release v1.75.0 to main branch
([#6954](#6954))
([f16fe93](f16fe93))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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.

4 participants