Skip to content

Discussion threads with agent sessions - #5

Merged
springfall2008 merged 17 commits into
mainfrom
feat/threads
Nov 7, 2026
Merged

springfall2008 merged 17 commits into
mainfrom
feat/threads

Conversation

@springfall2008

@springfall2008 springfall2008 commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Agents and people working on the same issue can now talk to each other through discussion threads. A thread lives in a scope, follows the memory permissions, and is linked to the memories it is about.

Design: docs/superpowers/specs/2026-11-07-threads-design.md. Plan: docs/superpowers/plans/2026-11-07-threads.md.

What's in it

  • One new migration, 20261107180000_threads.sql:
    • New tables for sessions, threads, posts, links and subscriptions. Members can only select them.
    • Every write goes through a SECURITY DEFINER function.
    • New memory columns created_session and updated_session, with an RLS check that the session belongs to the caller.
    • memory_view gains two label columns, and memory_history records the session.
    • adm_delete_thread / admin_delete_thread.
    • Thread purge after 30 days, added to purge_tombstones.
    • adm_delete_scope now refuses while the scope still holds threads.
  • Agent-held sessions. The thread tools that write (create_thread, post, resolve_thread, reopen_thread, subscribe) create a session when given none and return its id. The agent passes that id back, or the same session_label if the id is lost.
    • whats_new lists the session's subscribed threads that have posts from other sessions.
    • The tools that only read (read_thread, whats_new, unsubscribe) never create a session. An unknown label gives Session not found.
  • Ordering. Each post takes a per-thread seq under a row lock, so the "seen up to here" marker can't skip a post that was committed late. A session's own posts are excluded from its unread count by session id; the marker isn't moved past them.
  • PgThreadStore and 11 member tools: create_thread, post, read_thread, list_threads, resolve_thread, reopen_thread, link_memory, unlink_memory, subscribe, unsubscribe, whats_new. Admins also get admin_delete_thread.
  • Existing tools.
    • store, store_batch and update accept an optional session or session_label.
    • Memory results gain optional createdSession and updatedSession labels.
    • recall attaches threads to memories that have links. Only explicitly linked threads are listed in v1.
  • Scripts.
    • Backup and restore carry the thread data. Backup files written before this change still restore.
    • The admin CLI gets delete-thread, restore-thread and erase-thread.
    • The smoke test covers the thread tools.
    • README and CLAUDE.md are updated.
  • docs/claude-md-sample.md: a section users can copy into their own CLAUDE.md. It says when and why to use the shared memory and threads: scopes, keeping status memories true, session labels, the whats_new loop, and resolving with a note. It doesn't repeat the tool descriptions. The README links to it.

Nothing that works today changes: the new parameters are optional, and result shapes only gain optional fields.

Testing

All of these were run locally on the final head:

  • pgTAP: 10 files, 382 tests
  • deno task check
  • unit: 84
  • integration: 90
  • e2e: two MCP clients on one token hold a question-and-answer exchange through a thread
  • smoke.ts against the locally served function

CI runs check, unit, pgTAP and integration.

Rollout (after merge, each step with the maintainer's go-ahead)

  1. Take the pre-migration backup with the pre-threads backup.ts, run from a worktree of the pre-merge main. The new script reads the thread tables, so it fails on a database that hasn't been migrated. The backup file it writes still restores with the new script.
  2. Run supabase db push --remote --dry-run. Only 20261107180000_threads.sql should be pending.
  3. Push the migration.
  4. Deploy the function.
  5. Run smoke.ts with an admin token.

The migration only adds things. The function code already in production keeps working between the migration push and the function deploy.

Known follow-ups (not blocking)

  • mark_seen(…, NULL) marks the whole thread as seen. No tool passes null today; the fix needs a new migration with a coalesce.
  • The integration test for mapping a bad cursor date to Invalid cursor doesn't reach that code path. Use a date that passes the format check, such as 2026-13-45.
  • read_thread rejects after: 0, and a cursor with a timezone offset of +16h or more still returns Database error.
  • Small duplication: the guard helper, session resolution and scope-id lookups each exist in two stores or tool files.

🤖 Generated with Claude Code

springfall2008 and others added 17 commits November 7, 2026 16:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ssion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_at, bounds, hygiene, smoke)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008
springfall2008 merged commit f9a616e into main Nov 7, 2026
1 check passed
@springfall2008
springfall2008 deleted the feat/threads branch November 7, 2026 18:05
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