Legionis Week 9 Review

Search, Stability & Beta Readiness

Status: Weeks 1-9 Complete | Next: Beta Testing + Week 10 Launch Prep


What We Built: 9 Weeks Summary

WeekThemeKey Deliverables
1FoundationAuth (Clerk), DB (Neon/Drizzle), Billing (Stripe)
2Agent RuntimePrompt compiler, AI SDK v6 integration, 81 agents compiled
3Chat UISkill dispatch, persona system, chat container
4Google DriveOAuth, workspace files, file explorer
5Context LayerBYOT keys, token metering, context save/recall
6Sub-AgentsSpawn agent tool, skill execution, ROI tracking
7GatewaysMeeting Mode, PLT orchestration, 11 gateways
8Onboarding5-step flow, settings pages, error boundaries
9Beta ReadySearch, P0 fixes, invite system, feedback


Platform Stats

MetricCount
AI Agents81
Skills61
Gateways11
DB Tables10
API Routes22
Components30+


Week 9 Deliverables

6 tasks, 25 files changed, 1,233 lines added


9.1: Message Save Fix (P0)

Problem: Every time streaming finished, ALL messages were POSTed as INSERT-only. After 3 saves of a 10-message conversation, DB had 30 rows.

Fix:

Files: messages/route.ts, messages.ts, chat-container.tsx


9.2: Context Window Management (P0)

Problem: Full message history passed to streamText(). Long conversations would exceed model context limits and fail.

Fix:

Files: context-window.ts (new), runtime.ts


9.3: Search + Cmd+K

Postgres FTS instead of Typesense — zero infrastructure, auto-updating.

Files: 9 files (migration SQL, 3 query edits, 4 new components/routes)


9.4: Drive Status


9.5: Conversation UX Polish

Inline Rename: Replaced window.prompt() with inline :

Pagination:

9.6: Beta Invite System

Schema: invite_codes + beta_feedback tables

Invite Flow:

Feedback:

What to Test (Manual Verification)

Prerequisites

