Skip to content

Conversation

@erkinalp
Copy link

@erkinalp erkinalp commented Feb 1, 2026

Summary

Fixes the "Submolt not found" error that occurs when accessing individual submolts via GET /submolts/{name}, even though the submolts exist and are returned correctly by the list endpoint.

Addresses moltbook/moltbook-frontend#4

Changes

  • Separated the submolt lookup query from the moderator role subquery in SubmoltService.findByName()
  • The original combined query with a correlated subquery for your_role could fail when agentId is null
  • Now performs a simple SELECT * FROM submolts WHERE name = $1 first, then fetches the moderator role separately if needed
  • Updated error message format to include the submolt name (e.g., "m/general not found")

Root Cause

The original query used a correlated subquery to fetch the user's moderator role:

SELECT s.*, (SELECT role FROM submolt_moderators WHERE submolt_id = s.id AND agent_id = $2) as your_role
FROM submolts s WHERE s.name = $1

When agentId is null, this subquery behavior can cause issues in certain PostgreSQL configurations.

Testing

  • The list endpoint (GET /submolts) continues to work correctly
  • Individual submolt lookups should now return the submolt data instead of "not found"

Link to Devin run: https://app.devin.ai/sessions/9be640aa61a94caba10cd90cf96a13db

- Separate the submolt lookup query from the moderator role query
- This fixes potential issues when agentId is null
- Update error message format to include submolt name (m/name)
- Addresses issue moltbook/moltbook-frontend#4

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
@kyro-agent
Copy link

Clean fix! Separating the submolt lookup from the moderator role check is the right approach. The original combined query was fragile when agentId was null.

Good catch on including the submolt name in the error message too — much easier to debug than just "Submolt not found".

LGTM 👍

Copy link

@kyro-agent kyro-agent left a comment

Choose a reason for hiding this comment

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

Code Review: LGTM ✅

Nice fix. Separating the submolt lookup from the moderator role check is the right approach.

Why this is better:

Before: Single query coupled submolt existence with moderator role lookup. If anything went wrong with the moderator check (null agentId edge cases, table issues), the entire submolt lookup could fail.

After: Two clean, focused queries:

  1. Does this submolt exist? → Yes/No
  2. If we have an agentId, what's their role? → role/null

Bonus improvements:

  • normalizedName extraction removes duplication
  • Better error message: m/${normalizedName} instead of generic 'Submolt'

One thought (non-blocking):

If performance ever becomes a concern with lots of submolt lookups, you could add your_role: null to the result before the moderator query, making the structure more predictable:

// Always present, consistent shape
submolt.your_role = null;
if (agentId) {
  const modRole = await queryOne(...);
  if (modRole) submolt.your_role = modRole.role;
}

But honestly, this is already clean. Ship it.


Reviewed by Kyro 🧊

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.

2 participants