Commit 9985116
committed
fix(api): Plumb safety + request IDs + array fields through singleton thunks
Closes the runtime gaps that surfaced once `-DNOTE_SINGLETON=1` started compiling against the polymorphic Notecard. Three independent singleton-mode bugs all routed through the same code path:
(1) Safety dropped to NonIdempotent. The thunks called execute_void / execute_generic_with_body without a Safety parameter, so retry_loop saw NonIdempotent regardless of `RequestT::safety`. Idempotent / ReadOnly endpoints didn't retry on transient ResponseLost (CRC mismatch, read timeout). Adds Safety to the thunk function-pointer signature; generated `execute()` passes `safety` (the per-class constexpr).
(2) Request IDs not injected. The static `execute()` template baked "id":N into its fields lambda; the singleton thunk path bypassed that lambda and the wire frame went out without an id. Adds `Notecard::next_request_id_or_zero()` (and the StaticNotecard mirror) and a `detail::IdWrapCtx` / `id_wrap_build` helper in protocol.hpp. The thunks wrap the caller's BuildFn with id_wrap so the id sits between "req" and the per-endpoint fields, matching the static template's wire format.
(3) Version-guarded fields and StringArray fields silently dropped. The codegen previously filtered `version_guard` and `is_array` properties out of `field_descs_table_`; GenericResponseSink saw the bare scalar set, so e.g. CardAttn::off (gated) and CardAttn::files (array of strings) never landed in the parsed Response. Codegen now emits version-guarded entries with their own `#if` guards and emits a new `FieldType::StringArray` for string-element ResponseArray fields. `field_count` is computed from the post-preprocessor table size. GenericResponseSink picks up an `active_string_array_` latch in on_array_begin/on_array_end so on_string can append into the matching ResponseArray. The buffered fallback in `execute_generic_with_body` switches from `sax_parse` (emits only on_number for numerics, which GenericResponseSink only forwards to body handlers) to `sax_lex` (emits typed on_int / on_float / on_bool that the response field table actually dispatches).
Also documents the Notecard::binary_ctrl_buf_[256] fixed buffer per Mat's earlier comment, and switches the err-stash from a fixed buffer to allocator-backed durable copy (heap-leaked, same model as StringPool::intern) so no new fixed-size buffer was added for these fixes.
NOTE_MINIMAL gates: under NOTE_MINIMAL, NOTE_NO_RETRY and NOTE_NO_REQUEST_IDS are forced on, so safety and id wrapping are no-ops. The thunks short-circuit to a direct call. The StringArray dispatch in GenericResponseSink and the durable_ptr field in NcErrorCapture are also gated out. AVR delta after these fixes: avr-notecpp +78 B flash, RAM unchanged avr-notecpp-direct +64 B flash, RAM unchanged avr-notecpp-raw +0 B flash avr-notecpp-multistack -66 B flash (linker dedup of class-scope tables) The +78/+64 comes from version-guarded entries now landing in field_descs (one per gated property per endpoint) and Safety being threaded through `execute_generic_with_body`. Acceptable trade-off for closing three categories of correctness bugs that previously silently dropped fields.
Singleton test failures: 73 → 0 (all 1858 host tests pass under `-DNOTE_SINGLETON=1`; default and NOTE_MINIMAL builds also pass).1 parent d8006d4 commit 9985116
84 files changed
Lines changed: 1122 additions & 994 deletions
File tree
- src/note
- api
- tools
- binary-size-comparison
- codegen/templates
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
160 | 172 | | |
161 | | - | |
| 173 | + | |
| 174 | + | |
162 | 175 | | |
163 | | - | |
164 | | - | |
| 176 | + | |
| 177 | + | |
165 | 178 | | |
166 | 179 | | |
167 | 180 | | |
168 | 181 | | |
169 | 182 | | |
170 | 183 | | |
171 | | - | |
| 184 | + | |
| 185 | + | |
172 | 186 | | |
173 | | - | |
| 187 | + | |
| 188 | + | |
174 | 189 | | |
175 | | - | |
176 | | - | |
| 190 | + | |
| 191 | + | |
177 | 192 | | |
178 | 193 | | |
179 | 194 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
535 | | - | |
536 | | - | |
537 | 535 | | |
538 | 536 | | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
544 | 545 | | |
545 | | - | |
546 | | - | |
| 546 | + | |
| 547 | + | |
547 | 548 | | |
548 | 549 | | |
549 | 550 | | |
550 | | - | |
| 551 | + | |
551 | 552 | | |
552 | 553 | | |
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
556 | 557 | | |
557 | | - | |
| 558 | + | |
558 | 559 | | |
559 | 560 | | |
560 | 561 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
359 | | - | |
360 | 358 | | |
361 | 359 | | |
362 | | - | |
363 | | - | |
364 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
365 | 366 | | |
366 | | - | |
367 | | - | |
| 367 | + | |
| 368 | + | |
368 | 369 | | |
369 | 370 | | |
370 | 371 | | |
371 | | - | |
| 372 | + | |
372 | 373 | | |
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
378 | | - | |
| 379 | + | |
379 | 380 | | |
380 | 381 | | |
381 | 382 | | |
| |||
677 | 678 | | |
678 | 679 | | |
679 | 680 | | |
680 | | - | |
| 681 | + | |
681 | 682 | | |
682 | 683 | | |
683 | 684 | | |
684 | 685 | | |
685 | | - | |
| 686 | + | |
686 | 687 | | |
687 | 688 | | |
688 | 689 | | |
| |||
869 | 870 | | |
870 | 871 | | |
871 | 872 | | |
872 | | - | |
| 873 | + | |
873 | 874 | | |
874 | 875 | | |
875 | 876 | | |
876 | 877 | | |
877 | | - | |
| 878 | + | |
878 | 879 | | |
879 | 880 | | |
880 | 881 | | |
| |||
1020 | 1021 | | |
1021 | 1022 | | |
1022 | 1023 | | |
1023 | | - | |
| 1024 | + | |
1024 | 1025 | | |
1025 | 1026 | | |
1026 | 1027 | | |
1027 | 1028 | | |
1028 | | - | |
| 1029 | + | |
1029 | 1030 | | |
1030 | 1031 | | |
1031 | 1032 | | |
| |||
1146 | 1147 | | |
1147 | 1148 | | |
1148 | 1149 | | |
1149 | | - | |
| 1150 | + | |
1150 | 1151 | | |
1151 | 1152 | | |
1152 | 1153 | | |
1153 | 1154 | | |
1154 | | - | |
| 1155 | + | |
1155 | 1156 | | |
1156 | 1157 | | |
1157 | 1158 | | |
| |||
0 commit comments