Skip to content

feat: optimize server performance, SDK usability, and monorepo CI/CD#123

Open
Olympusxvn wants to merge 39 commits intoMystenLabs:devfrom
Olympusxvn:dev
Open

feat: optimize server performance, SDK usability, and monorepo CI/CD#123
Olympusxvn wants to merge 39 commits intoMystenLabs:devfrom
Olympusxvn:dev

Conversation

@Olympusxvn
Copy link
Copy Markdown

@Olympusxvn Olympusxvn commented Apr 28, 2026

Overview

This Pull Request introduces significant optimizations across the entire MemWal stack, focusing on database performance, SDK developer experience, and monorepo stability.

Key Changes

🚀 Rust Server & Database

  • IVFFlat Index: Added an IVFFlat index on vector embeddings (migration 004) to optimize write-heavy workloads.
  • Batch Processing: Implemented a new POST /api/remember/batch endpoint for atomic insertion of up to 100 items.
  • Caching: Added Redis-backed vector search caching with a 60s TTL to reduce pgvector overhead.
  • Sidecar Improvements: Added /embed-batch to the TypeScript sidecar for parallelized embeddings.

📦 TypeScript SDK

  • rememberBatch method: Added support for the new batch endpoint.
  • Resilience: Implemented exponential backoff retry logic (up to 3 retries) for transient network errors and 429 rate limits.
  • Connection Reuse: Added a custom HttpClient to support keep-alive and connection pooling.

🛠 Monorepo & CI/CD

  • Turborepo Integration: Configured turbo.json with a dependency-aware pipeline to speed up builds.
  • GitHub Actions: Added a robust CI workflow that builds the SDK and checks Rust code (clippy/fmt) on every push.
  • Dependency Fixes: Upgraded @types/react to v19 to resolve build errors in the chatbot app.

Documentation

Detailed changes and lessons learned are documented in the newly added CHANGELOG.md and lessons.md files within the PR.
update:
2026-04-29_memwal-code-review
2026-04-29_memwal-fix-plan
2026-04-29_memwal-lessons
OlympusXVN

Olympusxvn and others added 22 commits April 28, 2026 11:36
Server (Rust):
- Add IVFFlat index for vector search (migration 004)
- Add POST /api/remember/batch for batch memory storage
- Add Redis-backed search cache (60s TTL) for recall endpoints
- Add /embed-batch sidecar route for parallel text embedding
- Add upload_batch() for parallel Walrus uploads
- Increase DB pool to 20, add graceful SIGTERM shutdown

SDK (TypeScript):
- Add signedRequestWithRetry() with exponential backoff (429/network)
- Add rememberBatch() method for batch operations
- Add HttpClient wrapper with connection reuse (keep-alive)

Monorepo:
- Add Turborepo for cached builds with dependency graph
- Add TypeScript composite mode for project references
- Add GitHub Actions CI with pnpm + Rust caching

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Set FORCE_JAVASCRIPT_ACTIONS_TO_NODE24=true to avoid deprecation
warnings and bump project node-version from 20 to 22 (current LTS).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Clone state before .with_state() consumes it, so shutdown
handler can still access the DB pool for cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Allow dead_code on batch embedding/upload structs (available for future use)
- Replace as_bytes().len() with len() on strings
- Remove redundant .into_iter() in stream::iter()
- Allow clippy::too_many_arguments on upload_blob
- Allow clippy::type_complexity on batch insert tuple

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… time

Apps (chatbot, noter, researcher) run DB migrations during build which
requires a live PostgreSQL connection. CI only validates the SDK.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pnpm --filter triggers turbo's global task graph (^build resolves all
workspace packages). Using turbo run build --filter= properly scopes
execution to only the target package. Verified: Tasks 1/1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Chatbot uses React 19.0.1 and Next.js 16 but had @types/react ^18,
which lacks useActionState (introduced in React 19). Upgraded
@types/react and @types/react-dom to ^19 to match the runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
turbo is a devDependency, not globally installed in the runner.
pnpm exec resolves the binary from node_modules/.bin.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ixes

Added lesson MystenLabs#8 (turbo not in PATH — use pnpm exec) and CHANGELOG
entries MystenLabs#14 (@types/react upgrade) and MystenLabs#15 (turbo --filter for SDK).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: optimize server, SDK, and monorepo (v1)
…dy supports --provenance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 2 — HIGH security fixes:
- Remove Sui private key from Walrus upload HTTP body; sidecar now
  loads its own key pool from SERVER_SUI_PRIVATE_KEYS at startup
