Skip to content

Decouple parentID side effects (add isWorker flag) #222

Description

@OpenCodeEngineer

Parent: #217 (delta 2 of 4).
Prerequisite for #217 delta 1 (worker_ tools).*

Problem

`parentID` on `Session.Info` currently entangles three behaviors that should be independent:

  1. Default session listing filters with `roots: true` — children are hidden from the UI session list.
    • `packages/app/src/context/global-sync/session-load.ts:5`
    • `packages/opencode/src/session/session.ts:842` (`listByProject` applies `isNull(parent_id)` when `roots: true`)
  2. Removing a session cascade-deletes its children.
    • `packages/opencode/src/session/session.ts:561-563`
  3. Default title is auto-prefixed `"Child session - "`.
    • `packages/opencode/src/session/session.ts:511`

This is correct for `task`-tool subagents but blocks the manager/worker model from #217, where a worker session needs to:

  • be visible in the session list,
  • survive the manager being deleted/archived,
  • have a meaningful title.

Proposed change

Add an opt-out flag on `Session.Info`. Strawman:

```ts
// session/schema.ts ~line 186
isWorker: Schema.optional(Schema.Boolean) // or: detachedChild
```

Behavioral semantics when `isWorker === true`:

Call site Current behavior New behavior
`listByProject({ roots: true })` (`session.ts:842`) excluded included (treat as a root for listing)
`Session.remove(parent)` cascade (`session.ts:561-563`) child deleted child preserved, optionally re-parented or orphaned
Title generation (`session.ts:511`) `"Child session - …"` use provided title, no prefix

`Session.create` accepts the new flag; `task` tool keeps current behavior (does not set the flag). Worker spawn (see #217 delta 1) sets the flag.

Acceptance criteria

  • `isWorker` (or chosen name) added to schema + Drizzle table.
  • `listByProject` returns isWorker rows even when `roots: true`.
  • `Session.remove` does not cascade-delete isWorker children.
  • Default title generation skips the child prefix for isWorker sessions.
  • Migration handles existing rows (default `false`).
  • Test: create manager → create isWorker child → remove manager → assert worker still exists and is listed.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestinfraInfrastructure, CI, tooling, or release workpriority:mediumMedium priority

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions