Skip to content

Commit 13bdaae

Browse files
mayoalexanderclaude
andcommitted
fix(iris): Leads returned 400 on every board that had leads
Expected string | undefined, got {"source":null} at ["leads"][0]["keywords"] `keywords` comes back as an OBJECT on some rows. The mapper handled arrays and scalars and passed everything else through untouched, the response schema rejected it, and Effect failed the WHOLE request — 50 leads lost to one field on one row. MEASURED across all 25 boards: 4 return 400, 21 return 200 with zero leads. The 21 are not working — they are empty. Every board that has leads is broken, and every board that is fine has nothing to show. That is why nobody caught it: an empty list and a voided response render the same pane, so the surface looked healthy everywhere anyone clicked. anomalyco#679 Richard's Signal · anomalyco#662 KMG · anomalyco#657 ReachR · anomalyco#641 Pathways Engagement Fixed at the boundary and for all SEVEN string fields, not just the one that was caught — status, company, email, type, city, country and keywords were passed through with the same `?? undefined`, and nothing distinguishes keywords except that someone loaded a board that exercised it. `{"source": null}` carries no information, so it coerces to undefined rather than "[object Object]". After: 679→1, 662→1, 657→2, 641→1, with keywords reading "existing-contact" rather than failing the request. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JwiqN8M84qimu1TjZGSsdQ
1 parent b32b8cf commit 13bdaae

2 files changed

Lines changed: 87 additions & 8 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { str } from "./platform"
3+
4+
describe("str — the coercion that keeps one odd field from voiding a whole surface", () => {
5+
test("the exact payload that took Leads down: an object whose values are all null", () => {
6+
// Expected string | undefined, got {"source":null} at ["leads"][0]["keywords"]
7+
expect(str({ source: null })).toBeUndefined()
8+
})
9+
10+
test("an object that DOES carry information keeps it rather than printing [object Object]", () => {
11+
expect(str({ source: "linkedin", campaign: "q3" })).toBe("linkedin, q3")
12+
})
13+
14+
test("strings and arrays behave as they did before", () => {
15+
expect(str("hiring")).toBe("hiring")
16+
expect(str(["hiring", "remote"])).toBe("hiring, remote")
17+
})
18+
19+
test("empty is undefined, not an empty string — the schema field is optional", () => {
20+
expect(str("")).toBeUndefined()
21+
expect(str([])).toBeUndefined()
22+
expect(str({})).toBeUndefined()
23+
expect(str(null)).toBeUndefined()
24+
expect(str(undefined)).toBeUndefined()
25+
})
26+
27+
test("numbers and booleans survive as text", () => {
28+
expect(str(42)).toBe("42")
29+
expect(str(0)).toBe("0")
30+
expect(str(false)).toBe("false")
31+
})
32+
33+
test("nested nonsense still yields a string or nothing — never a throw", () => {
34+
expect(str([{ a: null }, { b: "x" }])).toBe("x")
35+
expect(str({ a: { b: { c: "deep" } } })).toBe("deep")
36+
expect(() => str(Symbol("s"))).not.toThrow()
37+
})
38+
})

‎packages/opencode/src/iris/platform.ts‎

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,47 @@ export interface Lead {
668668
keywords?: string
669669
}
670670

671+
/**
672+
* Anything fl-api hands us, as a string the wire schema will accept — or nothing.
673+
*
674+
* ## The outage this exists to end
675+
*
676+
* Every board that had leads returned HTTP 400 and rendered an empty pane:
677+
*
678+
* Expected string | undefined, got {"source":null} at ["leads"][0]["keywords"]
679+
*
680+
* `keywords` came back as an OBJECT on some rows. The mapper handled arrays and scalars and
681+
* passed everything else through untouched, the response schema rejected the payload, and
682+
* Effect failed the WHOLE request — 50 leads lost to one field on one row.
683+
*
684+
* It survived because of how it failed. The 21 boards with no leads returned a valid empty
685+
* 200, so the surface looked healthy everywhere anyone happened to click; the four boards that
686+
* actually had leads — Richard's Signal, KMG, ReachR, Pathways Engagement — were the only ones
687+
* that broke. An empty list is indistinguishable from a working empty list.
688+
*
689+
* So this coerces rather than trusts, and it is applied to EVERY string field, not just the one
690+
* that was caught: the other six are passed through with the same `?? undefined` that let this
691+
* one through, and there is nothing special about `keywords` except that someone loaded a board
692+
* that exercised it.
693+
*/
694+
export function str(v: unknown): string | undefined {
695+
if (v === null || v === undefined) return undefined
696+
if (typeof v === "string") return v || undefined
697+
if (typeof v === "number" || typeof v === "boolean") return String(v)
698+
if (Array.isArray(v)) {
699+
const parts = v.map((x) => str(x)).filter((x): x is string => !!x)
700+
return parts.length ? parts.join(", ") : undefined
701+
}
702+
if (typeof v === "object") {
703+
// `{"source": null}` carries no information — say nothing rather than print "[object Object]".
704+
const parts = Object.values(v as Record<string, unknown>)
705+
.map((x) => str(x))
706+
.filter((x): x is string => !!x)
707+
return parts.length ? parts.join(", ") : undefined
708+
}
709+
return undefined
710+
}
711+
671712
export async function fetchLeads(bloqId: number): Promise<PlatformResult<{ leads: Lead[] }>> {
672713
const userId = await resolveUserId()
673714
if (!userId) return { measured: false, reason: `not signed in (token: ${tokenSource()})`, data: { leads: [] } }
@@ -684,17 +725,17 @@ export async function fetchLeads(bloqId: number): Promise<PlatformResult<{ leads
684725
const leads: Lead[] = rows.map((l: any) => ({
685726
id: Number(l.id),
686727
name: String(l.name ?? l.full_name ?? "unnamed"),
687-
status: l.status ?? undefined,
688-
company: l.company ?? undefined,
689-
email: l.email ?? undefined,
728+
status: str(l.status),
729+
company: str(l.company),
730+
email: str(l.email),
690731
hot: Number(l.lead_score ?? l.leadScore ?? 0) >= 70,
691732
score: typeof l.lead_score === "number" ? l.lead_score : undefined,
692-
type: l.lead_type ?? undefined,
693-
city: l.city ?? undefined,
694-
country: l.country ?? undefined,
695-
createdAt: l.created_at ?? undefined,
733+
type: str(l.lead_type),
734+
city: str(l.city),
735+
country: str(l.country),
736+
createdAt: str(l.created_at),
696737
repliedAt: typeof l.has_replied === "boolean" ? l.has_replied : undefined,
697-
keywords: Array.isArray(l.keywords) ? l.keywords.join(", ") : (l.keywords ?? undefined),
738+
keywords: str(l.keywords),
698739
}))
699740
return { measured: true, data: { leads } }
700741
} catch (e) {

0 commit comments

Comments
 (0)