Commit 7b46ac6
authored
feat: Translate FDv2 payloads at the data source layer (#309)
BEGIN_COMMIT_OVERRIDE
feat: Translate FDv2 payloads at the data source layer
feat: Add FDv2 streaming source factories and query-parameter
authentication
END_COMMIT_OVERRIDE
## What this changes
Moves flag-eval translation out of the apply path and into the data
source layer, and introduces a typed `ChangeSet` distinct from the
wire-level `Payload`.
Previously the streaming and polling sources emitted a `ChangeSetResult`
carrying the raw wire `Payload` (a list of `Update`s with unparsed
object maps), and the flag-eval objects were converted to typed
descriptors later, at apply time in
`DataSourceEventHandler.handlePayload`. A payload that parsed at the
protocol level but whose flag objects were malformed therefore failed
*after* acquisition — surfacing as an invalid-message that drove a
connection restart, on a fixed interval, without ever arming the
orchestrator's fallback timer.
Now:
- `ChangeSet` carries typed `Map<String, ItemDescriptor>` updates plus
the type and selector. `translatePayload` converts a wire `Payload` into
a `ChangeSet`, throwing if any flag-eval object cannot be parsed.
- The streaming and polling sources translate at acquisition. A
translation failure becomes an **interrupted** source result, exactly
like a malformed protocol body — so the orchestrator's fallback timer
governs recovery (a source stuck on invalid data falls back after the
timeout instead of retrying forever). Streaming discards the partial
handler state and keeps the SSE connection; the server's next valid
payload is processed normally.
- `ChangeSetResult` carries the `ChangeSet`, and `handlePayload` applies
it directly with no conversion and no failure path of its own.
- The cache initializer builds its `ChangeSet` straight from the
already-typed cached evaluation results, dropping a JSON round-trip that
previously serialized typed results only to re-parse them.
This is foundational for the FDv2 data system: the streaming-source and
orchestrator PRs build on `ChangeSet`. Nothing constructs the FDv2
sources in production yet, so behavior is unchanged for shipping code.
## Testing
Source-layer tests cover a protocol-valid payload whose flag data cannot
be parsed: polling returns interrupted, and streaming returns
interrupted then recovers on the next valid payload. The flag manager /
event handler tests apply typed change sets directly (full replace,
partial without per-item version comparison, none). Cache initializer
tests assert the evaluation result is carried through without
re-parsing. Full `common_client` suite passes.
SDK-2186
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches FDv2 acquisition, URL/auth composition, and
error-classification paths that govern fallback and flag updates;
changes are largely behind not-yet-production FDv2 wiring but alter
recovery semantics when invalid flag data arrives.
>
> **Overview**
> FDv2 now separates wire **`Payload`** from typed **`ChangeSet`**
(`Map<String, ItemDescriptor>`). **`translatePayload`** runs in
polling/streaming (and cache builds descriptors directly), so
**`ChangeSetResult`** and **`handlePayload`** only apply already-typed
updates.
>
> **Malformed flag-eval data** is surfaced as **`interrupted`** at the
source layer (like other transient parse errors) instead of failing
later in the event handler—so the orchestrator’s fallback timer can kick
in rather than endless connection retries.
>
> Adds shared **`buildFDv2Uri`** (relay query params, `basis`,
`withReasons`) for polling and streaming; **`SourceFactoryContext`**
carries credential-driven **`auth`** query params. **Streaming
synchronizer factories** are implemented (SSE client, per-reconnect
URI/`basis`, legacy **`ping`** → one-shot poll, env ID fallback).
Streaming also maps **`UnrecoverableStatusError`** to terminal errors
with optional FDv1 fallback.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
38646ce. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent b20c35e commit 7b46ac6
22 files changed
Lines changed: 655 additions & 173 deletions
File tree
- packages/common_client
- lib/src/data_sources
- fdv2
- test/data_sources
- fdv2
Lines changed: 9 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
101 | | - | |
| 100 | + | |
102 | 101 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
107 | 106 | | |
108 | 107 | | |
109 | | - | |
110 | | - | |
| 108 | + | |
| 109 | + | |
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
115 | | - | |
116 | | - | |
| 114 | + | |
117 | 115 | | |
118 | | - | |
| 116 | + | |
119 | 117 | | |
120 | 118 | | |
121 | 119 | | |
| |||
Lines changed: 7 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | | - | |
| 69 | + | |
71 | 70 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 71 | + | |
| 72 | + | |
78 | 73 | | |
79 | 74 | | |
80 | 75 | | |
81 | | - | |
| 76 | + | |
82 | 77 | | |
83 | | - | |
84 | 78 | | |
85 | 79 | | |
86 | 80 | | |
| |||
95 | 89 | | |
96 | 90 | | |
97 | 91 | | |
98 | | - | |
| 92 | + | |
99 | 93 | | |
100 | | - | |
| 94 | + | |
101 | 95 | | |
102 | 96 | | |
103 | 97 | | |
| |||
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
Lines changed: 120 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
| 9 | + | |
7 | 10 | | |
| 11 | + | |
| 12 | + | |
8 | 13 | | |
9 | 14 | | |
10 | 15 | | |
| |||
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
| 21 | + | |
| 22 | + | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
| |||
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
| |||
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
66 | 137 | | |
67 | 138 | | |
68 | 139 | | |
| |||
130 | 201 | | |
131 | 202 | | |
132 | 203 | | |
133 | | - | |
134 | | - | |
135 | 204 | | |
136 | 205 | | |
137 | | - | |
138 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
139 | 209 | | |
140 | 210 | | |
141 | 211 | | |
| |||
155 | 225 | | |
156 | 226 | | |
157 | 227 | | |
158 | | - | |
159 | | - | |
160 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
161 | 269 | | |
162 | 270 | | |
163 | 271 | | |
| |||
173 | 281 | | |
174 | 282 | | |
175 | 283 | | |
176 | | - | |
177 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
178 | 287 | | |
179 | | - | |
| 288 | + | |
| 289 | + | |
180 | 290 | | |
181 | 291 | | |
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
9 | 22 | | |
10 | 23 | | |
11 | 24 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
0 commit comments