Workloop & Multi-LoRA AIPart 1 of 2

Why I Built Workloop: Turning Messy Client Revisions into an API-First, AI-Assisted Workspace

How unstructured client meetings, rigid todo apps, and coding-agent workflows pushed me to build a 66-endpoint Next.js and PostgreSQL workspace with fail-closed zero-login portals, direct Cloudflare R2 uploads, and Human-in-the-Loop AI.

Why I Built Workloop

No matter how detailed a project brief is at kickoff, revisions are guaranteed to happen. And when collaborating with non-technical stakeholders, revision feedback rarely arrives cleanly—ideas jump between topics during calls, arrive as fragmented chat messages, and contradict earlier notes.

For a long time, turning those messy meetings into trackable engineering work meant repeating the same four-step chore:

  1. Capture raw chaos during the call—half-sentences, feature tweaks, and shifting priorities scribbled fast in a scratchpad.
  2. Paste the dump into Gemini, Claude, or ChatGPT to extract an actionable task list.
  3. Manually triage urgency so critical blockers sit above minor polish items.
  4. Copy everything into a todo tool to actually track delivery.

Existing tools broke down on both ends of that workflow. Simple todo apps like Google Tasks stay lightweight, yet lack structured multi-round revision histories, deliverable attachments, or zero-login stakeholder review links. At the other extreme, suites like Jira bury daily solo or small-team execution under menus—and do not fit seamlessly into an API-first coding-agent loop, where an agent executes scoped tasks from the terminal, logs progress through the API, pauses at ready_for_review for manual human verification, and waits for sign-off before moving on.

Workloop (workloop.my.id) is the workspace I built to close that exact gap: a personal task, recurring schedule, and versioned deliverable revision app with built-in brief-to-task AI drafting, scoped wl_live_ API keys for coding agents, zero-login client portals, and a Turborepo monorepo (apps/web, apps/mobile, packages/shared) structured for cross-platform expansion. You can explore the interface immediately via Zero-Config Preview Mode without creating an account.

Workloop Today Dashboard showing active focus tasks, priorities, and AI-integrated workspace

Architecture Overview

Rather than bolting scripts onto a generic CRUD starter, Workloop separates security boundaries, binary storage, scheduling, and AI orchestration into explicit layers:

Browser UI / Coding Agent (wl CLI, wl_live_ API Key) / External Client (/p/[token], /r/[token])
  |
  v
