Skip to content

fix(server): scope sessions to connections and harden server limits - #888

Merged
ewhauser merged 1 commit into
mainfrom
claude/fix2-server-cli
Oct 20, 2026
Merged

ewhauser merged 1 commit into
mainfrom
claude/fix2-server-cli

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Fixes the server/CLI findings from the second review of main at 19ff56a.

Server

  • Sessions belong to the connection that created them. session.list shows only that connection's sessions, and get/exec/destroy from another connection return SESSION_NOT_FOUND. A connection's sessions are destroyed when it closes.
  • At most 64 connections at once (server.MaxConnections). A connection that leaves a request incomplete for 30s is closed; idle connections have no deadline. The decoder is replaced after each request so a large request's buffer is freed.
  • final_env is returned only when the request sets include_final_env: true, and it is capped at 1 MiB (final_env_truncated). This also stops --inherit-env values from being echoed by default. It still includes non-exported shell variables, because the runtime's FinalEnv doesn't record export status; with opt-in plus the size cap, filtering would need a runtime API change.
  • An unknown shell_variant or a startup_options entry that set -o rejects now returns -32602 INVALID_ARGUMENT instead of INTERNAL. This adds a small interp.IsSetOption helper (cross-area, 9 lines).

CLI

  • --readwrite-root: each new session re-checks os.SameFile against the directory validated at startup, before and after the mount opens. A rename-and-symlink swap now fails the session instead of mounting the target.
  • --root must be an existing directory; the check runs at startup.
  • New --max-exec-timeout flag (default 10m, must be positive) is wired to server.Config.MaxExecTimeout.
  • --rcfile FILE is value-taking, so gbash --rcfile /dev/null --root DIR -c pwd works.
  • On SIGINT/SIGTERM the server path cancels executions and removes its socket (signal.NotifyContext in serveServer, so interactive shells are unaffected).

Breaking for clients: final_env is now opt-in, and sessions can no longer be shared across connections.

SPEC §5 CLI bullets and §6.2 are updated, along with website/content/api/server.mdx. Every item has a regression test. go test -race ./server/... ./cli/... and make lint pass.

Scope session.list/get/exec/destroy to the creating connection, cap
connections, time out incomplete requests, free decoder buffers, make
final_env opt-in and size-capped, and classify bad shell_variant and
startup_options as INVALID_ARGUMENT.

CLI: pin --readwrite-root to its startup inode, reject a missing --root,
add --max-exec-timeout (default 10m), treat --rcfile as value-taking,
and stop the server cleanly on SIGINT/SIGTERM.
@ewhauser
ewhauser enabled auto-merge (squash) October 20, 2026 14:59
@ewhauser
ewhauser merged commit b462aa0 into main Oct 20, 2026
17 checks passed
@ewhauser
ewhauser deleted the claude/fix2-server-cli branch October 20, 2026 15:06
@ewhauser ewhauser mentioned this pull request Oct 20, 2026
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