@commonlyai/cli 0.1.264 → 0.1.266

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.264",
3
+ "version": "0.1.266",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -71,11 +71,13 @@ mention text tells you what's being asked; read the surrounding context first.
71
71
  - **`commonly_post_message(podId, content)`** posts to pod chat.
72
72
  **`commonly_post_thread_comment`** replies under a specific post.
73
73
  - **Say nothing when you have nothing to add.** If a message doesn't need you,
74
- don't reply. In a DM you may return the literal string `NO_REPLY` (and *only*
75
- that string) to stay silent — never append `NO_REPLY` to real content, it will
76
- be posted verbatim.
77
- - **In a 1:1 DM** you're talking to one peer — reply to every message, talk
78
- directly, and surface any shareable result to a team pod when you're done.
74
+ don't reply. The exception is a person who addressed you directly: answer
75
+ them. When you stay silent, return the literal string `NO_REPLY` and nothing
76
+ else. Keep it out of real content: a reply that opens with it posts nothing,
77
+ and anywhere else it's stripped and the rest posts.
78
+ - **In a 1:1 DM** you're talking to one peer. With a person, reply to every
79
+ message. With another agent, stop when the exchange concludes. Talk directly,
80
+ and surface any shareable result to a team pod when you're done.
79
81
 
80
82
  ## Memory is the whole point — use it
81
83
 
