Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix agents view session ordering (#446)

ktcf48f9f96648
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 9286d3a85c..29576300c9 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Fixed the Agents View reordering sessions whenever prompts or heartbeats updated their activity timestamps ([ENG-4650](https://linear.app/primeintellect/issue/ENG-4650/agents-view-shifts-session-list-constantly)).
- Added parent-scoped subagent lifecycle APIs: create children with readable default or orchestrator-chosen names, recover running or completed children through `rlm.list_subagents()`, continue them through agent messaging, and close/remove them with `rlm.delete_subagent()`.
- Changed shell commands to use discoverable agent, schedule, package, model, session, update, doctor, and full-shutdown verbs without exposing the background daemon hierarchy ([ENG-4538](https://linear.app/primeintellect/issue/ENG-4538/standardize-bash-command-conventions-and-improve-command-discovery)).
- Fixed unsupported Node versions crashing before startup by requiring Node 22.8.0 or newer and showing upgrade guidance before loading the CLI ([ENG-4260](https://linear.app/primeintellect/issue/ENG-4260/incorrect-node-version-breaks-first-launch)).
diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-state.ts b/packages/coding-agent/src/modes/agents-view/agents-view-state.ts
index 4889c501aa..39339a6f30 100644
--- a/packages/coding-agent/src/modes/agents-view/agents-view-state.ts
+++ b/packages/coding-agent/src/modes/agents-view/agents-view-state.ts
@@ -286,11 +286,15 @@ function compareAgentsViewRows(a: AgentsViewRow, b: AgentsViewRow): number {
if (sectionDiff !== 0) {
return sectionDiff;
}
- const modifiedDiff = getTimestamp(b.summary.modified) - getTimestamp(a.summary.modified);
- if (modifiedDiff !== 0) {
- return modifiedDiff;
+ const createdDiff = getTimestamp(b.summary.created) - getTimestamp(a.summary.created);
+ if (createdDiff !== 0) {
+ return createdDiff;
}
- return a.title.localeCompare(b.title);
+ const titleDiff = a.title.localeCompare(b.title);
+ if (titleDiff !== 0) {
+ return titleDiff;
+ }
+ return a.summary.sessionId.localeCompare(b.summary.sessionId);
}
function buildRowKeyMap(rows: readonly MutableAgentsViewRow[]): Map<string, MutableAgentsViewRow> {
diff --git a/packages/coding-agent/test/agents-view-state.test.ts b/packages/coding-agent/test/agents-view-state.test.ts
index 6492bc3e69..7b77933e62 100644
--- a/packages/coding-agent/test/agents-view-state.test.ts
+++ b/packages/coding-agent/test/agents-view-state.test.ts
@@ -80,26 +80,32 @@ describe("agents view state", () => {
expect(classifyAgentsViewSession(makeSummary({ activity: "idle", taskState: undefined }))).toBe("needs-input");
});
- test("sorts rows by section and most recent modified time", () => {
+ test("sorts rows by section and creation time", () => {
const rows = buildAgentsViewRows([
makeSummary({
+ id: "completed",
+ sessionId: "completed",
sessionName: "completed",
activity: "idle",
taskState: "completed",
messageCount: 2,
- modified: "2026-01-01T00:00:00Z",
+ created: "2026-01-03T00:00:00Z",
}),
makeSummary({
+ id: "older-working",
+ sessionId: "older-working",
sessionName: "older working",
activity: "working",
isStreaming: true,
- modified: "2026-01-01T00:00:00Z",
+ created: "2026-01-01T00:00:00Z",
}),
makeSummary({
+ id: "newer-working",
+ sessionId: "newer-working",
sessionName: "newer working",
activity: "working",
isStreaming: true,
- modified: "2026-01-02T00:00:00Z",
+ created: "2026-01-02T00:00:00Z",
}),
makeSummary({
sessionName: "heartbeat",
@@ -113,6 +119,44 @@ describe("agents view state", () => {
expect(rows.map((row) => row.section)).toEqual(["working", "working", "heartbeats", "completed"]);
});
+ test("keeps row order stable when modification times and daemon input order change", () => {
+ const older = makeSummary({
+ id: "older",
+ sessionId: "older",
+ sessionName: "older",
+ activity: "working",
+ created: "2026-01-01T00:00:00Z",
+ modified: "2026-01-04T00:00:00Z",
+ });
+ const newer = makeSummary({
+ id: "newer",
+ sessionId: "newer",
+ sessionName: "newer",
+ activity: "working",
+ created: "2026-01-02T00:00:00Z",
+ modified: "2026-01-03T00:00:00Z",
+ });
+
+ const initialOrder = buildAgentsViewRows([older, newer]).map((row) => row.summary.sessionId);
+ const refreshedOrder = buildAgentsViewRows([
+ { ...newer, modified: "2026-01-05T00:00:00Z" },
+ { ...older, modified: "2026-01-06T00:00:00Z" },
+ ]).map((row) => row.summary.sessionId);
+
+ expect(initialOrder).toEqual(["newer", "older"]);
+ expect(refreshedOrder).toEqual(initialOrder);
+ });
+
+ test("uses deterministic fallbacks when creation times are unavailable", () => {
+ const rows = buildAgentsViewRows([
+ makeSummary({ id: "beta-2", sessionId: "beta-2", sessionName: "beta", modified: "2026-01-03T00:00:00Z" }),
+ makeSummary({ id: "alpha", sessionId: "alpha", sessionName: "alpha", modified: "2026-01-02T00:00:00Z" }),
+ makeSummary({ id: "beta-1", sessionId: "beta-1", sessionName: "beta", modified: "2026-01-01T00:00:00Z" }),
+ ]);
+
+ expect(rows.map((row) => row.summary.sessionId)).toEqual(["alpha", "beta-1", "beta-2"]);
+ });
+
test("summarizes subagents on their parent and omits subagent rows", () => {
const rows = buildAgentsViewRows([
makeSummary({
@@ -737,14 +781,10 @@ printf 'src/referenced.ts\n'
const identity = `file:${opened.sessionFile}`;
const key = getAgentsViewSelectionKey(opened);
- test("re-finds the session after the list reorders", () => {
- // Returning bumps the opened session's modified time so it sorts first.
- const rows = buildAgentsViewRows([
- { ...opened, modified: "2026-01-02T00:00:00Z" },
- { ...other, modified: "2026-01-01T00:00:00Z" },
- ]);
- expect(rows[0]?.summary.sessionId).toBe("session-open");
- expect(resolveAgentsViewSelectionIndex(rows, identity, key)).toBe(0);
+ test("re-finds the session after a section change reorders the list", () => {
+ const rows = buildAgentsViewRows([{ ...opened, activity: "working" }, other]);
+ expect(rows[1]?.summary.sessionId).toBe("session-open");
+ expect(resolveAgentsViewSelectionIndex(rows, identity, key)).toBe(1);
});
test("falls back to activeSessionId when the row identity changed", () => {