Skip to content

agent.sessions: one view per session, every column carried - #76

Merged
asubbarao merged 5 commits into
mainfrom
sessions-carry-rows
Oct 19, 2026
Merged

asubbarao merged 5 commits into
mainfrom
sessions-carry-rows

Conversation

@asubbarao

Copy link
Copy Markdown
Owner

Folds agent.prompts into agent.sessions, so there is one per-session view, and stops dropping columns.

  • prompts is every typed prompt as its whole stream.blocks row (all columns), in order; first_prompt / last_prompt are full text, not 100-character heads.
  • Per session also: cwd, git_branch, entrypoint (latest), models, tools, files, has_agents, bytes, beside the existing activity and block_keys.
  • tool_name no longer falls back to call_id (Codex tool results have no name; tool_use_id already holds the id). That fallback made one session show 557 'tools'.
  • what-alok-said's collect.sql is one SELECT over agent.sessions; the agent-stream skill names the new columns.

Tested on dev as a query over the live stream.blocks: 1,082 sessions, 12,515 prompts after near-repeat dropping; the query runs and returns whole prompt rows (two sessions' rows were 421 KB, which is why readers select columns).

🤖 Generated with Claude Code

https://claude.ai/code/session_01NCnrCZ6kWmagfJjoK8jVGQ

…pts folded into it; tool_name is a name only

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCnrCZ6kWmagfJjoK8jVGQ
@asubbarao
asubbarao enabled auto-merge October 19, 2026 07:46
@asubbarao

Copy link
Copy Markdown
Owner Author

duckstack/review: failure

  • server/messages.sql:23 RULES.md 10 (lossless: derive a flag with CASE and filter in the next CTE; never silently drop rows): The view drops near-repeat prompts inside the WHERE clause, so a reader of agent.sessions can't get those rows back or tell how many were dropped, while the PR says it 'stops dropping columns'.
    Rewrite: ), prompt AS (
    SELECT *, coalesce(rapidfuzz_ratio(left(message_content, 100), lag(left(message_content, 100)) OVER (PARTITION BY session_id ORDER BY timestamp)) >= 90, false) AS is_near_repeat
    FROM session_blocks WHERE is_prompt
    ), prompts AS (
    SELECT session_id, array_agg(prompt ORDER BY timestamp) AS prompts
    FROM prompt GROUP BY session_id
    )
    -- and readers filter with [p FOR p IN prompts IF NOT p.is_near_repeat]; prompt_count/first_prompt/last_prompt use that filtered list

Opus 5.5, duckstack review queue (duckstack-review skill)

…ast skip them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCnrCZ6kWmagfJjoK8jVGQ
@asubbarao

Copy link
Copy Markdown
Owner Author

duckstack/review: failure

  • server/messages.sql:19 Check 9 / RULES.md 9 (short): The prompt_openings and prompt CTEs are two steps for one derived column. previous_opening exists only to feed the next CTE, and a window function can sit directly inside the comparison.
    Rewrite: ), prompt AS (
    SELECT *, coalesce(rapidfuzz_ratio(left(message_content, 100),
    lag(left(message_content, 100)) OVER (PARTITION BY session_id ORDER BY timestamp)) >= 90, false) AS is_near_repeat
    FROM session_blocks WHERE is_prompt
    ), prompts AS ( -- 6 lines become 4; prompt_openings is deleted

Opus 5.5, duckstack review queue (duckstack-review skill)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCnrCZ6kWmagfJjoK8jVGQ
@asubbarao

Copy link
Copy Markdown
Owner Author

duckstack/review: failure

  • skills/what-alok-said/SKILL.md:16 RULES.md 26 (tested before offered) / RULES.md 23: collect.sql ends with ORDER BY started;, so appending AND session_id IN (<its group>) to it, as this line says, gives invalid SQL. The advice cannot have been run.
    Rewrite: Nothing is stored: each reader in step 2 runs SELECT * EXCLUDE (block_keys) FROM agent.sessions WHERE session_id IN (<its group>) ORDER BY started;. Alternatively, collect.sql can put the window in a WHERE that readers replace, e.g. WHERE last_active > now() - INTERVAL 14 DAY with ORDER BY on its own line, and this step says to replace that line rather than append to the file.
  • server/blocks.sql:14 Check 9 (bloat) / shorter version; RULES.md 9: Removing 'call_id' leaves name_keys with a single key, so the list, its comprehension at the tool_name line and its EXCLUDE entry now do the work of one ->> and can be deleted.
    Rewrite: Line 14: SELECT ['text', 'thinking', 'output', 'content'] AS content_keys,
    parsed CTE: SELECT * EXCLUDE (b, content_keys, id_keys), ... , b ->> 'name' AS tool_name, ...
    (3 expressions become 1; the line count stays the same)

Opus 5.5, duckstack review queue (duckstack-review skill)

…e for readers to replace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCnrCZ6kWmagfJjoK8jVGQ
@asubbarao

Copy link
Copy Markdown
Owner Author

duckstack/review: success

No findings.

Opus 5.5, duckstack review queue (duckstack-review skill)

@asubbarao
asubbarao merged commit ffe87be into main Oct 19, 2026
3 of 4 checks passed
@asubbarao
asubbarao deleted the sessions-carry-rows branch October 19, 2026 08:03
asubbarao added a commit that referenced this pull request Oct 19, 2026
One row per session active in the last hour, from agent.sessions (#68, #76)
instead of unpacking agent.lines JSON: every column but prompts and
block_keys, minutes idle, and shares_branch_with as a list of session ids.
Codex sessions are included. Titles and linked PRs are dropped: stream.blocks
does not carry those lines. About 4 s against 20 s for the old read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant