Skip to content

Deploy from the browser IDE through the IDE server, which builds, stops, installs and starts (G395) - #977

Open
johannesPettersson80 wants to merge 4 commits into
mainfrom
work/g395-ide-deploy-in-rust
Open

johannesPettersson80 wants to merge 4 commits into
mainfrom
work/g395-ide-deploy-in-rust

Conversation

@johannesPettersson80

Copy link
Copy Markdown
Owner

What

The browser IDE's Deploy deploys. The IDE server builds the project for the runtime's computer or board, stops the runtime's program, installs the new one and starts it cold. The task panel shows each step (G395).

The old Deploy did not deploy in its main cases:

  • The browser built the project only when its own hash of the open tabs had changed. It then sent the project's .st files to POST /api/deploy, or to POST /api/deploy/proxy for a remote runtime. It sent no program image and stopped nothing.
  • POST /api/deploy accepts a deployment only while the program is stopped (specification 34 §11.2). So while the program ran, every deployment was refused, although the confirmation said the program would restart.
  • A stopped remote runtime wrote the sources under its src/, and its restart loaded its old program.tpi. The badge still turned In sync, from the hashes of the sources the browser had sent.
  • The rules (when to build, what to send, when to restart) were logic in JavaScript, which AGENTS.md does not allow.

Built on #976 (G383c), which merges first; #974 and #975 have merged.

The behaviour

Specification 11 has a new section, "Unified Web IDE deploy contract". The browser asks the user to confirm and saves the open tabs. It then starts a task with POST /api/ide/deploy {target, auth_basic}: target is null for the runtime that serves the IDE, or the address the Online panel connected to. The task:

  1. reads the runtime's status. Its platform names the build target: a device's board name (esp32c6, stm32u5a9), or the <arch> of a computer's <os>-<arch>. A platform whose target the build does not know ends the task before anything is built or stopped. host, the IDE server's own CPU, is never taken for the runtime's;
  2. builds the project with trust-runtime build --target <target> (specification 44 §4.1, §4.4). A failed build ends the task, and the program keeps running;
  3. stops a running program with shutdown, and waits up to 10 seconds for stopped. Otherwise it ends with the state, and nothing is deployed;
  4. deploys the image alone, with restart: "cold";
  5. waits up to 10 seconds for running. Otherwise it ends with the state and the fault.

A refused deployment writes nothing. If the program ran before, the task starts it again with restart warm and ends with the refusal. The route needs the web interface's Admin access, as POST /api/deploy does, and an Editor session. The standalone IDE server (trust-runtime ide serve) runs no program, so it answers a deployment to itself with 409. The confirmation says that the program stops and that the new one starts cold, with its RETAIN variables at their initial values. The badge asks again after the task.

Decisions

I made these under the owner's delegation of 22 and 25 November. They are recorded in the specification:

  • The image alone, with no sources and no configuration, as trust-runtime ctl install sends it. The runtime keeps the files of its project folder, and the image holds the texts of the program's files (specification 44 §5.3), which the badge compares.
    • Sending the sources as well does not work for many projects. POST /api/deploy checks a deployment with sources against the running HMI (specification 39 §16.4 item 6) by compiling the sent sources alone, with default settings. A project whose src/ uses a library outside src/, as memory_marker_counter uses Hmi.Display from libraries/hmi, is refused with 422. Sending the library files too would write them under the target's src/.
    • The cost: like ctl install, the deployment is not checked against the runtime's HMI. A binding to a variable the new program lacks shows "not in running program". Checklist item G396 covers checking the image itself, for every deployment path alike.
  • A board is deployed as a computer is, built for its board name: the boards work exactly like trust-runtime (owner, 16 October 2026), so the IDE refuses no board.
  • Build first, then stop. A failed build costs no downtime.
  • Cold start, as the old flow and its confirmation did. The program is replaced, so its RETAIN variables take their initial values.
  • A refusal starts the old program warm. The program stopped only for the deployment, and it is still installed.
  • POST /api/deploy/proxy is removed. Its only caller was the old flow. The task reaches a remote runtime through the same proxy_remote_post that /api/control/proxy uses, with the request's token and the connection's credentials.

The fix

  • web/ide_deploy.rs (new): run_deploy, the five steps over a DeployTarget with injected build, log and pause, and the task (start_ide_deploy_job, build_for). The task runs the build as a process of this executable, with its output streamed into the task panel.
  • web/ide_deploy/targets.rs (new): the two targets.
    • ThisRuntimeTarget dispatches control requests in this process. Its deployment goes through the same code as POST /api/deploy.
    • RemoteRuntime posts to the other runtime's /api/control and /api/deploy.
  • web/deploy_here.rs (new): POST /api/deploy's body after its authorization, shared by the route and the task. It covers the HMI check, the Stopped rule, the write, the HMI activation and the restart. ops_routes.rs calls it, with its behaviour unchanged.
  • web/ide_routes/deploy.rs (new): POST /api/ide/deploy. It checks Admin access, the POST policy, an Editor session, the body (1 MiB) and the active project, then picks the target and starts the task.
  • ide_tasks.rs: begin_ide_task_job and run_ide_task_process, split out of start_ide_task_job so that the deploy task shares them. The build, test and validate tasks behave as before.
  • aux_routes.rs: the proxy route is removed. proxy_remote_post, normalize_proxy_response and ProxyBasicAuth are shared with the task.
  • ide-online.js and ide-commands.js:
    • The old flow is removed: its build-before-deploy hashes, its sources payload and its /api/deploy/proxy call.
    • Deploy confirms and starts the task. The task panel shows the task.
    • Retry on a failed deploy goes through the same confirmation.
    • The badge asks again when a deploy task ends.
  • Specification 11: the new section.
  • The browser IDE guide (docs/public/start/program-in-browser.md): a section "Deploy Your Project".
  • Changelog: a fragment, under ### Fixed and ### Removed.

Tests

web::ide_deploy::tests (10), against a runtime that answers from a script and records each request:

  • a_running_program_is_stopped_then_the_new_one_is_deployed_and_started_cold: the exact requests (status, shutdown, the polls, the image with restart: "cold", the polls) and the log lines. It catches a deployment sent to a running program, sent before the stop is reported, carrying sources or another restart, and a task that ends before the program runs.
  • a_stopped_program_is_deployed_without_a_stop.
  • a_failed_build_leaves_the_program_running: only status was sent.
  • a_refused_deployment_starts_the_program_that_ran_again_warm.
  • a_refused_deployment_to_a_stopped_program_starts_nothing.
  • a_program_that_does_not_stop_within_ten_seconds_gets_no_deployment: 100 polls 100 ms apart, then no deployment.
  • a_new_program_that_does_not_run_ends_the_task_with_its_state_and_fault.
  • a_device_gets_the_project_built_for_its_board: esp32c6, built for esp32c6.
  • a_runtime_whose_programs_the_ide_does_not_build_gets_nothing: rp2040, linux-armv7, host and linux-host. Nothing is built or sent after the status.
  • the_target_is_a_computers_arch_or_a_devices_board: Linux, Windows and macOS computers, both boards, and host.

web_ide_integration (part_10, 2):

  • a_deployment_needs_the_admin_access_and_an_editor_session: 401 without the token, 401 without a session, and 403 for a Viewer session.
  • the_standalone_ide_server_refuses_a_deployment_to_itself: 409, and no task started.

computer_stopped_keeps_runtime_up (ide_deploy, 2), on real runtimes of memory_marker_counter built with this tree's toolchain:

  • the_ide_deploys_the_edited_project_to_the_running_runtime_that_serves_it: while the program runs, src/Main.st is edited to the second step and deployed through the IDE. The task names each step and succeeds. The counter that climbed by one in each scan then climbs by two, and the badge reads in sync.
  • the_ide_deploys_to_another_runtime_through_its_web_interface: runtime A's IDE deploys to runtime B. B's counter climbs by two, and B's src/Main.st stays as it was, since no sources are sent. A keeps running its own program, never stopped, and its program.tpi is unchanged.

Mutants, each failing at its own assertion:

  • the deployment sent without stopping the program: the running-program and refusal tests fail on the requests, and the ten-second test ends in success where it must fail;
  • the old program started again cold: the refusal test fails on restart {"mode":"cold"};
  • the program left stopped after a refusal: the refusal test fails without the warm restart;
  • success reported before the new program runs: the faulted-program test fails on Ok(());
  • the operating system taken for the CPU: the target test and every deployment test fail on linux-x86_64;
  • a stopped program started after a refusal: the stopped-refusal test fails on the restart;
  • the standalone server not refusing a deployment to itself: the route test gets 200 and a task;
  • a Viewer session allowed to deploy: the route test gets 200 instead of 403;
  • a board refused: the board test and the target test fail;
  • host taken for the runtime's target: the target test and the not-built test fail.

In the browser (Playwright on the builder, against trust-runtime run of examples/web_ui_complete_project built from this tree). I looked at each screenshot:

  • The badge read In sync. After an edit of src/main.st it read Modified (1).
  • Deploy asked: "Deploy the project to the runtime Cpu (127.0.0.1:18095)? The IDE builds the project for the runtime, stops the runtime's program and installs the new one. The new program starts cold: its RETAIN variables take their initial values." (The old flow asked "Deploy . to Cpu?".)
  • The task panel showed the build's output, then "Stopping the runtime's program...", "Installing the new program...", "Starting the new program (cold)...", "The new program runs." and the task "completed (success)". The toast said "Deployed: the new program runs."
  • The badge read In sync again, and the runtime reported state=running.

