Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(turn_state): persist sub-agent child tool arguments in snapshots\n\nA sub-agent's child tool call carried its arguments on the live\n`subagent_tool_call` socket event but never into the turn-state snapshot,\nso a reloaded child row came back with no input at all, and a degraded\ngeneric `tool` name lost the `query` it derives its search label from.\n\nPersist the arguments on `SubagentToolCall`, capped at 16 KiB. The\nsnapshot is rewritten in full at every tool boundary and a turn\naccumulates many child calls, so this follows\n`MAX_PERSISTED_TRANSCRIPT_ITEM` rather than the looser 64 KiB output cap.\nAn oversized payload degrades to a truncated string carrying the same\nmarker shape a truncated tool output uses; a null payload — the paths\nwhere the child's arguments were never materialised — serializes away\nentirely rather than persisting a meaningless "Input: null" row.\n\nThe field is deliberately not repeated on `SubagentTranscriptItem::Tool`.\nLike `output` and `failure`, it is a heavy payload that lives once on the\ncall row and is grafted onto the matching transcript item by `callId` in\n`subagentActivityFromPersisted`.\n\nAdditive and optional on both sides, so snapshots written before this\nfield still load.\n\nCloses #5987\n

Shanuf0fbd2c0d292
diff --git a/app/src/features/conversations/components/__tests__/SubagentDrawer.test.tsx b/app/src/features/conversations/components/__tests__/SubagentDrawer.test.tsx
index f885e4bdbb..4d079b2353 100644
--- a/app/src/features/conversations/components/__tests__/SubagentDrawer.test.tsx
+++ b/app/src/features/conversations/components/__tests__/SubagentDrawer.test.tsx
@@ -344,4 +344,26 @@ describe('SubagentDrawer', () => {
expect(screen.queryByTestId('assistant-ui-tool-input')).toBeNull();
expect(screen.queryByTestId('assistant-ui-tool-output')).toBeNull();
});
+
+ it('derives a search label from the arguments when the server label degraded to "tool"', () => {
+ // A provider that hands back a generic `tool` name leaves the row with
+ // nothing better than "Tool" unless the arguments are there to read. Those
+ // arguments only survive a reload because the snapshot now carries them
+ // (#5987) — without them this row reads "Tool" again after a refresh.
+ const transcript: SubagentTranscriptItem[] = [
+ {
+ kind: 'tool',
+ iteration: 1,
+ callId: 'c1',
+ toolName: 'tool',
+ status: 'success',
+ displayName: 'tool',
+ args: { query: 'openhuman turn state' },
+ },
+ ];
+ render(
+ <SubagentDrawer subagent={activity({ transcript })} status="success" onClose={() => {}} />
+ );
+ expect(screen.getByTestId('assistant-ui-tool-call').textContent).toContain('Searched the web');
+ });
});
diff --git a/app/src/store/__tests__/chatRuntimeSlice.subagentStream.test.ts b/app/src/store/__tests__/chatRuntimeSlice.subagentStream.test.ts
index 01621bf925..f3fe2dc436 100644
--- a/app/src/store/__tests__/chatRuntimeSlice.subagentStream.test.ts
+++ b/app/src/store/__tests__/chatRuntimeSlice.subagentStream.test.ts
@@ -1,7 +1,9 @@
import { describe, expect, it } from 'vitest';
+import type { PersistedTurnState } from '../../types/turnState';
import reducer, {
appendSubagentStreamDelta,
+ hydrateRuntimeFromSnapshot,
markSubagentCancelled,
recordSubagentTranscriptTool,
resolveSubagentTranscriptTool,
@@ -214,3 +216,70 @@ describe('markSubagentCancelled', () => {
).toEqual(base);
});
});
+
+describe('hydrateRuntimeFromSnapshot — sub-agent child tool arguments', () => {
+ function settledSnapshot(args: unknown): PersistedTurnState {
+ return {
+ threadId: THREAD,
+ requestId: 'req-1',
+ lifecycle: 'completed',
+ iteration: 1,
+ maxIterations: 10,
+ streamingText: '',
+ thinking: '',
+ startedAt: '2026-09-03T00:00:00Z',
+ updatedAt: '2026-09-03T00:00:00Z',
+ toolTimeline: [
+ {
+ id: ROW_ID,
+ name: 'subagent:researcher',
+ round: 1,
+ status: 'success',
+ subagent: {
+ taskId: 'sub-1',
+ agentId: 'researcher',
+ toolCalls: [
+ {
+ callId: 'c1',
+ toolName: 'tool',
+ status: 'success',
+ iteration: 1,
+ args,
+ output: '3 hits',
+ },
+ ],
+ transcript: [
+ { kind: 'tool', iteration: 1, callId: 'c1', toolName: 'tool', status: 'success' },
+ ],
+ },
+ },
+ ],
+ };
+ }
+
+ it('restores the child call arguments onto the call row and its transcript item', () => {
+ const state = reducer(
+ undefined,
+ hydrateRuntimeFromSnapshot({ snapshot: settledSnapshot({ query: 'turn state' }) })
+ );
+ const subagent = state.toolTimelineByThread[THREAD][0].subagent;
+ expect(subagent?.toolCalls[0].args).toEqual({ query: 'turn state' });
+ // The transcript item has no `args` of its own in the snapshot — it is
+ // grafted from the matching call by `callId`, the same way `output` and
+ // `failure` already are.
+ const item = subagent?.transcript?.[0];
+ expect(item?.kind).toBe('tool');
+ expect(item && item.kind === 'tool' ? item.args : undefined).toEqual({ query: 'turn state' });
+ });
+
+ it('leaves the arguments undefined for a snapshot written before the field existed', () => {
+ const snapshot = settledSnapshot(undefined);
+ delete snapshot.toolTimeline[0].subagent!.toolCalls[0].args;
+ const state = reducer(undefined, hydrateRuntimeFromSnapshot({ snapshot }));
+ const subagent = state.toolTimelineByThread[THREAD][0].subagent;
+ expect(subagent?.toolCalls[0].args).toBeUndefined();
+ // The rest of the row still rehydrates — a legacy snapshot must not be
+ // rejected, only rendered without an input block.
+ expect(subagent?.toolCalls[0].result).toBe('3 hits');
+ });
+});
diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.ts
index 2656796850..660d930c78 100644
--- a/app/src/store/chatRuntimeSlice.ts
+++ b/app/src/store/chatRuntimeSlice.ts
@@ -810,6 +810,10 @@ function subagentToolCallFromPersisted(call: PersistedSubagentToolCall): Subagen
outputChars: call.outputChars,
displayName: call.displayName,
detail: call.detail,
+ // Carry the persisted arguments so a rehydrated child row keeps its input
+ // block, and a degraded generic `tool` name can still derive its search
+ // label from `query` (#5987).
+ args: call.args,
// Carry the persisted failure explanation across the round-trip (#4459).
failure: parseToolFailure(call.failure),
// Carry the persisted (capped) result text so a rehydrated child row can
diff --git a/app/src/types/turnState.ts b/app/src/types/turnState.ts
index 92ea84bfa9..cdef1367cc 100644
--- a/app/src/types/turnState.ts
+++ b/app/src/types/turnState.ts
@@ -63,6 +63,15 @@ export interface PersistedSubagentToolCall {
displayName?: string;
/** Server-computed contextual detail (path / recipient / query). */
detail?: string;
+ /** Size-capped arguments the child invoked the tool with, so a rehydrated
+ * row shows what the sub-agent did and not just which tool it reached for
+ * (#5987). Mirrors the live `subagent_tool_call` event's `args`; an
+ * oversized payload arrives as a truncated string. Absent when the child's
+ * arguments were never materialised and on snapshots written before this
+ * field. Deliberately not repeated on {@link PersistedSubagentTranscriptItem}
+ * — like `output` and `failure` it is grafted onto the transcript item by
+ * `callId` in `subagentActivityFromPersisted`. */
+ args?: unknown;
/** Plain-language failure explanation for a FAILED child call (#4459).
* Mirrors the parent {@link PersistedToolTimelineEntry.failure}; absent on
* successful rows and on snapshots written before this field. */
diff --git a/src/openhuman/threads/turn_state/mirror_part_01.rs b/src/openhuman/threads/turn_state/mirror_part_01.rs
index 3a54a1deff..b5cd943002 100644
--- a/src/openhuman/threads/turn_state/mirror_part_01.rs
+++ b/src/openhuman/threads/turn_state/mirror_part_01.rs
@@ -30,6 +30,13 @@ const MAX_PERSISTED_TRANSCRIPT_ITEM: usize = 16 * 1024;
/// Marker appended once when a transcript prose item is truncated at its cap.
const TRANSCRIPT_TRUNCATION_MARKER: &str = "\n…[truncated]";
+/// Upper bound on the child tool arguments persisted per sub-agent call.
+/// Sized like [`MAX_PERSISTED_TRANSCRIPT_ITEM`] rather than the looser
+/// [`MAX_PERSISTED_TOOL_OUTPUT`]: a sub-agent turn accumulates many child
+/// calls and the snapshot file is rewritten in full at every tool boundary,
+/// so one `write_file`-shaped payload must not dominate every rewrite.
+const MAX_PERSISTED_TOOL_ARGS: usize = 16 * 1024;
+
/// Append `delta` to a coalescing transcript prose buffer, enforcing
/// [`MAX_PERSISTED_TRANSCRIPT_ITEM`] on a char boundary and stamping a one-time
/// truncation marker the first time the cap is hit. Once at the cap, further
@@ -82,6 +89,36 @@ fn cap_persisted_output(output: &str) -> Option<String> {
))
}
+/// Cap `arguments` for snapshot persistence. Returns `None` for a null
+/// payload — the observability bridge emits `Value::Null` on the paths where
+/// the child's arguments were never materialised, and a null would otherwise
+/// persist as a meaningless "Input: null" row.
+///
+/// A payload that serialises within [`MAX_PERSISTED_TOOL_ARGS`] is kept
+/// verbatim, so the rehydrated row renders the same structured input the live
+/// row did. An oversized one degrades to a truncated *string* carrying the
+/// same marker shape [`cap_persisted_output`] uses: the prefix is what the
+/// reader actually wants ("what did it search for?"), and a string is honest
+/// about no longer being parseable JSON.
+fn cap_persisted_args(arguments: &serde_json::Value) -> Option<serde_json::Value> {
+ if arguments.is_null() {
+ return None;
+ }
+ let rendered = arguments.to_string();
+ if rendered.len() <= MAX_PERSISTED_TOOL_ARGS {
+ return Some(arguments.clone());
+ }
+ let mut end = MAX_PERSISTED_TOOL_ARGS.saturating_sub(TRUNCATION_MARKER_BUDGET);
+ while end > 0 && !rendered.is_char_boundary(end) {
+ end -= 1;
+ }
+ let omitted = rendered.len() - end;
+ Some(serde_json::Value::String(format!(
+ "{}\n…[truncated {omitted} bytes of tool arguments]",
+ &rendered[..end]
+ )))
+}
+
/// In-process cursor that keeps the authoritative [`TurnState`] in sync
/// with the agent loop and writes it through to a [`TurnStateStore`].
pub struct TurnStateMirror {
diff --git a/src/openhuman/threads/turn_state/mirror_part_02.rs b/src/openhuman/threads/turn_state/mirror_part_02.rs
index be29db4231..c6019255b4 100644
--- a/src/openhuman/threads/turn_state/mirror_part_02.rs
+++ b/src/openhuman/threads/turn_state/mirror_part_02.rs
@@ -235,6 +235,7 @@ impl TurnStateMirror {
task_id,
call_id,
tool_name,
+ arguments,
iteration,
display_label,
display_detail,
@@ -251,6 +252,10 @@ impl TurnStateMirror {
output_chars: None,
display_name: display_label.clone(),
detail: display_detail.clone(),
+ // The live socket event already carries these; the
+ // snapshot has to as well or a reloaded child row
+ // comes back without its input (#5987).
+ args: cap_persisted_args(arguments),
failure: None,
output: None,
});
diff --git a/src/openhuman/threads/turn_state/mirror_tests_part_02_tests.rs b/src/openhuman/threads/turn_state/mirror_tests_part_02_tests.rs
index d6b5606bab..f527044b00 100644
--- a/src/openhuman/threads/turn_state/mirror_tests_part_02_tests.rs
+++ b/src/openhuman/threads/turn_state/mirror_tests_part_02_tests.rs
@@ -209,3 +209,172 @@ fn finish_first_turn_without_transcript_is_noop() {
assert_eq!(listed.lifecycle, TurnLifecycle::Interrupted);
assert_eq!(listed.streaming_text, "orphan partial");
}
+
+/// A sub-agent's child tool call must persist the arguments it was invoked
+/// with. Live, the `subagent_tool_call` socket event carries them; before
+/// #5987 the snapshot did not, so a reloaded child row came back with no
+/// "Input" block at all.
+#[test]
+fn subagent_tool_call_persists_its_arguments() {
+ let (_d, mut m) = fresh("t");
+ m.observe(&AgentProgress::SubagentSpawned {
+ agent_id: "researcher".into(),
+ task_id: "sub-1".into(),
+ mode: "typed".into(),
+ dedicated_thread: false,
+ prompt_chars: 10,
+ prompt: String::new(),
+ worker_thread_id: None,
+ display_name: Some("Researcher".into()),
+ });
+ m.observe(&AgentProgress::SubagentToolCallStarted {
+ agent_id: "researcher".into(),
+ task_id: "sub-1".into(),
+ call_id: "c1".into(),
+ tool_name: "tool".into(),
+ arguments: serde_json::json!({ "query": "openhuman turn state" }),
+ iteration: 1,
+ display_label: None,
+ display_detail: None,
+ });
+
+ let activity = m.snapshot().tool_timeline[0]
+ .subagent
+ .as_ref()
+ .expect("activity")
+ .clone();
+ assert_eq!(
+ activity.tool_calls[0].args,
+ Some(serde_json::json!({ "query": "openhuman turn state" })),
+ "child arguments must reach the snapshot verbatim"
+ );
+
+ // The payload is stored exactly once. `output` and `failure` already live
+ // only on the call row and are grafted onto the transcript item by
+ // `call_id` on the frontend; `args` deliberately follows them rather than
+ // duplicating up to 16 KiB into every full-file snapshot rewrite.
+ let json = serde_json::to_string(m.snapshot()).expect("serialize");
+ assert_eq!(
+ json.matches("\"args\"").count(),
+ 1,
+ "arguments must be persisted once, on the call row only"
+ );
+}
+
+/// The observability bridge emits `Value::Null` on the paths where a child's
+/// arguments were never materialised. Persisting that would render a
+/// meaningless "Input: null" row, so it must serialize away entirely.
+#[test]
+fn null_child_arguments_are_not_persisted() {
+ let (_d, mut m) = fresh("t");
+ m.observe(&AgentProgress::SubagentSpawned {
+ agent_id: "researcher".into(),
+ task_id: "sub-1".into(),
+ mode: "typed".into(),
+ dedicated_thread: false,
+ prompt_chars: 10,
+ prompt: String::new(),
+ worker_thread_id: None,
+ display_name: Some("Researcher".into()),
+ });
+ m.observe(&AgentProgress::SubagentToolCallStarted {
+ agent_id: "researcher".into(),
+ task_id: "sub-1".into(),
+ call_id: "c1".into(),
+ tool_name: "search".into(),
+ arguments: serde_json::Value::Null,
+ iteration: 1,
+ display_label: Some("Searching".into()),
+ display_detail: None,
+ });
+
+ let activity = m.snapshot().tool_timeline[0]
+ .subagent
+ .as_ref()
+ .expect("activity")
+ .clone();
+ assert_eq!(activity.tool_calls[0].args, None);
+ let json = serde_json::to_string(m.snapshot()).expect("serialize");
+ assert!(
+ !json.contains("\"args\""),
+ "a null payload must not occupy a field in the snapshot"
+ );
+}
+
+/// The snapshot file is rewritten in full at every tool boundary, so one
+/// `write_file`-shaped payload must not dominate it. An oversized argument
+/// blob degrades to a truncated string carrying the same marker shape a
+/// truncated tool output uses.
+#[test]
+fn oversized_child_arguments_are_truncated() {
+ let (_d, mut m) = fresh("t");
+ m.observe(&AgentProgress::SubagentSpawned {
+ agent_id: "writer".into(),
+ task_id: "sub-1".into(),
+ mode: "typed".into(),
+ dedicated_thread: false,
+ prompt_chars: 10,
+ prompt: String::new(),
+ worker_thread_id: None,
+ display_name: Some("Writer".into()),
+ });
+ let huge = "x".repeat(32 * 1024);
+ let arguments = serde_json::json!({ "path": "notes.md", "content": huge });
+ m.observe(&AgentProgress::SubagentToolCallStarted {
+ agent_id: "writer".into(),
+ task_id: "sub-1".into(),
+ call_id: "c1".into(),
+ tool_name: "write_file".into(),
+ arguments: arguments.clone(),
+ iteration: 1,
+ display_label: Some("Writing file".into()),
+ display_detail: None,
+ });
+
+ let activity = m.snapshot().tool_timeline[0]
+ .subagent
+ .as_ref()
+ .expect("activity")
+ .clone();
+ let args = activity.tool_calls[0].args.clone().expect("args persisted");
+ let text = args.as_str().expect("oversized args degrade to a string");
+ assert!(
+ text.len() <= 16 * 1024,
+ "truncated arguments must stay within the cap, got {}",
+ text.len()
+ );
+ assert!(
+ text.contains("…[truncated"),
+ "truncation must be visible to the reader"
+ );
+ // What is kept is a genuine prefix of the real arguments, not a summary —
+ // that leading slice is what tells the reader what the call was doing.
+ // Asserted against the serialized head rather than a specific key so the
+ // test does not depend on JSON object ordering.
+ let kept = text.split('\n').next().expect("prefix line");
+ assert!(
+ arguments.to_string().starts_with(kept),
+ "the persisted text must be the head of the real arguments"
+ );
+}
+
+/// `args` is additive: a snapshot written before #5987 has no such field and
+/// must still deserialize, leaving the row without an input rather than
+/// failing the whole thread's rehydration.
+#[test]
+fn legacy_subagent_tool_call_without_args_deserializes() {
+ let legacy = r#"{
+ "callId": "c1",
+ "toolName": "search",
+ "status": "success",
+ "iteration": 1,
+ "elapsedMs": 12,
+ "outputChars": 6,
+ "displayName": "Searching",
+ "output": "3 hits"
+ }"#;
+ let call: SubagentToolCall = serde_json::from_str(legacy).expect("legacy row must load");
+ assert_eq!(call.args, None);
+ assert_eq!(call.call_id, "c1");
+ assert_eq!(call.output.as_deref(), Some("3 hits"));
+}
diff --git a/src/openhuman/threads/turn_state/store_tests.rs b/src/openhuman/threads/turn_state/store_tests.rs
index 6f48527786..2ff2777ca3 100644
--- a/src/openhuman/threads/turn_state/store_tests.rs
+++ b/src/openhuman/threads/turn_state/store_tests.rs
@@ -86,6 +86,7 @@ fn roundtrips_subagent_interleaved_transcript_with_full_fidelity() {
output_chars: Some(6),
display_name: Some("Searching".into()),
detail: None,
+ args: Some(serde_json::json!({ "query": "rust serde" })),
failure: None,
output: Some("3 hits".into()),
}],
@@ -151,6 +152,15 @@ fn roundtrips_subagent_interleaved_transcript_with_full_fidelity() {
activity.transcript[2],
SubagentTranscriptItem::Text { .. }
));
+ // The child call's arguments are what the reloaded row's "Input" block
+ // renders from. Spot-checked by value (like the interleaving above) so a
+ // regression names the field instead of failing as one opaque struct
+ // inequality (#5987).
+ assert_eq!(
+ activity.tool_calls[0].args,
+ Some(serde_json::json!({ "query": "rust serde" })),
+ "child tool arguments must survive the disk round-trip"
+ );
assert_eq!(loaded.tool_timeline[0].seq, Some(3));
}
diff --git a/src/openhuman/threads/turn_state/types.rs b/src/openhuman/threads/turn_state/types.rs
index df3ef1fe9c..02b442bf3e 100644
--- a/src/openhuman/threads/turn_state/types.rs
+++ b/src/openhuman/threads/turn_state/types.rs
@@ -195,6 +195,19 @@ pub struct SubagentToolCall {
/// Server-computed contextual detail (e.g. the path / recipient).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub detail: Option<String>,
+ /// Size-capped arguments the child invoked the tool with, so a rehydrated
+ /// row shows *what* the sub-agent did and not just which tool it reached
+ /// for (#5987). Mirrors the live `subagent_tool_call` event's `args`
+ /// verbatim when it fits the cap; an oversized payload degrades to a
+ /// truncated string. `None` when the child's arguments were never
+ /// materialised and on legacy snapshots.
+ ///
+ /// Deliberately absent from [`SubagentTranscriptItem::Tool`]: like
+ /// `output` and `failure`, this is a heavy payload that lives once on the
+ /// call row, and the frontend grafts it onto the matching transcript item
+ /// by `call_id` when it rehydrates.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub args: Option<serde_json::Value>,
/// Plain-language failure explanation for a FAILED child call, so a
/// sub-agent's failed row carries the same "why + next" copy as a
/// main-agent row and it survives a snapshot round-trip (#4459). `None` on
diff --git a/tests/raw_coverage/memory_raw_coverage_e2e.rs b/tests/raw_coverage/memory_raw_coverage_e2e.rs
index 99e4f1a15f..4c66f97f55 100644
--- a/tests/raw_coverage/memory_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/memory_raw_coverage_e2e.rs
@@ -632,6 +632,7 @@ fn threads_turn_state_store_skips_corrupt_entries_and_marks_interrupted() {
display_name: None,
output: None,
detail: None,
+ args: None,
failure: None,
}],
transcript: vec![],
diff --git a/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs b/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
index 6eddb00955..854404c650 100644
--- a/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
@@ -3388,6 +3388,7 @@ fn turn_state_store_persists_lists_marks_and_clears_snapshots() {
display_name: None,
output: None,
detail: None,
+ args: None,
failure: None,
}],
transcript: vec![],