Commit 5907ce5
fix(commons): address PR #469 review — 18 bot comments (greptile + coderabbit)
Quick fixes:
- rac_llm_llamacpp.cpp: copy system_prompt in timed C-API; add try/catch
around generate_stream_with_timing to prevent C++ exceptions from
unwinding across extern "C" boundary (UB on WASM).
- rac_benchmark_stats.cpp: use Bessel-corrected stddev (÷ N−1) for sample
variability, not population stddev.
- llm_component.cpp: use component->actual_framework (not preferred) in
timing telemetry; null-check strdup before marking benchmark successful;
backfill timing_out->prompt_tokens/output_tokens when backend falls back
to plain streaming so decode-TPS stats are correct.
- runanywhere_commons_jni.cpp (timing entrypoint): parse configJson for
max_tokens/temperature/top_p/system_prompt; try onToken([B)Z before
(Ljava/lang/String;)Z and propagate onTokenExpectsBytes into ctx; wait
on cv for completion (10 min timeout) before DeleteGlobalRef to close a
use-after-free race.
Structural:
- llamacpp_backend.{h,cpp}: consolidate generate_stream and
generate_stream_with_timing into one function with optional
rac_benchmark_timing_t*. Gates all timestamp writes on timing_out.
Eliminates ~185 lines of duplicated code and restores three
already-drifted fixes: KV-cache clear + decode_failed_ reset before each
request (#356 regression), sampler chain rebuild on param change, and
chunked prefill via batch_size_ (avoids n_ctx allocation spike).
- rac_benchmark_log.{h,cpp}: migrate timing_to_json / timing_to_csv /
timing_log from char*/void to rac_result_t + out-params, matching the
project-wide include/rac/ convention.
- rac_benchmark_stats.{h,cpp}: extend rac_benchmark_summary_t with full
mean/stddev/min/max aggregates for prefill, decode-TPS, and E2E — not
just TTFT.
- rac_benchmark_metrics.cpp: replace two-slot atomic provider pointer
with mutex-guarded std::shared_ptr so teardown is lifetime-safe against
in-flight rac_benchmark_capture_metrics calls.
Tests: 32/32 rac_benchmark_tests pass (+3 new coverage tests).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent bacb277 commit 5907ce5
12 files changed
Lines changed: 379 additions & 283 deletions
File tree
- sdk/runanywhere-commons
- include/rac/core
- src
- backends/llamacpp
- core
- features/llm
- jni
- tests/benchmark
Lines changed: 47 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
17 | 23 | | |
18 | | - | |
19 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
| |||
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
| |||
45 | 54 | | |
46 | 55 | | |
47 | 56 | | |
48 | | - | |
49 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
50 | 65 | | |
51 | | - | |
| 66 | + | |
| 67 | + | |
52 | 68 | | |
53 | 69 | | |
54 | 70 | | |
| |||
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
63 | 90 | | |
64 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
65 | 94 | | |
66 | 95 | | |
67 | 96 | | |
| |||
75 | 104 | | |
76 | 105 | | |
77 | 106 | | |
78 | | - | |
79 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
80 | 111 | | |
81 | | - | |
| 112 | + | |
| 113 | + | |
82 | 114 | | |
83 | 115 | | |
84 | 116 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
76 | 84 | | |
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
81 | 93 | | |
82 | 94 | | |
83 | 95 | | |
| |||
Lines changed: 29 additions & 186 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
601 | | - | |
| 601 | + | |
| 602 | + | |
602 | 603 | | |
603 | 604 | | |
604 | 605 | | |
| |||
632 | 633 | | |
633 | 634 | | |
634 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
635 | 642 | | |
636 | 643 | | |
637 | 644 | | |
| |||
643 | 650 | | |
644 | 651 | | |
645 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
646 | 658 | | |
647 | 659 | | |
648 | 660 | | |
| |||
655 | 667 | | |
656 | 668 | | |
657 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
658 | 675 | | |
659 | 676 | | |
660 | 677 | | |
661 | 678 | | |
662 | 679 | | |
663 | 680 | | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
664 | 686 | | |
665 | 687 | | |
666 | 688 | | |
| |||
809 | 831 | | |
810 | 832 | | |
811 | 833 | | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
812 | 840 | | |
813 | 841 | | |
814 | 842 | | |
| |||
828 | 856 | | |
829 | 857 | | |
830 | 858 | | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
882 | | - | |
883 | | - | |
884 | | - | |
885 | | - | |
886 | | - | |
887 | | - | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | 859 | | |
1017 | 860 | | |
1018 | 861 | | |
| |||
0 commit comments