- Add x-sidecar-secret header to all sidecar calls (seal_decrypt was missing it)
- Atomic rate limiting via Redis Lua script (fixes TOCTOU race)
- remember_batch rate limit weight = 50 (was defaulting to 1)
- Cap user-supplied limit param at 100 across all handlers
- reqwest::Client: 30s request / 10s connect timeout

Phase 3 — MEDIUM hardening:
- CORS: replace permissive() with CORS_ORIGINS env-driven config
- Registry scan: hard cap at 20 pages (1,000 accounts) with warning log
- Search cache key: use full SHA-256 hash (was truncated to 16 chars)
- generate_embedding: return error when OPENAI_API_KEY missing (remove mock)
- Sidecar input validation: address/object-ID format, batch size caps (100),
  epochs range (1-200)

Also removes KeyPool from AppState/Config (sidecar owns upload keys now).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Phase 1 item 1.1: stop accepting the client's private key over HTTP.
The server now uses its own SERVER_SUI_PRIVATE_KEY for SEAL decryption.
Removes the x-delegate-key header extraction and the delegate_key field
from AuthInfo, fixing the cargo check compile error introduced when
types.rs was cleaned up in the security/v1 commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Olympusxvn
Copy link
Copy Markdown
Author

section with 16 numbered items covering all CRITICAL/HIGH/MEDIUM fixes across the Rust server and sidecar, cross-referencing the specific files and what changed.

  1. Private keys must never leave the owning process
  2. Silent dev fallbacks are production bugs in disguise
  3. Check-then-act isn't atomic — use a single round-trip (Lua/CAS)
  4. Trust boundaries need explicit auth even on localhost
  5. Truncated hashes cause silent correctness (and privacy) bugs
  6. Unbounded external scans need a hard cap
  7. Input validation belongs at the outermost boundary
  8. CORS "permissive" should be an explicit, warned-on decision
  9. The "it's the server's own key" distinction — when cross-process key transfer is unavoidable
  10. Every endpoint needs a rate limit weight assigned at creation, not retrofitted later.

Everything, a_busy_bee: review (verdict and fix plan), security
Copy link
Copy Markdown
Author

@Olympusxvn Olympusxvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request [PR #123] introduces performance optimizations and a major security overhaul regarding how SEAL credentials and Sui keys are handled.

Here is a concise summary of the changes across the key files:

  1. SDK & Frontend Logic
    packages/sdk/src/memwal.ts: Updates the client to support the new x-seal-session authentication. It implements better error sanitization and adds an AbortController with a 15s timeout for recall requests.

services/server/scripts/sidecar-server.ts: Enables CORS for frontend sponsorship, tightens batch decryption limits (from 100 to 25 items) to prevent OOM errors, and enforces strict validation on Sui object IDs and epochs.

  1. Core Server Authentication & DB
    services/server/src/auth.rs: Transitions from raw private keys to a dual-path authentication system. It now prioritizes x-seal-session (modern) but maintains x-delegate-key (legacy) for backward compatibility.

services/server/src/db.rs: Adds a new database migration (005) to handle expiration logic for the delegate key cache.

  1. Performance & Concurrency
    services/server/src/types.rs: Introduces a KeyPool structure. This uses a round-robin (AtomicUsize) mechanism to select Sui keys, allowing the server to sign and pay for gas on parallel uploads without bottlenecking.

services/server/src/routes.rs: The "brain" of the update. It implements Concurrent Decryption (using join_all) for memories, caps DB search results to 100 (security fix MED-3), and integrates the KeyPool into the upload flow.

  1. Infrastructure & Security Updates
    services/server/src/seal.rs: Updates encryption/decryption signatures to treat the sidecar secret as optional (Option<&str>), allowing for more flexible environment configurations.

services/server/src/walrus.rs: Modifies the Walrus upload request to include a key_index, ensuring the sidecar uses the specific key assigned by the server’s round-robin pool.

Error Handling: Updates AppError to generate a unique trace_id (UUID) for internal errors, masking sensitive system details from the end-user while allowing developers to track issues in logs.

Olympusxvn and others added 4 commits April 30, 2026 22:40
Two bugs from the merge commit broke all CI checks:
- TypeScript: constructor typed as MemWalConfig but accessed httpClient
- Rust: Err(e) arm placed inside Ok block due to trailing comma after inner match

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Constructor now uses intersection type for httpClient access.
Moves Err arm outside Ok block to fix mismatched delimiter in routes.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fixed: mismatched closing delimiter: 
 1260 |                                        
1299 |
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