Skip to content

feat(functions): report execution duration as wall clock in every path - #13754

Merged
ChiragAgg5k merged 2 commits into
mainfrom
feat/execution-duration-wall-clock
Sep 18, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
feat/execution-duration-wall-clock

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

What

duration on an execution now means the same thing however the execution was triggered: the total time the caller waited, cold start included.

Why

The field meant two different things depending on the path. A domain-routed request was timed around the whole request, so it included cold start. The executions API and the async worker stored the number the executor reports, whose timer starts only once the runtime is warm.

The gap is not small. A Console "Create execution" measured at 6.01s in the browser showed as 311ms in the Executions table — the missing 5.7s was almost entirely cold start, with nothing in the UI to say so. The same function invoked two ways produced non-comparable numbers in the same column, which also affects anything aggregating on duration.

What changed, visually

                  request in                                      response out
                      |                                                 ^
                      v                                                 |
  +-------------------+-------------------------------------------------+------+
  |  pod scheduling   |  image pull  |  runtime boot  |  your code runs         |
  |<------------------ cold start ------------------>|<---- execute ---->|      |
  +-------------------------------------------------------------------------+--+

  before
      domain path      |<========================= duration ===================>|
      API / async      .................................|<== duration ==>|
                                                         (cold start dropped)

  after
      all three paths  |<========================= duration ===================>|

Same function, same work; the only difference used to be which path you came in
through. A cold-started Console execution reported 311ms for a request the
browser measured at 6.01s, because everything left of execute was invisible.

How

Each of the three paths already measured the wall-clock window — and already used it, but only on the failure branch. On success they discarded it in favour of the executor's figure. Now both branches use the same window:

Path File
Domain router app/controllers/general.php:709
Executions API src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php:496
Async worker src/Appwrite/Platform/Workers/Functions.php:743

In all three, the timer starts immediately before the executor call and after the execution document is written, so no database work is folded in.

This also makes successes and failures consistent with each other. Because the failure branches were already using the wide window, a failed execution was already reported — and billed — on wall clock while a successful one was not.

No new field, no store migration, no response filter: duration keeps its name, type and shape, and only its meaning changes.

Billing

duration feeds executions.compute and executions.mbSeconds, so reported compute rises by the cold-start share of traffic — roughly +11.5% measured across a week of production telemetry. That share is concentrated in a small fraction of executions (about 1% carry a cold start), so it lands hardest, in relative terms, on low-traffic functions whose absolute usage sits inside the free allowance. Projects already paying overage are high-traffic and therefore rarely cold, and should see well under 1%.

Worth a changelog note regardless, since it is a silent semantic change to a billed field.

Not in scope

  • Generated SDKs and OpenAPI specs are not regenerated here; the duration description changed.
  • The Console still labels the column just "Duration". Making the UI say which window it shows is the remaining part of the original report.

Tests

Folded into the tests that already cover these paths rather than adding a new one.

testSyncCreateExecution capped duration at 1.5s — a bound that only held because cold start was excluded, so this change breaks it. It now measures the time the caller actually waited, client-side around the call, and asserts the reported duration tracks it. That is deliberately the same comparison that surfaced the bug: before this change a cold-started request reports a few hundred ms against several seconds of real wait and the assertion fails; after, the two track each other.

testFunctionsDomain gets the same check on the domain path, reading the execution back by the x-appwrite-execution-id header it already asserts on.

One existing ceiling is left alone: testCreateExecution asserts duration < 10. Cold start now counts toward it, but CI cold starts run well inside that.

Pint, PHPStan and the unit tier pass locally. The e2e tests need a running stack.

@ChiragAgg5k
ChiragAgg5k force-pushed the feat/execution-duration-wall-clock branch from c1e6ae2 to ed2e99e Compare September 18, 2026 08:59
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/execution-duration-wall-clock (after).

Metric Before After Change
🚀 Requests/sec 202.07 217.05 🟢 +7.4%
⏱️ Latency P50 86.63 ms 80.84 ms 🟢 -6.7%
⏱️ Latency P95 204.01 ms 189.12 ms 🟢 -7.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 80.84 189.12 13,623 217.05 -14.89
Account 151.47 292.85 717 11.94 -0.46
TablesDB 77.56 142.99 7,409 119.93 -13.25
Storage 75.51 170.78 3,585 60.04 -13.44
Functions 114.1 229.31 1,912 32.79 -20.73

Top API waits (after)

API request Max wait (ms)
account.name.update 488.45
functions.create 472.7
functions.variables.create 439.61
functions.variables.update 400.86
storage.files.create 381.96

@ChiragAgg5k
ChiragAgg5k force-pushed the feat/execution-duration-wall-clock branch 2 times, most recently from c148a7c to 378346c Compare September 18, 2026 09:01
@greptile-apps

greptile-apps Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge because no outstanding blocking correctness or repository-rule violation remains.

Summary

This PR standardizes function execution duration across domain, synchronous API, and asynchronous worker paths by recording the full server-side wall-clock interval, including cold-start time.

  • Uses the locally measured elapsed interval on successful and failed executions.
  • Updates the execution response model’s duration description and example.
  • Adds timing checks for synchronous API, domain-routed, and asynchronous executions.

Reviews (3) · Last reviewed commit: "test(functions): bound the async duratio..."

@ChiragAgg5k
ChiragAgg5k force-pushed the feat/execution-duration-wall-clock branch from 378346c to 574808b Compare September 18, 2026 09:06
`duration` meant two different things depending on how the execution was
triggered. A domain-routed request was timed around the whole request, so it
included cold start, while the executions API and the async worker stored the
executor's own figure, whose timer starts once the runtime is warm. A console
execution measured at 6.01s in the browser showed as 311ms in the table.

All three paths now store the wall-clock window they already measure. Each one
computed it for its failure branch and then threw it away on success; now both
branches use it.

`testSyncCreateExecution` capped duration at 1.5s, which only held while cold
start was excluded. It now bounds the reported duration against the time the
caller actually waited, which is the comparison that surfaced the bug in the
first place. `testScopes` covers the async worker by comparing its warm
execution against the cold one that precedes it.

Drops two UTF-8 assertions commented out since 2021, one of them against a
response field that has since been renamed.

`duration` feeds executions.compute and executions.mbSeconds, so reported
compute rises by roughly the cold-start share of traffic.
@ChiragAgg5k
ChiragAgg5k force-pushed the feat/execution-duration-wall-clock branch from 574808b to b97c779 Compare September 18, 2026 09:07
…cutions

The async assertion compared the queued execution against the cold synchronous
one before it, which assumed the worker reuses that same warm runtime. Nothing
pins it to one, and the old executor-reported durations could satisfy the same
ordering by chance, so it never tested the contract it claimed to.

It now bounds the stored duration against the observable window between
queueing the execution and seeing it complete.
@ChiragAgg5k
ChiragAgg5k merged commit 7e81326 into main Sep 18, 2026
51 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the feat/execution-duration-wall-clock branch September 18, 2026 09:29
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