Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## v0.11.0 · 2026-11-20

Starting and stopping cleanly, on Windows too: the engine's side. One engine of the app per data folder, an engine that leaves when its app is gone, a log file, and a start failure that is said before the app closes. The app's side of the same work (below, under "Not in this release") is still to come.

- One engine of the app serves a data folder. A second copy of FormEncoder on the same folder is told "formencoder is already running on [folder]" and does not start a second engine on the same queue and settings.
- An engine that was left running after its app had gone is ended and replaced by the next start of the app. An engine whose app is still there is never ended.
- The engine leaves within about two seconds when the app that started it is gone, however the app ended, and takes its lock and its address record with it.
- The engine keeps a log: `logs/formencoder-engine.log` in the data folder (`~/Formencoder`, or the folder `FORMENCODER_DATA_DIR` names). A refused start and an error that stops the engine are written there. An engine with no error stream, such as a build without a console, keeps its errors in `logs/formencoder-engine-errors.log`.
- A double click on the engine's own program opens FormEncoder instead of serving on its own; where no app is found beside it, it says so and stops. `formencoder-engine --headless`, the engine a command line or an agent's bridge starts with no app, serves as before, beside the app's engine if there is one.
- When the app cannot start its engine, the sentence is shown before the loading window closes; the window used to close first. The sentence says that a copy of FormEncoder may already be open and where the engine's log is.
- Changed: an engine that is asked to stop with a terminate signal gives up its lock and its address record and leaves with exit code 0.
- A terminal's reader no longer writes an error line when the engine is already on its way out.
- Not in this release: on Windows, tying the engine to the app through the system so that an app ended in Task Manager takes its engine with it at once; the engine's last lines and exit code in the failure message; a limit on the wait for the engine's address. Until then the engine's own watch is what ends it.
- Not run for this release: Windows, macOS, the desktop app (the change to it was not compiled) and a packaged engine. The checks ran on Linux from source, with stand-ins for the app.
- The version string inside the three browser demo bundles (`demo/assets/demo.js`, `demos/broadcast/assets/broadcast.js`, `demos/inspect/assets/inspect.js`) is bumped to 0.11.0 by hand, without a rebuild.

## v0.10.0 · 2026-11-19

The family's terminal panel, and four agent programs. The Terminal panel is now the one the other Form apps have, Google's Antigravity (`agy`) is offered beside Claude Code, Codex and Cursor, and FormEncoder finds these programs however it was started.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p>

<p align="center">
<img alt="version 0.10.0" src="https://img.shields.io/badge/version-0.10.0-eef0f4?style=flat-square">
<img alt="version 0.11.0" src="https://img.shields.io/badge/version-0.11.0-eef0f4?style=flat-square">
<img alt="Rust" src="https://img.shields.io/badge/Rust-engine-b7410e?style=flat-square&logo=rust&logoColor=white">
<img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-interface-3178c6?style=flat-square">
<img alt="macOS, Windows, Linux" src="https://img.shields.io/badge/macOS%20%C2%B7%20Windows%20%C2%B7%20Linux-native-2f7bf5?style=flat-square">
Expand Down Expand Up @@ -102,7 +102,7 @@ FormEncoder loads extensions made to the Form Extension Contract (API 1): FormPo

## Under the hood

Version 0.10.0 · Apache-2.0 · Rust encoding engine, Python service, TypeScript interface, Tauri 2 shell
Version 0.11.0 · Apache-2.0 · Rust encoding engine, Python service, TypeScript interface, Tauri 2 shell