Not run: a device in the loop. The task builds for a board by its board name, and the unit tests prove only that. No deployment to the bench ESP32-C6 was tried, since flashing it is the owner's call.

Checks

On the builder, over the worktree, which holds G383c's head bd982849c and this change:

  • fmt and the changelog fragments;
  • Clippy -D warnings on trust-runtime, all targets and features;
  • rustdoc with warnings denied on trust-runtime;
  • the web library tests (web::, 348, with web::ide_deploy's 10);
  • web_ide_integration (34, with part 10's 2);
  • computer_stopped_keeps_runtime_up (17, with ide_deploy's 2), with the toolchain of this tree;
  • the runtime vertical: api_smoke, debug_control, complete_program and runtime_reliability;
  • the Docs Pages job's five checks;
  • Windows Clippy (x86_64-pc-windows-gnu) on trust-runtime;
  • architecture-doctor --full-map: every check passes but FULLMAP-RUNTIMEBOUND and FULLMAP-RUNTIMESAFE, which need .git and always fail on the builder's copy;
  • the ten mutants above, each restored after its run, and trust-runtime rebuilt after them;
  • the pre-push contracts.

After main. G383a took main at d794363f6 and #966's pin-project-lite 0.2.19 (G397, e90222778), without which Supply Chain fails on every pull request, and G383b, G383c and G395 took it in turn. The top of the stack, which holds all four, was checked again on the builder: fmt, the changelog fragments, Clippy on trust-runtime-services and trust-runtime (all targets and features), rustdoc on trust-runtime, trust-runtime-services' library tests, trust-runtime's web library tests, native_image_header, native_small_program, web_ide_integration, computer_stopped_keeps_runtime_up, the runtime vertical and Windows Clippy. Each branch passed the pre-push contracts.

Found while building this, and kept for their own lanes:

  • G396: an installed image is not checked against the active HMI's bindings, by ctl install, an image-only POST /api/deploy or this task.
  • G398: a second deployment started while one runs interleaves with it.

The badge said Not deployed while the project's program ran: its rule, in
JavaScript, compared the open tabs with the sources of the last deployment
made from the same browser session. The browser now asks the runtime
program.sources and forwards it, with the open tabs' unsaved texts, to
POST /api/ide/sync-status. The IDE server compares the project's sources,
as the build collects and labels them, with the program: in sync when
their hash is the program's source_sha256, else modified with each file
that differs, not deployed without a program, unknown when the runtime
does not answer. The browser renders the answer.

The deploy flow's build-first rule still hashes the open tabs; it moves to
Rust with the deploy workflow (G395).
…nstalls and starts (G395)

The browser IDE's Deploy did not deploy in its main cases. It built the project only when its own
hash of the open tabs had changed, then sent the project's .st files without a program image to
POST /api/deploy, or to /api/deploy/proxy for another runtime, and stopped nothing: a running
runtime refused every deployment, and a stopped remote one restarted its old program while the
badge read In sync. Its rules were logic in JavaScript.

Specification 11, "Unified Web IDE deploy contract": POST /api/ide/deploy starts a task of the IDE
server that reads the runtime's status, builds the project for its target (a computer's CPU or a
board), stops a running program and waits up to 10 seconds, deploys the image alone with a cold
restart and waits up to 10 seconds for it to run. A refused deployment starts the program that ran
before again, warm. A failed build stops nothing. The standalone IDE server answers 409 for a
deployment to itself.

- web/ide_deploy.rs: the five steps over a DeployTarget, and the task that builds with this
  executable and streams the build's output into the task panel.
- web/ide_deploy/targets.rs: this runtime, through the same code as POST /api/deploy
  (web/deploy_here.rs, shared with ops_routes.rs), and another runtime through its web interface
  with the request's token and the connection's credentials.
- web/ide_routes/deploy.rs: the route (Admin access, Editor session, 1 MiB body).
- ide_tasks.rs: begin_ide_task_job and run_ide_task_process, shared by the tasks.
- aux_routes.rs: POST /api/deploy/proxy removed; its helpers are shared with the task.
- ide-online.js, ide-commands.js: Deploy confirms and starts the task; the old flow is gone.
- The browser IDE guide and a changelog fragment.

Tests: web::ide_deploy::tests (10, against a scripted runtime), web_ide_integration part 10 (access
and the standalone server), and computer_stopped_keeps_runtime_up's ide_deploy module (deploys to
the runtime that serves the IDE and to another one, on real runtimes).
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-03T05:37:00.504089Z
We couldn’t complete this review. Comment @codex review to try again.
0dd13bc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

This branch has not been deployed

No deployments
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