Repository navigation
Conversation
…ation MEMORY.md is only size-bounded while consolidation succeeds, yet memory_save and the agent's file tools append to it unbounded, and a daily ledger grows with every flush. Both prompts replayed those files whole, so once they outgrew the model's input window every flush and consolidation failed with the provider's invalid_parameter_error, and the only step able to shrink MEMORY.md could never run again. Replay at most the head of MEMORY.md and the tail of the ledger instead, sized to stay within the harness's 64k-token fallback input budget.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
I think the consolidation watermark needs to be fixed before merge. |
…t ledger entries Bounding the consolidation input with a tail cut dropped the oldest unconsolidated ledger entries while the watermark still advanced past them, so they were never merged. Consolidation now merges the oldest entries first in a bounded batch (60,000 chars per run, entries in append order, files by name). When the batch is cut, the watermark stays and a continuation cursor (ledger path and character offset) is persisted with it, so the next run resumes at the first unmerged entry; the watermark advances only once a run read everything selected. The cursor travels with the watermark in both the state file and the distributed store item.
|
Agreed — the tail cut silently dropped entries. Reworked in d08293e:
Why an offset cursor rather than per-entry timestamps: entry headers carry the clock of whichever instance appended them (flush uses Tests: |
juruoO-o
left a comment
There was a problem hiding this comment.
[P1] A ledger earlier than the cursor can receive a late append between bounded passes, for example from a writer using a different local date. readDailyBatch skips that whole file by name, then the completing pass advances the watermark past the append. I extended the existing two-day regression by appending one entry to OLDER_DAY between passes: the new fact was absent from the second model input. Please retain enough per-file progress (or an equivalent cutoff and replay rule) to consume writes made between passes before advancing past them. Please cover this with a late-append regression and confirm previously consumed entries are not resent.
…cursor A single cursor skipped every ledger sorting before it, so an entry appended to an already-consumed ledger between two bounded passes was never merged: the completing pass advanced the watermark past it. The state now records how far each ledger has been read, and the next pass reads every eligible ledger from its own offset.
|
Fixed in ab042c3: a single cursor no longer decides which ledgers are read. The state now keeps per-ledger progress (ledger path → characters already merged), and every eligible ledger is read from its own offset.
Regression Unchanged from before this PR: an append landing after a completing pass's Tests: Memory* 159 passed; core 3568, ag-ui 607, harness 2300 green; spotless clean. en/zh docs updated. |
AgentScope-Java Version
2.1.0-SNAPSHOT (
agentscope-harness)Description
Problem. In a long-running production agent the memory flush call started failing with the provider's
invalid_parameter_error: Range of input length should be [1, 1048576]on every run. The user message of that call was 2.03M characters:MEMORY.mdhad grown to 1.42M characters and today's daily ledger to 614K, and both were replayed whole into the prompt.Root cause.
MemoryFlushManagerandMemoryConsolidatorconcatenate the files they read into the prompt without any bound.MEMORY.mdis only size-bounded while consolidation succeeds:MemorySaveToolappends straight to it, and a daily ledger grows with every flush and save. Once either file outgrows the model's input window, both auxiliary calls fail every time, so the only step able to shrinkMEMORY.mdagain can never run. The harness budget check does not catch it either: the 2.5-chars-per-token estimate puts 2M characters at ~813K tokens, below a 1M window, while the provider's real count for CJK-heavy text is higher.Change. Flush replays a bounded slice of each file (new package-private
MemoryInputBudget); consolidation merges the pending entries in bounded oldest-first batches and keeps per-ledger progress between runs.MEMORY.md, trailing 32,000 characters of today's ledger. The cut is marked in the prompt and logged at WARN; cut points never split a UTF-16 surrogate pair.max(maxChars, 60,000)characters ofMEMORY.md(so a memory within its body target is never cut), plus the pending ledger entries oldest first (ledgers by name,##entries in append order), at most 60,000 characters per run. A single entry larger than that is merged head-truncated, so the input is always bounded.runStartonly when a run read every eligible ledger to its end. The offsets live with the watermark in both places it is stored: onepath<TAB>offsetline per ledger after the watermark line inmemory/.consolidation_state, and the same text underprogressin the store item (reads prefer the store).clock(rc)for flush, the system clock formemory_save). With several instances sharing a ledger, ordering or filtering by header time could skip entries; ledgers are append-only, so an offset is exact.HarnessContextBuilder, so they also work when the model reports no context window.With this in place a consolidated result replaces the oversized
MEMORY.mdand the system recovers on its own. Unchanged from before this PR: an append landing after a completing run'srunStartkeeps its ledger eligible through its mtime and is replayed from the start on the next run, as for any file modified during a run.Not changed.
MemorySaveToolstill appends toMEMORY.mddirectly. That is the source of the unbounded growth, but changing it alters default tool behaviour, so it is left for a separate discussion.Tests.
MemoryFlushManagerTest(oversized memory and ledger are capped, head and tail kept),MemoryInputBudgetTest(exact cut output, no split surrogate pair, under-limit passthrough),MemoryConsolidatorCommitGateTest:oversizedMemoryAndSingleOversizedEntryAreCappedAndStillCommit,cutBatchKeepsTheWatermarkAndTheNextRunMergesTheSkippedEntries(two-pass: the watermark stays, the skipped entry is merged next, consumed entries are not re-sent, state-file layout),writesToEarlierLedgersBetweenPassesAreMergedBeforeTheWatermarkAdvances(a late append to an already-consumed ledger and a newly created earlier ledger are merged before the watermark advances, consumed entries are not re-sent),cutBatchProgressIsVisibleThroughTheWatermarkStore(per-ledger offsets through the store). AllMemory*tests inagentscope-harnesspass (159 tests), and the fullagentscope-core,agentscope-extensions-ag-uiandagentscope-harnesssuites pass.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)