Skip to content

Commit e67dc2b

Browse files
committed
fix(webapp): keep the close action available for idle sessions
Address review on the sessions status change: - Keep the "Close session" action on the detail page for Idle sessions; they are open, only Closed and Expired are terminal. - Rename the status helper input from currentRunId to hasCurrentRun, since the detail page passes a run friendlyId, not the session's currentRunId. - Restore the Active tooltip copy so it stays accurate now that the Active filter also returns open, idle sessions. - Align the sessions docs example so the listed tag matches a top-level tag set at start time.
1 parent 799dbb4 commit e67dc2b

6 files changed

Lines changed: 20 additions & 17 deletions

File tree

apps/webapp/app/components/sessions/v1/SessionStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const allSessionStatuses = ["ACTIVE", "CLOSED", "EXPIRED"] as const satis
1313
>;
1414

1515
const descriptions: Record<SessionDisplayStatus, string> = {
16-
ACTIVE: "The session has a run currently executing.",
16+
ACTIVE: "The session is open and can receive input or schedule new runs.",
1717
IDLE: "The session is open but has no run currently executing.",
1818
CLOSED: "The session was closed; no further input or runs can be triggered against it.",
1919
EXPIRED: "The session passed its expiry time without being closed explicitly.",

apps/webapp/app/presenters/v3/SessionListPresenter.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class SessionListPresenter {
214214
const status = deriveSessionStatus({
215215
closedAt: session.closedAt,
216216
expiresAt: session.expiresAt,
217-
currentRunId: session.currentRunId,
217+
hasCurrentRun: session.currentRunId != null,
218218
currentRunStatus: currentRun?.status,
219219
now,
220220
});

apps/webapp/app/presenters/v3/deriveSessionStatus.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("deriveSessionStatus", () => {
1111
deriveSessionStatus({
1212
closedAt: PAST,
1313
expiresAt: null,
14-
currentRunId: "run_1",
14+
hasCurrentRun: true,
1515
currentRunStatus: "EXECUTING",
1616
now: NOW,
1717
})
@@ -23,7 +23,7 @@ describe("deriveSessionStatus", () => {
2323
deriveSessionStatus({
2424
closedAt: PAST,
2525
expiresAt: PAST,
26-
currentRunId: null,
26+
hasCurrentRun: false,
2727
currentRunStatus: undefined,
2828
now: NOW,
2929
})
@@ -35,7 +35,7 @@ describe("deriveSessionStatus", () => {
3535
deriveSessionStatus({
3636
closedAt: null,
3737
expiresAt: PAST,
38-
currentRunId: "run_1",
38+
hasCurrentRun: true,
3939
currentRunStatus: "EXECUTING",
4040
now: NOW,
4141
})
@@ -47,7 +47,7 @@ describe("deriveSessionStatus", () => {
4747
deriveSessionStatus({
4848
closedAt: null,
4949
expiresAt: FUTURE,
50-
currentRunId: "run_1",
50+
hasCurrentRun: true,
5151
currentRunStatus: "EXECUTING",
5252
now: NOW,
5353
})
@@ -59,7 +59,7 @@ describe("deriveSessionStatus", () => {
5959
deriveSessionStatus({
6060
closedAt: null,
6161
expiresAt: null,
62-
currentRunId: "run_1",
62+
hasCurrentRun: true,
6363
currentRunStatus: "EXPIRED",
6464
now: NOW,
6565
})
@@ -71,7 +71,7 @@ describe("deriveSessionStatus", () => {
7171
deriveSessionStatus({
7272
closedAt: null,
7373
expiresAt: null,
74-
currentRunId: null,
74+
hasCurrentRun: false,
7575
currentRunStatus: undefined,
7676
now: NOW,
7777
})
@@ -83,7 +83,7 @@ describe("deriveSessionStatus", () => {
8383
deriveSessionStatus({
8484
closedAt: null,
8585
expiresAt: null,
86-
currentRunId: "run_missing",
86+
hasCurrentRun: true,
8787
currentRunStatus: undefined,
8888
now: NOW,
8989
})

apps/webapp/app/presenters/v3/deriveSessionStatus.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export type DeriveSessionStatusInput = {
77
closedAt: Date | null;
88
/** `Session.expiresAt` — retention deadline, if any. */
99
expiresAt: Date | null;
10-
/** `Session.currentRunId` — pointer to the current run (no FK). */
11-
currentRunId: string | null;
10+
/** Whether the session points at a current run at all. */
11+
hasCurrentRun: boolean;
1212
/**
13-
* Status of the run named by `currentRunId`. `undefined` when there is no
14-
* current run, or the pointer couldn't be resolved (stale / cross-env).
13+
* Status of the current run. `undefined` when there is no current run, or the
14+
* pointer couldn't be resolved (stale / cross-env).
1515
*/
1616
currentRunStatus: TaskRunStatus | undefined;
1717
/** `Date.now()` at the time of derivation. */
@@ -38,7 +38,7 @@ export function deriveSessionStatus(input: DeriveSessionStatusInput): SessionDis
3838
}
3939

4040
const hasLiveRun =
41-
input.currentRunId != null &&
41+
input.hasCurrentRun &&
4242
input.currentRunStatus !== undefined &&
4343
!isFinalRunStatus(input.currentRunStatus);
4444

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.sessions.$sessionParam/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default function Page() {
119119
const status = deriveSessionStatus({
120120
closedAt: session.closedAt ? new Date(session.closedAt) : null,
121121
expiresAt: session.expiresAt ? new Date(session.expiresAt) : null,
122-
currentRunId: session.currentRun?.friendlyId ?? null,
122+
hasCurrentRun: session.currentRun != null,
123123
currentRunStatus: session.currentRun?.status,
124124
now: Date.now(),
125125
});
@@ -791,7 +791,7 @@ function OverviewTab({
791791
<SessionStatusCombo status={status} />
792792
</Property.Value>
793793
</Property.Item>
794-
{status === "ACTIVE" && (
794+
{(status === "ACTIVE" || status === "IDLE") && (
795795
<Dialog key={`close-${session.friendlyId}`}>
796796
<DialogTrigger asChild>
797797
<Button variant="danger/small">Close session…</Button>

docs/ai-chat/sessions.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ const { id, runId, publicAccessToken, isCached } = await sessions.start({
9999
type: "chat.agent",
100100
externalId: chatId,
101101
taskIdentifier: "my-chat",
102+
// Top-level tags live on the Session row and are what `sessions.list({ tag })` filters on.
103+
tags: [`chat:${chatId}`],
102104
triggerConfig: {
105+
// triggerConfig.tags tag each run the session schedules, not the session row.
103106
tags: [`chat:${chatId}`],
104107
basePayload: { /* whatever your task's payload shape is */ },
105108
},
@@ -153,7 +156,7 @@ Cursor-paginated list of Sessions in the current environment. Returns a `CursorP
153156
```ts
154157
for await (const s of sessions.list({
155158
type: "chat.agent",
156-
tag: `user:${userId}`,
159+
tag: `chat:${chatId}`,
157160
status: "ACTIVE",
158161
limit: 50,
159162
})) {

0 commit comments

Comments
 (0)