Commit 7892cdc
committed
fix local codex review
[P1] Avoid duplicating session history — packages/agents-core/src/runImplementation.ts:1861-1872
When we compute sessionItems for a custom sessionInputCallback, we rely on reference equality (historySet.has(item)) to decide which entries came from prior history. That assumes the callback
returns the exact same object references for every preserved history item. A very common sanitization pattern is to clone history items (e.g. history.map(item => structuredClone(item))) before
returning them. In that case none of the clones are found in historySet or newInputSet, so every history entry is treated as “appended” and we persist the entire history again. After one or
two turns the session now contains duplicate copies of every message and will grow explosively on subsequent runs. Please adjust the change detection (e.g. track by index/length or require the
callback to return new items explicitly) so that cloning history entries does not cause the memory to balloon.1 parent ce85e41 commit 7892cdc
File tree
2 files changed
+59
-11
lines changed- packages/agents-core
- src
- test
2 files changed
+59
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1858 | 1858 | | |
1859 | 1859 | | |
1860 | 1860 | | |
1861 | | - | |
1862 | | - | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
1863 | 1873 | | |
1864 | 1874 | | |
1865 | | - | |
1866 | | - | |
1867 | | - | |
1868 | | - | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
1869 | 1879 | | |
1870 | 1880 | | |
1871 | | - | |
1872 | | - | |
1873 | 1881 | | |
1874 | | - | |
1875 | | - | |
1876 | | - | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
1877 | 1890 | | |
1878 | 1891 | | |
1879 | 1892 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
813 | 813 | | |
814 | 814 | | |
815 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
816 | 851 | | |
817 | 852 | | |
818 | 853 | | |
| |||
0 commit comments