1. Seed an invite code:
   INSERT INTO invite_codes (code, max_uses)
   VALUES ('BETA2026', 50);

  • Start dev server:
  • cd C:\dev\legionis && npm run dev Open: http://localhost:4321


    Test 1: Message Save (P0 Fix)

  • Open a conversation (or start a new one)
  • Send 5 messages back and forth
  • Reload the page — messages should appear exactly once
  • Send 2 more messages, reload again
  • Expected: No duplicates. Message count matches actual exchanges.
  • DB check (optional):

    SELECT count(*) FROM messages
    WHERE conversation_id = '';
    -- Should equal actual message count
    


    Test 2: Context Window (P0 Fix)

  • Open a conversation
  • Send 20+ messages (can be quick ones like "hello", "test")
  • Keep going past 30 messages
  • Expected: Agent still responds, no 400/500 errors
  • Check server logs for: [agent:X] Truncated N -> M messages

  • Test 3: Search + Cmd+K

  • Create a few conversations with distinct titles
  • Press Cmd+K (or Ctrl+K)
  • Type a word from one of the titles
  • Expected: Matching conversations appear in results
  • Type an agent name like "product" — agents section appears
  • Type a skill like "prd" — skills section appears
  • Arrow keys + Enter to navigate/select
  • Click the search button in sidebar — should also open palette

  • Test 4: Drive Status

  • Look at the bottom of the sidebar
  • Expected: Green dot + "Drive connected" (if Drive is set up)
  • OR gray dot + "Drive not set up" (if not connected)
  • Hit GET /api/drive/status directly to verify JSON response

  • Test 5: Inline Rename

  • Hover over a conversation in the sidebar
  • Click the pencil icon
  • Expected: Title becomes an editable input, text selected
  • Type a new name, press Enter
  • Expected: Title updates immediately
  • Try Escape — should cancel without saving

  • Test 6: Conversation Pagination

  • Create 50+ conversations (or adjust PAGE_SIZE to 5 for testing)
  • Scroll to the bottom of the conversation list
  • Expected: "Load more" button appears
  • Click it — more conversations load below

  • Test 7: Beta Invite (New User Flow)

  • Sign out or use incognito
  • Sign up as a new user
  • After "Welcome" step, Expected: Invite Code screen appears
  • Try an invalid code — error message
  • Enter "BETA2026" — success, continue button enables
  • Complete remaining onboarding steps

  • Test 8: Feedback Button

  • Look at the bottom-right corner of the dashboard
  • Click "Feedback" button
  • Expected: Modal opens with Bug/Feature/General selector
  • Type feedback, click Submit
  • Expected: "Thank you" message, modal closes
  • Verify: SELECT * FROM beta_feedback;

  • Test Quick Reference

    #AreaWhat to CheckPass Criteria
    1MessagesNo duplicates after reloadCount matches actual
    2Context30+ turn conversation worksNo errors, agent responds
    3SearchCmd+K finds conversationsResults appear, grouped
    4DriveStatus badge in sidebarCorrect status shown
    5RenameInline edit on conversationsEnter saves, Esc cancels
    6Pagination50+ conversations load moreButton appears and works
    7InviteNew user needs codeInvalid rejected, valid accepted
    8FeedbackSubmit feedbackStored in DB


    Architecture After Week 9

    Browser (Next.js App Router)
    
    +-- Clerk Auth +-- Zustand Stores (conversations, search) +-- Chat Container (useChat + AI SDK) +-- Command Palette (Cmd+K) +-- Feedback Button
    API Routes (Vercel Serverless)
    +-- /api/chat (Agent Runtime + streamText) +-- /api/search (Unified FTS) +-- /api/conversations (CRUD + pagination + search) +-- /api/drive/* (OAuth, files, status) +-- /api/invite/* (validate, redeem) +-- /api/feedback (CRUD) +-- /api/webhooks/* (Clerk, Stripe)
    Neon PostgreSQL +-- 10 tables (users, workspaces, api_keys, conversations, messages, context_entries, file_references, usage_events, subscriptions, invite_codes, beta_feedback) +-- FTS indexes (tsvector + GIN)
    Google Drive API v3 +-- Workspace files +-- Agent deliverables


    Next Steps: Two Paths

    Path A: Operational Beta (Week 9 per plan)

    Path B: Launch Prep (Week 10 per plan)


    Recommended: Path A First

  • Self-test using the verification steps above
  • Fix any issues found
  • Seed 5-10 invite codes
  • Send to beta testers
  • Collect feedback for 1 week
  • Fix P0/P1 bugs
  • Then proceed to Week 10 launch prep

  • Key Files Modified (Week 9)

    FileChange
    messages/route.tsTransactional replace
    chat-container.tsxDedup hash guard
    context-window.tsNEW: Token estimation + truncation
    runtime.tsApply truncation before streamText
    conversations.tsFTS search + pagination
    context-entries.tsFTS search
    conversations/route.ts?q= search, ?offset/?limit
    search/route.tsNEW: Unified search API
    command-palette.tsxNEW: Cmd+K dialog
    sidebar.tsxSearch button, inline rename, load more, Drive badge
    drive/status/route.tsNEW: Health check
    drive-status-badge.tsxNEW: Sidebar status indicator
    resolve-workspace.tsReturns fallback flag
    schema.tsinvite_codes + beta_feedback tables
    invite-codes.tsNEW: Query functions
    beta-feedback.tsNEW: Query functions
    invite/validate/route.tsNEW: Code validation
    invite/redeem/route.tsNEW: Code redemption
    feedback/route.tsNEW: Feedback CRUD
    onboarding/page.tsxInvite code step (6 steps total)
    feedback-button.tsxNEW: Floating feedback UI
    dashboard/layout.tsxMount CommandPalette + FeedbackButton
    conversation-store.tshasMore + loadMore + PAGE_SIZE
    0001_fts_indexes.sqlNEW: FTS migration