Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix: unblock release migrations (#5162)
Multica Eve6a72f248a146
diff --git a/server/internal/handler/runtime.go b/server/internal/handler/runtime.goindex 7023fabdf4..c3c948a305 100644--- a/server/internal/handler/runtime.go+++ b/server/internal/handler/runtime.go@@ -20,10 +20,10 @@ import ()type AgentRuntimeResponse struct {- ID string `json:"id"`- WorkspaceID string `json:"workspace_id"`- DaemonID *string `json:"daemon_id"`- Name string `json:"name"`+ ID string `json:"id"`+ WorkspaceID string `json:"workspace_id"`+ DaemonID *string `json:"daemon_id"`+ Name string `json:"name"`// CustomName is the user-set display override (MUL-4217); null when the// runtime still uses its daemon-proposed Name. Clients show// CustomName ?? Name and seed the rename field from this raw value.@@ -768,6 +768,10 @@ func (h *Handler) DeleteAgentRuntime(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusInternalServerError, "failed to clean up channel installations")return}+ if err := qtx.DeleteChatPinnedAgentsByArchivedRuntimeAgents(r.Context(), rt.ID); err != nil {+ writeError(w, http.StatusInternalServerError, "failed to clean up chat pins")+ return+ }if err := qtx.DeleteArchivedAgentsByRuntime(r.Context(), rt.ID); err != nil {writeError(w, http.StatusInternalServerError, "failed to clean up archived agents")return@@ -1020,6 +1024,10 @@ func (h *Handler) ArchiveAgentsAndDeleteRuntime(w http.ResponseWriter, r *http.RwriteError(w, http.StatusInternalServerError, "failed to clean up channel installations")return}+ if err := qtx.DeleteChatPinnedAgentsByArchivedRuntimeAgents(r.Context(), rt.ID); err != nil {+ writeError(w, http.StatusInternalServerError, "failed to clean up chat pins")+ return+ }if err := qtx.DeleteArchivedAgentsByRuntime(r.Context(), rt.ID); err != nil {writeError(w, http.StatusInternalServerError, "failed to clean up archived agents")returndiff --git a/server/internal/handler/workspace.go b/server/internal/handler/workspace.goindex ccc85b17a2..2496087b5e 100644--- a/server/internal/handler/workspace.go+++ b/server/internal/handler/workspace.go@@ -731,6 +731,12 @@ func (h *Handler) DeleteWorkspace(w http.ResponseWriter, r *http.Request) {}}+ if err := h.Queries.DeleteChatPinnedAgentsByWorkspace(r.Context(), requester.WorkspaceID); err != nil {+ slog.Warn("delete workspace chat pins failed", append(logger.RequestAttrs(r), "error", err, "workspace_id", workspaceID)...)+ writeError(w, http.StatusInternalServerError, "failed to delete workspace")+ return+ }+// At this point workspaceMember has resolved → workspaceID is a valid UUID// (the lookup would have errored otherwise), so reuse the resolved value.if err := h.Queries.DeleteWorkspace(r.Context(), requester.WorkspaceID); err != nil {diff --git a/server/internal/migrations/migrations_lint_test.go b/server/internal/migrations/migrations_lint_test.goindex 7b570eab8b..c4b6f6c54c 100644--- a/server/internal/migrations/migrations_lint_test.go+++ b/server/internal/migrations/migrations_lint_test.go@@ -45,7 +45,6 @@ var legacyDuplicateMigrationStems = map[string][]string{"124": {"124_autopilot_run_planned_at", "124_channel_generalization", "124_task_prepare_lease"},"127": {"127_issue_pull_request_reference_only", "127_task_squad_id", "127_user_composio_connection"},"128": {"128_agent_task_queue_runtime_mcp_overlay", "128_autopilot_collaborator", "128_comment_routing_escalation"},- "145": {"145_agent_runtime_custom_name", "145_agent_task_coalesced_comments", "145_chat_read_cursor"},}var migrationPrefixPattern = regexp.MustCompile(`^(\d+)_`)@@ -176,7 +175,7 @@ func isKnownLegacyPrefix(prefix string) bool {"105", "106", "107", "108", "110", "114", "115", "116", "117", "118","119", "121", "123", "125", "126", "129", "130", "131", "132", "133","134", "135", "136", "137", "138", "139", "140", "141", "142", "143",- "144", "146", "147", "148":+ "144", "145", "146", "147", "148":return truedefault:return falsediff --git a/server/migrations/145_chat_read_cursor.down.sql b/server/migrations/145_chat_read_cursor.down.sqldeleted file mode 100644index db4df054f8..0000000000--- a/server/migrations/145_chat_read_cursor.down.sql+++ /dev/null@@ -1,16 +0,0 @@-ALTER TABLE chat_session ADD COLUMN unread_since TIMESTAMPTZ;---- Best-effort restore of the boolean flag: any session with an assistant--- message after its read cursor is stamped unread at the earliest such message.-UPDATE chat_session cs- SET unread_since = sub.first_unread- FROM (- SELECT m.chat_session_id, min(m.created_at) AS first_unread- FROM chat_message m- JOIN chat_session s ON s.id = m.chat_session_id- WHERE m.role = 'assistant' AND m.created_at > s.last_read_at- GROUP BY m.chat_session_id- ) sub- WHERE cs.id = sub.chat_session_id;--ALTER TABLE chat_session DROP COLUMN last_read_at;diff --git a/server/migrations/145_chat_read_cursor.up.sql b/server/migrations/145_chat_read_cursor.up.sqldeleted file mode 100644index dc20889471..0000000000--- a/server/migrations/145_chat_read_cursor.up.sql+++ /dev/null@@ -1,15 +0,0 @@--- IM-style unread: replace the per-session `unread_since` boolean flag with a--- read cursor `last_read_at`. Unread is now derived as the *count* of assistant--- messages after the cursor, so the chat list can show a real number (like an--- IM conversation) instead of a single dot.-ALTER TABLE chat_session ADD COLUMN last_read_at TIMESTAMPTZ NOT NULL DEFAULT now();---- Preserve existing unread state during the switch: a session currently flagged--- unread gets its cursor placed just before the first unread reply, so those--- messages still count. `unread_since` is the arrival time of the first unread--- assistant message.-UPDATE chat_session- SET last_read_at = unread_since - interval '1 microsecond'- WHERE unread_since IS NOT NULL;--ALTER TABLE chat_session DROP COLUMN unread_since;diff --git a/server/migrations/145_agent_task_coalesced_comments.down.sql b/server/migrations/150_agent_task_coalesced_comments.down.sqlsimilarity index 100%rename from server/migrations/145_agent_task_coalesced_comments.down.sqlrename to server/migrations/150_agent_task_coalesced_comments.down.sqldiff --git a/server/migrations/145_agent_task_coalesced_comments.up.sql b/server/migrations/150_agent_task_coalesced_comments.up.sqlsimilarity index 93%rename from server/migrations/145_agent_task_coalesced_comments.up.sqlrename to server/migrations/150_agent_task_coalesced_comments.up.sqlindex e3ed30b414..51d4d4b78b 100644--- a/server/migrations/145_agent_task_coalesced_comments.up.sql+++ b/server/migrations/150_agent_task_coalesced_comments.up.sql@@ -17,4 +17,4 @@-- Default '{}' (empty array, never NULL) so existing rows and every non-merge-- enqueue path keep working untouched.ALTER TABLE agent_task_queue- ADD COLUMN coalesced_comment_ids UUID[] NOT NULL DEFAULT '{}';+ ADD COLUMN IF NOT EXISTS coalesced_comment_ids UUID[] NOT NULL DEFAULT '{}';diff --git a/server/migrations/151_chat_read_cursor.down.sql b/server/migrations/151_chat_read_cursor.down.sqlnew file mode 100644index 0000000000..f36d756e7a--- /dev/null+++ b/server/migrations/151_chat_read_cursor.down.sql@@ -0,0 +1 @@+ALTER TABLE chat_session DROP COLUMN last_read_at;diff --git a/server/migrations/151_chat_read_cursor.up.sql b/server/migrations/151_chat_read_cursor.up.sqlnew file mode 100644index 0000000000..d3107d7b2e--- /dev/null+++ b/server/migrations/151_chat_read_cursor.up.sql@@ -0,0 +1,14 @@+-- IM-style unread: keep the old `unread_since` flag for rolling deploy /+-- rollback compatibility while adding a read cursor `last_read_at`. Unread is+-- now derived as the *count* of assistant messages after the cursor, so the chat+-- list can show a real number (like an IM conversation) instead of a single dot.+ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS unread_since TIMESTAMPTZ;+ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS last_read_at TIMESTAMPTZ NOT NULL DEFAULT now();++-- Preserve existing unread state during the switch: a session currently flagged+-- unread gets its cursor placed just before the first unread reply, so those+-- messages still count. `unread_since` is the arrival time of the first unread+-- assistant message.+UPDATE chat_session+ SET last_read_at = unread_since - interval '1 microsecond'+ WHERE unread_since IS NOT NULL;diff --git a/server/migrations/146_chat_pinned_agent.down.sql b/server/migrations/152_chat_pinned_agent.down.sqlsimilarity index 100%rename from server/migrations/146_chat_pinned_agent.down.sqlrename to server/migrations/152_chat_pinned_agent.down.sqldiff --git a/server/migrations/146_chat_pinned_agent.up.sql b/server/migrations/152_chat_pinned_agent.up.sqlsimilarity index 57%rename from server/migrations/146_chat_pinned_agent.up.sqlrename to server/migrations/152_chat_pinned_agent.up.sqlindex 11fd924ae5..89277b1c3a 100644--- a/server/migrations/146_chat_pinned_agent.up.sql+++ b/server/migrations/152_chat_pinned_agent.up.sql@@ -2,14 +2,17 @@-- agents the user keeps at the top of the conversation list for one-tap new-- chats. Kept separate from the generic `pinned_item` table (issues/projects)-- so it doesn't leak into the sidebar's pinned section.-CREATE TABLE chat_pinned_agent (+CREATE TABLE IF NOT EXISTS chat_pinned_agent (id UUID PRIMARY KEY DEFAULT gen_random_uuid(),- workspace_id UUID NOT NULL REFERENCES workspace(id) ON DELETE CASCADE,- user_id UUID NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,- agent_id UUID NOT NULL REFERENCES agent(id) ON DELETE CASCADE,+ workspace_id UUID NOT NULL,+ user_id UUID NOT NULL,+ agent_id UUID NOT NULL,position FLOAT NOT NULL DEFAULT 0,created_at TIMESTAMPTZ NOT NULL DEFAULT now(),UNIQUE (workspace_id, user_id, agent_id));-CREATE INDEX idx_chat_pinned_agent_user_ws ON chat_pinned_agent (workspace_id, user_id, position);+ALTER TABLE chat_pinned_agent+ DROP CONSTRAINT IF EXISTS chat_pinned_agent_workspace_id_fkey,+ DROP CONSTRAINT IF EXISTS chat_pinned_agent_user_id_fkey,+ DROP CONSTRAINT IF EXISTS chat_pinned_agent_agent_id_fkey;diff --git a/server/migrations/153_chat_pinned_agent_user_ws_index.down.sql b/server/migrations/153_chat_pinned_agent_user_ws_index.down.sqlnew file mode 100644index 0000000000..a65f43a8d7--- /dev/null+++ b/server/migrations/153_chat_pinned_agent_user_ws_index.down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS idx_chat_pinned_agent_user_ws;diff --git a/server/migrations/153_chat_pinned_agent_user_ws_index.up.sql b/server/migrations/153_chat_pinned_agent_user_ws_index.up.sqlnew file mode 100644index 0000000000..36489b917c--- /dev/null+++ b/server/migrations/153_chat_pinned_agent_user_ws_index.up.sql@@ -0,0 +1,4 @@+-- Single-statement migration: CREATE INDEX CONCURRENTLY cannot run inside a+-- transaction or a multi-command string.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_chat_pinned_agent_user_ws+ ON chat_pinned_agent (workspace_id, user_id, position);diff --git a/server/migrations/147_chat_agent_intro.down.sql b/server/migrations/154_chat_agent_intro.down.sqlsimilarity index 100%rename from server/migrations/147_chat_agent_intro.down.sqlrename to server/migrations/154_chat_agent_intro.down.sqldiff --git a/server/migrations/147_chat_agent_intro.up.sql b/server/migrations/154_chat_agent_intro.up.sqlsimilarity index 79%rename from server/migrations/147_chat_agent_intro.up.sqlrename to server/migrations/154_chat_agent_intro.up.sqlindex cae6d34394..e4f51d1695 100644--- a/server/migrations/147_chat_agent_intro.up.sql+++ b/server/migrations/154_chat_agent_intro.up.sql@@ -3,4 +3,4 @@-- NO visible user message: the intro run is driven server-side (see the chat-- prompt in server/internal/daemon/prompt.go) so the thread reads as the agent-- messaging its creator first, not the creator prompting the agent.-ALTER TABLE chat_session ADD COLUMN is_agent_intro BOOLEAN NOT NULL DEFAULT FALSE;+ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS is_agent_intro BOOLEAN NOT NULL DEFAULT FALSE;diff --git a/server/migrations/148_chat_session_pinned.down.sql b/server/migrations/155_chat_session_pinned.down.sqlsimilarity index 55%rename from server/migrations/148_chat_session_pinned.down.sqlrename to server/migrations/155_chat_session_pinned.down.sqlindex b0871b32cf..60ab75d65e 100644--- a/server/migrations/148_chat_session_pinned.down.sql+++ b/server/migrations/155_chat_session_pinned.down.sql@@ -1,2 +1 @@-DROP INDEX IF EXISTS idx_chat_session_pinned;ALTER TABLE chat_session DROP COLUMN IF EXISTS pinned_at;diff --git a/server/migrations/148_chat_session_pinned.up.sql b/server/migrations/155_chat_session_pinned.up.sqlsimilarity index 51%rename from server/migrations/148_chat_session_pinned.up.sqlrename to server/migrations/155_chat_session_pinned.up.sqlindex 820f610dd1..ec2cfb1186 100644--- a/server/migrations/148_chat_session_pinned.up.sql+++ b/server/migrations/155_chat_session_pinned.up.sql@@ -3,10 +3,4 @@-- `pinned_at` doubles as the sort key within the pinned group (most-recently-- pinned first) and as the boolean flag (NULL = not pinned). Sessions are-- already per-creator, so no extra user dimension is needed.-ALTER TABLE chat_session ADD COLUMN pinned_at TIMESTAMPTZ;---- Partial index over pinned rows only — the pinned group is small, and the--- list query orders by pinned_at within a single (workspace, creator) scan.-CREATE INDEX idx_chat_session_pinned- ON chat_session (creator_id, workspace_id, pinned_at DESC)- WHERE pinned_at IS NOT NULL;+ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS pinned_at TIMESTAMPTZ;diff --git a/server/migrations/156_chat_session_pinned_index.down.sql b/server/migrations/156_chat_session_pinned_index.down.sqlnew file mode 100644index 0000000000..fb4d8744d0--- /dev/null+++ b/server/migrations/156_chat_session_pinned_index.down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS idx_chat_session_pinned;diff --git a/server/migrations/156_chat_session_pinned_index.up.sql b/server/migrations/156_chat_session_pinned_index.up.sqlnew file mode 100644index 0000000000..81efa9e10b--- /dev/null+++ b/server/migrations/156_chat_session_pinned_index.up.sql@@ -0,0 +1,8 @@+-- Partial index over pinned rows only: the pinned group is small, and the list+-- query orders by pinned_at within a single (workspace, creator) scan.+--+-- Single-statement migration: CREATE INDEX CONCURRENTLY cannot run inside a+-- transaction or a multi-command string.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_chat_session_pinned+ ON chat_session (creator_id, workspace_id, pinned_at DESC)+ WHERE pinned_at IS NOT NULL;diff --git a/server/pkg/db/generated/chat.sql.go b/server/pkg/db/generated/chat.sql.goindex c288f8d5d4..2d6326b5ab 100644--- a/server/pkg/db/generated/chat.sql.go+++ b/server/pkg/db/generated/chat.sql.go@@ -72,7 +72,7 @@ func (q *Queries) CreateChatMessage(ctx context.Context, arg CreateChatMessagePaconst createChatSession = `-- name: CreateChatSession :oneINSERT INTO chat_session (workspace_id, agent_id, creator_id, title, runtime_id, is_agent_intro)VALUES ($1, $2, $3, $4, (SELECT runtime_id FROM agent WHERE id = $2), $5)-RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, runtime_id, last_read_at, is_agent_intro, pinned_at+RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, unread_since, runtime_id, last_read_at, is_agent_intro, pinned_at`type CreateChatSessionParams struct {@@ -103,6 +103,7 @@ func (q *Queries) CreateChatSession(ctx context.Context, arg CreateChatSessionPa&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -259,7 +260,7 @@ func (q *Queries) GetChatMessage(ctx context.Context, id pgtype.UUID) (ChatMessa}const getChatSession = `-- name: GetChatSession :one-SELECT id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, runtime_id, last_read_at, is_agent_intro, pinned_at FROM chat_session+SELECT id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, unread_since, runtime_id, last_read_at, is_agent_intro, pinned_at FROM chat_sessionWHERE id = $1`@@ -277,6 +278,7 @@ func (q *Queries) GetChatSession(ctx context.Context, id pgtype.UUID) (ChatSessi&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -286,7 +288,7 @@ func (q *Queries) GetChatSession(ctx context.Context, id pgtype.UUID) (ChatSessi}const getChatSessionInWorkspace = `-- name: GetChatSessionInWorkspace :one-SELECT id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, runtime_id, last_read_at, is_agent_intro, pinned_at FROM chat_session+SELECT id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, unread_since, runtime_id, last_read_at, is_agent_intro, pinned_at FROM chat_sessionWHERE id = $1 AND workspace_id = $2`@@ -309,6 +311,7 @@ func (q *Queries) GetChatSessionInWorkspace(ctx context.Context, arg GetChatSess&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -458,7 +461,7 @@ func (q *Queries) LinkChatMessageToTask(ctx context.Context, arg LinkChatMessage}const listAllChatSessionsByCreator = `-- name: ListAllChatSessionsByCreator :many-SELECT cs.id, cs.workspace_id, cs.agent_id, cs.creator_id, cs.title, cs.session_id, cs.work_dir, cs.status, cs.created_at, cs.updated_at, cs.runtime_id, cs.last_read_at, cs.is_agent_intro, cs.pinned_at,+SELECT cs.id, cs.workspace_id, cs.agent_id, cs.creator_id, cs.title, cs.session_id, cs.work_dir, cs.status, cs.created_at, cs.updated_at, cs.unread_since, cs.runtime_id, cs.last_read_at, cs.is_agent_intro, cs.pinned_at,(SELECT count(*) FROM chat_message mWHERE m.chat_session_id = cs.idAND m.role = 'assistant'@@ -495,6 +498,7 @@ type ListAllChatSessionsByCreatorRow struct {Status string `json:"status"`CreatedAt pgtype.Timestamptz `json:"created_at"`UpdatedAt pgtype.Timestamptz `json:"updated_at"`+ UnreadSince pgtype.Timestamptz `json:"unread_since"`RuntimeID pgtype.UUID `json:"runtime_id"`LastReadAt pgtype.Timestamptz `json:"last_read_at"`IsAgentIntro bool `json:"is_agent_intro"`@@ -526,6 +530,7 @@ func (q *Queries) ListAllChatSessionsByCreator(ctx context.Context, arg ListAllC&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -634,7 +639,7 @@ func (q *Queries) ListChatMessagesPage(ctx context.Context, arg ListChatMessages}const listChatSessionsByCreator = `-- name: ListChatSessionsByCreator :many-SELECT cs.id, cs.workspace_id, cs.agent_id, cs.creator_id, cs.title, cs.session_id, cs.work_dir, cs.status, cs.created_at, cs.updated_at, cs.runtime_id, cs.last_read_at, cs.is_agent_intro, cs.pinned_at,+SELECT cs.id, cs.workspace_id, cs.agent_id, cs.creator_id, cs.title, cs.session_id, cs.work_dir, cs.status, cs.created_at, cs.updated_at, cs.unread_since, cs.runtime_id, cs.last_read_at, cs.is_agent_intro, cs.pinned_at,(SELECT count(*) FROM chat_message mWHERE m.chat_session_id = cs.idAND m.role = 'assistant'@@ -671,6 +676,7 @@ type ListChatSessionsByCreatorRow struct {Status string `json:"status"`CreatedAt pgtype.Timestamptz `json:"created_at"`UpdatedAt pgtype.Timestamptz `json:"updated_at"`+ UnreadSince pgtype.Timestamptz `json:"unread_since"`RuntimeID pgtype.UUID `json:"runtime_id"`LastReadAt pgtype.Timestamptz `json:"last_read_at"`IsAgentIntro bool `json:"is_agent_intro"`@@ -705,6 +711,7 @@ func (q *Queries) ListChatSessionsByCreator(ctx context.Context, arg ListChatSes&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -820,7 +827,7 @@ UPDATE chat_sessionSET status = CASE WHEN $2::bool THEN 'archived' ELSE 'active' END,updated_at = now()WHERE id = $1-RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, runtime_id, last_read_at, is_agent_intro, pinned_at+RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, unread_since, runtime_id, last_read_at, is_agent_intro, pinned_at`type SetChatSessionArchivedParams struct {@@ -846,6 +853,7 @@ func (q *Queries) SetChatSessionArchived(ctx context.Context, arg SetChatSession&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -858,7 +866,7 @@ const setChatSessionPinned = `-- name: SetChatSessionPinned :oneUPDATE chat_sessionSET pinned_at = CASE WHEN $2::bool THEN COALESCE(pinned_at, now()) ELSE NULL ENDWHERE id = $1-RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, runtime_id, last_read_at, is_agent_intro, pinned_at+RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, unread_since, runtime_id, last_read_at, is_agent_intro, pinned_at`type SetChatSessionPinnedParams struct {@@ -885,6 +893,7 @@ func (q *Queries) SetChatSessionPinned(ctx context.Context, arg SetChatSessionPi&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -937,7 +946,7 @@ func (q *Queries) UpdateChatSessionSession(ctx context.Context, arg UpdateChatSeconst updateChatSessionTitle = `-- name: UpdateChatSessionTitle :oneUPDATE chat_session SET title = $2, updated_at = now()WHERE id = $1-RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, runtime_id, last_read_at, is_agent_intro, pinned_at+RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, unread_since, runtime_id, last_read_at, is_agent_intro, pinned_at`type UpdateChatSessionTitleParams struct {@@ -959,6 +968,7 @@ func (q *Queries) UpdateChatSessionTitle(ctx context.Context, arg UpdateChatSess&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,@@ -970,7 +980,7 @@ func (q *Queries) UpdateChatSessionTitle(ctx context.Context, arg UpdateChatSessconst updateChatSessionTitleIfCurrent = `-- name: UpdateChatSessionTitleIfCurrent :oneUPDATE chat_session SET title = $1, updated_at = now()WHERE id = $2 AND title = $3-RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, runtime_id, last_read_at, is_agent_intro, pinned_at+RETURNING id, workspace_id, agent_id, creator_id, title, session_id, work_dir, status, created_at, updated_at, unread_since, runtime_id, last_read_at, is_agent_intro, pinned_at`type UpdateChatSessionTitleIfCurrentParams struct {@@ -1001,6 +1011,7 @@ func (q *Queries) UpdateChatSessionTitleIfCurrent(ctx context.Context, arg Updat&i.Status,&i.CreatedAt,&i.UpdatedAt,+ &i.UnreadSince,&i.RuntimeID,&i.LastReadAt,&i.IsAgentIntro,diff --git a/server/pkg/db/generated/chat_pinned_agent.sql.go b/server/pkg/db/generated/chat_pinned_agent.sql.goindex 435c0e82d3..20eebc08b1 100644--- a/server/pkg/db/generated/chat_pinned_agent.sql.go+++ b/server/pkg/db/generated/chat_pinned_agent.sql.go@@ -63,6 +63,28 @@ func (q *Queries) DeleteChatPinnedAgent(ctx context.Context, arg DeleteChatPinnereturn err}+const deleteChatPinnedAgentsByArchivedRuntimeAgents = `-- name: DeleteChatPinnedAgentsByArchivedRuntimeAgents :exec+DELETE FROM chat_pinned_agent+WHERE agent_id IN (+ SELECT id FROM agent WHERE runtime_id = $1 AND archived_at IS NOT NULL+)+`++func (q *Queries) DeleteChatPinnedAgentsByArchivedRuntimeAgents(ctx context.Context, runtimeID pgtype.UUID) error {+ _, err := q.db.Exec(ctx, deleteChatPinnedAgentsByArchivedRuntimeAgents, runtimeID)+ return err+}++const deleteChatPinnedAgentsByWorkspace = `-- name: DeleteChatPinnedAgentsByWorkspace :exec+DELETE FROM chat_pinned_agent+WHERE workspace_id = $1+`++func (q *Queries) DeleteChatPinnedAgentsByWorkspace(ctx context.Context, workspaceID pgtype.UUID) error {+ _, err := q.db.Exec(ctx, deleteChatPinnedAgentsByWorkspace, workspaceID)+ return err+}+const getMaxChatPinnedAgentPosition = `-- name: GetMaxChatPinnedAgentPosition :oneSELECT COALESCE(MAX(position), 0)::float8 AS max_positionFROM chat_pinned_agentdiff --git a/server/pkg/db/generated/models.go b/server/pkg/db/generated/models.goindex b0ad168c32..b6204b0008 100644--- a/server/pkg/db/generated/models.go+++ b/server/pkg/db/generated/models.go@@ -326,6 +326,7 @@ type ChatSession struct {Status string `json:"status"`CreatedAt pgtype.Timestamptz `json:"created_at"`UpdatedAt pgtype.Timestamptz `json:"updated_at"`+ UnreadSince pgtype.Timestamptz `json:"unread_since"`RuntimeID pgtype.UUID `json:"runtime_id"`LastReadAt pgtype.Timestamptz `json:"last_read_at"`IsAgentIntro bool `json:"is_agent_intro"`diff --git a/server/pkg/db/queries/chat_pinned_agent.sql b/server/pkg/db/queries/chat_pinned_agent.sqlindex 60927a8f0f..7b86a7207b 100644--- a/server/pkg/db/queries/chat_pinned_agent.sql+++ b/server/pkg/db/queries/chat_pinned_agent.sql@@ -16,6 +16,16 @@ RETURNING *;DELETE FROM chat_pinned_agentWHERE workspace_id = $1 AND user_id = $2 AND agent_id = $3;+-- name: DeleteChatPinnedAgentsByWorkspace :exec+DELETE FROM chat_pinned_agent+WHERE workspace_id = $1;++-- name: DeleteChatPinnedAgentsByArchivedRuntimeAgents :exec+DELETE FROM chat_pinned_agent+WHERE agent_id IN (+ SELECT id FROM agent WHERE runtime_id = $1 AND archived_at IS NOT NULL+);+-- name: GetMaxChatPinnedAgentPosition :oneSELECT COALESCE(MAX(position), 0)::float8 AS max_positionFROM chat_pinned_agent