Repository navigation
feat(sente): move timed-out shell commands to the background instead of killing them - #73
Open
yukihamada wants to merge 2 commits into
Open
yukihamada wants to merge 2 commits into
yukihamada wants to merge 2 commits into
Conversation
…of killing them When a bash command is still running at its timeout, hand the process to a BackgroundJob (same registry as background tasks) instead of killing it. The model gets the job ID, PID, the output file it keeps streaming to, and is told to collect the result with the wait tool (kind "job"). - On by default; SENTE_SHELL_TIMEOUT_BACKGROUND=0 restores kill-on-timeout. - Register the existing wait tool (it was never exposed) and clarify its job param. - Interactive sessions get a synthetic <background_shell> message when the job finishes; one-shot `sente run` (SENTE_NONINTERACTIVE=1) does not inject a turn. - The process lives in its own scope: abort before the timeout, job cancel (session interrupt) and instance dispose (sente run exit) all kill the process group, escalating to SIGKILL after 3s, so nothing is orphaned or waited on forever. - Job output goes through SecretRedact; sandbox note and truncation as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Follow-up review fixes for timed-out shell commands moving to the background. - One-shot runs and subagents must wait in-turn: the message says the command stops when the reply ends, and wait answers pending with "call wait again" (no "do not retry"). `sente run` marks the session (metadata, so it also works over --attach) and, under --attach, aborts the session at the end so nothing is left running on the remote server. - No double delivery: a job whose result a wait call delivered (or is delivering) is not announced again. Interactive guidance is only "wait for the notification; end your reply if nothing else to do". - --unattended: the builtin policy allows wait on job_* (the tool still rejects other sessions' jobs). - Limits: background lifetime (SENTE_SHELL_BACKGROUND_MAX_MS, default 60 min) and per-session concurrency (SENTE_SHELL_BACKGROUND_MAX_JOBS, default 4). - wait is a job-only tool (no GitHub text) offered only once the session has a background shell job; it can stop a job by ID (stop: true). No PID kill hint. - A command that exits right at the deadline is treated as finished. - sente run and the TUI show "running in background (job …)" instead of completed. - Docs for the new environment variables; tests for grandchildren, spill after handover, real wait tool, notification suppression, failure notice, one-shot and subagent sessions, limits, stop, deadline race and the run renderer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
概要
シェル(bash)ツールで時間切れになったコマンドを、殺さずバックグラウンドジョブに移します(本家 anomalyco#63024 / anomalyco#63699 と同じ考え方)。Sente 既存の
BackgroundJobレジストリに乗せ、結果はwaitツールか完了通知で受け取ります。動き
BackgroundJob(typebash、metadatasessionId/pid/outputPath/mustWait)に引き渡す。締め切り直後に終わっていたものは普通の完了として扱う。<background_shell>を1回だけ入れる。waitで結果を受け取った(または受け取り中の)ジョブは通知しない。sente runとサブエージェント: 「返答を終えると実行が終わりコマンドも止まる。終える前に wait(job)、pending なら終わるまで再度呼ぶ」と案内。この種のジョブに限り、waitの pending 応答は「再試行しない」ではなく「もう一度呼ぶ」。sente runはセッションの metadata(sente.oneShot)で印を付けるので--attachでも効く。終了時に印を外し、--attachではセッションを abort して遠隔サーバーに残さない。waitツール: job 専用(GitHub の説明なし。引数はjob/timeout/stop)。そのセッションに背景シェルジョブができてから初めてツール一覧に出す(それまではトークン0)。stop: trueでジョブIDから停止。PID での kill 案内は出さない。--unattended: 組み込み許可リストでwaitをjob_*に限って許可(他セッションのジョブはツール側で拒否)。SENTE_SHELL_BACKGROUND_MAX_MS(既定60分)、セッションごとの同時数SENTE_SHELL_BACKGROUND_MAX_JOBS(既定4。超えたら従来どおり止めて理由を返す)。SENTE_SHELL_TIMEOUT_BACKGROUND=0で時間切れ時に止める従来の動き。時間切れメッセージにも1行、cli.mdx(英・日)にも記載。sente runと TUI で「running in background (job …)」と表示し、completed と区別。wait stop、sente run終了(インスタンス破棄)のどれでもプロセスグループ(子孫含む)を止め、SIGTERM を無視しても3秒で SIGKILL。テスト
bun run typecheck: packages/sente・packages/tui ともエラー0test/tool/shell-background.test.ts21件 pass(3回連続)。子孫まで停止、背景移行後の上限超え出力→ファイル退避、本物の wait ツール経由、wait 後の通知抑止、pending 後は通知される、失敗時通知、非対話・サブエージェントは待つ案内で通知なし、one-shot の pending は「再度呼ぶ」、stop、他セッション拒否、寿命上限、同時数上限、締め切り付近の競合、無効化、中断、インスタンス破棄test/cli/run/tool-bash-background.test.ts(表示)、registry.test.ts(wait の出し分け)、unattended.test.ts(wait 許可)追加test/tool/ test/background/ test/cli/run/ test/permission/ runtime-flags session/prompt: 868 pass / 15 fail。15件はすべて base でも失敗(webfetch 204/205、security-boundary-audit の redirect ×5、session/prompt の loop ×7、run-process の不安定1件)headless-model-fallbackを workflow_dispatch した run 45288524310)の失敗一覧に含まれる(新規失敗なし)Playwright does not support chromium on ubuntu26.04-x64で失敗(ランナー側の問題)実機(
teai/cheap)sleep 150; echo LONG_DONEを timeout 2000ms → 背景 → モデルが wait →Exit code: 0 / LONG_DONEを返して終了(158秒)。終了後sleep残存なし、セッションの印も解除済み🤖 Generated with Claude Code