loop: pauses interPromptPause seconds after the last prompt even when the generator is exhausted
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- tooling
Research direction
Start in src/loop.ts around lines 154-161 and inspect the loop entry point used by the one-prompt generator reproduction. Move the pause so it occurs only before non-initial prompts, then verify that a single yielded prompt completes without a trailing delay while multiple prompts remain spaced apart.
Written by the indexing model from the issue text.
Description
Observed behavior
In src/loop.ts, the interPromptPause sleep is placed at the bottom of the for await body (lines 154-161):
completed++;
if (completed >= maxPrompts) {
logger.state(`Reached limit of ${maxPrompts} prompts`);
return `Done (reached limit of ${maxPrompts} prompts)`;
}
// istanbul ignore else
if (interPromptPause !== 0) {
logger.info(`Pausing ${interPromptPause}s before next prompt`);
console.log(`Pause (${interPromptPause}s) before starting next prompt`);
await new Promise(resolve => {
setTimeout(resolve, interPromptPause * 1_000);
});
}
When the prompt generator yields its final prompt and is then exhausted (i.e. the run is ending naturally, not because maxPrompts was hit), the loop body still runs the pause after the final prompt before the for await advances, sees the generator is done, and exits with 'Done'. The user waits interPromptPause seconds for nothing.
The early-return for maxPrompts correctly skips the pause (because it returns before reaching it), but there is no equivalent check for "no more prompts coming". The bug is invisible at the default PAUSE_SECS = 5 but becomes obvious when users tune the pause up to manage rate limits (60s+).
Expected behavior
After the last prompt yielded by the generator, the loop should exit immediately rather than sleeping interPromptPause seconds first. The pause is supposed to space out between prompts; there is nothing to space against once the generator is exhausted.
Minimal reproduction
import { loop } from 'loop-the-loop';
class OnePrompt {
async *generate() {
yield { id: 'only', prompt: 'hi' };
}
}
console.time('loop');
await loop({
name: 'demo',
agent: /* any agent that returns success quickly */,
promptGenerator: new OnePrompt(),
interPromptPause: 30,
});
console.timeEnd('loop');
Observed: loop: ~30s (one quick agent call + a 30 s tail pause).
Expected: loop: <1s (one quick agent call, no trailing pause).
Suggested fix
Move the pause to the top of the loop body and skip it on the first iteration, so it pauses before each non-initial prompt rather than after each one:
let completed = 0;
let glitchCount = 0;
let first = true;
for await (const prompt of promptGenerator.generate(loopState)) {
if (!first && interPromptPause !== 0) {
logger.info(`Pausing ${interPromptPause}s before next prompt`);
console.log(`Pause (${interPromptPause}s) before starting next prompt`);
await new Promise(resolve => {
setTimeout(resolve, interPromptPause * 1_000);
});
}
first = false;
// ... process prompt ...
}
This preserves the inter-prompt spacing semantics and naturally avoids the trailing pause.
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from joewalker/loop-the-loop
-
bug S4
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal information Openbug S3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Difficulty 1/5 Under an hour Newbie friendliness 90/100
joewalker/loop-the-loop#79 ·
All issues in joewalker/loop-the-loop
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100