Commit a033b83
authored
🤖 fix: add elapsed_ms to bash_output to help detect busy loops (#1046)
## Problem
After restarting the app, agents can get stuck in tight loops calling
`bash_output` repeatedly on processes that no longer exist or have
already exited. The agent has no way to detect that responses are
returning immediately with no useful information.
## Solution
1. **Add `elapsed_ms` to bash_output response** - Shows how long the
tool spent waiting for output. If this is very low (<10ms), it suggests
no real waiting occurred.
2. **Add warning note for suspicious patterns** - When a response is
fast (<10ms), empty, and the process has exited, add a note: "Process
has exited and no new output. Avoid repeated polling of completed
processes."
This gives agents actionable feedback to break out of busy loops.
## Changes
- `src/common/types/tools.ts`: Add `elapsed_ms` field to
`BashOutputToolResult`
- `src/node/services/backgroundProcessManager.ts`: Return `elapsed_ms`
from `getOutput()`
- `src/node/services/tools/bash_output.ts`: Add warning note for fast
empty responses on exited processes
- `src/node/services/backgroundProcessManager.test.ts`: Add test for
`elapsed_ms`
## Testing
All existing tests pass plus new test for `elapsed_ms` field.
_Generated with `mux`_1 parent bfdb809 commit a033b83
File tree
4 files changed
+24
-1
lines changed- src
- common/types
- node/services
- tools
4 files changed
+24
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| 242 | + | |
| 243 | + | |
242 | 244 | | |
243 | 245 | | |
244 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
454 | 473 | | |
455 | 474 | | |
456 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| 424 | + | |
424 | 425 | | |
425 | 426 | | |
426 | 427 | | |
| |||
507 | 508 | | |
508 | 509 | | |
509 | 510 | | |
| 511 | + | |
510 | 512 | | |
511 | 513 | | |
512 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
0 commit comments