Repository navigation
fix(api): close_with_report conveys the close-boundary state as a value (#2039) - #2158
Merged
Merged
Conversation
…ue (#2039) rubash#2039: Session::close() consumed the session and returned only the i32 final status, with no face that conveys session state at the close boundary. Any host contract that reads session state AFTER close was forced to snapshot before closing — and a pre-close snapshot is structurally blind to the EXIT trap's own effects. That is the structural premise of the niu #668 cwd regression (the --cwd-state recorder must read the final directory after the EXIT trap, because a trap's cd is the session's last cwd write; niu's repair 208be63 had to split its finish funnel into trap-then-close composition to keep the read alive). GNU specification (the exit path's status half, unchanged by this fix): - third_party/bash/trap.c:1027 run_exit_trap() saves the entry status into trap_saved_exit_value (trap.c:1036) and returns it (trap.c:1052, 1094) — a bare `exit` inside the EXIT trap keeps the saved value. Oracle (WSL GNU Bash 5.3.x, script file): `trap 'exit 7' EXIT` -> 7; `trap 'cd /tmp' EXIT; exit 5` -> 5. Fix (the issue's primary candidate form: close reports the final state as a value; the pre-close-callback alternative stays with the contract batch, per the issue's "候选形态在该批统一裁"): - CloseReport (#[non_exhaustive], the RunOutcome growth discipline): status (the value close() returns) + cwd (session_cwd() — public_accessors.rs:1228, the engine cd-machinery state the §5.3 Session::cwd face reports — read AFTER script_driver::finish_shell returns, i.e. after the EXIT trap ran; script_driver.rs:5401 orders history write -> job flush -> EXIT trap -> debugger note -> procsub close, and the last two do not write cwd). - Session::close_with_report(mut self) -> CloseReport runs the identical exit path and reads the close-boundary state off the still-alive executor before the session drops. - Session::close(self) -> i32 keeps its exact 1.5.0 signature and now delegates to close_with_report().status — byte-identical return value, source compatibility preserved for out-of-tree hosts. No trait needed extension (close is an inherent method), so the #2144 defaulted-trait-method pattern is not applicable here. Tests (tests/issue2039_close_final_state_regressions.rs): the EXIT-trap cd pin (pre-close cwd() reports the pre-trap directory — the only read the old API allowed — while close_with_report().cwd reports the post-trap directory, engine-canonical via a trap-free control session), the status-resolution pin (exit 7 override, entry-status survival), and the close() delegation pin. Existing session_api close pins unchanged and green. A/B vs pristine 2503977: the face is absent on the base (grep count 0) and --test session_api passes on both sides (close() behavior identical); see REPORT.md for the run outputs. Commit disclosed as --no-verify: the pre-commit `cargo fmt --check` hook cannot run in this shell (cargo fmt: os error 206, filename or extension too long); rustfmt --edition 2021 --check was run explicitly over all three changed files and is clean. Fixes #2039
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.
Fixes #2039
Contract gap
Session::close()(src/api/session.rs, 1.5.0 API) consumed the session and returned only thei32final status, with no face that conveys session state at the close boundary. Any host contract that reads session state AFTER close was forced to snapshot before closing — and a pre-close snapshot is structurally blind to the EXIT trap's own effects. That is the structural premise of the niu #668 cwd regression (niu commit 208be63 had to split its finish funnel into trap-then-close composition to keep the post-trap read alive).GNU specification (status half, unchanged)
third_party/bash/trap.c:1027 run_exit_trap()saves the entry status intotrap_saved_exit_value(trap.c:1036) and returns it (trap.c:1052, 1094) — a bareexitinside the EXIT trap keeps the saved value. Oracle (WSL GNU Bash 5.3.x, script file):trap 'exit 7' EXIT-> 7;trap 'cd /tmp' EXIT; exit 5-> 5.Fix (the issue's primary candidate form: close reports the final state as a value)
CloseReport(#[non_exhaustive], theRunOutcomegrowth discipline):status(the valueclose()returns) +cwd(executor.session_cwd()—public_accessors.rs:1228, the engine cd-machinery state the §5.3Session::cwdface reports — read AFTERscript_driver::finish_shellreturns, i.e. after the EXIT trap ran;script_driver.rs:5401orders history write -> job flush -> EXIT trap -> debugger note -> procsub close, and the last two do not write cwd).Session::close_with_report(mut self) -> CloseReportruns the identical exit path and reads the close-boundary state off the still-alive executor before the session drops.Session::close(self) -> i32keeps its exact 1.5.0 signature and now delegates toclose_with_report().status— byte-identical return value; source compatibility preserved for out-of-tree hosts. No trait needed extension (closeis an inherent method), so the fix(history): carry history_base + hist_last_line_added through the HistoryProvider contract (#2007, #2006) #2144 defaulted-trait-method pattern is not applicable here. The pre-close-callback alternative stays with the contract batch, per the issue (候选形态在该批统一裁).Tests (
tests/issue2039_close_final_state_regressions.rs, publicrubash::apisurface only)close_with_report_conveys_the_exit_trap_cwd: pre-closesession.cwd()reports the pre-trap directory (the only read the old API allowed — cannot see the trap);close_with_report().cwdreports the post-trap directory (engine-canonical via a trap-free control session).close_with_report_status_is_the_exit_path_resolution: trapexit 7-> 7; no override -> entry status.close_keeps_the_i32_status_face: plainclose()unchanged (exit-7 -> 7; trap side effect lands).Results (release, Windows): issue2039 3/3 PASS;
--lib1063 passed / 0 failed / 3 ignored;--test session_api11 passed + 1 environment-bound failure (build_run_and_state_views_round_trip,\\?\verbatim-path mismatch) that fails IDENTICALLY on the pristine base 2503977 — pre-existing, not attributed to this diff.A/B vs pristine
Pristine detached worktree at 2503977: the new face is absent (grep count 0) and
--test session_apishows the identical failure signature as the branch — every other pin, includingclose_runs_exit_trap_and_persistent_procsub_delivery, passes on both sides, soclose()behavior is A/B-identical.Transport + fmt disclosure
cargo fmt --checkhook cannot run in this shell (cargo fmt: os error 206, filename or extension too long — same precedent as fix(history): carry history_base + hist_last_line_added through the HistoryProvider contract (#2007, #2006) #2144);rustfmt --edition 2021 --checkwas run explicitly over all three changed files and is clean.476a6c0f0269a132990b7bfce75a545c59e98975is byte-identical to the locally committed tree (git rev-parse HEAD^{tree}), and each blob sha equals the localgit hash-objectvalue. Local worktree commit:b8dec2dc(same tree).