Commit b4ed53d
feat: negotiated timeout with independent observer LLM pattern (#518)
* feat: add negotiated timeout mode with independent observer LLM pattern
When timeoutBehavior is set to 'negotiated', a separate LLM call (the
"timeout observer") runs independently when the operation timeout fires.
This works even when the main agent loop is blocked by long-running
delegates or MCP tools. The observer evaluates in-flight tools and
decides whether to grant more time or trigger graceful wind-down.
Key features:
- Independent observer pattern using generateText (not part of main loop)
- In-flight tool tracking via toolCall event emitter with human-readable
durations (e.g., "5m 23s")
- Configurable budget, max requests, and per-request limits
- Observer prompt includes stuck-loop detection guidance
- On decline: aborts in-flight tools, makes dedicated summary LLM call
with full conversation context
- Schema-aware abort recovery (returns valid JSON, no markdown notice)
- Task-aware abort recovery (acknowledges completed/incomplete tasks)
- completionPrompt correctly skipped after abort summary
- onStream callback receives abort summary text
- Full OTEL tracing for all observer decisions and state transitions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: add timeout modes documentation and SDK exports
- Add timeout options to top-level index.d.ts (timeoutBehavior,
gracefulTimeoutBonusSteps, negotiated timeout config, retry, fallback,
enableDelegate, enableBash, enableTasks)
- Export ENGINE_ACTIVITY_TIMEOUT_* constants from src/index.js
- Add comprehensive Timeout Modes section to npm/README.md with
examples, comparison table, and environment variable reference
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: add dedicated TIMEOUT_MODES.md reference page
Comprehensive guide covering all three timeout modes with flow
diagrams, observer pattern details, in-flight tool tracking,
stuck-loop detection, abort summary behavior, schema/task edge
cases, configuration reference, telemetry events, and examples.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: move timeout-modes to docs/probe-agent/sdk/
Move from npm/docs/TIMEOUT_MODES.md to docs/probe-agent/sdk/timeout-modes.md
to follow the project's documentation structure convention.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: trim README timeout section to brief summary with link
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: rewrite timeout docs as comprehensive architecture guide
Replace the negotiated-timeout-only docs with a full timeout
architecture reference covering all 6 layers: operation, request,
delegate, MCP, bash, and engine activity timeouts. Includes ASCII
layer diagram, complete env var reference, known limitations about
cross-layer coordination, and practical guidance for delegate/MCP
timeout sizing.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: delegate timeout inheritance and parent budget awareness
Delegates now inherit timeout settings (timeoutBehavior, requestTimeout,
gracefulTimeoutBonusSteps) from the parent agent. The delegate timeout is
capped to min(configured, remainingParentBudget * 0.9) so subagents
cannot consume the parent's entire budget. Subagent's internal
maxOperationTimeout is set to (externalTimeout - 15s) to allow its own
graceful wind-down before being externally killed.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: two-phase graceful stop with MCP graceful_stop support
When the negotiated timeout observer declines, instead of immediately
hard-aborting everything, we now do a two-phase shutdown:
1. Signal running delegates via triggerGracefulWindDown() so they can
finish their current step and produce a summary
2. Call graceful_stop on MCP servers that expose it, allowing agent-type
MCP servers to wrap up and return partial results
3. Hard abort only fires as a safety net after gracefulStopDeadline (45s)
Also adds InProcessMcpServer test helper using InMemoryTransport for
fast, deterministic MCP testing without spawning external processes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor: migrate MCP tests from stdio mock server to in-process
Replace stdio-based mockMcpServer.js with InMemoryTransport-based
in-process servers across all 4 MCP test files:
- mcpClientManager.test.js (70 tests, 0.3s down from 10s+)
- probeAgentMcp.test.js (15 tests, 2.7s down from 20s)
- mcpErrorHandling.test.js (18 tests, 3.4s down from 20s)
- mcpRobustness.test.js (12 tests, 3s down from 20s)
Tests are now deterministic (no connection failures), faster (no
process spawning), and use createStandardMockServer() which replicates
all 7 tools from the original mockMcpServer.js.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: update timeout architecture for two-phase graceful stop
Major updates to the timeout documentation:
- Two-phase graceful stop flow (signal wind-down, then hard abort)
- Delegate budget awareness (capped to parent's remaining time)
- Delegate timeout inheritance (timeoutBehavior, requestTimeout, etc.)
- MCP graceful_stop convention with implementation example
- gracefulStopDeadline configuration (new setting)
- Updated "How Timeouts Coordinate" section replacing old limitations
- New multi-agent MCP collaboration example
- Added gracefulStopDeadline to TypeScript declarations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add OTEL log bridge and comprehensive observability instrumentation
Add console-to-OTEL log bridge that patches console.log/info/warn/error
to emit OpenTelemetry log records and append trace context. Add tracer
events across graceful stop, delegation, subagent, and MCP lifecycles.
Add observability documentation covering all spans, events, and
integration patterns.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: handle quoted file paths with spaces in extract/search targets (#519)
Add splitQuotedString() parser that respects double/single-quoted strings
when splitting targets on whitespace/comma. Quoted paths like
"Customers/First American/Meeting Notes.md" are now preserved as single
targets instead of being split on spaces.
parseAndResolvePaths retains the existing space-splitting heuristic for
unquoted strings (backwards compatible).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: search dedup includes path in key, per-key counters, context-aware messages (#520)
- Include search path in dedup key so same query across different repos
is allowed (was: query+exact only, blocking cross-repo searches)
- Use per-key block counters instead of global counter to prevent
cross-query pollution
- Differentiate blocked messages: "found results" suggests extract,
"no results" suggests different keywords
- Detect ticket/issue ID patterns (e.g. TT-16546, JIRA-123) in
no-results responses and suggest searching for technical concepts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: improve search dedup messaging, exact=true guidance, and max-iteration diagnostics (#520)
- Enhance dedup blocked messages with exact=true/false toggle hints
- Add prompt guidance for exact=true with punctuation/literal patterns
- Expand "DUPLICATE SEARCH BLOCKED" advice with concrete alternatives
- Add tool call tracking and descriptive failure summary when max
iterations reached (helps parent agents understand what was tried)
- Last-iteration warning now includes searches attempted summary
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent a2bd4df commit b4ed53d
File tree
28 files changed
+4825
-502
lines changed- docs/probe-agent/sdk
- npm
- src
- agent
- mcp
- tools
- tests
- integration
- manual
- mcp
- unit
28 files changed
+4825
-502
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
0 commit comments