Skip to content

test(runtime): session-title deadline-abort test hangs under full-suite load on main #1222

Closed

Description

packages/runtime/src/__tests__/session-title.test.ts 的 aborts title generation when the provider exceeds its deadline(#1199 引入)在当前 main(8b9d69a)上跑 npm --workspace @maka/runtime run test 时稳定失败:

not ok 6 - aborts title generation when the provider exceeds its deadline
  failureType: 'cancelledByParent'
  error: 'Promise resolution is still pending but the event loop has already resolved'

特征:

  • 全套件内稳定失败(连续两次复现,pristine main worktree 亦复现);
  • 单独跑该文件(node --test dist/__tests__/session-title.test.js)5/5 通过;
  • 症状是测试留下未决 Promise,事件循环先行结束(cancelledByParent)——疑似 deadline/abort 路径下有未 await 的挂起 Promise 或未推进的计时器,在套件并行负载下暴露。

复现:main 上 npm --workspace @maka/runtime run test。在 #1122 的重建验证中发现,与该 PR 无关。

Activity

  1. Colafornia commented on Jul 19, 2026

    @Colafornia
    Member

    Thanks for reporting this — I’m working on a fix.

  2. UncertaintyDeterminesYou4ndMe commented on Jul 19, 2026

    @UncertaintyDeterminesYou4ndMe
    ContributorAuthor

    Some additional data points that may help — the "full-suite load vs single-file" split doesn't hold on my machine; the Node version does:

    Node node --test dist/__tests__/session-title.test.js (single file)
    v22.17.0 fails 5/5 runs (cancelledByParent, same error as above)
    v24.18.0 (CI's version) passes 5/5 runs

    So the deciding factor doesn't seem to be suite load per se, but whether anything else happens to keep the event loop alive for those 10 ms.

    Root cause hypothesis:

    1. The test's mock generateText returns a promise that never resolves — it only registers an abort listener.
    2. The implementation's deadline relies on AbortSignal.timeout(), whose internal timer is unref'ed and does not keep the Node.js event loop active.
    3. With nothing else scheduled, the event loop can drain before the 10 ms timer ever fires → the race promise is left pending → node:test reports cancelledByParent: 'Promise resolution is still pending but the event loop has already resolved'.

    Whether it reproduces then depends on incidental keep-alives in the process (Node version internals, leftover timers from sibling tests in the same process), which is why it looks load-dependent — it's really a liveness race.

    Suggested fix: in generateSessionTitle, drive the timeout branch of the Promise.race with an explicit (ref'ed) setTimeout that is cleared once the race settles, instead of piggybacking on AbortSignal.timeout's unref'ed timer. That keeps the loop alive deterministically and also makes the test independent of Node-version event-loop behavior. (An AbortController + abortController.abort(reason) from that same timer can still feed the abortSignal passed to generateText.)

    Repro used: packages/runtime → npm run build && node --test dist/__tests__/session-title.test.js, toggling Node via nvm between 22.17.0 and 24.18.0.

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