Repository navigation
fix(core): include a running tool's progress metadata when reading messages - #64929
Conversation
…ssages User decisions: - Fix reloads losing a running tool's progress metadata (F1) by overlaying it on message reads
User decisions: - Address review issues on the F1 fix
There was a problem hiding this comment.
The fix works and I found nothing that blocks it. I reproduced the problem on the base with opencode-drive and the simulated model: while an execute call running tools.shell("sleep 12") was still going, reading the session's messages returned metadata: {} for the running part. With this PR the same read returns { toolCalls: [{ tool: "shell", status: "running", … }], background: true }. The new test and the nearby store, execution and background tests pass, and typecheck:tsc in core is clean.
The map is cleared on every way a call settles (success, failure and bulk failure), and the overlay only touches parts that are still running, so settled parts are unchanged.
Public API: no endpoints, fields or events are added or removed. Message reads now return the same progress metadata for a running tool part that the session.tool.progress event already carries (backwards compatible).
There was a problem hiding this comment.
The new commit is a refactor and doesn't change behaviour. The module now exports itself as LiveToolMetadata, overlay uses the real SessionMessage types instead of loose casts, and the test builds real SessionMessage.Assistant values. I re-ran the mid-call read with opencode-drive and the simulated model: the running execute part still comes back with its toolCalls and background metadata. The tests and typecheck:tsc in core pass. Public API: unchanged. No new concerns.
Issue for this PR
Closes #
Type of change
What does this PR do?
A running tool call's progress metadata (
context.progress) only reaches clients through the ephemeralsession.tool.progressevent; the saved part gets metadata when the call settles. So a client that opens or reloads a session mid-call readsmetadata: {}fromGET /api/session/:id/messageand misses e.g. a foregroundexecute'sbackground/toolCalls(no Ctrl+B offer, inner shells shown as background shells) or a running subagent'ssessionID.The LLM event publisher now also records the latest progress in a small process-local map (
session/runner/live-tool-metadata.ts), cleared when the call settles or fails.SessionStoremessage reads (messages,messagesWithRefs,message,messageWithRefs) overlay it onto tool parts that are stillrunning. No new durable events or DB writes; settled parts are untouched.How did you verify your code works?
packages/core/test/session-live-tool-metadata.test.ts;bun run typecheck:tscin core.opencode serve(simulated LLM): a foregroundexecuterunningtools.shellnow reads back as{"status":"running","metadata":{"toolCalls":[{"tool":"shell","status":"running",...}],"background":true}}(was{}).Screenshots / recordings
N/A
Checklist