Skip to content

fix: remove orphaned duplicate balanceInterval in agent.mts - #26

Open
osr21 wants to merge 1 commit into
circlefin:masterfrom
osr21:fix/agent-balance-interval-leak
Open

fix: remove orphaned duplicate balanceInterval in agent.mts#26
osr21 wants to merge 1 commit into
circlefin:masterfrom
osr21:fix/agent-balance-interval-leak

Conversation

@osr21

@osr21 osr21 commented Jul 4, 2026

Copy link
Copy Markdown

Summary

Removes a duplicate/orphaned balanceInterval in agent.mts.

Bug

At startup, balanceInterval is assigned once right after the initial
deposit (balanceInterval = setInterval(checkAndRedeposit, 30_000);), and
then startPaymentLoop() is called immediately after, which assigns
balanceInterval again to a new interval. The first interval's handle is
overwritten before it's ever cleared, so it keeps running for the lifetime of
the process with no way to cancel it.

Net effect: checkAndRedeposit actually runs on two overlapping 30s
schedules instead of one (contradicting the comment above it), and one
setInterval handle leaks for the life of the CLI process.

Fix

Removed the premature top-level assignment. startPaymentLoop() already
sets up balanceInterval (and is the single place that creates/clears it
across pause/resume cycles triggered by handleLimitReached()), so nothing
else needs to schedule it beforehand.

Testing

Read-through / static verification — traced every assignment and
clearInterval call site for balanceInterval in agent.mts to confirm
startPaymentLoop() is the only place that should own it, and that this was
the sole leaked reference. No functional change to the deposit/payment logic
itself, only the interval bookkeeping.

startPaymentLoop() already assigns balanceInterval right after this line
runs (it is called unconditionally at the bottom of the file, and again
after every spending-limit pause/resume cycle). Setting it here too means
the handle from this first setInterval is immediately overwritten and can
never be cleared -- it keeps firing every 30s for the life of the process,
so checkAndRedeposit ends up running twice as often as the comments state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant