Skip to content

Commit eb8cdff

Browse files
committed
🤖 fix: guard script abort controller
_Generated with `mux`_ Change-Id: I1da3c370a76e61e583b3d266570caf6dcca2f0b6 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent af1096b commit eb8cdff

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

docs/scripts.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Scripts run in the workspace directory with full access to project secrets and e
3737
**Crucial**: The `# Description:` line is what the AI reads to understand the tool. Be descriptive about what the script does and what arguments it accepts.
3838

3939
3. **Make it executable**:
40+
4041
```bash
4142
chmod +x .cmux/scripts/deploy
4243
```
@@ -54,9 +55,11 @@ Every executable script in `.cmux/scripts/` is automatically registered as a too
5455
To make your scripts effective AI tools:
5556

5657
1. **Clear Descriptions**: Explicitly state what the script does and what arguments it expects.
58+
5759
```bash
5860
# Description: Fetch logs. Requires one argument: the environment name (dev|prod).
5961
```
62+
6063
2. **Robustness**: Use `set -euo pipefail` to ensure the script fails loudly if something goes wrong, allowing the AI to catch the error.
6164
3. **Feedback**: Use `MUX_PROMPT` to guide the AI on what to do next if the script succeeds or fails (see below).
6265

src/node/services/agentSession.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,14 @@ export class AgentSession {
512512
}
513513

514514
public startScriptExecution(): AbortSignal {
515-
this.scriptAbortController = new AbortController();
516-
return this.scriptAbortController.signal;
515+
assert(
516+
this.scriptAbortController === null,
517+
"AgentSession.startScriptExecution called while script is running"
518+
);
519+
520+
const abortController = new AbortController();
521+
this.scriptAbortController = abortController;
522+
return abortController.signal;
517523
}
518524

519525
public endScriptExecution(): void {

0 commit comments

Comments
 (0)