Skip to content

ariadne: py_console, a Python console for the x hosts (P2, first part) - #1195

Merged
transfix merged 11 commits into
masterfrom
feat/ox-py-console
Nov 14, 2026
Merged

transfix merged 11 commits into
masterfrom
feat/ox-py-console

Conversation

@transfix

Copy link
Copy Markdown
Owner

The first part of P2 in docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md: py_console (§4.5, "The console widget"; ARIADNE.md §9.6).

What it adds

  • A shipped component, cvc://components/py_console.ari. It has a text_view scrollback, a message_input and Clear. It is plain .ari over widgets every backend already draws, so it works the same in ariglx (ImGui), arix (the terminal) and ariglx-web (the browser). No core widget, loader or backend change. ImGui's input line has a Run button (ariglx, ariglx-web); arix runs a cell with Enter.
  • console: true in a document's python: block. The Python engine then exports (python-console ID SOURCE) and (python-console-clear ID) on that document's ScriptLane.
    • If the python: block lacks console: true, both raise PermissionError.
    • A document with no python: block has neither function: unload() puts the refusing natives back, so a reload that drops the console takes it away.
    • arisrvx warns that a server document's console: is ignored. Before, it was accepted silently.
  • Notebook-style cells in the block's own namespace (_ariadne_console, src/ariadne_python/ariadne_console.py):
    • stdout and stderr are captured (64 KB a cell). The last expression's repr is shown and kept as _ in that namespace, never builtins._.
    • input() gets EOFError, so a cell under arix never reads the terminal. SystemExit ends the cell, not the document.
    • A traceback shows only the cell's own frames. The cell's lines are in linecache under a per-load name (<console ID:N #xxxxxx>). Clear removes a console's cells, and closing a load's consoles removes all of that load's cells.
    • The scrollback echoes the cell after >>> and ..., and keeps 2000 lines.
    • Only the cell's thread is captured. sys.stdin, sys.stdout and sys.stderr hold proxies, and a ContextVar hands the running cell's streams to its own thread alone. Pool exports and the document's own threads keep the real streams, and a cell never reassigns them. A stream that was None reads nothing and writes nowhere.
  • The natives return a typed dict, {ok output log}. DSL values stay typed.
  • The console module is embedded on its own (kAriadneConsoleSource). ariadne_python.py is one configure_file literal, already half of MSVC's 16 KB cap. document_module_name() is now the one place that names a block's module. No registry and no new statics: the consoles hang off the lane's natives.
  • Docs. ARIADNE.md §9.6 (console: and "A console"), the roadmap's §4.5 "as built", and its P2 row.

Two commits: the feature, then review fixes (thread-only capture, per-load linecache names, the arisrvx warning, a stricter terminal test).

Tests (Windows, sandipaws)

  • ctest-ox-py-console.bat, CTEST_RE ^(arix_|ari_python_|ari_chat_component|ari_docset|AriadneComponents\.): 21 passed, 1 failed.
    • The failure is arix_python_program: ModuleNotFoundError: pycvc_gl. This tree builds with CVC_BUILD_PYCVC_GL=OFF, and that test's app.py imports pycvc_gl. This change doesn't touch it.
    • arix_py_console: passed, 16 cases. They include the new threads case (an async export prints while a cell runs, and the cell's output is its own), the trim case (2500 lines keep the last 2000, from "500" to "2499") and the linecache check in clear.
    • arix_engine_test (new gtest ArixEngine.AReloadIntoADocumentWithNoPythonBlockTakesTheConsoleAway): passed, 1/1.
    • arix_py_console_terminal, with the new PASS/FAIL regexes: passed.
  • ctest ^pycvc_ariadne: 2 passed, 0 failed (pycvc_ariadne, pycvc_ariadne_server).
  • Negative probe. I ran the tests with HEAD's ariadne_console.py and without the unload override. arix_engine_test failed, and arix_py_console failed on threads and clear, as expected. Then I restored the real sources and rebuilt.
  • Python probe. A script run under arix-py-prefix's python -I made 7 checks, and all 7 behaved as intended:
    • thread capture;
    • an overlapping redirect_stdout;
    • linecache clear and close;
    • another thread's input();
    • a leaked context;
    • a None stream;
    • the server warning.
  • clang-format 18.1.8 (git-clang-format --diff against the merge base): no changes.

Left out

  • No local run of the arisrvx server warning. This tree doesn't build arisrv (no gRPC or WS). I checked the warning with the Python probe instead. It drives ariadne_server._Program.load_block through a fake link, and through pycvc_ariadne_server.
  • No MAX_TEXT (1 MB) trim case. The finding asked only for the 2000-line trim.
  • No ariglx-web browser smoke run. The web tree here only compiles the touched sources and doesn't link. The new smoke case, "the py_console component runs a cell in the page", is in arigl_web_smoke.mjs.
  • The rest of P2: py_editor (ImGuiColorTextEdit needs a cvcpkg recipe), jedi completion, the console's history keys, and display().

Merging waits on Joe's review.

A shipped component, cvc://components/py_console.ari: a text_view
scrollback, a message_input with a Run button, and Clear. It is plain
.ari over widgets every backend already draws, so it works the same in
ariglx (ImGui), arix (the terminal) and ariglx-web (the browser), with
no core widget, loader or backend change.

A document turns it on with `console: true` in its python: block. The
Python engine then exports two natives on that document's ScriptLane:
(python-console ID SOURCE) and (python-console-clear ID). Each
submission runs as one notebook-style cell in the namespace the block
ran in (_ariadne_console, src/ariadne_python/ariadne_console.py):

- stdout and stderr are captured (64 KB a cell), and the last
  expression's repr is shown and kept as `_` in that namespace (never
  builtins._, which is process-wide);
- input() reads an empty stdin and raises EOFError, so a cell under
  arix never reads the terminal;
- an exception shows its traceback from the cell's own frames, its
  lines registered in linecache; SystemExit ends the cell, not the
  document;
- the scrollback echoes the cell after >>> and ..., and keeps 2000
  lines.

The natives return a typed dict {ok output log}; DSL values stay typed.
Without console: true they raise PermissionError. unload() puts the
refusing natives back, so the old namespace goes with its load and a
reload that drops console: true has no console.

The console module is embedded on its own (kAriadneConsoleSource):
ariadne_python.py is one configure_file literal, already half of MSVC's
16 KB cap. document_module_name() is now the one place that names a
block's module. No registry and no new statics: the consoles hang off
the lane's natives. Server hosts never reach load_block, so arisrvx is
unchanged.

Docs: ARIADNE.md 9.6 (console: and "A console"), the roadmap's 4.5 as
built, and its P2 row (left: py_editor, jedi completion, history keys,
display()).

Tests: arix_py_console (expression, print and stderr, a multi-line cell,
the shared namespace, _, a traceback without engine frames, SyntaxError,
SystemExit, input(), the output cap, clear, two consoles, bad
arguments), arix_py_console_off, arix_py_console_terminal,
ari_python_console_needs_arix; AriadneComponents.ShippedComponentsLoadClean
picks up py_console.ari; the ariglx-web smoke case "the py_console
component runs a cell in the page".
…xes)

