Repository navigation
fix: apply reviewed maintenance repairs for #3400 - #3685
kovtcharov wants to merge 9 commits into
Conversation
Ports the C++ toolbelt's ShellSession (cpp/include/gaia/process.h, amd#2810) to Python. What persists is the session state, not a resident child: each command runs a generated script that restores the session's directory and variables, sources the command from its own file, then reports the resulting pwd and environment to a side file the session absorbs. Not wired into the shell tool yet.
…and a reset A directory change or a variable set in one call is now still in effect for the next. Adds get_shell_state so the agent can read where it is rather than infer it, set_shell_variable because the shell's own export is not on the read-only whitelist, and reset_shell_session to recover a session that is wedged or in the wrong place. Command validation is unchanged and still applies per segment. Two seams needed care: a skill-granted binary still runs as argv, never as a string handed to a shell, and a cd into a directory the path policy refuses is not absorbed - otherwise persistence would be a way to read files by bare name from anywhere.
Also closes the chat agent's shell session in its teardown path, so the temp directory goes with the agent rather than waiting on the OS.
Also registers the session's bandit suppressions and drops the Popen kwargs dict that hid the call's overload from mypy.
…p asserting expansion The manifest's hand-typed tools_count still claimed 67; the three session tools take the flagship registry to 70. The environment test asserted a variable by echoing $VAR, which the POSIX path deliberately refuses to expand — re-quoting the validated tokens is what stops a variable the agent set from naming a file the path validator only ever saw as '$X'. It now reads the value back through the probe and the environment a child is handed, with a second test pinning that no interpolation happens.
On a Linux host the session told the model it had changed AWKPATH and AWKLIBPATH after every single command, and replayed both into the next script. gawk setenv()s them into its own process environment before BEGIN runs, and the session's bookkeeping dump is a gawk one-liner — so they land in the captured environment even though the shell never set them. The test that should have caught this allowed up to a quarter of the parent environment as spurious divergence, so one or two false positives passed in silence. It now asserts exactly zero, which means taking its own session: pytest rewrites PYTEST_CURRENT_TEST between the fixture's setup phase and the call phase, and a baseline captured in setup sees that as a genuine change.
Local repairs in `worktrees/3400`; no commits/pushes.
Verdict: Request changes (one small fix)This tightens the persistent shell session: terminal size no longer shows up as an "agent changed this variable", the session's temp directory now cleans itself up if an agent is abandoned without being closed, the What to fix before merge
Worth a second look, not blocking
Real-world evidenceN/A — no evidence bundle was produced for this PR, and the shell tools' surface couldn't be exercised here (the review environment had no working shell, so 🔍 Technical detailsIssues🟡
Python ≥3.10 is the floor ( 🟡 Two changes in one line. Agreed the old The No test covers either behaviour: a case where the state file is unwritable (or Nits🟢 Function-local imports in tests ( 🟢 The GC test depends on refcount timing ( Strengths
|
…esult Closing a session while a command is still running hands the temp-directory removal to that command, which does it from run()'s finally. TemporaryDirectory .cleanup() propagates OSError, so on Windows a file still held by a just-killed child turned a finished command into an exception instead of a ShellResult -- exactly the hung-command case this path exists for. Log and continue, matching the per-file os.remove loop three lines above, which had already made that call for this module. Not ignore_cleanup_errors=True: that is crash-safe but silent, and would drop the diagnostic the neighbouring code deliberately keeps. The new test pins the contract run()'s finally depends on; it raises PermissionError out of _discard_temp_dir without the fix.
|
The blocking item is fixed, but with a different fix than the one suggested — the suggested one is crash-safe and silent, and this file had already decided the other way three lines above. A failed temp-directory teardown no longer costs the caller a finished command. It now logs and continues, exactly like the per-file deletion loop immediately above it, so the crash goes away and the diagnostic survives. The second finding — three different conditions all reporting exit code 127 — is real, and I have deliberately not touched it. Picking a new sentinel and deciding whether the Windows branch follows is a shape decision that belongs with #3400, which this PR is stacked on and which is still waiting on a design call. Fixing it here would commit that decision by accident. Worth knowing regardless of the review: this can't merge ahead of #3400. 🔍 Technical detailsFixed in def _discard_temp_dir(self) -> None:
directory, self._temp_directory = self._temp_directory, None
self._temp_dir = None
if directory is not None:
# Runs from run()'s finally: a raise here would discard the
# ShellResult the command already produced.
try:
directory.cleanup()
except OSError as exc:
logger.warning(
"Could not remove shell session temp directory %s: %s",
directory.name, exc,
)Why not On the claim that the flag "covers the implicit finalizer path the new GC test relies on" — it isn't load-bearing there. The missing test now exists. With the fix, On the 127 collision. Agreed on the substance: Evidence gap noted in the review: the shell surface was exercised here — 43 real-subprocess tests on Windows, including the new teardown case. What is still unexercised is the |
179199b to
df6a23e
Compare
…nd's result `_discard_temp_dir` runs from `run()`'s `finally` when the session was closed while the command was still going — the straggler path this code exists for. `TemporaryDirectory.cleanup()` propagates, so on Windows a file a just-killed child still holds would raise there and discard the `ShellResult` that was about to be returned. `ignore_cleanup_errors=True` matches what the per-file `os.remove` loop three lines above already does, and covers the implicit finalizer too. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Closing this as superseded — the design it repairs is no longer on its own base branch.
Nothing is lost. #3400 carries the replacement and has since gained its own follow-up fix; #3380 still tracks the feature. Your own note here — "this can't merge ahead of #3400" — is what this comment is agreeing with, one step further. The Two scraps survive and both are already nits on #3400 rather than reasons to keep this open: 🔍 Technical detailsRefs. Base branch head
Scoped precisely: the session object no longer spawns anything. Per-commit applicability. Not reparable by rebase. 12 of 15 files conflict, and The merge direction is regressive. Taking this PR's side reverts CI. No test job ever ran here. All ~30 lanes are |
Follow-up fixes for #3400. Local repairs in
worktrees/3400; no commits/pushes.This PR targets the original feature branch because the current account cannot push to
amd/gaia. It carries the prepared maintenance changes for that PR.Test plan