Repository navigation
fix(functions): keep runtime and build job ids unambiguous when ids contain hyphens - #14817
Conversation
…ontain hyphens Runtime and job ids joined the project and deployment ids with a hyphen, which both may contain, so distinct pairs could map to the same id. Hyphenated pairs now carry the project id length; hyphen-free pairs keep their existing id so warm runtimes are reused.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
This PR changes how the executor derives runtime ids from project and deployment identifiers so that hyphen-containing ids can no longer collide with the
Reviewed commit: ad1e48d |
🟢 Tier S · Ready to mergeRuntime IDs now use one shared encoder for execution creation and runtime deletion, and build job IDs derive from that same encoding. Hyphen-free ID pairs retain their previous values, while hyphenated pairs include the project ID length; unit tests cover the resulting IDs and prefix behavior.
📂 Walkthrough · 4
Reviewed |
There was a problem hiding this comment.
Reworks the executor runtime id scheme to disambiguate project/deployment ids containing hyphens, fixing warm-runtime reuse and deletion.
Key findings
- 🟡 Upgrade orphans pre-existing hyphenated warm runtimes — Executor.php:49
| public static function runtimeId(string $projectId, string $deploymentId): string | ||
| { | ||
| $runtimeId = "{$projectId}-{$deploymentId}"; | ||
|
|
||
| if (\str_contains($projectId, '-') || \str_contains($deploymentId, '-')) { | ||
| $runtimeId .= '-' . \strlen($projectId); | ||
| } | ||
|
|
||
| return $runtimeId; | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Upgrade orphans pre-existing hyphenated warm runtimes
For any pair where the project id or deployment id contains a hyphen (the ProjectId validator allows hyphens), runtimeId now returns {projectId}-{deploymentId}-{strlen(projectId)} (src/Executor/Executor.php:49), so pre-upgrade runtimes running under the legacy {projectId}-{deploymentId} name become unreachable: deleteRuntime gets a 404 and silently returns true as "already gone" (src/Executor/Executor.php:78), while createExecution cold-starts a new container under the new id. The same rename applies to Deployments::id build-job keys (src/Appwrite/Deployment/Deployments.php:658), so cancel deletes a job id that no longer matches a pre-upgrade in-flight build (src/Appwrite/Deployment/Deployments.php:403). Impact: one-time orphaned containers and cold starts for every hyphenated project after upgrade, and unkillable in-flight builds, with cleanup left to executor idle eviction.
📋 Prompt for AI Agents
In src/Executor/Executor.php, extend deleteRuntime (around lines 65-93): when the DELETE for the canonical self::runtimeId() id returns 404 and the pair contains a hyphen (i.e. the canonical id differs from the raw {projectId}-{deploymentId} concatenation), retry once against the legacy id before treating 404 as success. This drains warm runtimes and build jobs created before the runtimeId format change. Note the same legacy-id concern for in-flight build jobs cancelled in src/Appwrite/Deployment/Deployments.php around line 403, and consider an upgrade note in docs/releases.md.
There was a problem hiding this comment.
Intentional, and covered in the PR description under Compatibility. The legacy {projectId}-{deploymentId} id is exactly the ambiguous one: for a hyphenated pair it can also be the runtime or build of a different project, so falling back to it on delete or cancel would bring back the behaviour this change removes. Hyphen-free pairs (all auto-generated ids) keep their id, so they see no cold start or orphan. Hyphenated pairs pay one cold start; their old runtimes are idle after the switch and are reaped by the executor inactivity cleanup, and builds already running under an old id finish normally.
There was a problem hiding this comment.
Thanks for the detailed explanation. The design choice is understood: falling back to the legacy id would reintroduce the ambiguity this change is specifically fixing, so the intentional one-time cold start for hyphenated pairs is a deliberate trade-off. That said, the finding remains open because the diff does not show the mitigation landing in code — specifically, 'deleteRuntime' still silently returns true on 404 with no legacy-id retry and no fallback drain path, and the upgrade note in docs/releases.md is not visible here. The executor inactivity reaper handling orphaned containers is a runtime-level safety net, but it is not a code-level fix to the finding. If the orphan/cold-start impact for hyphenated pairs is accepted as intentional and documented in the PR description and release notes, please point to that documentation so the finding can be reviewed against it.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
fix(functions): keep runtime and build job ids unambiguous when ids contain hyphens (cherry picked from commit e952e4e)
What
Runtime ids (
Executor) and build job ids (Deployments::id) were"{projectId}-{deploymentId}". Both ids may contain hyphens, so two different project/deployment pairs could produce the same id.Executor::runtimeId()is now the single place the id is built, used for creating executions and deleting runtimes, andDeployments::id()builds on it for job submit and cancel:{projectId}-{deploymentId}). Auto-generated ids fall here.{projectId}-{deploymentId}-{length}. The last segment always decodes the split point, so the mapping is injective, and these ids always have at least three hyphens, so they never equal an unchanged id (exactly one hyphen).The id keeps the
{projectId}-prefix that executor-side tooling matches on, keeps the existing charset (alphanumerics and hyphen), and grows by at most three characters, only for hyphenated pairs.The unused
$suffixargument ofExecutor::deleteRuntime()is removed (no callers).Compatibility
Hyphen-free pairs keep their id, so their warm runtimes and in-flight builds are untouched.
For hyphenated pairs, the first execution after the deploy starts a runtime under the new id (one cold start), and an old-id runtime is left to the executor's inactivity cleanup rather than deleted by its old id. A build already running under an old id is not cancellable by the new id and finishes normally. Both fallbacks were left out on purpose: the old ids are exactly the ambiguous ones, so deleting or cancelling by them is the behaviour this change removes.
Tests
tests/unit/Executor/ExecutorTest.php: hyphen-free ids are unchanged, aliasing pairs now get different ids, hyphenated ids never equal a hyphen-free id, the project prefix is kept.tests/unit/Deployment/DeploymentsTest.php: the same for job ids.testIdSeparatesHyphenatedPairsfails without the fix.Related: appwrite-labs/cloud#6673