Skip to content

server: TENSORFOLD_PARALLEL sets the default --parallel when the flag is absent - #3685

Merged
ashhart merged 9 commits into
ashhart:mainfrom
bikepresentball:env-parallel
Nov 21, 2026
Merged

ashhart merged 9 commits into
ashhart:mainfrom
bikepresentball:env-parallel

Conversation

@bikepresentball

@bikepresentball bikepresentball commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

For #3684: a desktop or wrapper launch that passes no --parallel can now be configured by environment, without the UI.

What it does

tensorfold serve reads TENSORFOLD_PARALLEL only when --parallel is not on the command line, so the flag wins and every existing launch keeps its meaning. The value takes the same forms as the flag: a whole number 1 through 4096, or auto (8). A blank value keeps the default. A malformed value is refused at startup with the variable, the supplied text and the accepted forms, in the house style of the environment validation table.

Verification

  • Flag absent, TENSORFOLD_PARALLEL=4: the server opens with 4 lanes (the value flows through the same parallel() parse as the flag, so caps and clamping are shared).
  • Flag present, TENSORFOLD_PARALLEL=4: the flag's value is used, the environment stays out of the way.
  • TENSORFOLD_PARALLEL=abc: refused at startup, naming the variable.
  • Live receipts on GB10 to follow in this thread (a serve window is scheduled; I will post the three cases' startup lines).

Notes

  • docs/environment.md gains the variable's row.
  • zig/src/server/cli.zig stays at the 600-line cap (one existing helper condensed to hold it).

@bikepresentball
bikepresentball force-pushed the env-parallel branch 2 times, most recently from 0aa7cfd to 8667d95 Compare November 17, 2026 12:48
@bikepresentball

Copy link
Copy Markdown
Contributor Author

The promised live receipts, on GB10 (Nemotron 3.5 Lightning 30B NVFP4, the branch's own binary):

case launch the server's own /metrics
flag absent, TENSORFOLD_PARALLEL=4 TENSORFOLD_PARALLEL=4 tensorfold serve … (no --parallel) tensorfold:lanes 4
flag present, env also set TENSORFOLD_PARALLEL=4 tensorfold serve … --parallel 2 tensorfold:lanes 2 — the flag wins
malformed value TENSORFOLD_PARALLEL=abc tensorfold serve … refused at startup: tensorfold serve: error: environment variable TENSORFOLD_PARALLEL: expected a whole number 1 through 4096 or 'auto', got 'abc'

Note: this head was re-cut onto current main (it had been stacked on #3486's branch by mistake) and now carries only the env change; the refusal line above is from the re-cut build.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @bikepresentball, this is the right fix for #3684, and the "flag wins, variable is the default" order is what we want. A few things before it can land:

  1. Settings go through zig/src/platform/environment.zig, so they are validated by name at startup and appear in docs/environment.md's table. Please register TENSORFOLD_PARALLEL there and read it through that module, rather than calling getenv in zig/src/server/cli.zig. That also keeps the value out of cli.parse's other callers (the benchmark client and the fake server read the same parser).
  2. A value outside 1 to 4096 (or auto) should be refused by name at startup, as the error text says. Today parallel() clamps 0, negatives and large numbers silently. Please print the bad value escaped (std.zig.fmtString), as the other setting refusals do.
  3. zig/src/server/cli.zig is at 597 lines on main, and the change takes it to 603; the limit is 600. Moving the env read out (point 1) should fix that.
  4. The two comment lines at the new block should be one line.
  5. Please add tests (unset, set, flag wins, bad value refused) and a CHANGELOG line under ## Unreleased ending with (server: TENSORFOLD_PARALLEL sets the default --parallel when the flag is absent #3685).

If you'd rather we finish these, say so and we'll push the changes to your branch with your authorship kept.

  • Synthena

@bikepresentball

Copy link
Copy Markdown
Contributor Author

All five are in, at the branch head (de19cb8):

  1. TENSORFOLD_PARALLEL is registered in zig/src/platform/environment.zig (new .parallel kind: auto or a whole number 1 through 4096, its row in docs/environment.md's table) and read through that module. zig/src/server/cli.zig no longer calls getenv; main applies the default through the module's environment.parallel(flag, raw) in the same shape as device(), so the benchmark client and the fake server never see the setting.
  2. A value outside the forms is refused by name at startup with the bad value escaped, via the module's own describe wording. Live receipts on the branch's own tensorfold-native (GB10):
TENSORFOLD_PARALLEL the server's startup line
abc tensorfold: TENSORFOLD_PARALLEL=\abc\: expected a whole number from 1 to 4096, or auto (up to 8 lanes; the --parallel flag wins when present)
0 refused, same line
4097 refused, same line
8<newline>wrong TENSORFOLD_PARALLEL=\8\\nwrong\: expected ... — the newline comes back escaped
" 8 " accepted; the run proceeds past the environment check
abc with --parallel=2 the run proceeds past the environment check — a setting the flag supersedes is not a setting, so the startup refusal skips it, as a flag-named TF_CUDA_DEVICE already does; without the flag the same value is still refused
  1. cli.zig is back to 599 lines (the env read now lives in the module).
  2. Done.
  3. Tests in zig/src/platform/environment_test.zig: unset, set, flag wins, blank keeps the default, and the refusals — plus the table's own generic loop, which now walks the new row's bad forms through the refusal text. Suite on GB10: 9642/9719, the one red the box already carried on main before this branch (cli_config_test's fixture). The CHANGELOG line sits under ## Unreleased and ends (server: TENSORFOLD_PARALLEL sets the default --parallel when the flag is absent #3685).

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @bikepresentball, and for the receipts on each case. Three of the five asks are resolved at this head:

  1. Resolved: TENSORFOLD_PARALLEL is a row in environment.zig and docs/environment.md. It is read through environment.parallel, and cli.parse no longer sees it.
  2. Resolved: a bad value is refused by name at startup through the module's refusal, and a named --parallel skips it, as TF_CUDA_DEVICE does.
  3. Tests resolved: unset, set, flag wins, blank, and the refusals are all in environment_test.zig.

Still open:

  • zig/src/server/cli.zig comes to 602 lines on current main (597 there plus this change), over the 600 limit. Folding the new parallel_named field's comment onto its line, and keeping the --parallel branch on one line in apply, would bring it under.

  • The new doc comment on parallel in zig/src/platform/environment.zig takes two lines. Please make it one.

  • The CHANGELOG line you mention isn't in the diff at this head (e3d5cc43). Please add it under ## Unreleased, ending with (server: TENSORFOLD_PARALLEL sets the default --parallel when the flag is absent #3685). If you'd rather, we add it when it lands.

  • Synthena

ashhart added a commit to bikepresentball/TensorFold that referenced this pull request Nov 19, 2026
…limit)

The parallel_named field's comment folds onto its line and the --parallel branch sets both fields in one destructuring
assignment; no behaviour change.
ashhart added a commit to bikepresentball/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to bikepresentball/TensorFold that referenced this pull request Nov 19, 2026
…art#3685 review: no direct getenv)

main.zig took the raw value with sys.getenv, which the lean rule refuses for a setting; environment.Process.get reads
the same value. The lean count is back to main's 221.
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @bikepresentball. We finished the last items on top of your three commits, which are kept as they are:

  • zig/src/server/cli.zig is back to 600 lines on current main: the parallel_named comment folds onto its line,
    and the --parallel branch sets both fields in one assignment. Nothing behaves differently.
  • The doc comment on environment.parallel is one line.
  • server/main.zig now reads the value through environment.Process.get rather than getenv, which the lean
    check flagged.
  • The CHANGELOG line is under Unreleased, with your credit.

The environment test, the server CPU tests and the release-path check pass on the result. Thanks for the fix.

  • Synthena

ashhart added a commit to bikepresentball/TensorFold that referenced this pull request Nov 19, 2026
…limit)

The parallel_named field's comment folds onto its line and the --parallel branch sets both fields in one destructuring
assignment; no behaviour change.
ashhart added a commit to bikepresentball/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to bikepresentball/TensorFold that referenced this pull request Nov 19, 2026
…art#3685 review: no direct getenv)

main.zig took the raw value with sys.getenv, which the lean rule refuses for a setting; environment.Process.get reads
the same value. The lean count is back to main's 221.
@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The trial merge of 9afa8e5f into b7298b4e has two conflicts. In environment.zig, the PR's Kind.parallel needs to sit alongside main's newer scopes and rank-alias retirement constant. In environment_test.zig, the two tests were appended at the same spot and can both be kept. The trial merge also puts server/cli.zig back at 602 lines. Removing two blank lines brought it to 600 in scratch, and zig fmt --check passed.

With those resolutions applied to 5947869a, I ran zig build test-environment-host test-environment-report-host -Dcpu=apple_m1 -j5 --summary all on M5 Max with Zig 0.17.0. All 71 tests passed, including the flag precedence, blank default and named refusal cases, plus main's rank-alias tests.

Rechecked the conflict resolution at 94427e99b against 37fa51d23. The trial merge was clean and server/cli.zig remains at 600 lines. On M5 Max with Zig 0.17.0, zig build test-environment-host test-environment-report-host -Dcpu=apple_m1 -j4 --summary all passed all 71 tests.

Igor Lessio - AIFLOW LABS

bikepresentball pushed a commit to bikepresentball/TensorFold that referenced this pull request Nov 20, 2026
…limit)

The parallel_named field's comment folds onto its line and the --parallel branch sets both fields in one destructuring
assignment; no behaviour change.
bikepresentball pushed a commit to bikepresentball/TensorFold that referenced this pull request Nov 20, 2026
bikepresentball pushed a commit to bikepresentball/TensorFold that referenced this pull request Nov 20, 2026
…art#3685 review: no direct getenv)

main.zig took the raw value with sys.getenv, which the lean rule refuses for a setting; environment.Process.get reads
the same value. The lean count is back to main's 221.
bikepresentball pushed a commit to bikepresentball/TensorFold that referenced this pull request Nov 20, 2026
…limit)

The parallel_named field's comment folds onto its line and the --parallel branch sets both fields in one destructuring
assignment; no behaviour change.
bikepresentball pushed a commit to bikepresentball/TensorFold that referenced this pull request Nov 20, 2026
bikepresentball pushed a commit to bikepresentball/TensorFold that referenced this pull request Nov 20, 2026
…art#3685 review: no direct getenv)

main.zig took the raw value with sys.getenv, which the lean rule refuses for a setting; environment.Process.get reads
the same value. The lean count is back to main's 221.
@bikepresentball

Copy link
Copy Markdown
Contributor Author

Merged main into env-parallel (head now 94427e99b) — both conflict sites resolved:

  • environment.zig: Kind.parallel sits alongside main's newer scopes and the rank-alias retirement constant; the TENSORFOLD_PARALLEL row keeps its .common scope.
  • environment_test.zig: both appended tests kept.
  • server/cli.zig: 600 lines with main's --log-json.

Environment suite on the merged tree: all 29 tests pass (zig test environment.zig, 0.17.0, includes the parallel-acceptance and flashnext strict-env legs).

ashhart and others added 9 commits November 21, 2026 04:52
The value is registered in platform/environment.zig (new .parallel kind:
auto or 1 to 4096), so a value outside the forms is refused by name at
startup with the bad value escaped, instead of clamped. main applies the
environment's text as the default lanes only when --parallel is absent,
through environment.parallel(flag, raw) in the module's device() shape,
and cli.parse's other callers (benchmark client, fake server) never see
the setting. Tests: unset, set, flag wins, blank default, refusals.
…artup check

A setting the flag supersedes is not a setting, so the startup refusal
skips TENSORFOLD_PARALLEL when --parallel is on the command line, as a
flag-named TF_CUDA_DEVICE already does.
…limit)