Next.js 15 App Router + React 19 (44 route files, 66 REST & SSE /api/v1/* endpoints)
  |-- Auth & RLS       -> Supabase Auth + scoped wl_live_ bearer keys + HMAC PIN cookies
  |-- Database         -> PostgreSQL / Drizzle ORM (17 tables, RLS, pg_cron recurrences)
  |-- Binary Pipeline  -> Private Cloudflare R2 (presigned 300s PUT / 900s GET + HeadObject verify)
  |-- Rate Limiting    -> Upstash Redis REST (2s timeout) + bounded 5k in-memory fallback
  |-- Notifications    -> In-app + FCM HTTP v1 Web Push + Resend / Brevo email dispatch
  |
  v
Human-in-the-Loop SSE AI Drawer
  |-- Custom Model     -> Workloop AI Service (Qwen2.5-7B Multi-LoRA, Part 2)
  |-- BYOK Providers   -> AES-256-GCM encrypted keys (Gemini, Groq, OpenRouter, SSRF-guarded Custom)
  |-- Safety Barrier   -> Write tools emit Draft Confirmation Cards (zero blind DB writes)

Let's walk through the four core engineering decisions that hold the system together.

1. Versioned Deliverable Revisions & the API-First Agent Loop

Flat task comment threads break down fast once a deliverable hits round two or three. Stakeholders ask "did we already fix item #4 from Tuesday?" while implementation notes, uploaded previews, and approval decisions blur into one chronological feed.

Workloop models revisions first-class via versioned rounds (v1, v2, ...) paired with atomic checklists across a strict six-state workflow:

backlog -> in_progress -> ready_for_review -> revision_needed -> approved -> done

Because 66 /api/v1/* endpoints expose tasks, milestones, revision checklists, and status transitions behind scoped wl_live_ API keys, an external coding agent fits cleanly into the loop:

  • The agent claims queued tasks via REST, appends milestone notes, and flips the status to ready_for_review.
  • It stops there. A human reviewer inspects the deliverable manually, either promoting it to approved/done or creating a structured revision_needed round that queues the next concrete checklist.

Workloop Task Detail view with versioned deliverable revision rounds and checklists

2. Fail-Closed Zero-Login Stakeholder Portals (/p/[token] & /r/[token])

Requiring non-technical clients to register an account and verify an email just to submit an intake brief (/p/[token]) or review a deliverable (/r/[token]) kills adoption. They will simply drop screenshots in WhatsApp instead.

The engineering problem is allowing frictionless browser access without exposing private workspace data to token guessing or brute-force PIN attacks. In apps/web/src/lib/share-links.ts, Workloop enforces four invariants:

LayerSecurity MechanismImplementation Detail
Token LookupDigest-only indexingPlaintext share tokens are hashed with SHA-256 before querying; raw lookup tokens are never queried directly
PIN StoragePer-link salted scryptStored as scrypt$<16-byte-salt>$<derived-hex> and verified via constant-time timingSafeEqual
Unlock SessionFail-closed HMAC-SHA256 cookie12-hour HttpOnly cookie (wl_share_pin_*); production fails closed if SHARE_COOKIE_SECRET (< 16 chars) is missing
Brute-Force GuardHybrid distributed rate limiter5 failures per 15-minute window via Upstash Redis REST (2,000 ms timeout) falling back to a bounded 5,000-entry Map

Choosing a bounded 5,000-entry in-memory fallback with active expiration pruning ensures that even if Redis is unconfigured or times out during a transient spike, the rate limiter neither crashes requests nor leaks unbounded serverless memory.

export function verifyPin(pin: string, storedHash: string): boolean {
  const parts = storedHash.split('$');
  if (parts.length !== 3 || parts[0] !== 'scrypt') return false;
  const [, salt, expectedHex] = parts;
  if (!salt || !expectedHex) return false;

  const actual = scryptSync(pin, salt, 32);
  const expected = Buffer.from(expectedHex, 'hex');
  if (actual.length !== expected.length) return false;
  return timingSafeEqual(actual, expected);
}

3. Direct-to-R2 Presigned Pipeline (and an AWS SDK v3 Gotcha)

Proxying PDFs, mockups, and screen recordings through Next.js API routes burns serverless execution time and bandwidth limits. Workloop keeps Cloudflare R2 completely private and uses a three-step Direct-to-R2 handoff instead:

  1. Mint Presigned PUT (300s TTL): The server validates MIME type, byte size, and sanitizes the filename (owners/{ownerId}/tasks/{taskId}/{uuid}-{safeName}).
  2. Direct Browser PUT: The client uploads the binary directly to Cloudflare R2 without touching Next.js memory.
  3. Server Verification & Cleanup: On confirmation, the API runs HeadObjectCommand against R2 to verify the object exists and matches metadata before writing the attachment record. Unconfirmed orphans are swept by a daily cron job, and downloads issue short-lived 900s presigned GET URLs (inline or attachment disposition).

One real production pitfall surfaced immediately with modern @aws-sdk/client-s3: newer SDK versions default to injecting flexible checksum query/header parameters into presigned URLs that browser-to-R2 CORS uploads can trip over. Disabling automatic checksum injection unless required resolved the R2 presign mismatch cleanly:

cachedR2Client = new S3Client({
  region: 'auto',
  endpoint: customEndpoint || `https://${accountId}.r2.cloudflarestorage.com`,
  forcePathStyle: Boolean(customEndpoint),
  requestChecksumCalculation: 'WHEN_REQUIRED',
  responseChecksumValidation: 'WHEN_REQUIRED',
  credentials: { accessKeyId, secretAccessKey },
});

4. Human-in-the-Loop SSE AI Drawer & AES-256-GCM BYOK

To eliminate the "notes app -> chat with LLM -> manually copy into todo" round-trip, Workloop embeds a streaming Server-Sent Events AI assistant directly inside the workspace. Users can either connect their own Workloop AI Service endpoint or bring their own API keys (BYOK) for Gemini, Groq, OpenRouter, or an SSRF-guarded custom OpenAI-compatible URL.

Stored provider credentials are encrypted server-side using AES-256-GCM with a fresh 96-bit random IV per write (v1:<ivB64>:<authTagB64>:<ciphertextB64>), rejecting any tampered authentication tags on decryption.

Most importantly, the AI assistant never directly creates tasks or overwrites revisions on a single user prompt. Instead, the model is restricted to read-only inspection tools alongside write-draft tools that stream an editable Draft Confirmation Card into the UI. I can tweak the extracted priority, Jakarta (+07:00) deadline, requester tag, or checklist bullets right inside the card—and whenever I edit a draft before approving it, Workloop logs the correction pair via POST /api/v1/ai/feedback.

Workloop AI Assistant Drawer generating an editable Draft Confirmation Card from raw notes

Why I Did Not Stop at Commercial BYOK APIs

BYOK works well out of the box, yet relying purely on hosted commercial endpoints left two things unsolved—the exact same motivation that drove me when building kosera-ai-service:

  1. I wanted deeper hands-on mastery over fine-tuning, structured tool-calling alignment, and real-world evaluation—not just prompt engineering.
  2. Messy bilingual Indonesian/English client briefs and WhatsApp-style revision notes behave differently from clean English SaaS benchmarks, so I wanted a dedicated 7B QLoRA adapter tuned specifically for Workloop's tools, Asia/Jakarta timestamps, and confirmation-card contract.

In Part 2: Fine-Tuning a 7B Human-in-the-Loop Tool-Calling Model & Multi-LoRA Engine, I break down the 750-conversation dataset, the Unsloth inference token-duplication bug I hit in evaluation, serving three domain LoRA adapters (workloop, kosera, portfolio) from a single GPU base model, and the honest gap between a 97.81% held-out score and noisy out-of-distribution WhatsApp prompts.

Both codebases are open source: rizalkr/workloop and rizalkr/workloop-ai-service.