Share stored JSON payloads across code mode cells with Arc (#47036)

## Why

Creating a cell deep-copies every stored JSON value, including values the cell never loads. Storing a value also duplicates its payload between the cell's local state and pending writes.

## What changed

Use `Arc<JsonValue>` throughout the session store, cell runtime, and completion writes to share immutable payloads. Keep a separate map snapshot for each cell so later commits cannot change its view of stored values.

GitOrigin-RevId: 4535f0f2ed0c8f8cbfb8d24cf1cb44cbc74472b5
This commit is contained in:
Charlie Marsh
2026-09-21 13:57:22 +00:00
committed by copyberry
parent 3ead673946
commit dd6eff3954
8 changed files with 23 additions and 16 deletions
@@ -43,7 +43,9 @@ pub(crate) struct SessionRuntime {
}
struct Inner {
stored_values: Mutex<HashMap<String, JsonValue>>,
// Cells snapshot the keys while sharing immutable payloads, so later commits cannot
// change an existing cell's view and unused values do not need to be copied.
stored_values: Mutex<HashMap<String, Arc<JsonValue>>>,
cells: Mutex<HashMap<CellId, CellHandle>>,
cell_tasks: TaskTracker,
shutdown_token: CancellationToken,
@@ -277,7 +279,7 @@ impl<D: SessionRuntimeDelegate> CellHost for RuntimeCellHost<D> {
async fn commit_completion(
&self,
stored_value_writes: HashMap<String, JsonValue>,
stored_value_writes: HashMap<String, Arc<JsonValue>>,
event: CellEvent,
pending_initial_yield_items: Option<Vec<OutputItem>>,
cell_state: Arc<CellState>,
@@ -114,7 +114,7 @@ async fn termination_rejects_a_waiting_store_commit_before_the_next_cell_can_loa
let commit = host.commit_completion(
HashMap::from([(
"candidate".to_string(),
JsonValue::String("lost".to_string()),
Arc::new(JsonValue::String("lost".to_string())),
)]),
completion.clone(),
/*pending_initial_yield_items*/ None,