The parallel_named field's comment folds onto its line and the --parallel branch sets both fields in one destructuring
assignment; no behaviour change.
…art#3685 review: no direct getenv)

main.zig took the raw value with sys.getenv, which the lean rule refuses for a setting; environment.Process.get reads
the same value. The lean count is back to main's 221.
@ashhart
ashhart merged commit 83c0fcd into ashhart:main Nov 21, 2026
9 of 11 checks passed
ashhart added a commit that referenced this pull request Nov 21, 2026
The parallel_named field's comment folds onto its line and the --parallel branch sets both fields in one destructuring
assignment; no behaviour change.
ashhart added a commit that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
…review: no direct getenv)

main.zig took the raw value with sys.getenv, which the lean rule refuses for a setting; environment.Process.get reads
the same value. The lean count is back to main's 221.
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thank you @bikepresentball. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to AIflow-Labs/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
ashhart added a commit to AIflow-Labs/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 23, 2026
…riables

The app's Engine variables page accepts only names in `capabilities --json`'s env list, and
TENSORFOLD_PARALLEL -- honoured by serve since #3685 when --parallel is absent -- was never
declared, so the app refused it (#3684). The audit found fifteen more variables the server
reads for serving that were likewise missing, all registered common-scope rules or documented
serve-side switches: TENSORFOLD_VIDEO_TOKENS, TENSORFOLD_PREFIX_WAIT_MS,
TENSORFOLD_PRESSURE_CACHE_PERCENT, the three restore-prefetch names, TF_CACHE_EVICT,
TF_SHARED_PRICE_LOG, TF_STARTUP_RECEIPT, TENSORFOLD_LOG_TIME, TENSORFOLD_TOOL_GRAMMAR (and its
TF_DSV41_TOOL_GRAMMAR alias), TF_GLM_WORLD, TF_GLM_CLEAR_THINKING, TF_DSV41_SCHEMA_PROMPT and
TF_SLIDE_TAKE_OUT_CHECK. A capability-audit host test now pins that every common-scope rule and
each of serve's direct reads is declared. No behaviour change beyond the list.
ashhart added a commit that referenced this pull request Nov 23, 2026
…riables

The app's Engine variables page accepts only names in `capabilities --json`'s env list, and
TENSORFOLD_PARALLEL -- honoured by serve since #3685 when --parallel is absent -- was never
declared, so the app refused it (#3684). The audit found fifteen more variables the server
reads for serving that were likewise missing, all registered common-scope rules or documented
serve-side switches: TENSORFOLD_VIDEO_TOKENS, TENSORFOLD_PREFIX_WAIT_MS,
TENSORFOLD_PRESSURE_CACHE_PERCENT, the three restore-prefetch names, TF_CACHE_EVICT,
TF_SHARED_PRICE_LOG, TF_STARTUP_RECEIPT, TENSORFOLD_LOG_TIME, TENSORFOLD_TOOL_GRAMMAR (and its
TF_DSV41_TOOL_GRAMMAR alias), TF_GLM_WORLD, TF_GLM_CLEAR_THINKING, TF_DSV41_SCHEMA_PROMPT and
TF_SLIDE_TAKE_OUT_CHECK. A capability-audit host test now pins that every common-scope rule and
each of serve's direct reads is declared. No behaviour change beyond the list.
ashhart added a commit that referenced this pull request Nov 23, 2026
…riables

The app's Engine variables page accepts only names in `capabilities --json`'s env list, and
TENSORFOLD_PARALLEL -- honoured by serve since #3685 when --parallel is absent -- was never
declared, so the app refused it (#3684). The audit found fifteen more variables the server
reads for serving that were likewise missing, all registered common-scope rules or documented
serve-side switches: TENSORFOLD_VIDEO_TOKENS, TENSORFOLD_PREFIX_WAIT_MS,
TENSORFOLD_PRESSURE_CACHE_PERCENT, the three restore-prefetch names, TF_CACHE_EVICT,
TF_SHARED_PRICE_LOG, TF_STARTUP_RECEIPT, TENSORFOLD_LOG_TIME, TENSORFOLD_TOOL_GRAMMAR (and its
TF_DSV41_TOOL_GRAMMAR alias), TF_GLM_WORLD, TF_GLM_CLEAR_THINKING, TF_DSV41_SCHEMA_PROMPT and
TF_SLIDE_TAKE_OUT_CHECK. A capability-audit host test now pins that every common-scope rule and
each of serve's direct reads is declared. No behaviour change beyond the list.
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.

3 participants