Phase 15: extend debug diag with compaction source and delivery branch
Log sourceInferred, isIdle, deliveryBranch on session_compact and mid_turn_deliver after steer for B-003 troubleshooting. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+17
-3
@@ -1,16 +1,28 @@
|
|||||||
import type { ExtensionContext, Skill } from "@earendil-works/pi-coding-agent";
|
import type { ExtensionContext, Skill } from "@earendil-works/pi-coding-agent";
|
||||||
import type { SkillReinjectSettings } from "./settings.js";
|
import type { SkillReinjectSettings } from "./settings.js";
|
||||||
import type { ExtensionState } from "./state.js";
|
import type { CompactionSource, ExtensionState } from "./state.js";
|
||||||
|
|
||||||
export type ReinjectDiagPhase = "session_compact" | "before_agent_start";
|
export type ReinjectDiagPhase = "session_compact" | "before_agent_start" | "mid_turn_deliver";
|
||||||
|
|
||||||
/** Filter snapshot for debug logging (Phase 14 / B-002). */
|
/** Optional compaction/delivery context for debug snapshots (Phase 15 / B-003). */
|
||||||
|
export interface ReinjectDiagContext {
|
||||||
|
compactionSource?: CompactionSource | null;
|
||||||
|
sourceInferred?: boolean;
|
||||||
|
deliveryBranch?: "before_agent_start" | "steer" | "none";
|
||||||
|
isIdle?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Filter snapshot for debug logging (Phase 14 / B-002, Phase 15 / B-003). */
|
||||||
export interface ReinjectDiagSnapshot {
|
export interface ReinjectDiagSnapshot {
|
||||||
tracked: string[];
|
tracked: string[];
|
||||||
kept: string[];
|
kept: string[];
|
||||||
registered: string[];
|
registered: string[];
|
||||||
planned: string[];
|
planned: string[];
|
||||||
pending: string[];
|
pending: string[];
|
||||||
|
compactionSource?: CompactionSource | null;
|
||||||
|
sourceInferred?: boolean;
|
||||||
|
deliveryBranch?: "before_agent_start" | "steer" | "none";
|
||||||
|
isIdle?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildReinjectDiagSnapshot(
|
export function buildReinjectDiagSnapshot(
|
||||||
@@ -18,6 +30,7 @@ export function buildReinjectDiagSnapshot(
|
|||||||
registeredSkills: readonly Pick<Skill, "name">[],
|
registeredSkills: readonly Pick<Skill, "name">[],
|
||||||
keptPresent: ReadonlySet<string>,
|
keptPresent: ReadonlySet<string>,
|
||||||
planned: readonly string[],
|
planned: readonly string[],
|
||||||
|
context?: ReinjectDiagContext,
|
||||||
): ReinjectDiagSnapshot {
|
): ReinjectDiagSnapshot {
|
||||||
return {
|
return {
|
||||||
tracked: state.skills.map((skill) => skill.name),
|
tracked: state.skills.map((skill) => skill.name),
|
||||||
@@ -25,6 +38,7 @@ export function buildReinjectDiagSnapshot(
|
|||||||
registered: registeredSkills.map((skill) => skill.name),
|
registered: registeredSkills.map((skill) => skill.name),
|
||||||
planned: [...planned],
|
planned: [...planned],
|
||||||
pending: [...state.pendingReinject],
|
pending: [...state.pendingReinject],
|
||||||
|
...context,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+37
-4
@@ -107,7 +107,9 @@ export default function skillReinject(pi: ExtensionAPI): void {
|
|||||||
const trackedNames = state.skills.map((skill) => skill.name);
|
const trackedNames = state.skills.map((skill) => skill.name);
|
||||||
const keptEntries = getKeptEntries(branch, event.compactionEntry.firstKeptEntryId);
|
const keptEntries = getKeptEntries(branch, event.compactionEntry.firstKeptEntryId);
|
||||||
const keptPresent = skillsPresentInKeptWindow(keptEntries, trackedNames);
|
const keptPresent = skillsPresentInKeptWindow(keptEntries, trackedNames);
|
||||||
|
const sourceBeforeMark = compactionRuntime.pendingCompactionSource;
|
||||||
ensureCompactionSourceMarked(compactionRuntime);
|
ensureCompactionSourceMarked(compactionRuntime);
|
||||||
|
const sourceInferred = sourceBeforeMark === null;
|
||||||
const shouldReinject = consumeCompactionOnSessionCompact(
|
const shouldReinject = consumeCompactionOnSessionCompact(
|
||||||
compactionRuntime,
|
compactionRuntime,
|
||||||
state,
|
state,
|
||||||
@@ -121,16 +123,30 @@ export default function skillReinject(pi: ExtensionAPI): void {
|
|||||||
: planReinject(state, settings, ctx, event, skills);
|
: planReinject(state, settings, ctx, event, skills);
|
||||||
|
|
||||||
applyPendingReinjectAfterCompact(state, compactionRuntime, shouldReinject, planned);
|
applyPendingReinjectAfterCompact(state, compactionRuntime, shouldReinject, planned);
|
||||||
|
const isIdle = ctx.isIdle();
|
||||||
|
const deliveryBranch: "before_agent_start" | "steer" | "none" =
|
||||||
|
!shouldReinject || planned.length === 0
|
||||||
|
? "none"
|
||||||
|
: deliveryMode === "defer" && !isIdle
|
||||||
|
? "steer"
|
||||||
|
: deliveryMode === "defer"
|
||||||
|
? "before_agent_start"
|
||||||
|
: "none";
|
||||||
notifyReinjectDiag(
|
notifyReinjectDiag(
|
||||||
ctx,
|
ctx,
|
||||||
settings,
|
settings,
|
||||||
"session_compact",
|
"session_compact",
|
||||||
buildReinjectDiagSnapshot(state, skills, keptPresent, planned),
|
buildReinjectDiagSnapshot(state, skills, keptPresent, planned, {
|
||||||
|
compactionSource: state.lastCompactionSource,
|
||||||
|
sourceInferred,
|
||||||
|
deliveryBranch,
|
||||||
|
isIdle,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (deliveryMode === "defer") {
|
if (deliveryMode === "defer") {
|
||||||
if (shouldReinject && planned.length > 0 && !ctx.isIdle()) {
|
if (shouldReinject && planned.length > 0 && !isIdle) {
|
||||||
deliverDeferredReinjectSteer(
|
const steered = deliverDeferredReinjectSteer(
|
||||||
pi,
|
pi,
|
||||||
state,
|
state,
|
||||||
settings,
|
settings,
|
||||||
@@ -139,6 +155,19 @@ export default function skillReinject(pi: ExtensionAPI): void {
|
|||||||
event.compactionEntry.id,
|
event.compactionEntry.id,
|
||||||
ctx,
|
ctx,
|
||||||
);
|
);
|
||||||
|
if (steered) {
|
||||||
|
notifyReinjectDiag(
|
||||||
|
ctx,
|
||||||
|
settings,
|
||||||
|
"mid_turn_deliver",
|
||||||
|
buildReinjectDiagSnapshot(state, skills, keptPresent, planned, {
|
||||||
|
compactionSource: state.lastCompactionSource,
|
||||||
|
sourceInferred,
|
||||||
|
deliveryBranch: "steer",
|
||||||
|
isIdle,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
persistState();
|
persistState();
|
||||||
return;
|
return;
|
||||||
@@ -201,7 +230,11 @@ export default function skillReinject(pi: ExtensionAPI): void {
|
|||||||
ctx,
|
ctx,
|
||||||
settings,
|
settings,
|
||||||
"before_agent_start",
|
"before_agent_start",
|
||||||
buildReinjectDiagSnapshot(state, skills, keptPresent, []),
|
buildReinjectDiagSnapshot(state, skills, keptPresent, [], {
|
||||||
|
deliveryBranch:
|
||||||
|
state.pendingReinject.length > 0 ? "before_agent_start" : "none",
|
||||||
|
isIdle: ctx.isIdle(),
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
const pendingBefore = state.pendingReinject.length;
|
const pendingBefore = state.pendingReinject.length;
|
||||||
const deferred = tryConsumeDeferredReinject(
|
const deferred = tryConsumeDeferredReinject(
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ describe("buildReinjectDiagSnapshot", () => {
|
|||||||
[{ name: "beta" }],
|
[{ name: "beta" }],
|
||||||
new Set(["gamma"]),
|
new Set(["gamma"]),
|
||||||
["alpha"],
|
["alpha"],
|
||||||
|
{
|
||||||
|
compactionSource: "auto",
|
||||||
|
sourceInferred: true,
|
||||||
|
deliveryBranch: "steer",
|
||||||
|
isIdle: false,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
).toEqual({
|
).toEqual({
|
||||||
tracked: ["alpha"],
|
tracked: ["alpha"],
|
||||||
@@ -29,6 +35,10 @@ describe("buildReinjectDiagSnapshot", () => {
|
|||||||
registered: ["beta"],
|
registered: ["beta"],
|
||||||
planned: ["alpha"],
|
planned: ["alpha"],
|
||||||
pending: ["alpha"],
|
pending: ["alpha"],
|
||||||
|
compactionSource: "auto",
|
||||||
|
sourceInferred: true,
|
||||||
|
deliveryBranch: "steer",
|
||||||
|
isIdle: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user