Repository navigation
fix(builds): bound the unmeasured build duration by the build's timeout - #14029
Conversation
When a build's exit callback carries no measured duration, Jobs::duration() falls back to wall clock since buildStartedAt. #13582 removed the clamp from #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]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
🔵 Tier A · Mergeable after minor fixes
The pull request caps unmeasured build duration at the build timeout plus 300 seconds while preserving valid measured durations. A protected timeout hook defaults to the environment configuration and allows downstream workers to supply project-specific timeouts. The latest changes pass the platform database and project into that hook and pass its result explicitly into the duration calculation. Latest changes: The timeout hook now receives the platform database and project, and its result is passed explicitly to duration().
Fix with agent prompt### Issue 1
src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php:459-460
**Preserve the timeout used when the build was submitted**
This reads the current timeout, not necessarily the one used to queue the build: changing `_APP_COMPUTE_BUILD_TIMEOUT` before a delayed exit arrives changes the billed cap for an existing build. Please retain the submitted timeout in callback metadata or deployment state, using current configuration only for older jobs without it.
### Issue 2
src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php:826-828
**Restore regression coverage for the unmeasured duration cap**
Moving the calculation back into the worker leaves the late, unmeasured callback case without regression coverage: the existing Functions duration test only exercises an ordinary successful build. Please cover a delayed unmeasured exit and a measured duration beyond the cap through an integration test, or restore a tested domain calculation; AGENTS.md disallows unit-testing private worker methods.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 1
⏳ Still open from earlier reviews · 2
Reviewed the commits since |
Review on #14029: the worker already has the project's plan, which is where the build was queued with its timeout, so there's no need to echo the timeout through the job's meta; the Deployments change is reverted. The duration logic moves into Appwrite\Deployment\BuildDuration, which takes the clock as an argument, and is unit-tested there instead of through the worker, as AGENTS.md asks (workers are covered by e2e). Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
| // The same timeout the build was queued with: the plan's, else the operator's. | ||
| $timeout = (int) ($plan['buildTimeout'] ?? System::getEnv('_APP_COMPUTE_BUILD_TIMEOUT', 900)); |
There was a problem hiding this comment.
Preserve the timeout used when the build was submitted
This reads the current timeout, not necessarily the one used to queue the build: changing _APP_COMPUTE_BUILD_TIMEOUT before a delayed exit arrives changes the billed cap for an existing build. Please retain the submitted timeout in callback metadata or deployment state, using current configuration only for older jobs without it.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php
Line: 459-460
Comment:
**Preserve the timeout used when the build was submitted**
This reads the current timeout, not necessarily the one used to queue the build: changing `_APP_COMPUTE_BUILD_TIMEOUT` before a delayed exit arrives changes the billed cap for an existing build. Please retain the submitted timeout in callback metadata or deployment state, using current configuration only for older jobs without it.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · bug · Reply if this doesn't apply.
Drops the BuildDuration class and its test from the previous commit: the bound is two lines in Jobs::duration(), with the timeout taken from the worker's injected plan at the call site. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
…out, no plan lookup Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
…orker state Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
When a build's exit callback carries no measured duration,
Jobs::duration()falls back to wall-clock time sincebuildStartedAt, and that duration is what usage bills as build compute (memory × buildDuration × cpusinUsage/Build.php).#13430 capped the duration at the build timeout. #13582 removed that cap so a measured duration that runs past the timeout (termination grace) is kept, which was right, but it also left the fallback unbounded. In production, an exit reported seven weeks after its build started was billed as 50 days of build compute on a 4 GB build.
Change (one file)
Jobs::duration()is capped at the build timeout plus the 300s of headroomDeploymentsalready grants the build's credentials.buildTimeout()+ 300s.buildTimeout()is a protected hook that defaults to_APP_COMPUTE_BUILD_TIMEOUT; an extension whose builds are submitted with per-project timeouts overrides it to return the timeout that build actually had.Tests
None in this PR. AGENTS.md keeps unit tests to libraries and leaves workers to e2e, and no e2e can produce an exit that arrives weeks late without a measurement. While developing, a unit harness around the exit handler confirmed the behaviour:
mainrecords the full 50 days, this change records the timeout plus 300s, and a measured duration past the timeout is kept. That harness isn't included, per the rule.🤖 Generated with Claude Code