[claude] Add session_messages table for conversation history (#37) #80

Open
claude wants to merge 1 commits from claude/issue-37 into main
Collaborator

Fixes #37

Changes

  • New schema: session_messages table (id, session_id, role, content, session_request_id, created_at) with index on session_id
  • New migration: 0008_session_messages.sql
  • New endpoint: GET /sessions/:id/messages — returns the full conversation history for a session (macaroon-authed)
  • Message persistence: User and assistant messages are now inserted transactionally during POST /sessions/:id/request alongside the session_request and balance update

Design decisions

  • Messages are stored separately from session_requests to provide a clean conversation-history view without billing/token metadata
  • Each message links back to its session_request_id for cross-referencing
  • Assistant content uses the result (complete), reason (rejected), or errorMessage (failed) depending on request outcome
  • All writes happen inside the existing transaction for atomicity
Fixes #37 ## Changes - **New schema**: `session_messages` table (`id`, `session_id`, `role`, `content`, `session_request_id`, `created_at`) with index on `session_id` - **New migration**: `0008_session_messages.sql` - **New endpoint**: `GET /sessions/:id/messages` — returns the full conversation history for a session (macaroon-authed) - **Message persistence**: User and assistant messages are now inserted transactionally during `POST /sessions/:id/request` alongside the session_request and balance update ## Design decisions - Messages are stored separately from `session_requests` to provide a clean conversation-history view without billing/token metadata - Each message links back to its `session_request_id` for cross-referencing - Assistant content uses the result (complete), reason (rejected), or errorMessage (failed) depending on request outcome - All writes happen inside the existing transaction for atomicity
claude added 1 commit 2026-03-23 01:52:13 +00:00
feat: add session_messages table for conversation history
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
b4aa672c58
Add a session_messages table that stores the full user/assistant
conversation history within a session. Each session request now
persists both the user message and assistant response atomically
alongside the session_request and balance update.

- New schema: session_messages (id, session_id, role, content,
  session_request_id, created_at) with index on session_id
- New migration: 0008_session_messages.sql
- New endpoint: GET /sessions/:id/messages (macaroon-authed)
- Messages inserted transactionally during POST /sessions/:id/request

Fixes #37

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
First-time contributor

Timmy review: Clean design — separate messages table, transactional writes, macaroon-authed endpoint. Has merge conflicts. Please rebase onto main and force-push, then I will merge.

**Timmy review:** Clean design — separate messages table, transactional writes, macaroon-authed endpoint. Has merge conflicts. Please rebase onto main and force-push, then I will merge.
First-time contributor

Design looks right — separate table for conversation history, transactional writes alongside billing, macaroon auth on the endpoint. Approved in principle.

However this PR has merge conflicts against main. Please rebase and force-push, then I will merge.

Design looks right — separate table for conversation history, transactional writes alongside billing, macaroon auth on the endpoint. Approved in principle. However this PR has merge conflicts against main. Please rebase and force-push, then I will merge.
First-time contributor

Clean design. Separate messages table with session_request_id cross-reference, transactional writes, macaroon auth. Approved in principle.

Has merge conflicts (mergeable=false). Rebase onto main and force-push, then I will merge.

Clean design. Separate messages table with session_request_id cross-reference, transactional writes, macaroon auth. Approved in principle. Has merge conflicts (mergeable=false). Rebase onto main and force-push, then I will merge.
First-time contributor

Design looks good — clean schema, transactional writes, proper separation from session_requests. Ready to merge once conflicts against main are resolved. Please rebase on main and force-push.

Design looks good — clean schema, transactional writes, proper separation from session_requests. Ready to merge once conflicts against main are resolved. Please rebase on main and force-push.
First-time contributor

Good work — schema design is clean, transactional writes are the right call, endpoint makes sense. However this PR has merge conflicts (mergeable=false). Please rebase on main and force-push. Will merge once green.

Good work — schema design is clean, transactional writes are the right call, endpoint makes sense. However this PR has merge conflicts (mergeable=false). Please rebase on main and force-push. Will merge once green.
First-time contributor

Good work - clean schema, transactional writes, proper indexing. But this has a merge conflict (mergeable=false). Please rebase on main and force-push so I can merge it.

Good work - clean schema, transactional writes, proper indexing. But this has a merge conflict (mergeable=false). Please rebase on main and force-push so I can merge it.
First-time contributor

Design looks solid — separate messages table with session_request_id cross-ref is the right call. Has merge conflicts. Rebase on main and force-push, then I will merge.

Design looks solid — separate messages table with session_request_id cross-ref is the right call. Has merge conflicts. Rebase on main and force-push, then I will merge.
First-time contributor

LGTM — clean schema, proper migration, transactional writes. Has merge conflicts against main. Please rebase and force-push, then I will merge.

LGTM — clean schema, proper migration, transactional writes. Has merge conflicts against main. Please rebase and force-push, then I will merge.
First-time contributor

session_messages schema and endpoint look clean. Transactional writes are the right call. Merge conflicts need resolving — rebase on main and force-push. Will merge once green.

session_messages schema and endpoint look clean. Transactional writes are the right call. Merge conflicts need resolving — rebase on main and force-push. Will merge once green.
First-time contributor

LGTM — clean schema, transactional writes, good design. Merge conflicts — please rebase on main and force-push.

LGTM — clean schema, transactional writes, good design. Merge conflicts — please rebase on main and force-push.
First-time contributor

Code looks good — clean schema, proper transactional writes, sensible separation from session_requests. Ready to merge once conflicts are resolved. Please rebase onto main and force-push. Will merge immediately after.

Code looks good — clean schema, proper transactional writes, sensible separation from session_requests. Ready to merge once conflicts are resolved. Please rebase onto main and force-push. Will merge immediately after.
First-time contributor

Good work. Clean schema, transactional writes, proper migration. But this PR has merge conflicts. Please rebase on main and force-push. Will merge once green.

Good work. Clean schema, transactional writes, proper migration. But this PR has merge conflicts. Please rebase on main and force-push. Will merge once green.
First-time contributor

Has merge conflicts. Please rebase onto main and force-push. Will merge once clean.

Has merge conflicts. Please rebase onto main and force-push. Will merge once clean.
First-time contributor

Good work — schema design is clean, transactional writes are correct, endpoint is well-scoped. However this PR has merge conflicts with main (mergeable=false). Please rebase onto main and force-push to resolve. Will merge once conflicts are cleared.

Good work — schema design is clean, transactional writes are correct, endpoint is well-scoped. However this PR has merge conflicts with main (mergeable=false). Please rebase onto main and force-push to resolve. Will merge once conflicts are cleared.
First-time contributor

Merge conflicts — please rebase onto main and force-push. Design is solid, will merge once clean.

Merge conflicts — please rebase onto main and force-push. Design is solid, will merge once clean.
First-time contributor

LGTM — solid schema, transactional writes, clean endpoint. Has conflicts with main. Please rebase onto main and force-push, then I will merge.

LGTM — solid schema, transactional writes, clean endpoint. Has conflicts with main. Please rebase onto main and force-push, then I will merge.
First-time contributor

LGTM — clean schema, transactional writes. Merge conflicts need resolving. Rebase on main and force-push, then I will merge.

LGTM — clean schema, transactional writes. Merge conflicts need resolving. Rebase on main and force-push, then I will merge.
First-time contributor

LGTM — clean schema, transactional writes, good separation from billing data. Cannot merge due to conflicts. Please rebase on main and force-push, then I will squash-merge.

LGTM — clean schema, transactional writes, good separation from billing data. Cannot merge due to conflicts. Please rebase on main and force-push, then I will squash-merge.
First-time contributor

Schema and endpoint look clean. Cannot merge — conflicts. Please rebase on main and force-push.

Schema and endpoint look clean. Cannot merge — conflicts. Please rebase on main and force-push.
First-time contributor

session_messages schema + endpoint look correct. Transactional writes are the right call. But PR has merge conflicts (mergeable=false). Rebase onto main and force-push, then I will merge.

session_messages schema + endpoint look correct. Transactional writes are the right call. But PR has merge conflicts (mergeable=false). Rebase onto main and force-push, then I will merge.
First-time contributor

LGTM — clean schema, transactional writes, good endpoint design. Approved for merge. Needs rebase onto current main.

LGTM — clean schema, transactional writes, good endpoint design. Approved for merge. Needs rebase onto current main.
First-time contributor

LGTM — clean schema, transactional writes, good separation from billing data. Has merge conflicts against main. Please rebase and force-push, then I will squash-merge.

LGTM — clean schema, transactional writes, good separation from billing data. Has merge conflicts against main. Please rebase and force-push, then I will squash-merge.
First-time contributor

LGTM — clean schema, transactional writes, proper separation from billing data. Has merge conflicts. Rebase on main and force-push, then I will merge.

LGTM — clean schema, transactional writes, proper separation from billing data. Has merge conflicts. Rebase on main and force-push, then I will merge.
First-time contributor

Timmy review: Clean schema, transactional writes, proper separation from billing data. Approved in principle but merge conflicts block this. Rebase onto main and force-push.

Timmy review: Clean schema, transactional writes, proper separation from billing data. Approved in principle but merge conflicts block this. Rebase onto main and force-push.
First-time contributor

LGTM. Merge conflicts — please rebase onto main and force-push. Will merge once mergeable.

LGTM. Merge conflicts — please rebase onto main and force-push. Will merge once mergeable.
First-time contributor

Clean schema design, transactional writes, good separation from billing data. Has merge conflicts against main. Rebase and force-push, then I will merge.

Clean schema design, transactional writes, good separation from billing data. Has merge conflicts against main. Rebase and force-push, then I will merge.
First-time contributor

Merge conflicts — please rebase onto main and force-push.

Merge conflicts — please rebase onto main and force-push.
First-time contributor

Clean implementation — separate messages table, transactional writes, macaroon-authed endpoint. Design is sound.

This PR has merge conflicts against main (mergeable=false). Please rebase onto main and force-push, then I will merge.

Clean implementation — separate messages table, transactional writes, macaroon-authed endpoint. Design is sound. This PR has merge conflicts against main (mergeable=false). Please rebase onto main and force-push, then I will merge.
First-time contributor

LGTM — clean schema, transactional writes. Has merge conflicts against main. Please rebase and force-push, then I will merge.

LGTM — clean schema, transactional writes. Has merge conflicts against main. Please rebase and force-push, then I will merge.
First-time contributor

LGTM — clean schema, transactional writes, good separation from session_requests. But mergeable=false (merge conflicts with main). Rebase on main and force-push, then I will squash-merge.

LGTM — clean schema, transactional writes, good separation from session_requests. But mergeable=false (merge conflicts with main). Rebase on main and force-push, then I will squash-merge.
First-time contributor

[timmy-review] Cannot merge — has conflicts with main. Please rebase onto current main and force-push, or open a fresh PR if branch is too stale.

[timmy-review] Cannot merge — has conflicts with main. Please rebase onto current main and force-push, or open a fresh PR if branch is too stale.
First-time contributor

Clean schema design -- separate messages table with session_request backlink, transactional writes. Has merge conflicts though. Rebase on main and force-push, then I will merge.

Clean schema design -- separate messages table with session_request backlink, transactional writes. Has merge conflicts though. Rebase on main and force-push, then I will merge.
First-time contributor

session_messages schema + endpoint look clean. mergeable=false - needs rebase onto main. Rebase and push, then I will merge.

session_messages schema + endpoint look clean. mergeable=false - needs rebase onto main. Rebase and push, then I will merge.
First-time contributor

Clean schema design. Conflicts with main — rebase and force-push, then I can merge.

Clean schema design. Conflicts with main — rebase and force-push, then I can merge.
First-time contributor

Clean schema design. Merge conflicts block this — rebase onto main and repush.

Clean schema design. Merge conflicts block this — rebase onto main and repush.
First-time contributor

Still has merge conflict. Rebase onto main and force-push. 35 comments accumulated — address outstanding feedback, then will merge.

Still has merge conflict. Rebase onto main and force-push. 35 comments accumulated — address outstanding feedback, then will merge.
First-time contributor

All 5 tower PRs conflict. This one (session_messages) is most foundational. Rebase onto main and force-push. Merge order: #80 > #93 > #109 > #110 > #112.

All 5 tower PRs conflict. This one (session_messages) is most foundational. Rebase onto main and force-push. Merge order: #80 > #93 > #109 > #110 > #112.
First-time contributor

LGTM. Foundational schema, clean design. Merge conflicts — rebase on main. This merges first (lowest migration #).

LGTM. Foundational schema, clean design. Merge conflicts — rebase on main. This merges first (lowest migration #).
Rockachopa approved these changes 2026-03-30 17:06:38 +00:00
Rockachopa left a comment
First-time contributor

Code Review: [claude] Add session_messages table for conversation history (#37)

Reviewer: Timmy (automated review)
Recommendation: APPROVE (with note: needs rebase to merge)

Summary

Adds a session_messages table to persist conversation history (user + assistant messages) within sessions. Clean, focused PR with 4 files changed and ~88 lines added.

Code Quality: A

Schema:

  • session_messages table with serial PK, session FK reference, role (user/assistant), content, optional session_request_id linkage
  • Proper Zod validation schema via createInsertSchema
  • Type exports for SessionMessage and InsertSessionMessage
  • Index on session_id for efficient lookups
  • Migration is clean and correct with IF NOT EXISTS

API endpoint:

  • GET /sessions/:id/messages with proper macaroon authentication
  • Returns messages ordered by ID (insertion order = chronological)
  • Clean response shape: {sessionId, messages: [{id, role, content, sessionRequestId, createdAt}]}

Message persistence:

  • Both user and assistant messages inserted within the existing session request transaction — atomic and correct
  • Smart handling: assistant message only inserted if content is non-empty (handles rejection/error cases)

Minor Notes

  1. Not mergeableMergeable: False. Needs rebase.
  2. Legacy wizard-era PR (March 23). Despite being stale, this is foundational infrastructure that's still relevant.
  3. Ordering by sessionMessages.id (serial PK) — correct for chronological order since serial auto-increments. However, explicit ordering by created_at would be more semantically clear.
  4. No pagination. The messages endpoint returns all messages for a session. For long sessions this could be large. Consider adding limit and offset query params in a future iteration.
  5. Role validation. The SESSION_MESSAGE_ROLES const and SessionMessageRole type exist in the schema, but the DB column is just TEXT. A CHECK constraint in the migration (CHECK (role IN ('user', 'assistant'))) would enforce this at the DB level.

What's Good

  • This is exactly the right size for a PR: one feature, one table, one endpoint, clean integration
  • Transaction-safe message persistence
  • Proper authentication on the read endpoint
  • Foundation for conversation context in future session requests

Verdict

Clean, focused, well-implemented. This table is needed infrastructure for session-based conversation history. Approve — just needs a rebase.

## Code Review: [claude] Add session_messages table for conversation history (#37) **Reviewer:** Timmy (automated review) **Recommendation:** APPROVE (with note: needs rebase to merge) ### Summary Adds a `session_messages` table to persist conversation history (user + assistant messages) within sessions. Clean, focused PR with 4 files changed and ~88 lines added. ### Code Quality: A **Schema:** - `session_messages` table with serial PK, session FK reference, role (user/assistant), content, optional session_request_id linkage - Proper Zod validation schema via `createInsertSchema` - Type exports for `SessionMessage` and `InsertSessionMessage` - Index on `session_id` for efficient lookups - Migration is clean and correct with `IF NOT EXISTS` **API endpoint:** - `GET /sessions/:id/messages` with proper macaroon authentication - Returns messages ordered by ID (insertion order = chronological) - Clean response shape: `{sessionId, messages: [{id, role, content, sessionRequestId, createdAt}]}` **Message persistence:** - Both user and assistant messages inserted within the existing session request transaction — atomic and correct - Smart handling: assistant message only inserted if content is non-empty (handles rejection/error cases) ### Minor Notes 1. **Not mergeable** — `Mergeable: False`. Needs rebase. 2. **Legacy wizard-era PR** (March 23). Despite being stale, this is foundational infrastructure that's still relevant. 3. **Ordering by `sessionMessages.id`** (serial PK) — correct for chronological order since serial auto-increments. However, explicit ordering by `created_at` would be more semantically clear. 4. **No pagination.** The messages endpoint returns all messages for a session. For long sessions this could be large. Consider adding `limit` and `offset` query params in a future iteration. 5. **Role validation.** The `SESSION_MESSAGE_ROLES` const and `SessionMessageRole` type exist in the schema, but the DB column is just `TEXT`. A CHECK constraint in the migration (`CHECK (role IN ('user', 'assistant'))`) would enforce this at the DB level. ### What's Good - This is exactly the right size for a PR: one feature, one table, one endpoint, clean integration - Transaction-safe message persistence - Proper authentication on the read endpoint - Foundation for conversation context in future session requests ### Verdict Clean, focused, well-implemented. This table is needed infrastructure for session-based conversation history. Approve — just needs a rebase.
First-time contributor

Ezra review: Agent-generated PR from claude. Appears to be from Replit Timmy Tower sessions. Alexander — merge or close at your discretion.

Ezra review: Agent-generated PR from claude. Appears to be from Replit Timmy Tower sessions. Alexander — merge or close at your discretion.
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
This pull request has changes conflicting with the target branch.
  • artifacts/api-server/src/routes/sessions.ts
  • lib/db/migrations/0008_session_messages.sql
  • lib/db/src/schema/session-messages.ts
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin claude/issue-37:claude/issue-37
git checkout claude/issue-37
Sign in to join this conversation.
No Reviewers
4 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: replit/timmy-tower#80