- **Engine:** seven `fencoder` Rust crates in `native/`, loaded by the Python service as the `fe_core` extension.
- **FFmpeg:** a pinned LGPL build, run as a separate program and never linked.
Expand Down
36 changes: 36 additions & 0 deletions backend/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,39 @@ Refers to `backend/app/functions/session.py` (`Session.run`, `Session.sent`), `b
- Seen with a headless session before any test was run again: queued with `1:1,movie=...`, `1:1;x` and `1:1 /...` the engine held `1:1` each time and `guard.before` refused with `params.settings.video.pixelAspect ... holds a filtergraph, option or path character`; `4:3` and `source` were held as sent and allowed. Then `tests/test_functions.py`: 42 passed (39 passed, 3 failed before).
- Not changed: the engine (no Rust change, not rebuilt) and the commands the window and agents use, where such a value is still corrected to `1:1` and not refused.

## One engine of the app per data folder, a log file, and the engine leaves with its app (unreleased, after 0.10.0)

Refers to `backend/app/core/startup.py` (new), `backend/app/core/runtime.py` (new), `backend/formencoder_engine.py` (`serve`, `watch_shell`, `_leave`, `main`), `backend/tests/test_startup.py` (new) · kind: feature · logged: unreleased · 2026-11-19

- Why: the family's Windows start and stop pattern, as built in FormTools 0.10.0. On Windows an engine can be left behind after a quit, a second start meets it, and a failed start says nothing. Nothing here has run on Windows.
- `startup.py` is FormTools's file at its `origin/main`, with only the names at its top changed: `APP`, `NAMES`, `ALONE_ENV` (`FORMENCODER_NO_SHELL`), `ERRORS_NAME`, and `SHELL_ENV`, which is `FORMENCODER_PARENT_PID`: the released shell already gives the engine its own process id under that name, so the shell needs no new variable. `PLACES` is unchanged; this app's engine is one file beside the app in all three install layouts.
- `runtime.py` holds what is this app's own: the log file `logs/formencoder-engine.log` in the data folder (rotating, 1 MB, three kept, the loggers `formencoder` and `uvicorn`), the claim with its log line, and the release of the lock.
- The order in `serve`: the data folder and the log, a kept standard error (`logs/formencoder-engine-errors.log` when there was none), the started-alone branch, the lock, the watch, then the port, the window key line and the server as before. A data folder that cannot be made is one sentence and exit code 5; a held lock is the sentence "formencoder is already running on [folder] (engine process N)." in the log and on standard error and exit code 2; started alone it opens the app beside it and returns 0, or says it serves nothing on its own and returns 4. An error that ends the engine is written to the log before it is raised.
- What was kept and what was replaced. The entry's own `_alive` and `_watch_parent` are gone: the watch is `startup.watch` on the same variable, asking every two seconds where the old loop asked every second. When the shell is gone the engine gives up the lock, withdraws `engine.json` as before, and leaves with 0.
- Decision, headless. `--headless` is the engine a command line or an agent's bridge starts on purpose with no app (`agent/client.py` starts a frozen engine this way), on a fixed port. It takes no lock and never takes the started-alone branch: a headless engine and the app's engine could serve one data folder before this change, and a lock held by a headless engine, which has no shell, would refuse the app. It gets the log, the kept standard error and the watch when it was given a process id. So the lock is between engines of the app (and development runs of the entry without the flag).
- Decision, the port. `app.core.config` is now imported before the port is known, because the data folder comes from it, and it reads `FORMENCODER_PORT` when it is imported. The entry reads the wanted port before that import, as before, and sets `config.PORT` to the bound port beside the environment variable. `FORMENCODER_DESKTOP` and `FORMENCODER_DIST` are still set before the import.
- New: SIGTERM gives up the lock and withdraws `engine.json` after the server has stopped, and the exit code is then 0 (it was the signal's). The log gets one line with the address when serving starts; uvicorn's level stays at warning.
- The released engine wrote no lock, so the first start after the update finds none and replaces nothing. A released engine already leaves by itself within a second when its shell is gone, on Windows too.
- Seen on Linux, from the source entry with stand-in shells (`sleep`): a second engine with a live shell on the same folder left with 2 and the sentence while the first kept answering, and the log held the refusal; an engine whose stand-in shell ended left with 0 in 1.3 s and the lock and `engine.json` were gone; a holder stopped with SIGSTOP whose shell was gone was ended (exit 137) and replaced, with the line in the log; locks holding `not json at all`, `[1, 2]`, `{"pid": "x"}` and nothing were replaced; a lock naming an unrelated `sleep` was replaced and the `sleep` kept running; with `sys.frozen` set and a stand-in app in each layout (beside the engine, one folder up, `Contents/MacOS`, `/usr/bin`) the stand-in app was started, the exit code was 0 and there was no lock, no `engine.json`; with no app near, 4 and the sentence; a headless engine, also with `sys.frozen` set, served beside a held lock and left it as it was; with standard output, with output and error, and with all three streams closed the engine answered its health route, and descriptors 0 to 2 were the null device.
- Tests, written after that: `tests/test_startup.py`, FormTools's with the names changed, the stand-in app beside the engine, and three more for what is this app's own (the refusal through the entry, `engine.json` withdrawn with the lock, headless). 15 passed.
- Not run: Windows, macOS, a really frozen engine. Every Windows-only line in `startup.py` (`_kernel`, `_open_windows`, `_alive_windows`, `_created_windows`, `_end_windows`, the handle branch of `watch`, `SetDllDirectoryW` and the detached flags in `open_app`) has never run.
- Held: the shell side (the job object, the failure text with the engine's last lines and exit code, a limit on the wait for the address). Two processes, the app's engine and a headless one, can write the one log file; on Windows its rotation at 1 MB would then fail for as long as both run.

## The start failure is said before the loading window closes (unreleased, after 0.10.0)

Refers to `src-tauri/src/main.rs` (the `None` arm of the engine's start in `setup`) · kind: fix · logged: unreleased · 2026-11-19

- Why: when the engine gave no address and key, the loading window was closed first and the sentence shown after it. The loading window is then the app's last window, and a tester of another app in the family saw the app go without a word. With the lock, a second copy of the app is now a start that fails on purpose, so the sentence matters more.
- The sentence is shown first and the loading window is closed only after it returns. The sentence now says that a copy of FormEncoder may already be open, since only one copy can use the data folder, and where the engine's log is (`logs/formencoder-engine.log` in the data folder).
- The engine's variable: nothing to change. The shell already sets `FORMENCODER_PARENT_PID` to its own process id, and that is the variable the engine's lock and watch read.
- Not compiled: the desktop shell cannot be built here (no WebKit libraries). The change is one string and two statements in another order, read against FormTools's `main.rs` and FormTxt's same change. Not run on any system.
- Held: `win_job.rs` (the job object, which needs the engine's start moved off tauri-plugin-shell or the child's process opened by id), `engine_start.rs` (the failure text with the engine's last lines, its exit code and the log's full path), a limit on the wait for the address, and the window that fails to build (`Err(_) => close_splash`), which still closes the loading window without a sentence.

## A terminal's reader thread tolerates an event loop that is already closed (unreleased, after 0.10.0)

Refers to `backend/app/routers/terminal.py` (`pump`) · kind: fix · logged: unreleased · 2026-11-19

- Why: the log of the pull request's test job held `RuntimeError: Event loop is closed` from a terminal's reader thread. The thread hands each piece of output, and at the end its end notice, to the event loop that opened the terminal; when that loop is already closed (a finished test, an engine on its way out) nobody is left to receive either. It was a line in the log, not a failure.
- In `pump`, a hand-over of output that raises `RuntimeError` ends the read loop, and the hand-over of the end notice ignores the same error. The wait for the child stays where it was, so the child is still reaped.
- Seen: the whole backend suite with this change, 279 passed, and its output held no `Event loop is closed` line. Whether the line shows on this machine without the change was not looked at.

2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.0"
__version__ = "0.11.0"
63 changes: 63 additions & 0 deletions backend/app/core/runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import json
import logging
import os
from logging.handlers import RotatingFileHandler
from pathlib import Path

from . import startup

LOG_NAME = "formencoder-engine.log"
LOG_FOLDER = "logs"
LOG_BYTES = 1_048_576
LOG_KEEP = 3
LOGGERS = ("formencoder", "uvicorn", "uvicorn.error", "uvicorn.access")
FORMAT = "%(asctime)s %(levelname)s %(name)s %(message)s"
HANDLER = "formencoder-file"


def start_logging(data: Path) -> Path:
folder = data / LOG_FOLDER
folder.mkdir(parents=True, exist_ok=True)
path = folder / LOG_NAME
for held in logging.getLogger("formencoder").handlers:
if held.get_name() == HANDLER and getattr(held, "baseFilename", "") == os.path.abspath(path):
for name in LOGGERS:
if held not in logging.getLogger(name).handlers:
logging.getLogger(name).addHandler(held)
return path
stop_logging()
handler = RotatingFileHandler(path, maxBytes=LOG_BYTES, backupCount=LOG_KEEP, encoding="utf-8")
handler.setFormatter(logging.Formatter(FORMAT))
handler.set_name(HANDLER)
for name in LOGGERS:
logger = logging.getLogger(name)
logger.addHandler(handler)
if name == "formencoder":
logger.setLevel(logging.INFO)
logging.getLogger("formencoder").info("engine started, pid %s, data folder %s", os.getpid(), data)
return path


def stop_logging() -> None:
for name in LOGGERS:
logger = logging.getLogger(name)
for handler in list(logger.handlers):
if handler.get_name() == HANDLER:
logger.removeHandler(handler)
handler.close()


def claim(data: Path, shell: int) -> Path:
lock, replaced = startup.claim(data, shell)
if replaced:
logging.getLogger("formencoder").warning("an engine left running without its app was stopped (process %s)", replaced)
return lock


def release(data: Path) -> None:
path = data / startup.LOCK_NAME
try:
if int(json.loads(path.read_text(encoding="utf-8")).get("pid", 0)) == os.getpid():
path.unlink()
except (OSError, ValueError, TypeError, AttributeError):
pass
Loading
Loading