@yagni-app/code-staging 1.2.14-staging.2423.1 → 1.2.14-staging.2442.1

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.
@@ -38,6 +38,7 @@ export type RunStageFn = (stage: PipelineStage, ctx: {
38
38
  lens?: ReviewLens;
39
39
  grounded?: boolean;
40
40
  }, deps: RunStageDeps) => Promise<StageResult>;
41
+ export declare const IDLE_TIMEOUT_MESSAGE = "stage exceeded its idle timeout";
41
42
  /** True when at least {@link MODEL_BOUND_SHARE} of a stage's elapsed time was spent outside tools. */
42
43
  export declare function isModelBound(elapsedMs: number, toolMs: number): boolean;
43
44
  /** One telemetry record per attempt (routed through the orchestrator logger). */
@@ -46,7 +46,7 @@ const WALL_TIMEOUT_MODEL_MESSAGE = `${WALL_TIMEOUT_MESSAGE} while waiting on the
46
46
  * real wall window of many minutes.
47
47
  */
48
48
  const MODEL_BOUND_SHARE = 0.6;
49
- const IDLE_TIMEOUT_MESSAGE = "stage exceeded its idle timeout";
49
+ export const IDLE_TIMEOUT_MESSAGE = "stage exceeded its idle timeout";
50
50
  /** True when at least {@link MODEL_BOUND_SHARE} of a stage's elapsed time was spent outside tools. */
51
51
  export function isModelBound(elapsedMs, toolMs) {
52
52
  if (elapsedMs <= 0)
@@ -49,6 +49,7 @@ import { type CodeWriter } from "./codeWriter.js";
49
49
  import { type AttemptResult, type CloudIdentity, type CloudStage } from "./cloud.js";
50
50
  import type { ContinuationInputs } from "./continuation.js";
51
51
  import { type PlanChange } from "./planChanges.js";
52
+ import { type ResilienceAttemptRecord } from "./resilience.js";
52
53
  import { type RunStageDeps } from "./runner.js";
53
54
  import { type SessionTicketPath } from "./ticketPath.js";
54
55
  import type { JsonEvent, ModelTier, PipelineStage, StageId, StageResult, StopReason } from "./types.js";
@@ -222,6 +223,28 @@ export declare function childStderrTail(stderr: string): string;
222
223
  * else clean. Red tests and empty searches are errored `bash` calls and never
223
224
  * count: the gate asks whether the edits landed.
224
225
  */
226
+ /**
227
+ * How long a turn's child may write no event at all before the turn ends it
228
+ * (YAG-1295): a model call whose stream went silent mid-message (2026-11-12,
229
+ * a retried call that began a tool call and then sent nothing for 40
230
+ * minutes) is otherwise never ended from inside the session, and its
231
+ * heartbeat keeps the host's stall watch from seeing it. Every token delta
232
+ * counts as an event, and a running tool or subagent (the verification
233
+ * subagent may run for two hours) defers the window, as in the stage-graph
234
+ * lane (`resilience.ts`); the window is that lane's idle window, well above a
235
+ * thinking model's quiet stretch.
236
+ */
237
+ export declare const SESSION_SILENCE_MS: number;
238
+ /** What a turn its silence watch ended says, in its result's notes and on its stderr. */
239
+ export declare const SILENT_STREAM_NOTE: string;
240
+ /**
241
+ * The silence watch's record, in the extension's log: one content-free line
242
+ * for each model call it ended (its stage, how long it ran, whether the model
243
+ * or a tool held the time), so how often turns die this way can be counted.
244
+ * A call that ended on its own writes nothing: one per turn would be noise.
245
+ * Only the idle timer is silence: the 24 hour wall is not, and writes nothing.
246
+ */
247
+ export declare function sessionSilenceTelemetry(sessionId: string | undefined): (rec: ResilienceAttemptRecord) => void;
225
248
  export declare function turnStop(run: StageResult, writes: boolean, aborted: boolean): {
226
249
  stop: StopReason;
227
250
  note?: string;
@@ -272,6 +295,10 @@ export interface SessionTurnDeps {
272
295
  rss: number;
273
296
  heapUsed: number;
274
297
  };
298
+ /** The silence watch's window ({@link SESSION_SILENCE_MS}); a test sets a short one. */
299
+ silenceMs?: number;
300
+ /** Where the silence watch's records go ({@link sessionSilenceTelemetry}); a test reads them. */
301
+ telemetry?: (rec: ResilienceAttemptRecord) => void;
275
302
  /** A yak's placed values (YAG-1209); absent, read from the machine, null on any other. */
276
303
  placedValues?: PlacedValues | null;
277
304
  }
@@ -310,7 +337,16 @@ export interface TurnPulse {
310
337
  lastTool: string | null;
311
338
  /** When the child last wrote an event; null before its first. */
312
339
  lastEventAt: number | null;
340
+ /**
341
+ * Tool calls started and not yet ended, by their call id: a subagent is
342
+ * one, however long it runs, and an end said twice ends only its own call.
343
+ */
344
+ toolsRunning: Set<string>;
345
+ /** Tool calls started without a call id and not yet ended: counted, never matched. */
346
+ unnamedToolsRunning: number;
313
347
  }
348
+ /** How many tool calls the turn's model has running. */
349
+ export declare function toolsInFlight(pulse: TurnPulse): number;
314
350
  /** One child event folded into the pulse: its spend, its tool, its time. */
315
351
  export declare function notePulse(pulse: TurnPulse, event: JsonEvent, at: number): void;
316
352
  /** The heartbeat line a turn writes on the stream. */
@@ -48,6 +48,7 @@ import { createHash } from "node:crypto";
48
48
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
49
49
  import { homedir } from "node:os";
50
50
  import { isAbsolute, join, relative } from "node:path";
51
+ import { logEvent } from "../errorSink.js";
51
52
  import { openPlacedValues } from "../placedValues.js";
52
53
  import { scanChange } from "./changeScan.js";
53
54
  import { CODE_WRITER_ENV, ignoredCodeWriter, resolveCodeWriter, } from "./codeWriter.js";
@@ -62,12 +63,14 @@ import { healPlacedSecrets, publicationBase } from "./placedValueHeal.js";
62
63
  import { extractPlanJson } from "./planOutput.js";
63
64
  import { checkPlanPaths, selfReviewPlan, selfReviewSection } from "./planReview.js";
64
65
  import { PLAN_CHANGES_RULE, parsePlanChanges, planChangeNote, } from "./planChanges.js";
66
+ import { IDLE_TIMEOUT_MESSAGE, withResilience, } from "./resilience.js";
65
67
  import { runStage as defaultRunStage } from "./runner.js";
66
68
  import { scrubSecrets } from "./scrubSecrets.js";
67
69
  import { DECISIONS_READ_TOOL, PLAN_JSON_CONTRACT, YAK_PLAN_JSON_CONTRACT } from "./stages.js";
68
70
  import { planReviewRoundsFor, planSizeOf, sessionTicketPathOf, TICKET_PATH_FILE_NAME, } from "./ticketPath.js";
69
71
  import { STAGE_WRAP_UP_GRACE_MS } from "./stageClock.js";
70
72
  import { editsMostlyFailed } from "./events.js";
73
+ import { DEFAULT_RESILIENCE_POLICY } from "./types.js";
71
74
  import { baselineDirs, parseChangedPaths, planPaths } from "./verify.js";
72
75
  import { snapshotWorkspace } from "./workspace.js";
73
76
  /** The one tier the session's writer runs on; its subagents keep their own. */
@@ -573,8 +576,67 @@ export function childStderrTail(stderr) {
573
576
  * else clean. Red tests and empty searches are errored `bash` calls and never
574
577
  * count: the gate asks whether the edits landed.
575
578
  */
579
+ /**
580
+ * How long a turn's child may write no event at all before the turn ends it
581
+ * (YAG-1295): a model call whose stream went silent mid-message (2026-11-12,
582
+ * a retried call that began a tool call and then sent nothing for 40
583
+ * minutes) is otherwise never ended from inside the session, and its
584
+ * heartbeat keeps the host's stall watch from seeing it. Every token delta
585
+ * counts as an event, and a running tool or subagent (the verification
586
+ * subagent may run for two hours) defers the window, as in the stage-graph
587
+ * lane (`resilience.ts`); the window is that lane's idle window, well above a
588
+ * thinking model's quiet stretch.
589
+ */
590
+ export const SESSION_SILENCE_MS = DEFAULT_RESILIENCE_POLICY.idleTimeoutMs;
591
+ /** What a turn its silence watch ended says, in its result's notes and on its stderr. */
592
+ export const SILENT_STREAM_NOTE = `The session's model call sent nothing for ${Math.round(SESSION_SILENCE_MS / 60_000)} minutes, so the turn ended it; the next turn resumes the same conversation.`;
593
+ /**
594
+ * The silence watch over one child: only the idle window. One attempt, so a
595
+ * silent call is never sent again here (the host resumes the conversation),
596
+ * and a wall far past any session window, since the turn's own clock is its
597
+ * stage's `timeBudgetMs`.
598
+ */
599
+ function silenceWatch(base, silenceMs, telemetry) {
600
+ return withResilience(base, {
601
+ ...DEFAULT_RESILIENCE_POLICY,
602
+ idleTimeoutMs: silenceMs,
603
+ wallTimeoutMs: 24 * 60 * 60_000,
604
+ maxAttempts: 1,
605
+ }, { telemetry });
606
+ }
607
+ /**
608
+ * The silence watch's record, in the extension's log: one content-free line
609
+ * for each model call it ended (its stage, how long it ran, whether the model
610
+ * or a tool held the time), so how often turns die this way can be counted.
611
+ * A call that ended on its own writes nothing: one per turn would be noise.
612
+ * Only the idle timer is silence: the 24 hour wall is not, and writes nothing.
613
+ */
614
+ export function sessionSilenceTelemetry(sessionId) {
615
+ return (rec) => {
616
+ if (rec.outcome !== "timeout" || rec.timeoutKind !== "idle")
617
+ return;
618
+ logEvent({
619
+ source: "session_lane",
620
+ level: "error",
621
+ event: "model_call_silent",
622
+ sessionId,
623
+ fields: {
624
+ stage: rec.stageId,
625
+ elapsedMs: rec.elapsedMs,
626
+ ...(rec.toolMs !== undefined ? { toolMs: rec.toolMs } : {}),
627
+ ...(rec.modelBound !== undefined ? { modelBound: rec.modelBound } : {}),
628
+ },
629
+ });
630
+ };
631
+ }
576
632
  export function turnStop(run, writes, aborted) {
577
- if (aborted || run.stopReason === "aborted")
633
+ if (aborted)
634
+ return { stop: "aborted" };
635
+ // Ended by its own silence watch (YAG-1295), which aborts the child: never a person's abort.
636
+ if (run.errorMessage === IDLE_TIMEOUT_MESSAGE) {
637
+ return { stop: "failed", note: SILENT_STREAM_NOTE };
638
+ }
639
+ if (run.stopReason === "aborted")
578
640
  return { stop: "aborted" };
579
641
  if (run.timedOut) {
580
642
  return { stop: "budget_exceeded", note: "The turn ran out of the run's time and was stopped." };
@@ -628,11 +690,27 @@ const EXECUTION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{
628
690
  export function sessionInboxDir(inputDir, executionId) {
629
691
  return EXECUTION_ID.test(executionId) ? join(inputDir, "inbox", executionId) : null;
630
692
  }
693
+ /** How many tool calls the turn's model has running. */
694
+ export function toolsInFlight(pulse) {
695
+ return pulse.toolsRunning.size + pulse.unnamedToolsRunning;
696
+ }
631
697
  /** One child event folded into the pulse: its spend, its tool, its time. */
632
698
  export function notePulse(pulse, event, at) {
633
699
  pulse.lastEventAt = at;
634
- if (event.type === "tool_execution_start" && event.toolName)
635
- pulse.lastTool = event.toolName;
700
+ if (event.type === "tool_execution_start") {
701
+ if (event.toolCallId)
702
+ pulse.toolsRunning.add(event.toolCallId);
703
+ else
704
+ pulse.unnamedToolsRunning += 1;
705
+ if (event.toolName)
706
+ pulse.lastTool = event.toolName;
707
+ }
708
+ if (event.type === "tool_execution_end") {
709
+ if (event.toolCallId)
710
+ pulse.toolsRunning.delete(event.toolCallId);
711
+ else
712
+ pulse.unnamedToolsRunning = Math.max(0, pulse.unnamedToolsRunning - 1);
713
+ }
636
714
  const usage = event.type === "message_end" ? event.message?.usage : undefined;
637
715
  if (usage && event.message?.role === "assistant") {
638
716
  pulse.tokens +=
@@ -649,6 +727,7 @@ export function heartbeatLine(pulse, stage, at, memory) {
649
727
  rssBytes: memory?.rss ?? null,
650
728
  heapUsedBytes: memory?.heapUsed ?? null,
651
729
  sinceEventMs: pulse.lastEventAt === null ? null : Math.max(0, at - pulse.lastEventAt),
730
+ toolsInFlight: toolsInFlight(pulse),
652
731
  yagni: { stage },
653
732
  };
654
733
  }
@@ -675,7 +754,13 @@ export async function runSessionTurn(input, deps = {}) {
675
754
  const now = deps.now ?? Date.now;
676
755
  const memory = deps.memory ?? processMemory;
677
756
  const stage = feedStage(input.stage);
678
- const pulse = { tokens: 0, lastTool: null, lastEventAt: null };
757
+ const pulse = {
758
+ tokens: 0,
759
+ lastTool: null,
760
+ lastEventAt: null,
761
+ toolsRunning: new Set(),
762
+ unnamedToolsRunning: 0,
763
+ };
679
764
  const beat = (deps.every ?? everyUnref)(() => {
680
765
  try {
681
766
  input.emit(heartbeatLine(pulse, stage, now(), memory()));
@@ -699,7 +784,7 @@ async function runTurn(input, deps, pulse) {
699
784
  const remove = deps.remove ?? ((path) => rmSync(path, { force: true }));
700
785
  const exec = deps.exec ?? finishExec;
701
786
  const snapshot = deps.snapshot ?? snapshotWorkspace;
702
- const runStage = deps.runStage ?? defaultRunStage;
787
+ const runStage = silenceWatch(deps.runStage ?? defaultRunStage, deps.silenceMs ?? SESSION_SILENCE_MS, deps.telemetry ?? sessionSilenceTelemetry(input.childEnv.YAGNI_SESSION_ID?.trim()));
703
788
  const now = deps.now ?? Date.now;
704
789
  const readOrNull = (path) => {
705
790
  try {
@@ -4,8 +4,6 @@ type PlanSize = (typeof SIZES)[number];
4
4
  export interface SessionTicketPath {
5
5
  /** The plan review's rounds by the plan's own size. */
6
6
  planReviewRounds: Record<PlanSize, number>;
7
- /** The fix rounds a review may start before a person is asked. */
8
- fixRoundCap: number;
9
7
  }
10
8
  /** The host's file as the turn reads it, or null for none, or one that is not the one-session path. */
11
9
  export declare function sessionTicketPathOf(text: string | null): SessionTicketPath | null;
@@ -5,7 +5,9 @@
5
5
  * `ticketPathFileOf` in `@yagni/shared`). The session holds no copy of the
6
6
  * rule: it reads the numbers. Without the file, or with one that does not
7
7
  * read, the turn works as it did before the path existed: the long plan,
8
- * four review rounds, every review item addressed.
8
+ * four review rounds, every review item addressed. A file an older host
9
+ * wrote may still carry `fixRoundCap`: it is read past, since no fix-round
10
+ * cap remains (YAG-1368).
9
11
  */
10
12
  import { extractPlanJson } from "./planOutput.js";
11
13
  import { MAX_PLAN_REVIEW_ROUNDS } from "./planReview.js";
@@ -34,12 +36,9 @@ export function sessionTicketPathOf(text) {
34
36
  const small = rounds(by.small);
35
37
  const standard = rounds(by.standard);
36
38
  const complex = rounds(by.complex);
37
- const cap = file.fixRoundCap;
38
39
  if (small === null || standard === null || complex === null)
39
40
  return null;
40
- if (typeof cap !== "number" || !Number.isInteger(cap) || cap < 1)
41
- return null;
42
- return { planReviewRounds: { small, standard, complex }, fixRoundCap: cap };
41
+ return { planReviewRounds: { small, standard, complex } };
43
42
  }
44
43
  /** The size a plan's text gives itself in its plan-json block, or null. */
45
44
  export function planSizeOf(planText) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2423.1",
3
+ "version": "1.2.14-staging.2442.1",
4
4
  "description": "YAGNI Code: a terminal coding agent that already knows your company. One YAGNI login routes the model and grounds the agent in your team's context.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "YAGNI, Inc. <jack@yagni.app> (https://yagni.app)",
@@ -58,5 +58,5 @@
58
58
  "turndown": "^7.2.4",
59
59
  "typebox": "^1.3.15"
60
60
  },
61
- "yagniSourceSha": "14fd58667767a13fd60443e502979402b8572fda"
61
+ "yagniSourceSha": "37f51eca2557c3da0a60b330ae1c2d46bae2ea07"
62
62
  }