anomalyco / anomalyco/opencode

Forked parent session opens original child session, so Back returns to original parent

Open
#42,341 0 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Aug 13, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Summary

When a session with a task/subagent child is forked, the forked parent still points at the original child session. Entering that child from the fork and clicking "back to parent" returns to the original parent session instead of the forked parent.

Reproduction

  1. Start a parent session S1.
  2. Have it call the task tool / a subagent, producing child session C.
  3. Fork S1, producing S2.
  4. In S2, click/open the task's child session.
  5. In the child session, click the UI action to return to the parent/main session.

Expected behavior

The child reached from S2 should return to S2, or the fork should create/repoint a fork-local child session whose parentID is S2.

Actual behavior

The child returns to S1.

Root cause from code reading

The child session's parent link is written only when the task creates the subagent session:

  • packages/opencode/src/tool/task.ts: sessions.create({ parentID: ctx.sessionID, ... })

So if the task ran in S1, child C permanently has parentID = S1.

Session fork then copies only messages/parts into a new root session:

  • packages/opencode/src/session/session.ts: fork() creates a new session without a parentID, then copies messages and parts.
  • It does not clone child sessions.
  • It does not rewrite copied task part metadata such as metadata.sessionId to point at a fork-local child.

The web UI's parent navigation reads the stored child parent directly:

  • packages/app/src/pages/session.tsx: openParent navigates to info()?.parentID.
  • packages/app/src/pages/session/composer/session-composer-region-controller.ts: child/back state also comes from sync().session.get(id)?.parentID.

Because the child reached from the fork is still the original child C, C.parentID is still S1, so Back navigates to S1.

Notes

This is related to session hierarchy/forking, but I did not find an existing issue for this exact fork-local child lineage bug. Related but different issues/PRs:

  • #16639 requests allowing parentID when forking sessions.
  • #15972 / #15993 / #23365 cover TUI nested subagent navigation, not web/app forked-parent child lineage.

A UI-only history workaround would make Back appear to work for one navigation path, but the underlying data would still be inconsistent after refresh/deep-link/multiple entry points. The durable fix seems to be in Session.fork: clone/re-fork task child sessions reachable from copied task parts and rewrite the copied task part metadata to point at those fork-local children with parentID = forkedSession.id.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.