Repository navigation
fix(studio): prevent terminal tool hangs in credential scan (#12048) - #12087
danielhanchen merged 20 commits into
Conversation
Two self-referential VAR=$VAR assignments inside one quoted string could expand without a fixed point and recurse indefinitely in the pre-dispatch credential guard, freezing the backend. Skip self-referential env captures and cap assignment-expansion depth during the scan.
|
Reproduced this on main, where |
|
Repaired at 34b1abf. The quoted self-reference command now finishes, while credential reads hidden behind long alias chains, concrete self-reference path fragments, or assignment-shaped log messages are refused. Assignment expansion has a finite budget and fails closed if it cannot finish. Quoted inline shell programs remain covered. Default and alternate parameter operators use the prior binding and distinguish unset from empty values. 235 focused tests passed on Python 3.13.14/Linux x86_64, including the Studio auth guard suite and retained independent cases. Negative controls exposed the defects before each repair. All 18 default/alternate operator cases also agree with real Bash path expansion. Live terminal reads against an initialized database containing only a synthetic value now refuse the alias, self-reference, quoted-log, and parameter-operator bypasses in normal software-safeguard and Bypass Permissions modes, with no synthetic value in model output. Repository formatting, Ruff and diff checks passed. The earlier Python 3.11/3.13/3.14, fuzz, concurrency, streaming and timeout qualification was reused as requested; the broad matrix was not rerun. The separate Python 3.14 long-expression recursion failure also occurs on base and remains unchanged. The previously noted prior-default limitation is resolved by the parameter-operator correction above. Verification details, before/after execution results and reproducers. Review mirror. |
|
Review record for #12087, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#181. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
…i#12048) (unslothai#12087) * fix(studio): bound shell assignment expansion in credential scan Two self-referential VAR=$VAR assignments inside one quoted string could expand without a fixed point and recurse indefinitely in the pre-dispatch credential guard, freezing the backend. Skip self-referential env captures and cap assignment-expansion depth during the scan. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix incomplete credential assignment scans failing open * preserve concrete paths in self-referential shell assignments * separate quoted assignment scans from shell bindings * respect prior bindings in self-referential parameter operators * Keep self-referential studio home assignments naming the install * Trim comments in the credential scan fix * Keep self-doubling shell assignments from growing without bound * Keep scoped empty assignments from erasing an outer binding * Scan each variable use with the binding active at that point * Trim comments after review * Walk shell assignments once for both expansion orders * Let a top-level empty assignment clear the binding * Expand arguments with the outer binding past a command-prefix assignment * Treat assignment-shaped arguments as binding nothing * Compute assignment scope in one pass so many empty assignments scan in linear time * Trim comments after review --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: mahiatlinux <[email protected]> Co-authored-by: Daniel Han <[email protected]>
Summary
Fixes #12048 — terminal tool calls could stay in Running indefinitely (past Max Tool Call Duration) because the pre-dispatch studio credential guard could recurse without bound while expanding shell assignments in quoted strings (e.g.
echo "A=$A B=$B"). That work runs synchronously on the backend event loop and holds the GIL, so notool resultlog line is emitted and the UI never receives completion.Changes
_references_studio_credential_here, allowing long finite alias chains and refusing commands when expansion exhausts its budget or grows excessively.Testing
test_two_self_referential_assignments_in_one_quoted_string_do_not_hangintest_studio_auth_guard.pyManual smoke:
_references_studio_credential_hereon ordinaryecho/catcommands completes in <1msRepair verification: 235 focused tests passed on Python 3.13.14/Linux x86_64; live synthetic
auth.dbreads were refused in normal and Bypass Permissions execution. Verification details and retained earlier test evidence.