Skip to content

Contexts and the write gate

virtufin-tui supports multiple virtufin-api endpoints ("contexts") so you can operate against dev, staging, and prod from the same session.

The contexts file and its fields: The contexts file. Switching step by step: Switch context.

Switching

Go to the Contexts page (Config › Contexts in the default layout; Switch context step by step). Highlight a context and press Enter to make it active. The TUI first checks that the context's api answers (one keyed call); only then does it switch: the new context is saved as the active one, the current gRPC channel closes and new ones open, and the dashboard refreshes within 1 second. A context that does not answer (or refuses the key) is reported as a toast, and the current one stays active. A switch prepares the new context as startup does: scenario.LIVE is created when it is missing, and your init_scripts run against it.

The context row under the tab bar names the active context on every tab (Trading adds the Scenario), so no action runs without the context in sight.

No active context

If no context is active -- for example the stored active_context names a context that no longer exists in contexts.toml, or the file was never created -- the TUI does not exit. It starts on the Contexts page, lists every configured context, and shows each one as not connected (red). No endpoint is watched while unbound. Every other pane but Home says it needs a context until one is picked. Highlight a context and press Enter to connect; from then on the normal lifecycle (including each context's liveness watch) resumes. With no contexts configured at all, the Contexts page shows no contexts configured in <path> and nothing to switch to.

Connection status & errors

Every context row on the Contexts page shows a colored dot: green (reachable), red (not reachable), gray (not checked yet). The Home page's connection line shows the same dot for the active context. On a red dot, the specific reason is shown next to it — e.g. Invalid or missing API key (bad/missing api_key, distinct from other failures), Server unavailable (check host/port/network), or the raw gRPC status for anything else. The dots are pushed, not probed: each context has one gRPC health stream (grpc.health.v1.Health/Watch) whose status the api pushes when it changes, on a channel whose keepalive pings notice a dead path. liveness_keepalive_seconds in config.toml sets the ping interval (default 20): a silently dead connection turns red after about that plus 10 s; 0 turns liveness off. Each time a context comes up, one keyed call checks its API key. Switching context also validates the new connection immediately, so a bad key on the target context is reported right away as a toast. The Key column shows where the effective key comes from: cfg (contexts.toml), env (VIRTUFIN_API_KEY), or -- (none configured).

Protected contexts and the write gate

A context with protected = true is one where a mistake costs (production). Its context row is red on every tab (PROTECTED: changes ask first), and every change the TUI makes there asks first in a dialog: creating, deleting, starting and stopping workers and setting their tags, worker commands other than status, state saves and deletes, scheduling and deleting triggers — from the pages, their dialogs and the AI tab alike. After a yes, the further changes of the next 5 s go through without asking (one action is often several calls); a no leaves everything as it was. Scripts run as their own processes and are not covered.