fix: abort listener leak in agent-loop.ts sleep and code-mode/service.ts delay

Open Beginner friendly
#80 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript
Domain
tooling

Research direction

Read sleep() in packages/core/src/agent/agent-loop.ts and delay() in packages/core/src/tools/code-mode/service.ts, then run pnpm check and pnpm test:coverage. Remove the timer-success cleanup calls described in the issue while preserving the abort-handler cleanup. Done means all 1475 tests pass and repeated shared-signal sleep calls keep the abort listener count stable.

Written by the indexing model from the issue text.

Description

Bug

sleep() in agent-loop.ts and delay() in code-mode/service.ts call signal.removeEventListener('abort', ...) in the timer success callback. This prematurely removes the abort listener from shared AbortController signals, so other operations waiting on the same signal miss abort notifications.

Fix

Remove the removeEventListener call from the timer success path. The { once: true } option already handles cleanup when the listener fires (either on abort or on success). The abort handler still explicitly removes the listener as a defensive measure.

Scope

  • packages/core/src/agent/agent-loop.ts — remove spurious removeEventListener in sleep()
  • packages/core/src/tools/code-mode/service.ts — same pattern in delay()

No public API changes.

Verification

pnpm check   # all pass
pnpm test:coverage  # 1475 tests pass, coverage 83.66% stmt / 84.97% branch

Manual: abort listener count stays stable across 100+ repeated sleep() calls with a shared AbortController.

Dominant language
TypeScript
Stars
54
Forks
20
Avg merge
2h 58m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stepfun-ai/Step-Code

All issues in stepfun-ai/Step-Code

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.