Repository navigation
Ariadne loader: about 1 KB of stack a level, and a document nests at most 256 levels - #1586
Merged
Merged
Conversation
…most 256 levels The .ari loader parsed a document a level at a time with a 95 KB frame (parse_widget_impl: MSVC gave each by-value Widget temporary of its per-kind branches a slot of its own), so a load took about 100 KB of stack a widget level and 200 KB an include: level: 9 include: levels on wasm's 2 MiB stack, 40 on 8 MiB (the 41-deep `ari snapshot` crash). - parse_widget_impl's branches are never-inlined functions, each building its widget in place. parse_widget, parse_seq, expand_include, expand_load and parse_document build in place too, and what a level does besides going down is in functions of their own. MSVC Release frames: parse_widget_impl 95,656 -> 248 bytes, expand_load 11,384 -> 584, parse_document 6,264 -> 344, parse_seq 3,432 -> 568, expand_include 3,384 -> 296. A level now takes about 0.9 KB through include:s: 1,177 include: levels load on 2 MiB (was 9), 266 on 512 KiB (was 1). - kMaxNesting (256, loader.h): a widget is a level, and so is each include: and load: entry, counted across every unit and fragment (Nesting, shared by a load:'s sub-Ctx). The first widget past it stops the parse and the load fails, its error at the widget's place (in an include: expansion, the same place in the unit's template), counting the include:s and load:s on the way and naming each that goes into another file. LoadResult::error_source, error_line and error_column hold the place. The shipped documents nest at most 11 levels. - ari validate reports such an error at its place (file:line:col: error: ...), and --json adds load_error_source, load_error_line and load_error_column. - any_descendant_repeats and refs_from_widget are loops. Tests: the loader at the limit and one past it through plain children, include: and load:; a document at the limit through include:s and through load:s loads and draws on a 2 MiB stack (8 MiB in a Debug build); ari_validate_too_deep; probes for the schema check and yaml-cpp's parse alone, and for a deep fragment loaded at the limit. docs/ARIADNE.md §6.7, with §6.1, §6.3, §14.3.
transfix
enabled auto-merge (squash)
November 27, 2026 07:29
transfix
added a commit
that referenced
this pull request
Nov 27, 2026
…ounts-fb75fd #1586 builds each widget in place and splits expand_load into read_fragment, open_mount and finish_mount. SH1's LoadOutcome (why a fragment was not mounted, its canonical path, whether it has a scene, and the min_libcvc gate a run-time mount keeps) moves into read_fragment, and expand_load passes it through. parse_mounts builds its slot in place like the other widgets. load_mount gives its context a Nesting, as load_node does, and refuses a document nested past kMaxNesting with that error rather than mounting it cut short: a mounts: entry's document nests as a document of its own does. New AriadneLoader.LoadMountRefusesADocumentNestedPastTheLimit. ARIADNE.md: #1586's "How deep a document nests" keeps 6.7, which its error message cites, and mounts: is now 6.8; SH1's references to it follow. The deep nesting tests keep both sides.
transfix
added a commit
that referenced
this pull request
Nov 27, 2026
…bare name - close_mount cleared the mount's principal right after quit_app, before the children that share its scope were killed, and the Runtime's teardown before the group's own teardown reaped what was left. A program built in between would have run as the scope's parent, local in a catalog shell. Both now clear it once the mount's processes are gone. - mount_principal gave "file:" (no directory) for a mount whose name has no directory and whose loader gives no canonical path, and SH11's store refuses an empty file: principal, so open_mount refused every such mount (AriadneDeepNesting.AMountsSlotsEntriesDraw, from #1586). Such a name is in the current directory: file:.
transfix
added a commit
that referenced
this pull request
Nov 28, 2026
…rincipal (#1576) * Ariadne shell SH11: the network, credentials, keys and sign-ins per principal A program's verbs are bound to the network of the principal its scope runs as (docs/roadmap/ARIADNE_SHELL.md 4.12), so a document mounted beside nicotina cannot post as the reader or reach the origins nicotina may. - principal.h: a table per app of scope to principal (local, file:<dir>, remote:<origin>), the innermost recorded scope deciding and a local one inside a sandboxed one unable to raise it; hosts may check a principal as it is recorded. - CredentialStore: one store and file, viewed per principal (for_principal); each view has its own entries, bindings and renewers. File lines are "<principal> <name> <origin> <token>"; three-word lines load as local. - enable_net: each program's http verbs, fetch, http-upload, ws-*, net-*, open-url and oidc-* use net_host_access(app, scope): the launcher's for local, its own origin and granted origins for remote:, granted origins only for file:. A local application may have its own policy, credential store and e2ee store. - WebSocket handles and OIDC sign-ins are their owner's; a sandboxed principal's sign-ins are not posted to the global oidc# channel. - e2ee: a sandboxed principal gets its own in-memory key store. - Pictures, video and Save with auth: are fetched as the widget's principal. - Tests: ariadne_net_principal_test (credential isolation, allowlists, the file, nicotina's own policy and store against a local stand-in, WebSockets, sign-ins, e2ee, pictures) and the store's own in net_policy_test. * SH11: scope last in ImageRequest, PlayerSource and MediaSave The new scope member sat between auth and w in ImageRequest, so the positional initializers in ariadne_media_test.cpp (uri, auth, w, h, fit, shape) no longer compiled, and every package job failed on it. Each struct now ends with scope, so an initializer written before SH11 still lines up and leaves scope empty (the launcher's). * SH11 on SH1's mounts: each mount runs as its principal - open_mount records the mount's principal (SH1's mount_principal, with the entry's net_policy, credential_store and e2ee_store) under its scope before any of its programs is built; a check that fails refuses the mount. close_mount and the Runtime's teardown clear it. - shell.ari: a catalog entry's net_policy, credential_store and e2ee_store (relative to the catalog) are kept with its row; such an entry opens under its slug with them written into shell.apps.<slug> first. - Tests: a catalog mount as local and another file as file:<dir> (credentials and allowlist), a local application's own network from its entry and the refusals, and shell.ari's catalog entry with its own network. - ARIADNE.md 6.7 lists the entry's keys; ARIADNE_SHELL.md's SH11 note says where the principal is recorded. * SH11 on the merged SH1: clear a mount's principal last; file:. for a bare name - close_mount cleared the mount's principal right after quit_app, before the children that share its scope were killed, and the Runtime's teardown before the group's own teardown reaped what was left. A program built in between would have run as the scope's parent, local in a catalog shell. Both now clear it once the mount's processes are gone. - mount_principal gave "file:" (no directory) for a mount whose name has no directory and whose loader gives no canonical path, and SH11's store refuses an empty file: principal, so open_mount refused every such mount (AriadneDeepNesting.AMountsSlotsEntriesDraw, from #1586). Such a name is in the current directory: file:. * SH11: compare the shell test's store path canonically AriadneComponents.ShellGivesACatalogEntryItsOwnNetwork compared the credential store's path with temp_directory_path() / ... after lexically_normal. On the windows-2022 runner the temp directory comes back in its 8.3 spelling (C:/Users/RUNNER~1/...), while the store's path is resolved to long names, so the same file compared unequal. Both sides are now weakly_canonical. Reproduced locally with TMP set to a short-name folder: the old assertion fails, the new one passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
.ariloader ran out of native stack at shallow nesting:parse_widget_implhad a 95 KB frame, and it runs once a level. This PR makes a level cheap, then caps nesting at 256 levels with an error that says where. The per-frame walk was made stackless in #1577; after this PR the loader's limit is the only depth limit a document has.The frame, before and after
MSVC 14.44 Release x64 (
/FAslisting ofloader.cpp), in bytes:parse_widget_implexpand_loadparse_documentparse_seqexpand_includeparse_widgetMSVC gave each by-value
Widgettemporary in the per-kind branches (text(),separator(),spinner(), ...) a slot of its own, and aWidgetis about 3.3 KB. Now:Widget &w).parse_widget,parse_seq,expand_include,expand_loadandparse_documentbuild in place too.parse_leaf, 2,984 B) andfinish_mount(2,344 B) are never on the way down.wasm32 (em++ -O2,
loader.cppcompiled alone, shadow stack read from each prologue):parse_widget_impl3,184 → inlined intoparse_widget(48),expand_load3,696 → 272,parse_seq1,472 → 144,parse_document1,456 → 80. That is about 0.2–0.3 KB a level there.Depth per stack, before and after
Bisected with
ariadne_deep_nesting_test's probes (MSVC Release; the "after" include column with the limit lifted for the measurement):include:levels, masterinclude:, this PR(a) From the walk session's measurement on 327a791; the rest measured here on 93c9da4.
An
include:level is two levels of the count. So the parse alone goes about 2,350 levels deep on 2 MiB, and the 256 limit is about 9× under that. Inline nesting stops at 246 on 2 MiB and on 8 MiB: that is yaml-cpp's own parse cap (about 500 levels of YAML, two a widget). The inline numbers are dominated by the schema check (see "What the limit does not bound").The limit
kMaxNesting = 256(loader.h).include:andload:entry. The unit's or fragment's widgets go on below the entry. The count runs across every unit and mounted fragment: aNestingstate on theCtx, shared with aload:'s sub-Ctxthe waymount_countis. It is per load, never a static.okfalse, no tree). Its error is at that widget's place; in aninclude:expansion, that is the same place in the unit's template, found by the key/index path. The error counts theinclude:s andload:s on the way down, and names each one that goes into another file:LoadResult::error_source,error_lineanderror_columnhold the place.ari validate: reports the error there, compiler-style (deep.ari:514:9: error: a widget nested deeper than 256 levels ...).--jsonaddsload_error_source,load_error_lineandload_error_column. A JSON schema cannot count across files, soari.v1.schema.jsonis unchanged..ariin libcvc nests 11 levels (thevolume_gridfamily). GRL-SNAM's documents nest 8, SH1'sshell.ari4. The 40-deep include test is 82.any_descendant_repeatsandrefs_from_widgetare loops now.What the limit does not bound (findings, not changed here)
load:s a 246-deep inline fragment, which is checked before its parse is refused (DISABLED_ProbeLoadDeepFragmentAtTheLimit).parse_scene_node: it recurses a scene level at a time with an 8.7 KB MSVC frame (2 KB wasm), bounded only by yaml-cpp (about 245 scene levels, about 2.1 MB on MSVC). The limit doesn't count scene nodes.Tests
ariadne_loader_test:NestingLimitCountsPlainChildren,NestingLimitCountsIncludesandNestingLimitCountsLoads. Each has a document at 256 that loads and one at 257 that fails, with its place checked (line and column, the files on the way).ariadne_deep_nesting_test: a document nested to the limit throughinclude:s, and one throughload:s, each loads and draws on a 2 MiB stack (8 MiB in a Debug build, whose frames are several times larger); one past the limit fails there. There are new probes for the schema check alone, yaml-cpp's parse alone, and a deep fragment loaded at the limit.ari_validate_too_deep(ctest): a generated 128-unit document, reported atvalidate_too_deep.ari:514:9.Run locally (Windows, MSVC Release, with the validator and FTXUI):
ariadne_loader_test277,ariadne_schema_test13 + 1 skipped,ariadne_host_test69,ariadne_deep_nesting_test13 + 1 skipped (tvision),ariadne_runtime_test368, and theari_*ctests (11,ari_validate_too_deepamong them). Not run here: Linux, macOS, wasm (CI).Docs
docs/ARIADNE.mdhas a new §6.7 "How deep a document nests". §6.1 and §6.3 point to it, and §14.3 covers the placed load error inari validate.Conflicts expected
expand_load's failure paths (LoadOutcome). These now live inread_fragment.repeat:key. That now lives incommon_keys.