feat: report task duration on job outcomes - #504
Merged
Conversation
The worker already measured wall time for metrics; outcomes dropped it, so no shell could report a job's duration without timing it again.
📝 WalkthroughWalkthroughChangesTask duration reporting
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Worker
participant RustScheduler
participant JavaBridge
participant OutcomeEvent
Worker->>RustScheduler: report result with wall_time_ns
RustScheduler->>JavaBridge: onOutcome(..., wallTimeNs)
JavaBridge->>OutcomeEvent: create outcome event
OutcomeEvent-->>JavaBridge: expose durationMs()
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
pratyush618
approved these changes
Jul 23, 2026
This was referenced Jul 24, 2026
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.
Closes #483.
Java exposed only raw timestamps, so every consumer recomputed elapsed time by hand. The
cause sat one layer down: the worker does measure execution time and puts
wall_time_nson theJobResult, butScheduler::handle_resultspent it onrecord_metricand returned aResultOutcomecarrying no timing at all. No shell couldreport a job's duration without timing the run a second time.
ResultOutcomenow carrieswall_time_nson every variant, and each SDK surfaces it.Core
wall_time_nsonSuccess/Retry/DeadLettered/Cancelled, populated at everyconstruction site including the batch-success path.
0is the contract's "not measured"— a job that failed before it ever executed, or one the core recovered rather than a
worker finishing it. Every shell maps
0to its own absent value, so an unmeasured runnever reads as an instant one.
Java
OutcomeEvent.durationMs()—Long, null when unmeasured. The existing 6-argconstructor stays, delegating with
0.NodeSnapshot.durationMs()andcompensationDurationMs()— computed from thetimestamps already on the snapshot, null until the leg has both started and finished.
TaskContext.elapsedMs()— monotonic, soafter/onErrorhooks stop hand-rolling atimer in the attributes map.
WorkerBridge.onOutcometakes a trailinglong wallTimeNs; the JNI descriptor mustmatch exactly, so this is a signature change rather than an overload.
Node
JsOutcome.duration_msflows intoOutcomeEvent.durationMs.Python
duration_mson the retry/dead/cancelled payloads (from the outcome) and oncompleted/failed (from the
perf_counterstart the task body already keeps), so oneduration field is present on every job event regardless of which side emits it.
Verification
cargo test --workspacegreen;--features postgresand--features redischeck clean../gradlew buildgreen — spotless, strict javadoc, tests.reportsHowLongTheTaskRanproves the duration over the real JNI path: a 60ms task reports >= 50ms on both the
outcome event and the middleware context.
Out of scope
Webhook bodies and the dashboard workflow-node payload are cross-SDK wire contracts —
adding a duration there needs all shells moved together, so they are untouched here.
Summary by CodeRabbit
New Features
Documentation
Tests