@commonlyai/cli 0.1.287 → 0.1.288
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 +1 -1
- package/src/commands/agent.js +54 -15
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -2532,6 +2532,7 @@ export const performRun = ({
|
|
|
2532
2532
|
// settled; anything thrown after a spawn that resolved means the reply never
|
|
2533
2533
|
// reached the pod. Off, `turn` writes nothing.
|
|
2534
2534
|
const runTurn = async (args) => {
|
|
2535
|
+
wrapperSpokeInTurn = false;
|
|
2535
2536
|
const turn = turnRunner.begin({ eventType: args.event.type });
|
|
2536
2537
|
try {
|
|
2537
2538
|
return await runTurnBody({ ...args, turn });
|
|
@@ -2559,7 +2560,7 @@ export const performRun = ({
|
|
|
2559
2560
|
const key = `model-unavailable:${failure.model || 'unknown'}`;
|
|
2560
2561
|
try {
|
|
2561
2562
|
if (!noticeDue(agentName, key, MODEL_UNAVAILABLE_HINT_WINDOW_MS)) return;
|
|
2562
|
-
const delivery = await
|
|
2563
|
+
const delivery = await deliverTurnNotice({
|
|
2563
2564
|
client,
|
|
2564
2565
|
podId: hintPodId,
|
|
2565
2566
|
text: modelUnavailableHint(failure.model),
|
|
@@ -2627,10 +2628,22 @@ export const performRun = ({
|
|
|
2627
2628
|
// past its duplicate guard, since a second cut-off has no open ask to carry it.
|
|
2628
2629
|
// A turn only agents woke gets no line: "ask me again" isn't for them, and in
|
|
2629
2630
|
// an agent-dm the line would wake the peer into a paid turn.
|
|
2630
|
-
|
|
2631
|
+
// F279: an event let go after three failures counts too, because the server's
|
|
2632
|
+
// retry is 10 to 20 minutes off and the kernel skips its own line once the
|
|
2633
|
+
// agent has posted. `part` is what one of its attempts posted. It may come back
|
|
2634
|
+
// and fail again, so it hears this once.
|
|
2635
|
+
const noteFailedTurnPart = async (failedEvents) => {
|
|
2636
|
+
if (!failedTurn?.preSpawnIds || wrapperSpokeInTurn) return;
|
|
2637
|
+
const tail = await failedTurn.snapshotMessages(50);
|
|
2638
|
+
const ownPost = tail && newestOwnPostSince(tail, failedTurn.preSpawnIds);
|
|
2639
|
+
if (ownPost) failedEvents.forEach((event) => heldRetryParts.set(String(event._id), ownPost));
|
|
2640
|
+
};
|
|
2641
|
+
|
|
2642
|
+
const noticeCutOff = async (lostEvents, { released = [], part = null } = {}) => {
|
|
2631
2643
|
const turnArgs = failedTurn;
|
|
2632
2644
|
failedTurn = null;
|
|
2633
|
-
const waiting = lostEvents.filter((event) => event.deliveryMode !== 'digest'
|
|
2645
|
+
const waiting = [...lostEvents, ...released].filter((event) => event.deliveryMode !== 'digest'
|
|
2646
|
+
&& !cutOffTold.has(String(event._id))
|
|
2634
2647
|
&& (someoneIsWaiting(event) || PERSON_WAITING_EVENT_TYPES.has(event.type)));
|
|
2635
2648
|
if (!turnArgs || turnArgs.trigger === 'agent' || waiting.length === 0) return;
|
|
2636
2649
|
const { eventPodId } = turnArgs;
|
|
@@ -2642,8 +2655,9 @@ export const performRun = ({
|
|
|
2642
2655
|
// prove this seat replied, and this has no own-post check.
|
|
2643
2656
|
// It stands on the prompt instead: a person's direct @ isn't offered
|
|
2644
2657
|
// silence, so their item checkpoints only after a reply. That holds only
|
|
2645
|
-
// for a known person, which an 'unknown' comment isn't
|
|
2646
|
-
|
|
2658
|
+
// for a known person, which an 'unknown' comment isn't, and for an item
|
|
2659
|
+
// that checkpointed, which a released one didn't.
|
|
2660
|
+
if (turnArgs.trigger !== 'human' || !lostEvents.includes(waiting[0])) return;
|
|
2647
2661
|
delivery = await deliverCommentReply({
|
|
2648
2662
|
client, ...target, text: CUT_OFF_NOTICE, onlyIfUnanswered: false,
|
|
2649
2663
|
});
|
|
@@ -2651,7 +2665,8 @@ export const performRun = ({
|
|
|
2651
2665
|
const tail = turnArgs.preSpawnIds ? await turnArgs.snapshotMessages(50) : null;
|
|
2652
2666
|
// Nothing of this seat's in the pod means no half answer to explain: a
|
|
2653
2667
|
// deliberate silence checkpoints too, and a requeue takes a row as well.
|
|
2654
|
-
const ownPost =
|
|
2668
|
+
const ownPost = (lostEvents.some((event) => waiting.includes(event))
|
|
2669
|
+
&& tail && newestOwnPostSince(tail, turnArgs.preSpawnIds)) || part;
|
|
2655
2670
|
if (!ownPost) return;
|
|
2656
2671
|
delivery = await deliverChatReply({
|
|
2657
2672
|
client,
|
|
@@ -2666,7 +2681,12 @@ export const performRun = ({
|
|
|
2666
2681
|
if (delivery.skipped || delivery.refused) {
|
|
2667
2682
|
log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: `
|
|
2668
2683
|
+ `${delivery.reason || 'the notice was not posted'}`);
|
|
2669
|
-
} else
|
|
2684
|
+
} else {
|
|
2685
|
+
waiting.forEach((event) => cutOffTold.add(String(event._id)));
|
|
2686
|
+
// The line covers every part so far, so a sibling let go later has none.
|
|
2687
|
+
heldRetryParts.clear();
|
|
2688
|
+
log(`[inbox.batch] told pod ${eventPodId} this agent was cut off before it finished`);
|
|
2689
|
+
}
|
|
2670
2690
|
} catch (noticeError) {
|
|
2671
2691
|
log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: ${noticeError.message}`);
|
|
2672
2692
|
}
|
|
@@ -2807,7 +2827,7 @@ export const performRun = ({
|
|
|
2807
2827
|
} catch (error) {
|
|
2808
2828
|
if (error.code === 'seat_model_missing' && eventPodId && !missingModelNotices.has(eventPodId)) {
|
|
2809
2829
|
try {
|
|
2810
|
-
const delivery = await
|
|
2830
|
+
const delivery = await deliverTurnNotice({
|
|
2811
2831
|
client,
|
|
2812
2832
|
podId: eventPodId,
|
|
2813
2833
|
text: "This agent has no model set; add environment.model to its configuration.",
|
|
@@ -3412,7 +3432,7 @@ export const performRun = ({
|
|
|
3412
3432
|
});
|
|
3413
3433
|
let posted = false;
|
|
3414
3434
|
try {
|
|
3415
|
-
const delivery = await
|
|
3435
|
+
const delivery = await deliverTurnNotice({
|
|
3416
3436
|
client,
|
|
3417
3437
|
podId: eventPodId,
|
|
3418
3438
|
text,
|
|
@@ -3471,6 +3491,18 @@ export const performRun = ({
|
|
|
3471
3491
|
let tickUnsettled = [];
|
|
3472
3492
|
// eventId → consecutive local failures, for HELD_RETRY_MAX_FAILURES.
|
|
3473
3493
|
const heldRetryFailures = new Map();
|
|
3494
|
+
// Event id to what a failed attempt on it posted, for noticeCutOff. Read as each
|
|
3495
|
+
// attempt fails, because the attempt's own snapshot then leaves out the notices
|
|
3496
|
+
// the wrapper posted after earlier ones: those aren't part of an answer. A notice
|
|
3497
|
+
// inside the attempt can't be told from a post that way, so that attempt isn't
|
|
3498
|
+
// read, which can only cost the line.
|
|
3499
|
+
const heldRetryParts = new Map();
|
|
3500
|
+
let wrapperSpokeInTurn = false;
|
|
3501
|
+
const deliverTurnNotice = (notice) => {
|
|
3502
|
+
wrapperSpokeInTurn = true;
|
|
3503
|
+
return deliverChatReply(notice);
|
|
3504
|
+
};
|
|
3505
|
+
const cutOffTold = new Set();
|
|
3474
3506
|
// eventId → turns passed over, for PAST_CAP_MAX_CARRIES.
|
|
3475
3507
|
const pastCapCarries = new Map();
|
|
3476
3508
|
// The current batch's items past the cap. Kept out here because the tick needs
|
|
@@ -3525,6 +3557,7 @@ export const performRun = ({
|
|
|
3525
3557
|
// tick adds to the carry, never replaces it.
|
|
3526
3558
|
const holdForRetry = async (failedEvents, untriedEvents = [], pastCap = []) => {
|
|
3527
3559
|
const released = [];
|
|
3560
|
+
let part = null;
|
|
3528
3561
|
const carry = [];
|
|
3529
3562
|
const seen = new Set();
|
|
3530
3563
|
for (const event of failedEvents) {
|
|
@@ -3534,8 +3567,10 @@ export const performRun = ({
|
|
|
3534
3567
|
const failures = (heldRetryFailures.get(id) || 0) + 1;
|
|
3535
3568
|
// A stop wins over the local limit: the sweep would make this event
|
|
3536
3569
|
// wait 10–20 minutes, and the server's ceiling bounds a hand-back.
|
|
3537
|
-
if (running && failures >= HELD_RETRY_MAX_FAILURES)
|
|
3538
|
-
|
|
3570
|
+
if (running && failures >= HELD_RETRY_MAX_FAILURES) {
|
|
3571
|
+
released.push(event);
|
|
3572
|
+
part = part || heldRetryParts.get(id) || null;
|
|
3573
|
+
} else {
|
|
3539
3574
|
heldRetryFailures.set(id, failures);
|
|
3540
3575
|
carry.push(event);
|
|
3541
3576
|
}
|
|
@@ -3576,6 +3611,7 @@ export const performRun = ({
|
|
|
3576
3611
|
if (!running) {
|
|
3577
3612
|
heldRetry = [...heldRetry, ...carry];
|
|
3578
3613
|
heldRetryFailures.clear();
|
|
3614
|
+
heldRetryParts.clear();
|
|
3579
3615
|
pastCapCarries.clear();
|
|
3580
3616
|
const confirmed = await renewHeldDeliveries(failedEvents);
|
|
3581
3617
|
return {
|
|
@@ -3589,7 +3625,7 @@ export const performRun = ({
|
|
|
3589
3625
|
const dropped = carry.filter((event) => !stillHeld(event, confirmed));
|
|
3590
3626
|
heldRetry = [...heldRetry, ...held];
|
|
3591
3627
|
const heldIds = new Set(heldRetry.map((event) => String(event._id)));
|
|
3592
|
-
for (const counts of [heldRetryFailures, pastCapCarries]) {
|
|
3628
|
+
for (const counts of [heldRetryFailures, heldRetryParts, pastCapCarries]) {
|
|
3593
3629
|
for (const id of [...counts.keys()]) {
|
|
3594
3630
|
if (!heldIds.has(id)) counts.delete(id);
|
|
3595
3631
|
}
|
|
@@ -3601,7 +3637,7 @@ export const performRun = ({
|
|
|
3601
3637
|
);
|
|
3602
3638
|
}
|
|
3603
3639
|
return {
|
|
3604
|
-
held, released, handedBack: [], lost: dropped.filter((event) => failedEvents.includes(event)),
|
|
3640
|
+
held, released, part, handedBack: [], lost: dropped.filter((event) => failedEvents.includes(event)),
|
|
3605
3641
|
};
|
|
3606
3642
|
};
|
|
3607
3643
|
|
|
@@ -3659,6 +3695,7 @@ export const performRun = ({
|
|
|
3659
3695
|
heldGreeting = [];
|
|
3660
3696
|
tickUnsettled = [];
|
|
3661
3697
|
heldRetryFailures.clear();
|
|
3698
|
+
heldRetryParts.clear();
|
|
3662
3699
|
clearHeldRenewal();
|
|
3663
3700
|
return carry.length ? handBackDeliveries(carry, 'stop') : Promise.resolve([]);
|
|
3664
3701
|
};
|
|
@@ -4314,8 +4351,10 @@ export const performRun = ({
|
|
|
4314
4351
|
nextPollDelayMs = retry.delayMs;
|
|
4315
4352
|
retryScheduled = true;
|
|
4316
4353
|
tickUnsettled.push(...claimedAfter(groupIndex));
|
|
4354
|
+
const attempted = failedEvents.filter((event) => !pastCapEvents.includes(event));
|
|
4355
|
+
await noteFailedTurnPart(attempted);
|
|
4317
4356
|
const hold = await holdForRetry(
|
|
4318
|
-
|
|
4357
|
+
attempted,
|
|
4319
4358
|
untriedAfter(groupIndex),
|
|
4320
4359
|
pastCapEvents,
|
|
4321
4360
|
);
|
|
@@ -4348,7 +4387,7 @@ export const performRun = ({
|
|
|
4348
4387
|
});
|
|
4349
4388
|
if (onError) onError(wrapped);
|
|
4350
4389
|
else log(`[inbox.batch] ${wrapped.message}`);
|
|
4351
|
-
await noticeCutOff(hold.lost);
|
|
4390
|
+
await noticeCutOff(hold.lost, { released: hold.released, part: hold.part });
|
|
4352
4391
|
await noticeCantAnswer(err, [...failedEvents, ...untriedAfter(groupIndex)]);
|
|
4353
4392
|
};
|
|
4354
4393
|
let batch;
|