Skip to content

fix(core): scope revert to delegated subagent steps - #65370

Open
ZQinyee wants to merge 1 commit into
anomalyco:devfrom
ZQinyee:subagent-revert-direct
Open

ZQinyee wants to merge 1 commit into
anomalyco:devfrom
ZQinyee:subagent-revert-direct

Conversation

@ZQinyee

@ZQinyee ZQinyee commented Nov 21, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #63884.

Type of change

  • Bug fix

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?

  • Added real Git snapshot and SQLite regression coverage for background edits, continued child sessions, direct child prompts, same-path sibling edits, delayed legacy follow-ups, nested subagents, and revert/clear.
  • The delayed legacy case failed before the enqueue-event lookup and passed after it.
  • bun run script/test.ts test/session-revert.test.ts test/tool-subagent.test.ts: 17 passed, 0 failed.
  • bun run typecheck:tsc in packages/core: passed.
  • Prettier and git diff --check: passed.

Screenshots / recordings

Core session logic only.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #54026

Public API: adds promptMessageID to the subagent tool result metadata (backwards compatible)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Before

After

{ timeout: 15_000 },
)

it.live(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parent timeline revert misses file edits from background subagents

1 participant