feat: cache-aware foreground tool timeouts - #422
Merged
Conversation
… the cache deadline
…-timeouts # Conflicts: # packages/coding-agent/src/changes.md
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.
Summary
The
bashtool (and, cross-repo, omo'stasktool) now size how long they block in the foreground on the active model's prompt-cache lifetime instead of a fixed 600s ceiling. A 5-minute cache yields a ~270s safe ceiling (30s buffer); a still-running foreground command is handed to a background session alive at that deadline rather than blocking past cache expiry or being killed.Blocking past the cache lifetime expires the cache and forces a full re-read on the next request. Sizing the ceiling by the TTL keeps the cache warm without losing the running work.
Plan:
.omo/plans/cache-aware-tool-timeouts.mdWhat changed
packages/airesolvePromptCacheTtlSeconds(model, env?). Mirrors each API's ownresolveCacheRetentionprecedence verbatim (anthropic falls back to"long"and honors the bareprocess.env.PI_CACHE_RETENTIONbranch; openai/bedrock fall back to"short"; pi-messages returnsundefined). Unknown-cache APIs (google, mistral, pi-messages) and retention"none"→undefined.packages/coding-agentcorepromptCachesettings (cacheAwareTimeoutsdefault true,safetyBufferSecondsdefault 30),prompt-cache-budget.ts, typedExtensionContext.getPromptCacheSafeWaitSeconds(), advisoryPI_PROMPT_CACHE_SAFE_WAIT_SECONDSenv bridge refreshed on session start/reload/model select.bash-timeoutextensionresolveEffectiveBashTimeouts()caps the recommended max at the budget; the policy prompt is rebuilt perbefore_agent_startand names the ceiling + the prompt-cache reason.terminalextensionterminal.timeoutActionis now implemented and drives foreground auto-detach at deadment D.The explicit timeout
Tis never shortened — it stays the native PTY kill deadline, and still applies after a detach.Zero behavior change when no budget applies
TTL unknown (google), retention
none, orcacheAwareTimeouts: false→ the injected default and recommended max keep today's values and the policy prompt is byte-identical under strict===(pinned by test).Detach linearization
Exit > abort > detach. When D fires: queue one microtask → check exit → check abort → install the settled-aware
onExitgate → recheck → commit detach and remove the abort listener synchronously. An exit or abort at/before that point wins; an abort after commit is ignored (kill_bashbecomes the stop surface).readDelta()is called exactly once at detach, sobash_outputcontinues without duplication.Verification
All green in single runs:
packages/ai:prompt-cache-ttl.test.ts24/24 (RED 23/23 captured first)packages/coding-agent: 8 suites (terminal-bash-auto-detach,terminal-extension,terminal-settings-notify,terminal-monitor,bash-timeout-extension,prompt-cache-budget,prompt-surface-stale-wait-idioms,5943regression) → 89/89npm run check→ exit 0 (includescheck:browser-smoke)Real-surface QA (real PTY, D shrunk to 5s,
timeoutAction: background):senpi-qa channels:
pty-drive8/8 (native backend, no orphans),cli-smoke8/8,mock-loop --with-tool --api anthropic-messages4/4. The real~/.senpi/agent/auth.jsonsha256 was asserted unchanged in every run.Note on the browser boundary
The first implementation imported
supportsPromptCachingdirectly frombedrock-converse-stream.ts, which dragged the AWS SDK into the browser-safe root and brokecheck:browser-smokewith 18 unresolvednode:*errors. Fixed by moving the pure compat predicates into the browser-safe utility, with the API modules importing from it and re-exporting — one source of truth, no divergence risk.Companion change
The omo side (
packages/senpi-taskbounded foreground wait +promoteToBackground) landed separately in the omo repo as6846ef8c2, written against the frozen contract (feature-detected getter, then env, else unbounded) so it works with older senpi too.Summary by cubic
Makes foreground tool waits cache‑aware.
bashnow caps foreground blocking to the active model’s prompt‑cache TTL (minus a buffer) and auto‑detaches before expiry so the cache stays warm and the work continues in the background. Defaults are safe; setpromptCache.cacheAwareTimeouts: falseto opt out andterminal.timeoutAction: "background"to enable auto‑detach.New Features
packages/ai: Added browser‑saferesolvePromptCacheTtlSeconds(model, env?)withPROMPT_CACHE_TTL_SHORT_SECONDS/PROMPT_CACHE_TTL_LONG_SECONDS. Moved pure compat predicates into a shared utility and re‑exported from API modules.packages/coding-agent: NewpromptCachesettings (cacheAwareTimeoutsdefault true,safetyBufferSecondsdefault 30). ExposedgetPromptCacheSafeWaitSeconds()on the extension context and mirrored the budget inPI_PROMPT_CACHE_SAFE_WAIT_SECONDS(cleared when absent).bash-timeoutextension: Caps the recommended max timeout to the cache‑safe budget and updates the policy prompt to explain the cache reason. Explicittimeoutvalues are unchanged.terminalextension: Implementedterminal.timeoutAction. Withbackground, foreground runs that exceed the budget auto‑detach at the deadline; the original native timeout still applies. No change when the budget is absent ortimeoutActioniskill.Bug Fixes
bash-timeoutextension: Tolerates a missing extension context in timeout handlers to avoid crashes when the context isn’t provided.Written for commit 4cada46. Summary will update on new commits.