Repository navigation
Conversation
There was a problem hiding this comment.
Reverting a parent prompt now undoes a background subagent's edit. I reproduced the bug from #63884 on the base with opencode-drive and a simulated model: a background child appends to file.txt, then Revert from /timeline leaves the file unchanged. With this PR the same Revert lists M file.txt -1 and restores the file. The touched tests (17) and typecheck:tsc in packages/core pass. When only the parent's own steps are involved, revert behaves as before.
Public API: the subagent tool result metadata gains a promptMessageID field (additive, backwards compatible). Nothing else outside core changes.
#64359 fixes the same issue. This PR also covers the direct-child-prompt case that its author reported there, so maintainers will want to pick one.
My main ask is about the new test. It's one ~160-line scenario covering seven cases and is hard to follow. Its legacy case relies on a Bun.sleep(10) timing window (see inline).
Related: #54026
| { timeout: 15_000 }, | ||
| ) | ||
|
|
||
| it.live( |
There was a problem hiding this comment.
This one test runs about 160 lines and chains seven scenarios (background edit, continued child, direct child prompt, same-path sibling edits, legacy follow-up, nested child, revert/clear) through shared files and state. When it fails, it's hard to tell which behaviour broke. Could you split it into a few small tests, one per behaviour, or cut it down to the core cases? The background edit, the continued child with a direct child prompt in between, and the nested child would be enough.
| }) | ||
| }), | ||
| ) | ||
| yield* Effect.promise(() => Bun.sleep(10)) |
There was a problem hiding this comment.
The legacy case depends on wall-clock windows (time.ran/time.completed against the event and message created timestamps), and this Bun.sleep(10) is what separates them. That is likely to be flaky on a slow CI machine. Can it be made deterministic, e.g. by setting the timestamps explicitly, or dropped if the legacy path is covered elsewhere?


Issue for this PR
Closes #63884.
Type of change
What does this PR do?
Reverting a parent prompt now follows the background subagent prompts that were delegated by its tool calls, including nested subagents. The subagent result records the admitted prompt ID so a continued child session is bounded to the prompt that belongs to that call.
For older results without a prompt ID, the lookup uses the durable inbox enqueue event. This covers follow-ups queued while the tool runs and delivered after it returns.
The restore plan keeps edits from direct child prompts and other sessions. If another writer changes the same path between delegated steps, it restores that intervening version; if another writer changes it afterward, the newer version stays on disk.
How did you verify your code works?
bun run script/test.ts test/session-revert.test.ts test/tool-subagent.test.ts: 17 passed, 0 failed.bun run typecheck:tscinpackages/core: passed.git diff --check: passed.Screenshots / recordings
Core session logic only.
Checklist
Added by the opencode bot (AI-generated).
Related: #54026
Public API: adds
promptMessageIDto the subagent tool result metadata (backwards compatible)