anomalyco / anomalyco/opencode

shell.created event never includes pid (publishes the pre-spawn info)

Open Beginner friendly
#43,078 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Version

opencode2 v0.0.0-beta-17519 (branch beta, commit 6106cb6)

Summary

The shell.created event publishes the pre-spawn Info object, so pid is always undefined for subscribers. The POST /api/shell HTTP response does include the pid, so the omission only affects event consumers.

Where

In packages/core/src/shell.ts:

  • L205-214: info is built before the spawn, with no pid.
  • L236-239: after the spawn, the pid is attached to a copy kept in session.info:
    info: produce(info, (draft) => { draft.pid = handle.pid }).
  • L331: the event is published with the original object, discarding the copy that carries the pid:
    yield* bus.publish(Shell.Event.Created, { info }).

pid is optional in the schema (packages/schema/src/shell.ts:36-49), so this is not a type error — the field is simply always absent on the event.

Impact

A plugin cannot correlate a shell with an OS process from events alone. ctx.shell exposes only hook("create.before") (packages/plugin/src/promise/shell.ts:15-17), and the plugin Context (packages/plugin/src/promise/plugin.ts:17-33) has no shell client or server URL, so there is no in-process way to fetch the pid afterwards.

The workaround is scanning ps for a child of the server process that is its own process-group leader, matching start time and command — racy, and it breaks whenever the spawner is not the plugin's own process.

Suggested fix

Publish the post-spawn info. session is already in scope — it is used on the very next line.

-              yield* bus.publish(Shell.Event.Created, { info })
+              yield* bus.publish(Shell.Event.Created, { info: session.info })
Repro
  1. Subscribe to events (in-process plugin via ctx.event.subscribe(), or the event stream).
  2. POST /api/shell with any long-running command.
  3. The HTTP response contains "pid": <n>; the shell.created event for the same shell id has no pid.

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.

Research direction

Start in packages/core/src/shell.ts at the post-spawn update around lines 236-239 and the shell.created publish around line 331. Read packages/schema/src/shell.ts to confirm pid is optional, then verify that the event publishes the post-spawn session info. Done means shell.created includes the same pid as the POST /api/shell response.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.