Repository navigation
fix(builds): cap the billed build duration at the build timeout - #13430
Merged
Merged
Conversation
Jobs::duration() measures wall clock from buildStartedAt, which the first log callback stamps — so a build that never streamed a line falls back to the deployment's creation time and measures its whole queue wait. That value is what Usage\Build::publish() bills, at memory x duration x cpus, and it is billed for 'failed' exactly as for 'ready'. The executor backend could not produce this: it measured microtime() around the build's own execution, so queue wait was structurally unbillable. Since builds moved to the jobs-service the mean billed duration of a *failed* build has gone 111s (Jun) -> 157s (Jul) -> 491s (Aug) while successful builds held at ~52s, and failed builds are now 57% of all billed build compute fleet-wide. One production project shows the shape plainly: 2,286 of its 2,311 failed August builds have buildStartedAt NULL, empty buildLogs, "exit code -1", and durations at 904-912s. On s-2vcpu-2gb that is ~1.0 GB-hour billed per build that never ran — 1,869 of its 1,878 billed GB-hours for the month. Clamp to _APP_COMPUTE_BUILD_TIMEOUT, the same ceiling Deployments hands the jobs-service as timeoutSeconds: no job outlives it, so nothing past it can have been build time. Guarded so a 0 or negative value leaves the measurement alone rather than zeroing every build. This is a ceiling, not the whole fix — a starved build still bills the full timeout. Billing 0 when buildStartedAt is NULL, and the build fan-out that starves them, are follow-ups. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
Greptile SummaryThe PR caps jobs-service build duration at the configured compute build timeout, preventing excessive queue wait from producing billing duration above that ceiling.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "test(builds): drop the build duration ca..." | Re-trigger Greptile |
Removed at request; the cap in Jobs::duration() is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
lohanidamodar
approved these changes
Aug 31, 2026
NancyWei123
pushed a commit
to NancyWei123/appwrite
that referenced
this pull request
Sep 30, 2026
When a build's exit callback carries no measured duration, Jobs::duration() falls back to wall clock since buildStartedAt. appwrite#13582 removed the clamp from appwrite#13430 so measured durations past the timeout (termination grace) are kept, but that also left the fallback unbounded: an exit reported seven weeks after its build started was billed as 50 days of build compute. The build's timeout now travels in the job's meta and comes back on its exit callback. The fallback is capped at that timeout plus the 300s of headroom Deployments already grants the build's credentials, or at _APP_COMPUTE_BUILD_TIMEOUT for jobs submitted before this change. Measured durations are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What
Jobs::duration()— the single writer ofbuildDurationon the jobs-service path — is clamped to_APP_COMPUTE_BUILD_TIMEOUT.Why
duration()measures wall clock frombuildStartedAt, which only the first log callback stamps. A build that never streamed a line has no stamp, so it falls back to the deployment's creation time and measures its entire queue wait.Usage\Build::publish()then bills that value atmemory × duration × cpus, and billsfailedexactly as it billsready.The executor backend could not produce this: it measured
microtime()around the build's own execution (Builds.php:170→:452), so queue wait was structurally unbillable. That path was removed in a82dc6e after the jobs-service landed in d1b1ab9.Fleet-wide, from
projects_usage_events_daily:Mean successful build held at 51.5s throughout. Failed builds went from 17% of billed build compute in June to 57% in August.
One production project shows the shape plainly. Of its 2,311 failed August builds, 2,286 have
buildStartedAt = NULL, emptybuildLogsapart fromBuild failed with exit code -1, and durations clustered at 904–912s (the 900s timeout). Ons-2vcpu-2gbthat is ~1.0 GB-hour billed per build that never ran — 1,869 of its 1,878 billed GB-hours for the month.The change
Clamp to
_APP_COMPUTE_BUILD_TIMEOUT, the same ceilingDeploymentshands the jobs-service astimeoutSeconds. No job outlives it, so nothing past it can have been build time. Guarded so a0or negative value leaves the measurement alone rather than zeroing every build's duration.Scope — this is a ceiling, not the whole fix
A starved build still bills the full 900s, so this recovers little for the project above. Deliberately out of scope, as follow-ups:
buildStartedAtisNULL. No log line means no build ran; that is the fix that actually zeroes this class of charge.buildingandwaitingfrom mid-August.Builds::sendUsage()runs in afinally, so the template hand-off path publishesMETRIC_BUILDS + 1at statusprocessingand the Jobs worker publishes again. Inflates the build count only;buildDurationis still null there.Test
No automated test. Verified by hand: with
_APP_COMPUTE_BUILD_TIMEOUT=900, a deployment created three hours earlier withbuildStartedAtnull finalizes atbuildDuration = 900(10801 before the change), and the publishedbuilds.mbSecondsis 2048 x 900 x 2 rather than 2048 x 10801 x 2.Pint, PHPStan and
tests/unit/{Platform/Workers,Workers,Deployment}pass.