A cell no longer swaps sys.stdin, sys.stdout and sys.stderr for the
process. A cell gives up the GIL, so other threads run while it does:
an async export on the pool, or a thread of the document's. Before,
their print() landed in the cell's output and scrollback, their input()
got EOFError, and a redirect_stdout of their own that overlapped a cell
could leave sys.stdout on a dead StringIO for the rest of the process.

- The first document with a console puts a _Stream in each of the
  three, and every later load with a console checks again. The cell's
  thread gets the running cell's streams (a ContextVar the cell sets
  and resets); every other thread, and any thread between cells, gets
  the stream the proxy stands in for. A cell's streams are closed when
  it ends, so a context it leaves behind falls back too. A stream that
  was None reads nothing and writes nowhere.
- linecache: a cell's file name carries its load's tag
  (<console ID:N #xxxxxx>), so a reload or the next document no longer
  overwrites an earlier load's entries. Clear takes a console's cells
  out. When the natives let go of a load's consoles they close them,
  which takes all of that load's cells out.
- arisrvx: a server document's console: was accepted silently and did
  nothing. Its load now warns that the key is ignored.
- arix_py_console_terminal matches the output on the scrollback's row,
  and fails on a line of the process's own stdout.

Tests: arix_py_console gets a threads case (an async export prints
while a cell runs, and the cell's output is its own), a trim case (2500
lines keep the last 2000, from "500" to "2499") and a linecache check
in clear. The new arix_engine_test hosts the engine under one
AppRuntime and reloads it from a console document into one with no
python: block: both natives raise PermissionError, and the first load's
cells have left linecache when a third load's block looks. With the old
console module and no unload override, the threads case and
arix_engine_test fail.

Docs: ARIADNE.md 9.6 and the roadmap's 4.5 now say that a document
whose python: block lacks console: true gets a PermissionError, and one
with no python: block has neither function. The Run button is ImGui's
(ariglx, ariglx-web), and arix runs a cell with Enter.
pycvc-linux builds the scripting hosts by name (ari, arix, ariglx), and
its scripting-host step runs every test matching ^arix_. This branch adds
arix_engine_test, which matched but was never built, so ctest reported it
"Not Run" and the job failed. The build step now names it too.
@transfix
transfix enabled auto-merge (squash) November 13, 2026 03:54
…app (master builds again)

#1197's ariadne_wasm_browser_test.cpp (built natively as ariadne_wasm_transform_test wherever
wasmtime is found, and in the wasm-guests node job) still called register_script_engine(engine)
and unregister_script_engine("wasm"), which #1203 replaced with the (app, ...) forms. #1197's CI ran
before #1203 landed, so master at accadc3 doesn't compile it.

