Skip to content

fix(functions): keep runtime and build job ids unambiguous when ids contain hyphens - #14817

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/runtime-id-encoding
Oct 22, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/runtime-id-encoding

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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, and Deployments::id() builds on it for job submit and cancel:

  • If neither id contains a hyphen, the id is unchanged ({projectId}-{deploymentId}). Auto-generated ids fall here.
  • Otherwise the project id length is appended: {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 $suffix argument of Executor::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. testIdSeparatesHyphenatedPairs fails without the fix.
  • Existing Functions and Sites e2e suites cover execution, deletion and cancel paths (CI).

Related: appwrite-labs/cloud#6673

…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.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Upgrade orphans pre-existing hyphenated warm runtimes — Executor.php:49

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 projectId-deploymentId concatenation, and simplifies deleteRuntime accordingly. Unit tests are added for both the deployment runtime-id derivation and the executor's id/delete handling.

Files Change
src/Appwrite/Deployment/Deployments.php Derives runtime ids with hyphen disambiguation for project/deployment pairs.
src/Executor/Executor.php Updates runtime id parsing and removes the suffix parameter from deleteRuntime.
tests/unit/Deployment/DeploymentsTest.php Adds coverage for the new runtime-id derivation.
tests/unit/Executor/ExecutorTest.php Adds coverage for the executor id scheme and delete path.

Reviewed commit: ad1e48d

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Runtime 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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Executor/Executor.php Adds the shared runtime ID encoder and uses it for execution creation and runtime deletion; removes the unused delete suffix parameter.
src/Appwrite/Deployment/Deployments.php Build job IDs now derive from the shared runtime ID encoding.
tests/unit/Deployment/DeploymentsTest.php Covers unchanged hyphen-free job IDs and separation of an example pair that previously aliased.
tests/unit/Executor/ExecutorTest.php Covers runtime ID compatibility, separation examples, and retained project prefix.

Reviewed ad1e48d · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/Executor/Executor.php
Comment on lines +49 to +58
public static function runtimeId(string $projectId, string $deploymentId): string
{
$runtimeId = "{$projectId}-{$deploymentId}";

if (\str_contains($projectId, '-') || \str_contains($deploymentId, '-')) {
$runtimeId .= '-' . \strlen($projectId);
}

return $runtimeId;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/runtime-id-encoding (after).

Metric Before After Change
🚀 Requests/sec 209.01 213.09 ⚪ +2%
⏱️ Latency P50 79.75 ms 81.03 ms ⚪ +1.6%
⏱️ Latency P95 196.63 ms 193.36 ms ⚪ -1.7%
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 81.03 193.36 13,509 213.09 -3.28
Account 151.98 294.82 711 11.81 -18.62
TablesDB 78.82 153.67 7,347 118.07 +14.05
Storage 74.27 172.77 3,555 59 -16.25
Functions 113.57 226.22 1,896 32.1 -30.78

Top API waits (after)

API request Max wait (ms)
account.name.update 437.58
functions.variables.update 377.35
account.prefs.update 366.11
tablesdb.rows.create 342.35
storage.buckets.create 326

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@ChiragAgg5k
ChiragAgg5k merged commit e952e4e into main Oct 22, 2026
126 of 128 checks passed
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix(functions): keep runtime and build job ids unambiguous when ids contain hyphens

(cherry picked from commit e952e4e)
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.

1 participant