@code-yeongyu/senpi-agent-core 2026.11.19 → 2026.11.21-2

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.
@@ -137,6 +137,9 @@ async function runLoop(initialContext, newMessages, initialConfig, signal, emit,
137
137
  };
138
138
  // Check for steering messages at start (user may have typed while waiting)
139
139
  let pendingMessages = await drainSteering();
140
+ // Follow-ups an error-ended run parked are taken here, so this run writes them even if its request fails.
141
+ if (pendingMessages.length === 0 && config.takeFollowUpsAtStart)
142
+ pendingMessages = await drainFollowUp();
140
143
  // Outer loop: continues when queued follow-up messages arrive after agent would stop
141
144
  while (true) {
142
145
  let hasMoreToolCalls = true;
package/dist/agent.d.ts CHANGED
@@ -90,6 +90,8 @@ export declare class Agent {
90
90
  private readonly listeners;
91
91
  private readonly steeringQueue;
92
92
  private readonly followUpQueue;
93
+ /** The last run ended in a provider error with follow-ups queued: the next run takes them at its first turn. */
94
+ private followUpsParked;
93
95
  convertToLlm: (messages: AgentMessage[]) => Message[] | Promise<Message[]>;
94
96
  transformContext?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<AgentMessage[]>;
95
97
  streamFunction: StreamFn;
@@ -235,6 +237,7 @@ export declare class Agent {
235
237
  private createContextSnapshot;
236
238
  private createLoopConfig;
237
239
  private runWithLifecycle;
240
+ private lastAssistantStopReason;
238
241
  private canDrainQueuedMessagesAfterRun;
239
242
  private runQueuedMessagesAfterAgentEnd;
240
243
  private handleRunFailure;
package/dist/agent.js CHANGED
@@ -97,6 +97,10 @@ class PendingMessageQueue {
97
97
  end++;
98
98
  return this.messages.slice(0, end);
99
99
  }
100
+ /** Every queued message, whatever the drain mode. */
101
+ all() {
102
+ return this.messages.slice();
103
+ }
100
104
  drain() {
101
105
  const drained = this.peek();
102
106
  this.messages = this.messages.slice(drained.length);
@@ -139,6 +143,8 @@ export class Agent {
139
143
  }
140
144
  constructor(options) {
141
145
  this.listeners = new Set();
146
+ /** The last run ended in a provider error with follow-ups queued: the next run takes them at its first turn. */
147
+ this.followUpsParked = false;
142
148
  // Older compiled consumers may omit options or streamFn even though the current API requires them.
143
149
  const runtimeOptions = options ?? {};
144
150
  this.#internalChannel = runtimeOptions.internalChannel;
@@ -249,9 +255,10 @@ export class Agent {
249
255
  }
250
256
  /** Preview next-turn messages, or both queues with { all: true }, without consuming them. */
251
257
  peekQueuedMessages(options) {
252
- const steering = this.steeringQueue.peek();
258
+ // `all` is every queued message: in `one-at-a-time` mode a queue's next drain is only its head (omo#14428).
253
259
  if (options?.all)
254
- return [...steering, ...this.followUpQueue.peek()];
260
+ return [...this.steeringQueue.all(), ...this.followUpQueue.all()];
261
+ const steering = this.steeringQueue.peek();
255
262
  return steering.length > 0 ? steering : this.followUpQueue.peek();
256
263
  }
257
264
  /** Active abort signal for the current run, if any. */
@@ -383,7 +390,10 @@ export class Agent {
383
390
  }
384
391
  async runPromptMessages(messages, options = {}) {
385
392
  await this.runWithLifecycle(async (signal) => {
386
- await runAgentLoop(messages, this.createContextSnapshot(), this.createLoopConfig(options), (event) => this.processEvents(event), signal, this.streamFunction);
393
+ await runAgentLoop(messages, this.createContextSnapshot(),
394
+ // A run started from new input takes follow-ups an error-ended run parked; a retry or other continuation
395
+ // leaves them for that run (omo#14428).
396
+ this.createLoopConfig({ ...options, takeParkedFollowUps: true }), (event) => this.processEvents(event), signal, this.streamFunction);
387
397
  });
388
398
  }
389
399
  /**
@@ -393,6 +403,8 @@ export class Agent {
393
403
  async runQueuedMessages(queue, options) {
394
404
  const pendingQueue = queue === "steering" ? this.steeringQueue : this.followUpQueue;
395
405
  const port = this.queuedInputPort;
406
+ // This run starts from the queue itself, so it takes the parked input in the queue's own drain order.
407
+ this.followUpsParked = false;
396
408
  if (!port) {
397
409
  await this.runPromptMessages(pendingQueue.drain(), options);
398
410
  return;
@@ -465,6 +477,9 @@ export class Agent {
465
477
  }
466
478
  createLoopConfig(options = {}) {
467
479
  let skipInitialSteeringPoll = options.skipInitialSteeringPoll === true;
480
+ const takeFollowUpsAtStart = options.takeParkedFollowUps === true && this.followUpsParked;
481
+ if (takeFollowUpsAtStart)
482
+ this.followUpsParked = false;
468
483
  let steeringQueueGeneration = this.steeringQueue.getClearGeneration();
469
484
  let followUpQueueGeneration = this.followUpQueue.getClearGeneration();
470
485
  const finishTurn = this.finishTurn;
@@ -534,6 +549,7 @@ export class Agent {
534
549
  };
535
550
  return queuedInputPort ? queuedInputPort.claim("steering", drain) : drain();
536
551
  },
552
+ takeFollowUpsAtStart,
537
553
  getFollowUpMessages: async () => {
538
554
  const drain = () => {
539
555
  followUpQueueGeneration = this.followUpQueue.getClearGeneration();
@@ -577,6 +593,14 @@ export class Agent {
577
593
  this.hasQueuedMessages()) {
578
594
  await this.runQueuedMessagesAfterAgentEnd(abortController.signal);
579
595
  }
596
+ // Follow-ups an error-ended run parked join the next run's first turn boundary, so their entries are
597
+ // written even when that run's provider request fails too (omo#14428). A suppressed drain only hands this
598
+ // run's post-run decision to its owner (a retry, a compaction, agent_before_settle); the mark affects only
599
+ // the next run, so it holds either way.
600
+ this.followUpsParked =
601
+ !abortController.signal.aborted &&
602
+ this.followUpQueue.hasItems() &&
603
+ this.lastAssistantStopReason() === "error";
580
604
  }
581
605
  catch (error) {
582
606
  await this.handleRunFailure(error, abortController.signal.aborted);
@@ -585,6 +609,10 @@ export class Agent {
585
609
  this.finishRun();
586
610
  }
587
611
  }
612
+ lastAssistantStopReason() {
613
+ const lastMessage = this._state.messages.at(-1);
614
+ return lastMessage?.role === "assistant" ? lastMessage.stopReason : undefined;
615
+ }
588
616
  canDrainQueuedMessagesAfterRun() {
589
617
  const lastMessage = this._state.messages[this._state.messages.length - 1];
590
618
  return (lastMessage?.role !== "assistant" ||
@@ -5,6 +5,8 @@ export declare const internalProgressSink: unique symbol;
5
5
  type ProgressSink = (progress: AssistantProgress) => Promise<void> | undefined;
6
6
  export type InternalLoopConfig = AgentLoopConfig & {
7
7
  [internalProgressSink]?: ProgressSink;
8
+ /** Poll the follow-up queue at the first turn boundary when no steering is queued (omo#14428). */
9
+ takeFollowUpsAtStart?: boolean;
8
10
  };
9
11
  type InternalEvent = {
10
12
  event: AgentEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-agent-core",
3
- "version": "2026.11.19",
3
+ "version": "2026.11.21-2",
4
4
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -76,8 +76,8 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "@earendil-works/chord": "0.99.1",
79
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.19",
80
- "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.19",
79
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.21-2",
80
+ "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.21-2",
81
81
  "diff": "9.0.0",
82
82
  "ignore": "7.0.9",
83
83
  "typebox": "1.3.34",