Recorder saves thenable and cross-realm Promise tool results as synchronous empty objects
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- node.js, typescript
- Domain
- devtools, testing-qa
Research direction
Start at the createRecorder().tool() entry point and trace how tool results are classified, recorded, replayed, and tracked as in flight. Reproduce the listed native Promise, thenable, cross-realm Promise, sync, rejection, and overlap cases, then add controls for each behavior. Done means settled values and serialized rejections replay asynchronously, sync behavior is preserved, and concurrency markers remain correct; note that linked pull request #194 is already open.
Written by the indexing model from the issue text.
Description
Problem
On next (4c19918ea42e47d0e180a511961dd55c43aa614f), createRecorder().tool() misclassifies a custom thenable or a Promise from another realm as synchronous because runLive checks instanceof Promise.
Awaiting the live tool yields its result, but the recording saves {} with sync: true. A JSON round-trip followed by replay then yields {} instead of the original result. The same assumption in async tracking means overlapping tools can also lose their concurrent marker.
Reproduction
Node 24.22.1 and pinned pnpm 10.28.2. This was reproduced against the complete built @statelyai/agent/testing entry after a frozen-lockfile install and package build; the existing 30 equivalence tests pass on the unchanged base. No model calls, keys or network services are involved.
import { createRecorder } from '@statelyai/agent/testing';
import vm from 'node:vm';
for (const [name, fn] of [
['native', () => Promise.resolve({answer:42})],
['thenable', () => ({then(resolve) {resolve({answer:42});}})],
['other-realm-promise', () => vm.runInNewContext('Promise.resolve({answer:42})')]
]) {
const record = createRecorder();
const first = await record.tool('lookup', fn)();
const recording = JSON.parse(JSON.stringify(record.recording));
const replay = createRecorder({replay: recording});
const second = await replay.tool('lookup', () => { throw new Error('must not execute'); })();
console.log(JSON.stringify({name, first, second, recorded:recording.effects}));
}
Observed:
[
{
"name": "native",
"first": {
"answer": 42
},
"second": {
"answer": 42
},
"recorded": [
{
"kind": "tool",
"name": "lookup",
"step": 0,
"input": [],
"output": {
"answer": 42
}
}
]
},
{
"name": "thenable",
"first": {
"answer": 42
},
"second": {},
"recorded": [
{
"kind": "tool",
"name": "lookup",
"step": 0,
"input": [],
"sync": true,
"output": {}
}
]
},
{
"name": "other-realm-promise",
"first": {
"answer": 42
},
"second": {},
"recorded": [
{
"kind": "tool",
"name": "lookup",
"step": 0,
"input": [],
"sync": true,
"output": {}
}
]
}
]
The native Promise control replays {answer:42}, while both other awaited tools replay {}. The module's record/replay contract says tools are answered from their recorded results without repeating side effects.
Expected scope
Record settled values and serialized rejections from promise-like tool results, including another realm's Promise, and replay those asynchronously. Preserve ordinary synchronous return/throw behavior and the existing error serialization rules. Count an asynchronous call as in-flight until settlement so overlap and later sequential calls retain correct markers. Include resolve/reject, native Promise, ordinary sync, and concurrency controls; do not make all tools async to solve the problem.
This concerns tool result classification and tracking; model stream-iteration errors are a separate behavior and not part of this proposal.
- Dominant language
- TypeScript
- Stars
- 508
- Forks
- 29
- Avg merge
- 8h 54m
- Merged PRs (30d)
- 74
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from statelyai/agent
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Trace JSON serialization loses own data keys and cross-realm Error detailsPossibly taken @jihtsan claimed this 33 days ago. Open
Difficulty 3/5 Half a day Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
Recorder replays a failed model stream as a successful partial streamPossibly taken @jihtsan claimed this 34 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
statelyai/agent#84 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
statelyai/agent#65 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zabuton-app/meguri#875 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
iruzen-dono/workless#117 ·
Maintainers usually reply within 1 day
-
area:api area:web wave wave:trivial
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vetro-protocol/vetro-monorepo#1321 ·
Maintainers usually reply within 1 day