Work Flagship case study

Ledger

A production-shaped case study for investigating SaaS revenue anomalies with cited evidence, auditable runs, and approval-gated actions.

Role: Solo builder · full ownership Stack: Next.js · FastAPI · LangGraph · Postgres Status: Public case study
Layer 1 — 60-second scan

MRR dropped. A fluent answer is not enough.

Production teams need evidence, versioned tools, blocked risky actions, traces, cost, and regression checks - not only a confident summary.

Primary demo prompt: “MRR dropped this week. Investigate the cause, identify affected accounts, cite evidence, recommend actions, and draft follow-ups.”

  • Problem Incident investigation across billing, usage, tickets, and docs where trust requires citations and auditability.
  • My role End-to-end ownership: product framing, agent workflow, control plane, evals, UI, deployment safety, and public packaging.
  • Audience Engineers and product teams evaluating AI full-stack judgment, not merchant adoption metrics.

Key capabilities

  • 01 Evidence-backed diagnosis with SQL, tickets, product events, and docs
  • 02 Ordered run steps, traces, token/cost estimates, and failure visibility
  • 03 Tool permissions and approval queue for risky customer-facing actions
  • 04 Immutable agent versions plus A-vs-B eval comparison
  • 05 Deterministic default path so the demo works without a paid LLM
Layer 2 — Technical deep dive

How Ledger earns trust under inspection

Ledger is deliberately not a chat demo. It is a fixed investigation workflow plus a control plane that makes versions, tools, runs, approvals, and evals inspectable.

Investigation workflow and state transitions

The investigation path is a fixed LangGraph DAG rather than open-ended tool thrashing. That keeps execution reconstructable: every run persists input, ordered steps, blocked calls, trace reference, model usage, final report, mock actions, and approval decisions.

Typical flow:

  • Select or detect a revenue anomaly / seeded incident
  • Gather structured metrics and account impact
  • Join support tickets and product events
  • Retrieve relevant runbooks or knowledge docs
  • Produce a cited root-cause report and recommended actions
  • Queue customer-facing follow-ups behind approval

Failed runs stay visible. When a path ends without a final report, the failure and step trail remain inspectable instead of disappearing into a successful-looking summary.

Evidence and citation model

Claims are expected to point back to retrieved evidence: SQL-derived metrics, tickets, product events, knowledge documents, or incident records. The UI exposes report citations alongside the step timeline so a reviewer can verify why a diagnosis exists.

Design rule: the evidence classifier / retrieved sources are the source of truth. An optional LLM may synthesize wording through a structured schema; it does not invent or override the supported conclusion.

Deterministic-before-LLM design

The public demo path is meant to work without a paid model provider. Default configuration uses deterministic local diagnosis, local embeddings, and local trace identifiers. Provider-backed synthesis is optional and documented, not required for the core demo.

That choice is deliberate for transparent review: a reader can inspect behavior even when external model APIs are unavailable or undesirable.

Tool permissions and approval boundary

Tools are registered with schemas and permission scopes. Published agent versions snapshot prompt, model, enabled tools, and allowed scopes. Risky customer-facing actions (Slack, email, CRM, task creation in the product model) remain mocks until an operator approves or rejects them.

  • Policy checks run before tool dispatch
  • Blocked calls are recorded with reason
  • Approval queue is a first-class surface, not a sidebar afterthought
  • No fully autonomous write path for sensitive actions

Eval design and a regression example

Seeded scenarios double as regression tests. The good published version is compared against an intentionally degraded version so a reviewer can see a pass-rate drop and a specific failing case instead of trusting a single happy path.

From project verification notes (deterministic default path): good version 6/6, degraded version 5/6, with a flagged regression such as eval_usage_drop_after_import_outage. Root-cause scoring on the default path uses exact matching against deterministic diagnosis - reviewers should know what is and is not being measured.

Stripe sandbox as planned evidence adapter

Status: planned / in progress for the public case study - not claimed as a live production Stripe integration on the public demo.

The intended boundary is narrow: Stripe test-mode is an evidence adapter that normalizes sandbox customers, subscriptions, and invoices into Ledger's existing billing model. Investigation logic stays outside Stripe. Signature verification, event idempotency, out-of-order handling, and reconciliation belong to the adapter, not to free-form agent improvisation.

  • No live merchant credentials in the anonymous deployment
  • No checkout, refunds, or Stripe write actions in case-study scope
  • Sandbox / Test Clock scenarios only when the adapter ships

Deployment and public-demo safety

Target public surface: ledger.leihuang.me. Topology follows Vercel (Next.js) + Render (API, worker, Postgres/pgvector, Redis-compatible storage). For an anonymous public deployment:

  • Read-only operator UI posture (OPERATOR_UI_ENABLED=false)
  • No operator / eval / ingest / Stripe / model secrets in public client config
  • Anonymous mutation attempts fail closed and must not change state
  • Seeded synthetic business data only - no real customer records

Honest demo note: treat the public deployment as a read-only evidence surface. Operator recording and mutating review happen in authenticated or local environments, never by leaking tokens into public client variables.

Tradeoffs, failure modes, limitations

  • Synthetic data. Accounts, invoices, tickets, and incidents are seeded fixtures, not real merchants.
  • Mock external actions. Slack / email / CRM / task side effects are mocked behind approvals.
  • Sandbox Stripe only when present. Do not read this page as claiming a live commerce integration.
  • Deterministic eval bar. Default root-cause scoring is exact-match on the deterministic classifier path; it does not fully grade free-form LLM wording.
  • Fixed investigation graph. Auditable by design; less free-form than a fully dynamic agent planner.
  • Case-study scope, not a startup claim. No merchant adoption, revenue impact, or production customer usage is implied.

What I would change for real production

  • Stronger multi-tenant isolation and operator authentication as defaults
  • Richer semantic grading for evals beyond exact root-cause strings
  • Harder schema guarantees that every successful report carries non-empty citations
  • Broader connector framework only after the evidence contract stays boringly solid
  • Operational runbooks and on-call surfaces for long-running eval/worker failure modes

Links