perf: Session.children() iterates over all sessions in the project #5742

Closed
opened 2026-02-16 17:56:19 -05:00 by yindo · 0 comments
Owner

Originally created by @goniz on GitHub (Jan 14, 2026).

Originally assigned to: @thdxr on GitHub.

Issue

The function Session.children() reads ALL the sessions of the project from disk each call to enumerate the child sessions:

export const children = fn(Identifier.schema("session"), async (parentID) => {
    const project = Instance.project
    const result = [] as Session.Info[]
    for (const item of await Storage.list(["session", project.id])) {
      const session = await Storage.read<Info>(item)
      if (session.parentID !== parentID) continue
      result.push(session)
    }
    return result
})

Suggestion:

introduce a field in the session that lists the child sessions to allow for O(1) access to child sessions

Originally created by @goniz on GitHub (Jan 14, 2026). Originally assigned to: @thdxr on GitHub. ### Issue The function [`Session.children()`](https://github.com/anomalyco/opencode/blob/4347a77d89a0b397b2e5aa6165f33313f7fbaf6e/packages/opencode/src/session/index.ts#L312) reads *ALL* the sessions of the project from disk each call to enumerate the child sessions: ```typescript export const children = fn(Identifier.schema("session"), async (parentID) => { const project = Instance.project const result = [] as Session.Info[] for (const item of await Storage.list(["session", project.id])) { const session = await Storage.read<Info>(item) if (session.parentID !== parentID) continue result.push(session) } return result }) ``` ### Suggestion: introduce a field in the session that lists the child sessions to allow for O(1) access to child sessions
yindo added the perf label 2026-02-16 17:56:19 -05:00
yindo closed this issue 2026-02-16 17:56:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5742