Skip to content

WIP: design+fix(api): Session env-boundary inventory + InvocationShape construction (#2084, #2130) - #2324

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/2084-2130-session-env
Oct 31, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/2084-2130-session-env

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Joint contract cluster for #2084 + #2130 (unfrozen 2026-10-31; milestone 1.5.0).

Design first — docs/design/session-env-boundary.md (successor section; the frozen 1.5.0 text is untouched):

  • [api] 进程内 Session 改写宿主进程环境与信号处置,后代子进程继承(嵌入契约面待盘点裁定) #2084: complete inventory of process-global write points in a Session's lifetime (env mirror families, locale sync, winsize sync, respawn transport keys, signal entry-policy + trap reconciles + mailbox, umask, cwd, process statics), each adjudicated CLI-necessity vs embedding disposition. The clear cases get code in this PR: session-end restoration of kernel signal dispositions (the S4 evidence: an interactive library session left SIGQUIT ignored in its host process) via a first-birth snapshot restored at the last root executor's drop, and umask birth-snapshot + conditional drop restore.
  • [design] 启动形状收进 Session 构造面:引擎内部状态退出用户环境表(#2129 结构层) #2130: InvocationShape { interactive, login, respawn: RespawnSource } on the Session builder; typed invocation state on the Executor with write-through funnels (set_env/remove_env/mark_login_shell/whole-table restore), so host seeds keep working bit-for-bit while in-session script assignments to the carriers lose decision power; the read-point census (~45 sites) migrated per the table in the design doc, with named reasons for every residual carrier read.

Hard gates: #2129 pins, #2072 pins, startup-file chain tests — unchanged expectations; the CLI binary form constructs its session with the shape its argv implies (its existing set_env seeds write through).

Ledger flags for the collector (docs/api-ledger.md NOT edited here — byte-identity across repos is the collector's pairing): new symbols rubash::api::InvocationShape, rubash::api::RespawnSource, method rubash::api::SessionBuilder::invocation_shape, method rubash::api::Session::invocation_shape, method rubash::executor::Executor::invocation_interactive, method rubash::executor::Executor::invocation_login.

Refs #2084 / Refs #2130 (per-commit).

…e census

Refs #2084, Refs #2130. Successor section to the frozen 1.5.0
Session API design: full inventory of process-global write points
in a Session's lifetime with per-row adjudications (restore /
scope / documented contract), the disposition snapshot-restore
mechanism, and the #2130 read-point census for the four shape
carriers with migrate/projection/host verdicts per site.
Refs #2084

The entry policy (SIGPIPE reset, rubash#1333; SIGQUIT ignore,
sig.c:102 -> sig.c:333; fatal handlers, rubash#1475) was applied
once per process and never restored: a library Session that ran
and dropped left the host process with the shell's dispositions,
so a child spawned afterwards inherited an ignored SIGQUIT and
showed `trap -- '' SIGQUIT` (the #2084 evidence).

- capture_entry_and_policy splits into one-shot entry *facts*
  (ENTRY_IGNORED) and a re-appliable entry *policy*
  (ENTRY_POLICY_APPLIED): install_fatal_handlers re-reads the
  current dispositions as chain targets, so re-application after
  a restore is consistent.
- acquire_session_policy/release_session_policy (kill.rs-level
  wrappers session_dispositions_acquire/release): root executors
  hold counted shares behind the process-state lock; the first
  share of an era snapshots the full sigaction structs of every
  managed signal plus the fatal quartet, the last release
  reinstalls them verbatim and rewinds the recorded-state words
  (foreign handlers record state 3, which never equals a
  reconcile target, so later eras always re-apply honestly).
Refs #2130

GNU keeps the invocation shape in process-local globals
(shell.c:497-503 login_shell, shell.c:540-549 interactive_shell);
rubash carried it in __RUBASH_INTERACTIVE / __RUBASH_LOGIN_SHELL
env-table entries that any script assignment could forge and
every decision point had to re-read from the table.

- New construction surface: rubash::api::InvocationShape
  { interactive, login, respawn: RespawnSource { Fresh,
  EngineChild } } with SessionBuilder::invocation_shape and
  Session::invocation_shape. The per-flag builder methods
  (login_shell / interactive) now also declare the shape, so
  build() applies it authoritatively (previously the interactive
  flag never reached the executor at all).
- Typed state: ShellState::invocation_interactive /
  invocation_login with Executor::invocation_interactive() /
  invocation_login() / set_invocation_shape(). The
  set_env/remove_env funnels write through, so every existing
  host seed (builder, main.rs argv classification,
  mark_login_shell, restore_shell_env via
  sync_invocation_state_from_table) keeps state and projection
  in step. Script assignments write the table directly, so they
  now forge only the projection, never a decision.
- Read-point census (docs/design/session-env-boundary.md §2):
  ~50 carrier reads across 20 files; every decision point
  migrated (command_dispatch/execute/prepare,
  temporary_assignments, pwd_loop_builtins, job_builtins,
  parameter_errors, trap_exec, compound_exec, expand_word,
  prompt_expansion, bind_builtins, external_inner,
  printf_path_builtins, script_driver, public_accessors'
  diagnostic-prefix family). Zero unexplained residuals: the
  remaining table reads are projections ($-/option faces), two
  builtin-ABI readers whose contract is the env map itself
  (kill.rs trap reconcile, set.rs error prefix, both named in
  the census), the host's own classification reads in main.rs,
  and test seeds. One recorded tightening: decision points use
  value semantics (== "1" via the field); no production writer
  writes anything but "1"/remove.
- Session::source_startup_files is a no-op for
  RespawnSource::EngineChild (execute_cmd.c:1576: a forked
  subshell never re-sources) — the API form of main.rs's respawn
  door.
- Executor gains the #2084 process-state fields
  (owns_session_process_state / birth_process_umask /
  session_set_umask, declared here; wiring lands in the next
  commit), and Executor::drop releases the signal-policy share
  and conditionally restores a session-set umask.
- Pins (src/api/consumer_tests.rs):
  issue2130_invocation_shape_reaches_executor_state,
  issue2130_forged_carrier_assignment_does_not_flip_decisions,
  issue2130_engine_child_shape_skips_startup_files,
  issue2084_session_end_restores_host_process_state.
Refs #2084

Wires the kill.rs signal-policy ownership (previous commit) and
the umask restore into the executor lifecycle:

- new_inner: a root executor that outlives its construction
  (every Executor::new that is not the process-exit form) takes
  a policy share BEFORE the mailbox registration applies the
  entry policy, so the era snapshot is the host's own
  dispositions; it also records its birth process umask. The
  process-exit form holds no share (its dispositions die with
  the process, unobservable — the CLI form is unchanged), and
  command-substitution fork copies hold no share and journal
  no umask.
- execute_umask journals the value whenever the builtin changes
  __RUBASH_UMASK; the root Drop restores the birth mask only
  when the process still carries this session's setting (the
  G-03 conditional discipline: a later writer is never
  overridden). The #1907 fork-saved umask precedent covers the
  subshell boundary; this covers the session boundary.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 08:25
…inery, route interactivity reads through invocation_interactive()
@caomengxuan666
caomengxuan666 merged commit 450f564 into master Oct 31, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2084-2130-session-env branch November 2, 2026 01:08
SpookyWaste pushed a commit to SpookyWaste/rubash that referenced this pull request Nov 12, 2026
…, Refs unixwin#2130)

Collector pairing for unixwin#2324: the typed InvocationShape /
RespawnSource family it published in rubash::api is recorded
in the ledger (header addendum, §2.1 api row, §4 tier row,
§6 symbol block: 2 items, 2 variants, 8 methods), staged
ahead of host adoption like the kill-hook records before it.
niubash consumes none of it yet; its consumption today is
the engine's own build path, the migrated carrier reads,
and the in-tree consumer tests.

check-api-ledger: 186 symbols present (was 174);
--niu completeness green, no new warnings.
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