Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions packages/core/src/__tests__/lifecycle-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,69 @@ describe("check (single session)", () => {
expect(lm.getStates().get("app-1")).toBe("stuck");
});

it("does not mark orchestrator sessions stuck when idle exceeds agent-stuck threshold", async () => {
config.reactions = {
"agent-stuck": { auto: true, action: "notify", threshold: "1m", priority: "urgent" },
};

const notifier = createMockNotifier();
const registry = createMockRegistry({
runtime: plugins.runtime,
agent: plugins.agent,
notifier,
});

vi.mocked(plugins.agent.getActivityState).mockResolvedValue({
state: "idle",
timestamp: new Date(Date.now() - 120_000),
});

const session = makeSession({ status: "working", metadata: { agent: "mock-agent" } });
session.lifecycle.session.kind = "orchestrator";

const lm = setupCheck("app-1", {
session,
metaOverrides: { agent: "mock-agent" },
registry,
});

await lm.check("app-1");

expect(lm.getStates().get("app-1")).toBe("working");
expect(notifier.notify).not.toHaveBeenCalled();
});

it("still marks worker sessions stuck and fires the agent-stuck reaction when idle exceeds threshold", async () => {
config.reactions = {
"agent-stuck": { auto: true, action: "notify", threshold: "1m", priority: "urgent" },
};

const notifier = createMockNotifier();
const registry = createMockRegistry({
runtime: plugins.runtime,
agent: plugins.agent,
notifier,
});

vi.mocked(plugins.agent.getActivityState).mockResolvedValue({
state: "idle",
timestamp: new Date(Date.now() - 120_000),
});

const lm = setupCheck("app-1", {
session: makeSession({ status: "working", metadata: { agent: "mock-agent" } }),
metaOverrides: { agent: "mock-agent" },
registry,
});

await lm.check("app-1");

expect(lm.getStates().get("app-1")).toBe("stuck");
expect(notifier.notify).toHaveBeenCalledWith(
expect.objectContaining({ type: "reaction.triggered" }),
);
});

it("still auto-detects PR before marking idle sessions as stuck", async () => {
config.reactions = {
"agent-stuck": { auto: true, action: "notify", threshold: "1m" },
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/lifecycle-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,14 @@ export function createLifecycleManager(deps: LifecycleManagerDeps): LifecycleMan
});
}

// Orchestrator sessions are human-driven and idle by design while waiting
// for user input — never escalate them to stuck via idle decay. Same
// authoritative `lifecycle.session.kind` check as the agent-report branch
// above (string-matching role/id suffixes misses numbered orchestrator IDs).
if (
detectedIdleTimestamp &&
hasPositiveIdleEvidence(activitySignal) &&
lifecycle.session.kind !== "orchestrator" &&
isIdleBeyondThreshold(session, detectedIdleTimestamp)
) {
return commit({
Expand Down