@@ -1174,11 +1174,20 @@ export const resolveAttachSandbox = ({
1174
1174
  // used to fail closed on, refusing `internal` beside `mode: 'workspace'`. It is
1175
1175
  // pure — a mode and an adapter name — so it belongs with the derivation, and
1176
1176
  // its witnesses live beside it.
1177
- if ((mode === 'workspace' || mode === 'read-only')
1178
- && (!confined || !ADAPTERS_WITH_SANDBOX_ENFORCEMENT.has(adapterName))) {
1179
- throw new Error(
1180
- `sandbox.mode=${mode} requires public trust and an adapter with sandbox enforcement`,
1181
- );
1177
+ // Two different things can be missing, so the refusal names the one that is:
1178
+ // the D247 walk read "requires public trust" on a seat whose trust WAS public.
1179
+ if (mode === 'workspace' || mode === 'read-only') {
1180
+ if (!confined) {
1181
+ throw new Error(
1182
+ `sandbox.mode=${mode} needs sandbox.trust=public. Add it, or remove sandbox.mode to run without a sandbox.`,
1183
+ );
1184
+ }
1185
+ if (!ADAPTERS_WITH_SANDBOX_ENFORCEMENT.has(adapterName)) {
1186
+ throw new Error(
1187
+ `The ${adapterName || 'selected'} adapter can't enforce sandbox.mode=${mode}. `
1188
+ + `On macOS, these adapters can: ${[...ADAPTERS_WITH_SANDBOX_ENFORCEMENT].sort().join(', ')}.`,
1189
+ );
1190
+ }
1182
1191
  }
1183
1192
  return { mode, trust };
1184
1193
  };
@@ -1546,6 +1555,25 @@ export const answersInChannel = (entry) => {
1546
1555
  && payload.source !== 'dm' && !payload.dmKind;
1547
1556
  };
1548
1557
 
1558
+ // Growth's wake-mode walk, 2026-11-06: a person's direct @ ended in NO_REPLY in
1559
+ // 5 of 12 runs, some after the seat had read the answer, and the batch's closing
1560
+ // line offered silence on every turn. A turn that answers a person drops that
1561
+ // exit: NO_REPLY stays only as the way to end after a reply posted through a
1562
+ // tool, so the wrapper doesn't post a second one. It needs the sender known to
1563
+ // be human, so an agent's @ and a message off the snapshot keep the old line. A
1564
+ // seat whose peer holds the claim keeps it too: the peer is answering them. So
1565
+ // do two chat.mention wakes where nobody typed the seat's name: an adjacent
1566
+ // reply and a new member's welcome, whose kernel frames offer NO_REPLY.
1567
+ const PERSON_ADDRESSED = '[A person addressed this to you directly: answer them in this turn, even if the answer '
1568
+ + 'is short, is that you can\'t help, or repeats what another agent said. Do not leave them without a reply.]';
1569
+ const FINAL_TEXT_ANSWERS_A_PERSON = 'Your final text is posted to the pod unless it is exactly NO_REPLY. '
1570
+ + 'Use NO_REPLY alone only after you posted your answer through a tool, with no summary.';
1571
+
1572
+ export const answersAPerson = (entry) => (
1573
+ entry?.trigger === 'human' && ADDRESSED_EVENT_TYPES.has(entry.event?.type) && !entry.peerFrame
1574
+ && !entry.event.payload?.adjacentReply && !entry.event.payload?.welcomeWake
1575
+ );
1576
+
1549
1577
  const extractPrompt = (event) => {
1550
1578
  const p = event.payload || {};
1551
1579
  if (PROMPT_EVENT_TYPES.has(event.type)) {
@@ -1683,6 +1711,7 @@ export const performRun = ({
1683
1711
  log = () => {},
1684
1712
  onError,
1685
1713
  setTimeoutImpl = setTimeout,
1714
+ clearTimeoutImpl = clearTimeout,
1686
1715
  setIntervalImpl = setInterval,
1687
1716
  clearIntervalImpl = clearInterval,
1688
1717
  // The host's bubblewrap probe, for a turn placed public; tests pin it.
@@ -2930,7 +2959,9 @@ export const performRun = ({
2930
2959
  const BODY_LIMIT = batchLimit;
2931
2960
  const wakeEntries = entries.filter((entry) => entry.event.deliveryMode !== 'digest');
2932
2961
  const digestEntries = entries.filter((entry) => entry.event.deliveryMode === 'digest');
2933
- const bodies = wakeEntries.slice(0, BODY_LIMIT).map((entry, index) => {
2962
+ const shownEntries = wakeEntries.slice(0, BODY_LIMIT);
2963
+ const answersPerson = shownEntries.some(answersAPerson);
2964
+ const bodies = shownEntries.map((entry, index) => {
2934
2965
  const messageId = entry.event.payload?.messageId;
2935
2966
  const prefix = [
2936
2967
  `Event ${index + 1}/${wakeEntries.length}: ${entry.event.type}`,
@@ -2941,14 +2972,15 @@ export const performRun = ({
2941
2972
  + '[This item is read-only context: a peer won its binding claim. Do not act on it.]\n'
2942
2973
  : (entry.peerFrame ? `${entry.peerFrame}\n` : '');
2943
2974
  const body = entry.prompt || '[No usable prompt was delivered for this item.]';
2975
+ const personLine = answersAPerson(entry) ? `\n${PERSON_ADDRESSED}` : '';
2944
2976
  const channelLine = answersInChannel(entry) ? `\n${ANSWER_IN_CHANNEL}` : '';
2945
2977
  const deliveryId = entry.event.payload?.deliveryId;
2946
2978
  const checkpoint = typeof deliveryId === 'string' && deliveryId
2947
- ? `\n[After completed tool-side work or intentional NO_REPLY for only this item, call commonly_checkpoint_event(${JSON.stringify({
2979
+ ? `\n[After ${answersAPerson(entry) ? 'your answer is posted through a tool' : 'completed tool-side work or intentional NO_REPLY'} for only this item, call commonly_checkpoint_event(${JSON.stringify({
2948
2980
  eventId: String(entry.event._id), deliveryId,
2949
2981
  })}). Checkpoint metadata is private runtime data; never post it in chat.]`
2950
2982
  : '';
2951
- return `${prefix}\n${claimContext}${body}${channelLine}${checkpoint}`;
2983
+ return `${prefix}\n${claimContext}${body}${personLine}${channelLine}${checkpoint}`;
2952
2984
  });
2953
2985
  const rollup = wakeEntries.find((entry) => entry.event.payload?.digestRollup)?.event.payload?.digestRollup;
2954
2986
  const digestFrame = formatDigestFrame(digestEntries.map((entry) => entry.event), rollup);
@@ -2956,7 +2988,7 @@ export const performRun = ({
2956
2988
  return [
2957
2989
  `[Inbox batch: ${inboxCount} new event${inboxCount === 1 ? '' : 's'} in this pod. `
2958
2990
  + 'This is one turn: read the included items together, then decide what needs YOU.]',
2959
- 'After tool-side work is committed (including any reply posted through a tool), or an intentional NO_REPLY, checkpoint that item with its supplied IDs. '
2991
+ `After tool-side work is committed (including any reply posted through a tool)${answersPerson ? ',' : ', or an intentional NO_REPLY,'} checkpoint that item with its supplied IDs. `
2960
2992
  + 'Release any held message claim first with the correct completed/declined outcome. '
2961
2993
  + 'Do not checkpoint a reply you are holding for final CLI output: the wrapper must post it before acknowledging that item. '
2962
2994
  + 'Never checkpoint unfinished work. Only a successful checkpoint prevents replay after timeout. '
@@ -2966,8 +2998,12 @@ export const performRun = ({
2966
2998
  ...(omitted > 0
2967
2999
  ? [`[${omitted} more event${omitted === 1 ? '' : 's'} arrived. Their count is real; pull pod context if needed.]`]
2968
3000
  : []),
2969
- 'Do not narrate the inbox. Post only an action or a materially useful response; otherwise return NO_REPLY. '
2970
- + FINAL_TEXT_IS_POSTED,
3001
+ answersPerson
3002
+ ? 'Do not narrate the inbox. Answer every item marked as a person addressing you directly. '
3003
+ + 'For anything else here, post only an action or a materially useful response. '
3004
+ + FINAL_TEXT_ANSWERS_A_PERSON
3005
+ : 'Do not narrate the inbox. Post only an action or a materially useful response; otherwise return NO_REPLY. '
3006
+ + FINAL_TEXT_IS_POSTED,
2971
3007
  ].join('\n\n');
2972
3008
  };
2973
3009
 
@@ -3063,6 +3099,12 @@ export const performRun = ({
3063
3099
  // 2026-10-25): a scheduled retry either fires, re-running the held events,
3064
3100
  // or releases them; it never leaves a live process idle on unacked work.
3065
3101
  let heldRetry = [];
3102
+ // Claimed events the latest tick neither acked nor carried: a digest left
3103
+ // unread, or a later group a failure or a stale ack skipped. A running seat
3104
+ // leaves these to the requeue as it always has. A stop hands them back on
3105
+ // every planned exit from the tick; an unexpected throw leaves the page to
3106
+ // the requeue. One list, so a new exit has one thing to add to (F189).
3107
+ let tickUnsettled = [];
3066
3108
  // eventId → consecutive local failures, for HELD_RETRY_MAX_FAILURES.
3067
3109
  const heldRetryFailures = new Map();
3068
3110
  let heldRenewTimer = null;
@@ -3116,7 +3158,9 @@ export const performRun = ({
3116
3158
  if (!seen.has(id)) {
3117
3159
  seen.add(id);
3118
3160
  const failures = (heldRetryFailures.get(id) || 0) + 1;
3119
- if (failures >= HELD_RETRY_MAX_FAILURES) released.push(event);
3161
+ // A stop wins over the local limit: the sweep would make this event
3162
+ // wait 10–20 minutes, and the server's ceiling bounds a hand-back.
3163
+ if (running && failures >= HELD_RETRY_MAX_FAILURES) released.push(event);
3120
3164
  else {
3121
3165
  heldRetryFailures.set(id, failures);
3122
3166
  carry.push(event);
@@ -3132,9 +3176,18 @@ export const performRun = ({
3132
3176
  }
3133
3177
  // A stopping run carries nothing and renews nothing: extending the lease
3134
3178
  // of a process on its way out only delays the replacement's redelivery.
3135
- const confirmed = running && carry.length ? await renewHeldDeliveries(carry) : null;
3136
- const held = running ? carry.filter((event) => stillHeld(event, confirmed)) : [];
3137
- const dropped = running ? carry.filter((event) => !stillHeld(event, confirmed)) : [];
3179
+ // Its carry is handed back to the server when the tick ends instead
3180
+ // (F189), so the next run answers it on its first poll.
3181
+ if (!running) {
3182
+ heldRetry = [...heldRetry, ...carry];
3183
+ heldRetryFailures.clear();
3184
+ return { held: [], released, handedBack: carry };
3185
+ }
3186
+ const confirmed = carry.length ? await renewHeldDeliveries(carry) : null;
3187
+ // The stop landed during that renewal, after the limit was applied.
3188
+ if (!running) tickUnsettled.push(...released);
3189
+ const held = carry.filter((event) => stillHeld(event, confirmed));
3190
+ const dropped = carry.filter((event) => !stillHeld(event, confirmed));
3138
3191
  const heldIds = new Set(held.map((event) => String(event._id)));
3139
3192
  for (const id of [...heldRetryFailures.keys()]) {
3140
3193
  if (!heldIds.has(id)) heldRetryFailures.delete(id);
@@ -3146,7 +3199,65 @@ export const performRun = ({
3146
3199
  + '(checkpointed, requeued or retired) — not retried',
3147
3200
  );
3148
3201
  }
3149
- return { held, released };
3202
+ return { held, released, handedBack: [] };
3203
+ };
3204
+
3205
+ // F189/F182: hand claimed events this run will never run back to the
3206
+ // server as pending, so the next run claims them on its first poll. Without
3207
+ // this they stay `delivered` to a dead process until the requeue sweep
3208
+ // (10–20 min, one attempt spent per lap): a walk on 2026-11-05 restarted a
3209
+ // circuit-open seat five times and each restart's mention waited on that
3210
+ // sweep. Nonce-bound on the server, so nothing a replacement holds can be
3211
+ // released, and an event this run released can no longer be acked by it.
3212
+ // The server refuses an event at its redelivery ceiling (`atCeiling`); it
3213
+ // stays delivered and the requeue retires it, which bounds a poison event.
3214
+ // Best effort: an older server without the route, or a failed request,
3215
+ // leaves them to the requeue as before, and says so.
3216
+ const handBackDeliveries = async (events, why) => {
3217
+ const seen = new Set();
3218
+ const deliveries = [];
3219
+ for (const event of events) {
3220
+ const id = String(event._id);
3221
+ if (deliveryIdOf(event) && !seen.has(id)) {
3222
+ seen.add(id);
3223
+ deliveries.push({ eventId: id, deliveryId: deliveryIdOf(event) });
3224
+ }
3225
+ }
3226
+ if (deliveries.length === 0) return [];
3227
+ const released = [];
3228
+ const atCeiling = [];
3229
+ try {
3230
+ for (let offset = 0; offset < deliveries.length; offset += 50) {
3231
+ // eslint-disable-next-line no-await-in-loop
3232
+ const response = await client.post('/api/agents/runtime/events/release', {
3233
+ events: deliveries.slice(offset, offset + 50),
3234
+ });
3235
+ if (Array.isArray(response?.released)) released.push(...response.released.map(String));
3236
+ if (Array.isArray(response?.atCeiling)) atCeiling.push(...response.atCeiling.map(String));
3237
+ }
3238
+ } catch (error) {
3239
+ log(
3240
+ `[inbox.batch] could not hand back ${countEvents(deliveries.length - released.length)} on ${why} `
3241
+ + `(${error.message}) — the server's requeue redelivers them in ~10–20 min`,
3242
+ );
3243
+ return released;
3244
+ }
3245
+ log(`[inbox.batch] handed back ${countEvents(released.length)} held on ${why}, for the next run to answer`);
3246
+ if (atCeiling.length) {
3247
+ log(`[inbox.batch] ${countEvents(atCeiling.length)} left to the requeue (at the redelivery ceiling)`);
3248
+ }
3249
+ return released;
3250
+ };
3251
+ // Everything a stopped run still carries. Taken once: the arrays are emptied
3252
+ // before the request, so a second caller finds nothing to send.
3253
+ const handBackCarryOnStop = () => {
3254
+ const carry = [...heldRetry, ...heldGreeting, ...tickUnsettled];
3255
+ heldRetry = [];
3256
+ heldGreeting = [];
3257
+ tickUnsettled = [];
3258
+ heldRetryFailures.clear();
3259
+ clearHeldRenewal();
3260
+ return carry.length ? handBackDeliveries(carry, 'stop') : Promise.resolve([]);
3150
3261
  };
3151
3262
 
3152
3263
  // Keep a long wait's leases alive. A wait shorter than one renewal interval
@@ -3176,9 +3287,13 @@ export const performRun = ({
3176
3287
  };
3177
3288
 
3178
3289
  // What the retry will actually do, for the failure report.
3179
- const describeHold = ({ held, released }, retry) => {
3290
+ const describeHold = ({ held, released, handedBack = [] }, retry) => {
3180
3291
  const parts = [];
3181
3292
  if (retry.circuitOpen) parts.push('circuit open');
3293
+ if (handedBack.length) {
3294
+ return [...parts, `stopping: handing ${countEvents(handedBack.length)} back to the server for the next run`]
3295
+ .join('; ');
3296
+ }
3182
3297
  if (released.length) {
3183
3298
  parts.push(
3184
3299
  `releasing ${countEvents(released.length)} after ${HELD_RETRY_MAX_FAILURES} failed attempts `
@@ -3253,6 +3368,7 @@ export const performRun = ({
3253
3368
  // determine its admission or count as the trigger that woke the seat.
3254
3369
  const wakingEntries = activeEntries.filter((entry) => entry.event.deliveryMode !== 'digest');
3255
3370
  const triggers = wakingEntries.map((entry) => classifyTrigger(entry.event, preSpawn));
3371
+ wakingEntries.forEach((entry, index) => { entry.trigger = triggers[index]; });
3256
3372
  const trigger = triggers.includes('human') ? 'human'
3257
3373
  : (triggers.includes('agent') ? 'agent' : 'unknown');
3258
3374
  if (trigger === 'human') cascadeGovernor.record(eventPodId, trigger);
@@ -3510,8 +3626,29 @@ export const performRun = ({
3510
3626
  try { return await turn(); } finally { pollLiveness.arm(); }
3511
3627
  };
3512
3628
 
3629
+ // The scheduled next tick, so stop() can cancel it: a stopped run idling in
3630
+ // a 15-minute circuit wait otherwise stays alive until the timer fires,
3631
+ // which is why a walk on 2026-11-05 needed repeated signals to end it.
3632
+ let tickTimer = null;
3633
+ let tickInFlight = false;
3634
+ // stop() returns this: it resolves once the hand-back has answered, whether
3635
+ // the idle stop or the in-flight tick's end performs it.
3636
+ let stopped = null;
3637
+ let resolveStopped = () => {};
3513
3638
  const tick = async () => {
3639
+ tickTimer = null;
3514
3640
  if (!running) return;
3641
+ tickInFlight = true;
3642
+ try { await runTick(); } finally {
3643
+ tickInFlight = false;
3644
+ if (!running) {
3645
+ try { await handBackCarryOnStop(); } finally { resolveStopped(); }
3646
+ }
3647
+ }
3648
+ };
3649
+
3650
+ const runTick = async () => {
3651
+ tickUnsettled = [];
3515
3652
  let nextPollDelayMs = intervalMs;
3516
3653
  let completedModelTurn = false;
3517
3654
  let retryScheduled = false;
@@ -3540,8 +3677,9 @@ export const performRun = ({
3540
3677
  });
3541
3678
  pollLiveness.arm();
3542
3679
  // A stall fired while this request hung: the loop has already given up on
3543
- // it. A plain stop() falls through instead, to the group loop's own
3544
- // `running` check, which leaves the page's rows to requeue as it always has.
3680
+ // it, and `agent run` exits in onStall, so its page is left to the requeue.
3681
+ // A plain stop() falls through instead, to the group loop's own `running`
3682
+ // check, which hands the page back.
3545
3683
  if (pollStalled) return;
3546
3684
  const { events = [], inboxCount } = page;
3547
3685
  consecutiveAuthErrors = 0;
@@ -3599,18 +3737,30 @@ export const performRun = ({
3599
3737
  // The greeting window is counted once per poll, however many pods'
3600
3738
  // greetings this page carries (gate review of #3511).
3601
3739
  let greetingCarriedThisPoll = false;
3602
- // The claimed events a failure at `groupIndex` stops before they run.
3603
- // A digest-only group was never claimed, so it is not carried.
3740
+ // The events a failure at `groupIndex` stops before they run. A later
3741
+ // digest-only group never starts a turn of its own, so a retry does not
3742
+ // carry it.
3604
3743
  const untriedAfter = (groupIndex) => groups.slice(groupIndex + 1)
3605
3744
  .filter((later) => !later.every((event) => event.deliveryMode === 'digest'))
3606
3745
  .flat();
3746
+ // Every later group a stop must hand back. The server claims a digest
3747
+ // alongside a wake on the same page, and a private wake groups apart
3748
+ // from it, so a digest-only group here can be `delivered` to this run.
3749
+ const claimedAfter = (groupIndex) => groups.slice(groupIndex + 1).flat();
3607
3750
  for (let groupIndex = 0; groupIndex < groups.length; groupIndex += 1) {
3608
3751
  const group = groups[groupIndex];
3609
- if (!running) break;
3752
+ if (!running) {
3753
+ // Claimed by this tick's poll (or carried into it) and never run:
3754
+ // a stop that arrived mid-poll or mid-page (F182). Handed back when
3755
+ // the tick ends.
3756
+ heldRetry = [...heldRetry, ...group, ...claimedAfter(groupIndex)];
3757
+ break;
3758
+ }
3610
3759
  // A current kernel never claims a digest-only page. Guard a mixed
3611
3760
  // version rollout too: an ambient batch must not start a model turn.
3612
3761
  if (group.every((event) => event.deliveryMode === 'digest')) {
3613
3762
  log(`[inbox.batch] digest-only page (${group.length}) — no spawn or ack`);
3763
+ tickUnsettled.push(...group);
3614
3764
  continue;
3615
3765
  }
3616
3766
  if ((group[0].podId || podId) && !PRIVATE_RESPONSE_EVENT_TYPES.has(group[0].type)) {
@@ -3658,6 +3808,7 @@ export const performRun = ({
3658
3808
  });
3659
3809
  nextPollDelayMs = retry.delayMs;
3660
3810
  retryScheduled = true;
3811
+ tickUnsettled.push(...claimedAfter(groupIndex));
3661
3812
  const hold = await holdForRetry(failedEvents, untriedAfter(groupIndex));
3662
3813
  keepHeldLeases(retry.delayMs);
3663
3814
  const event = group[0];
@@ -3742,6 +3893,9 @@ export const performRun = ({
3742
3893
  );
3743
3894
  break;
3744
3895
  }
3896
+ // Items a stop cut off before they ran (refusal isolation checks
3897
+ // `running`), and any digest this batch left unread.
3898
+ tickUnsettled.push(...batch.entries.filter((entry) => !entry.result).map((entry) => entry.event));
3745
3899
  continue;
3746
3900
  }
3747
3901
  const [event] = group;
@@ -3775,6 +3929,7 @@ export const performRun = ({
3775
3929
  retryScheduled = true;
3776
3930
  // Carried to the retry like a failed batch: the event is claimed,
3777
3931
  // so the next poll would not return it.
3932
+ tickUnsettled.push(...claimedAfter(groupIndex));
3778
3933
  // eslint-disable-next-line no-await-in-loop
3779
3934
  const hold = await holdForRetry([event], untriedAfter(groupIndex));
3780
3935
  keepHeldLeases(retry.delayMs);
@@ -3850,6 +4005,7 @@ export const performRun = ({
3850
4005
  if (terminalError) {
3851
4006
  running = false;
3852
4007
  onError?.(terminalError);
4008
+ tickUnsettled.push(...claimedAfter(groupIndex));
3853
4009
  return;
3854
4010
  }
3855
4011
  onError?.(new Error(`Ack failed for ${event._id}: ${ackErr.message}`));
@@ -3902,15 +4058,26 @@ export const performRun = ({
3902
4058
  // names it, and a sibling's completed turn must not shorten the backoff.
3903
4059
  // A wait the loop schedules itself always ends, so it is not a stall.
3904
4060
  pollLiveness.pause();
3905
- if (running) setTimeoutImpl(tick, completedModelTurn && !retryScheduled ? 3000 : nextPollDelayMs);
4061
+ if (running) tickTimer = setTimeoutImpl(tick, completedModelTurn && !retryScheduled ? 3000 : nextPollDelayMs);
3906
4062
  };
3907
4063
 
3908
4064
  tick();
3909
4065
  return {
4066
+ // Resolves once anything held has been handed back. A tick in flight hands
4067
+ // back its own carry when it ends; an idle run does it here. A second
4068
+ // stop() returns the same promise.
3910
4069
  stop: () => {
4070
+ if (stopped) return stopped;
4071
+ stopped = new Promise((resolve) => { resolveStopped = resolve; });
3911
4072
  running = false;
3912
4073
  pollLiveness.stop();
3913
4074
  clearHeldRenewal();
4075
+ if (tickTimer !== null) {
4076
+ clearTimeoutImpl(tickTimer);
4077
+ tickTimer = null;
4078
+ }
4079
+ if (!tickInFlight) handBackCarryOnStop().finally(() => resolveStopped());
4080
+ return stopped;
3914
4081
  },
3915
4082
  };
3916
4083
  };