As #1203 did for ariadne_wasm_test.cpp: SetUp no longer registers the engine, and the TearDown
that unregistered it goes. Each of the file's 18 AppRuntimes already calls
use_script_engine(engine), which registers it on that runtime's app.
… app

#1203 gives every cvc command its app as an argument, removes cvc_app() and
makes cvc::ariadne::load_string take the app. It merged after #1168 and #1180,
whose new code still used the old forms, so master does not build:
- src/cvc-cli/main.cpp: cmd_trace (#1168) takes cvc::app & like the other
  commands and replays on it, not cvc_app().
- src/cvc/tests/ariadne_runtime_test.cpp: #1180's three AriadneRichText
  tests pass their app to load_string; each already makes one.
@transfix
transfix merged commit e1eca3e into master Nov 14, 2026
28 checks passed
@transfix
transfix deleted the feat/ox-py-console branch November 14, 2026 17:47
transfix added a commit that referenced this pull request Nov 14, 2026
CI at 9d002d1 built it on master as of 09:28, after #1197 added
ariadne_wasm_browser_test.cpp with register_script_engine calls that
predate #1203 (all three package-linux lanes and wasm-guests failed to
compile it). Master fixed that in #1229, and the load_string calls
#1169 left in the loader and chart tests in #1190. This merge takes
master as it is now, so CI builds on those fixes. No conflicts.

Master's new natives (#1190's file-pick and http-upload, #1195's
py_console, #1169's chart) build against this branch's call_args
context as they are.

Checked on Windows (MSVC Release): full build; the Ariadne, net, HTTP,
state_exec, groups, slices, async-call, cycle-registry and multi-app
ctests, 1336/1336. ariadne_wasm_browser_test is not built here (it needs
wasmtime or Emscripten); master's CI builds it.
transfix added a commit that referenced this pull request Nov 14, 2026
…#1222-#1225, #1229)

Master's #1190 (file-pick and http-upload) was written for a single async host; this branch runs
an isolated document's programs on its own group's host, on a pool worker in an `any` group.

- net_intrinsics.cpp: StartedRequest takes master's deliver()/on_outcome, settling through the
  host's finisher. http-upload is its own provider, `any` as the requests are: it parks on the
  calling program's host (ictx.host), takes its progress path from ictx.root_path (no tree walk
  on a worker), and a started upload (a browser page) keeps the host's finisher, not the host.
- ariadne.cpp: file-pick, file-info and file-forget bind into the program's env as they are, in
  every group (install_backend_verbs), not through the backend verbs' host_proxied wrapper, which
  cannot park an async verb. file-pick parks on the program's own host, claims the Runtime's
  picker hub under its lock where it is called, and opens the picker on the host thread
  (exec_pool::run_on_host; inline when called there). Its answer goes through the host's
  finisher, as the host may be gone by then.
- ci.yml: the sanitizer list keeps this branch's tests and master's point_classes_test.
- STATE_EXEC_THREADED.md: rows for http-upload, the file verbs, and the contours and
  point-classes providers. The last two are registered without a kind, so they are host_only, and
  an isolated document in an app that installs them goes to a host-affinity group.
- New test: AriadneIsolatedDocs.FilePickOpensItsPickerOnTheFramesThread.
transfix added a commit that referenced this pull request Nov 14, 2026
One conflict, master's #1195 (py_console) in the class this branch
reworked, python_engine.cpp's PythonScriptEngine:
- load_block keeps master's order (the block's object lives on for
  consoles_for) with this branch's take_error(helper); unload comes in
  beside the engine's private EngineState pointer.
- export_console's natives described their own errors through the
  process-wide g_helper this branch removed. export_console now takes
  the helper and its natives hold a reference of their own, let go as
  their consoles are; unload passes none.
- The engine's constructor describes a console that fails to load with
  st.helper, which is up by then.

Checked on Windows (MSVC Release): full build; format clean on changed
lines; the host, Python and multi-app ctests with master's console
tests, 47/47 (skips as before: no FTXUI or matplotlib here), among them
arix_engine_test, which reloads documents with and without a console.
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