Skip to content

Fix CLI local function emulation for OpenRuntimes v5#1454

Merged
ChiragAgg5k merged 7 commits intomasterfrom
codex/fix-cli-local-run-openruntimes-v5
Apr 16, 2026
Merged

Fix CLI local function emulation for OpenRuntimes v5#1454
ChiragAgg5k merged 7 commits intomasterfrom
codex/fix-cli-local-run-openruntimes-v5

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

@ChiragAgg5k ChiragAgg5k commented Apr 16, 2026

Summary

This fixes appwrite run function in the CLI SDK for current OpenRuntimes v5 images, fixes the local runtime startup command so functions actually stay up after a successful build, and adds a regression test so this path is covered in future CLI test runs.

What changed

  • switched local Docker image resolution from openruntimes/*:v4-* to openruntimes/*:v5-*
  • updated local runtime start commands from sh helpers/server.sh to bash helpers/server.sh because the v5 helper uses bash-only features like shopt
  • made Docker pull/build/copy/start failures fatal so appwrite run function stops immediately instead of continuing into misleading build/start steps after a Docker failure
  • reused a single runtime image resolver in the local emulation layer to keep pull/build/start behavior consistent
  • added CLI Bun regression assertions that validate the generated local emulation uses OpenRuntimes v5, starts local runtimes with bash helpers/server.sh, and keeps the Docker failure-handling guards in the generated CLI source

Problem

appwrite run function in the generated CLI was still targeting v4 OpenRuntimes tags. For a current runtime like node-25, the local runner tried to use openruntimes/node:v4-25, which does not exist.

It also ignored non-zero Docker exits, so the command kept going into build/start even after the image lookup failed.

After switching the image tag to v5, local startup still failed because the generated start command invoked helpers/server.sh with sh, but the v5 helper script is a bash script.

Before

Compiled from examples/cli with:

php example.php
cd examples/cli
bun run mac-arm64
./build/appwrite-cli-darwin-arm64 run function --function-id local-run-check --port 3137 --no-reload

Observed output before this fix:

ℹ Info: Verifying Docker image ...
ℹ Info: Building function using Docker ...
Unable to find image 'openruntimes/node:v4-25' locally

docker: Error response from daemon: manifest for openruntimes/node:v4-25 not found: manifest unknown: manifest unknown

Run 'docker run --help' for more information

ℹ Info: Starting function using Docker ...
♥ Hint: Function automatically restarts when you edit your code.
Unable to find image 'openruntimes/node:v4-25' locally
docker: Error response from daemon: manifest for openruntimes/node:v4-25 not found: manifest unknown: manifest unknown

Run 'docker run --help' for more information

✗ Error: Failed to start function with error: connect ECONNREFUSED 127.0.0.1:3137

Observed output after only switching the image tag, before fixing the startup shell:

ℹ Info: Starting function using Docker ...
[open-runtimes] Runtime started.
helpers/server.sh: line 4: shopt: not found
✓ Success: Visit http://localhost:3137/ to execute your function.

The container exited immediately after that and curl http://127.0.0.1:3137/ failed.

After

Verified with the same loop from examples/cli:

php example.php
cd examples/cli
bun run mac-arm64
./build/appwrite-cli-darwin-arm64 run function --function-id local-run-check --port 3137 --no-reload
curl -sS http://127.0.0.1:3137/

Observed output after this fix:

ℹ Info: Verifying Docker image ...
ℹ Info: Building function using Docker ...
[open-runtimes] Build finished.
ℹ Info: Starting function using Docker ...
[open-runtimes] Runtime started.
✓ Success: Visit http://localhost:3137/ to execute your function.
HTTP server successfully started!

Response from the local function:

{"ok":true,"method":"GET","path":"/"}

Docker also shows the local runtime container staying up:

local-run-check   openruntimes/node:v5-25   Up ...   0.0.0.0:3137->3000/tcp

Regression coverage

The existing generated CLI Bun tests now assert:

  • openRuntimesVersion === "v5"
  • systemTools.node.startCommand === "bash helpers/server.sh"
  • the generated lib/emulation/docker.ts still contains the explicit Docker failure-handling path for pull/start behavior

These run through the normal CLI PHPUnit flow via tests/languages/cli/test.js and the CLIBun10/11/13 test classes.

Validation

  • php example.php
  • cd examples/cli && bun run mac-arm64
  • cd examples/cli && ./build/appwrite-cli-darwin-arm64 run function --function-id local-run-check --port 3137 --no-reload
  • curl -sS http://127.0.0.1:3137/
  • cd examples/cli && bunx eslint lib/emulation/docker.ts lib/emulation/utils.ts
  • vendor/bin/phpunit tests/CLIBun13Test.php

Notes

  • examples/* is gitignored in this repository, so the generated CLI was regenerated and used for verification but is not part of the committed diff.
  • bun run lint still reports a large number of unrelated, pre-existing generated CLI lint issues outside the touched local emulation files.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 16, 2026

Greptile Summary

This PR fixes appwrite run function for OpenRuntimes v5 by updating the image tag from v4 to v5, switching the container start invocation from sh to bash (required by v5's shopt usage), making Docker pull/build/copy/start failures fatal instead of silently continuing, and adding regression tests that assert the v5 image tag and bash start command in the generated CLI. All three issues flagged in the prior review round (build container leaked on failure, zero-exit false-success before port opens, and the pre-flight ENOENT race) are addressed by the finally-block dockerStop, the Promise.race process-exit detection, and the existsSync guard before getFunctionFiles, respectively.

Confidence Score: 5/5

Safe to merge — all prior P1 findings are addressed and no new blocking issues were found.

All three issues from the previous review round are resolved. The waitForProcessOutput Promise technically never settles when the process exits without emitting the needle, but this is fully mitigated by the 1500ms timeout in the downstream Promise.race. Remaining observations are P2 style concerns that don't block correctness.

templates/cli/lib/emulation/docker.ts warrants a quick read for the two-phase startup detection logic, but no blocking issues remain.

Important Files Changed

Filename Overview
templates/cli/lib/emulation/utils.ts Bumps openRuntimesVersion from "v4" to "v5" and changes all startCommand values from "sh helpers/server.sh" to "bash helpers/server.sh" — straightforward mechanical change, no logic issues.
templates/cli/lib/emulation/docker.ts Major refactor: extracts helper functions (getFunctionFiles, assertFunctionSourceCode, getRuntimeImageName, waitForProcessClose, assertDockerSuccess, waitForProcessOutput), makes Docker pull/build/copy failures fatal, and adds two-phase port+log detection for dockerStart. One minor concern: waitForProcessOutput's internal Promise never settles if the process exits without the needle, but this is fully guarded by the 1500ms timeout in the race.
templates/cli/lib/commands/run.ts Adds assertFunctionSourceCode preflight and reload guards, lazy "Runtime logs:" header, and improves error messaging; changes a log call to hint — all correct.
templates/cli/lib/commands/update.ts Pure Prettier-style reformatting — no logic changes.
templates/cli/lib/utils.ts Single Prettier-style reformat of syncVersionCheckCache call — no logic changes.
tests/Base.php Adds CLI_LOCAL_FUNCTION_EMULATION_RESPONSES constant with the two new test markers; straightforward and correct.
tests/CLIBun10Test.php Adds CLI_LOCAL_FUNCTION_EMULATION_RESPONSES to the expected response set, matching the order it appears in test.js.
tests/CLIBun11Test.php Same as CLIBun10Test — adds CLI_LOCAL_FUNCTION_EMULATION_RESPONSES to expected responses.
tests/CLIBun13Test.php Same as CLIBun10Test — adds CLI_LOCAL_FUNCTION_EMULATION_RESPONSES to expected responses.
tests/languages/cli/test.js Adds runtime config assertions (openRuntimesVersion === "v5", startCommand === "bash helpers/server.sh") and an assertFunctionSourceCode integration test with proper try/finally cleanup; Prettier reformatting throughout.

Reviews (5): Last reviewed commit: "Refine CLI local run output" | Re-trigger Greptile

Comment thread templates/cli/lib/emulation/docker.ts
Comment thread templates/cli/lib/emulation/docker.ts Outdated
Comment thread templates/cli/lib/emulation/docker.ts
@ChiragAgg5k ChiragAgg5k merged commit bd4b6bb into master Apr 16, 2026
56 checks passed
@ChiragAgg5k ChiragAgg5k deleted the codex/fix-cli-local-run-openruntimes-v5 branch April 16, 2026 03:58
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