Skip to content

feat(server): bound the finished tasks InMemoryTaskStore keeps - #407

Closed
gulldan wants to merge 5 commits into
a2aproject:mainfrom
gulldan:feat/inmemory-task-store-limit
Closed

gulldan wants to merge 5 commits into
a2aproject:mainfrom
gulldan:feat/inmemory-task-store-limit

Conversation

@gulldan

@gulldan gulldan commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #406 → #405 → #407 → #411 → #395. Stacked on #405: review only the last commit.

Fixes #401.

Problem

InMemoryTaskStore never removes a task, TaskStore has no delete, and once DefaultRequestHandler::new takes the store the embedder cannot reach it, so a long-running agent keeps every task it has ever served. 20,000 tasks with one 4 KiB artifact each held 192 MiB RSS (program in #401). §13.4: agents SHOULD implement appropriate data retention policies.

Change

InMemoryTaskStore::new().with_terminal_task_limit(n) keeps at most n tasks in a terminal state:

  • a task is counted once, when it first reaches a terminal state — through update, begin_cancel, or create of an already terminal task; re-applying the same terminal state does not count it again;
  • past n, the task that reached its terminal state earliest is purged, under the same write lock;
  • tasks that are not terminal (working, input-required, auth-required) are never purged;
  • a purged task reads as TaskNotFoundError, which §3.3.2 describes for a task "already completed and purged".

InMemoryTaskStore::new() keeps every task and tracks nothing extra, as before. save_task returns the task it wrote rather than re-reading the store, so a task that is purged right after finishing still gets its response.

Tests

  • test_terminal_task_limit_purges_the_oldest_finished_task: limit 2; three tasks complete, the first is purged, a working task survives, a re-applied terminal state is not counted twice, a cancel and a create of a failed task each push out the next oldest, and the store ends with exactly two entries.
  • test_unlimited_store_keeps_every_finished_task: without a limit all 100 finished tasks stay and no order is tracked.
  • The program from [Feat]: a2a-server: let InMemoryTaskStore bound how many finished tasks it keeps #401 on this branch with with_terminal_task_limit(1_000): 19.6, 19.9, 20.7, 18.9 MiB RSS at 5,000/10,000/15,000/20,000 tasks, 1,000 stored (on main: 51.7 → 192.2 MiB, all 20,000 stored).
  • CI steps on Linux, stable 1.99.1: cargo metadata --locked, cargo hack check --all-targets --each-feature, cargo fmt --check, cargo hack clippy --all-targets --each-feature -- -D warnings, cargo test --workspace --exclude itk-rust-current-agent, copyright headers — all green.

Overlap with the A2A 1.1 stack

#385–#397 also edit inmemory.rs (e.g. list_scoped) and keep the plain HashMap, so this diff does not apply as is on refs/pull/396/head; the change is local to the store and carries over directly. Happy to rebase once the stack lands.

🤖 Generated with Claude Code

The JSON-RPC transport never looked at the status of a response. An
error that something in front of the agent answers itself (an
authenticating proxy's 401, a gateway's 429 or 502) carries no
JSON-RPC envelope, so the caller got "failed to parse JSON-RPC
response" and could not tell a credential or rate-limit problem from
a broken server. A streaming call answered that way without a content
type was handed to the SSE parser and came back as an empty stream.

A body that is not a JSON-RPC envelope is now reported with its
status, as the REST transport already does ("HTTP 429 Too Many
Requests: <body>"); a JSON-RPC envelope is still decoded whatever the
status, and a non-success status is never treated as a stream.

Fixes: a2aproject#404

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
@gulldan
gulldan requested a review from a team as a code owner October 31, 2026 10:22
The streaming test matched on the result and panicked in an `Ok` arm that a
passing run never reaches, so that line stayed uncovered. Taking the error
with `.err().expect()` keeps the assertion and needs no `Debug` on the stream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
muscariello and others added 3 commits October 31, 2026 16:53
google.protobuf.Value carries every number as a double, and
proto_value_to_json_value turned each one back into a JSON float, so
an integer in a data part or in metadata reached the executor, and a
client's decoded response, as 3600.0. serde then refuses it for an
integer type ("invalid type: floating point `3600.0`, expected u32").

A whole number within +-2^53, where a double is exact, is now given
back as an integer; other numbers stay floats. The round-trip tests
that used floats to work around this now use integers, and a new
protojson test decodes a JSON-RPC SendMessage whose data part holds an
integer and deserializes it into u32.

Fixes: a2aproject#399

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
InMemoryTaskStore never removed a task, and TaskStore has no delete,
so a long-running agent kept every task it ever served: 20,000 tasks
with a 4 KiB artifact each held 192 MiB.

InMemoryTaskStore::with_terminal_task_limit(n) keeps at most n tasks
in a terminal state and purges the one that reached its terminal state
earliest. Tasks that are not terminal are never purged, and a purged
task reads as TaskNotFoundError, which A2A 3.3.2 allows for a task
that was completed and purged. new() keeps every task, as before. With
a limit of 1,000 the same run stays at about 20 MiB.

Fixes: a2aproject#401

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@muscariello

Copy link
Copy Markdown
Member

Superseded by #441, which carries the same commit on an in-repo branch so the stack can be reviewed one commit at a time.

@muscariello muscariello closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: a2a-server: let InMemoryTaskStore bound how many finished tasks it keeps

2 participants