Feature(Go): terminal_close, idle sweep and legacy-client guard
Add the terminal_close tool so a caller can release a shell session explicitly instead of waiting for it to age out. The tool is idempotent for the session it names, rejects a session_id that does not match the live session with -32002, and runs without the per-device lock so it can interrupt a terminal_exec call that is still polling on the same device. Give hub leases a generation counter: the generation is bumped when a pending lease is created and carried across a device re-login. MCP-side closes pass the generation, so a stale session can no longer tear down a shell a human operator opened after the device reconnected. The reaper runs on a 30 s ticker (shortened when TermIdle is smaller), skips sessions that are still opening, and reclaims idle sessions as well as commands overdue past the one-hour busy cap. The pre-bind terminal-close path in cmd no longer closes unconditionally; it touches only a pending lease, because an unbound sub-connection carries no lease identity and may be a stale orphan. Covered by unit tests for close semantics, lock exemption, reaper lifecycle and lease-generation ownership, plus a live run against a Debug ghost: close before and during a command, reopen, idle reap and mismatched-id rejection all behave as specified. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
599c891c00
commit
808747f9d2
10 files changed
+633
-52
No files matched your search
@@ -20,6 +20,14 @@ var writeTools = map[string]bool{
|
||||
"terminal_close": true,
|
||||
}
|
||||
|
||||
// unlockedTools run without the per-device lock. terminal_close must be usable
|
||||
// while a terminal_exec call is still waiting on the same device: that call
|
||||
// holds the lock for its whole timeout, and a close that answers -32003 could
|
||||
// never interrupt it.
|
||||
var unlockedTools = map[string]bool{
|
||||
"terminal_close": true,
|
||||
}
|
||||
|
||||
// toolDef holds one published definition plus its name, so filtering does not
|
||||
// re-parse the JSON on every tools/list call.
|
||||
type toolDef struct {
|
||||
|
||||
Reference in new issue
Block a user