Skip to content

[Bounty: $100] Await in-flight task promises in AgentRuntime.stop() instead of busy-polling #259

Description

@talentedtee2021-ux

Context
AgentRuntime in src/runtime/agent-runtime.ts stores only task IDs in inFlightTasks, and drainInFlightTasks() busy-waits by sleeping Math.min(5, remaining) milliseconds in a loop until the deadline. This polling wastes CPU during every graceful stop and makes the wait granularity dependent on an arbitrary 5 ms tick rather than actual task completion.

Proposed Change
Track the promises of in-flight executeTask() calls (or a shared deferred) alongside the ID set, and have stop() await them with a timeout (e.g. Promise.race against the configured drainTimeoutMs) so shutdown completes as soon as work finishes without polling.

Acceptance Criteria

  • stop({ drainTimeoutMs }) returns promptly when in-flight tools finish early instead of waiting up to the full timeout in 5 ms slices.
  • Tasks that exceed drainTimeoutMs still leave stop() unblocked, and the runtime reports the stranded state.
  • getInFlightTaskCount() semantics and the drain test in tests/runtime/stress-hardening.test.ts remain green.
  • No busy-wait loop remains in agent-runtime.ts.

Suggested Label
DX

ETA: 24 hours

Activity

  1. rputasidigital commented on Sep 5, 2026

    @rputasidigital
    Contributor

    Implemented promise tracking in executeTask() and replaced busy-polling with Promise.race in stop(), fulfilling all acceptance criteria. Submitted PR: #363 (Payout Wallet: GwGvT7jeUa9GPYYfSbnT2HRzTyZk6xeqs9EG7443tGi)

  2. added 5 commits that reference this issue on Sep 6, 2026
    6ba8164
    972d223
    9bedb56
    a2064e2
    38ad7d7
  3. hummern commented on Sep 6, 2026

    @hummern
    Contributor

    /claim #259\n\nPR #385 merged. EVM payout: 0x01d830d1e147e36eaaf3697b71923c3959c8a85e

  4. hummern commented on Sep 6, 2026

    @hummern
    Contributor

    Correction: EVM wallet is 0x01d830d1e147e36eaaf3697b71923c3959c8a85e (previous comment had a typo)

  5. Senthemodder commented on Sep 6, 2026

    @Senthemodder
    Contributor

    /claim #259
    /bounty claim 0xad4215910eb90f2d5c948cdb074a6c1487c4136f

    Hi @David-patrick-chuks-02, claiming the bounty for Issue #259 with PR #280 (merged in commit 38ad7d788ea65d703f90bf517d97b8ff1ab61b12).

    Note for maintainers regarding claim priority:

    USDC Payout Address (BSC BEP-20 / EVM): 0xad4215910eb90f2d5c948cdb074a6c1487c4136f

  6. Senthemodder commented on Sep 6, 2026

    @Senthemodder
    Contributor

    @David-patrick-chuks-02 ⚠️ Bounty Security / Bot Spoofing Advisory for Maintainers

    Hi David, wanted to bring to your direct attention two automated bot patterns actively attempting to intercept bounty payouts across the repositories before settlements are processed:

    1. Sniper Bot (@hummern / @kveita) on agentlily-runtime:

    2. Wallet Spoof Bot (@Zhiyilang074811) on lily-sdk:

      • Spammed 69+ threads across the org attempting to spoof authors' PRs.
      • Example: On PR #533 (which I authored), @Zhiyilang074811 commented claiming ownership of my PR and providing an external Solana wallet (3rb3NNa...).

    All my merged contributions across agentlily-runtime, lily-sdk, and lily-frontend are formally recorded and claimed under my official EVM wallet:
    0xad4215910eb90f2d5c948cdb074a6c1487c4136f (USDC on BSC BEP-20)

    Thank you for your review, time, and diligence!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions