Skip to content

agentop configure codex/opencode can wait on itself when an agent runs it #1530

Open

Description

@Alan-Cha

Problem

agentop configure codex enable|disable (#1526) and agentop configure opencode enable|disable restart the agent's background service so it picks up the new proxy settings. If the agent itself runs that command — you ask Codex or OpenCode to "run agentop configure codex enable" — the restart targets the service handling the very turn that is running the command.

Codex. From Codex's source (0.163.0–0.164.0); not reproduced:

  1. The turn runs agentop configure codex enable and can't finish until agentop does.
  2. agentop runs codex app-server daemon restart. The daemon drains running turns before stopping, for up to its shutdown grace (60s by default, configurable to 5 minutes).
  3. The only running turn is the one waiting on agentop, so the drain waits out the whole grace.
  4. Then the daemon is force-stopped. agentop runs inside that turn and may be killed with it, before the new daemon starts. Codex can be left with no daemon until someone restarts it by hand.

OpenCode. Same shape: agentop runs opencode service restart on the service handling the session that asked. Not checked: whether OpenCode's restart waits for that session or cuts it off.

Claude Code has no background service, so there is nothing to restart and no exposure.

Today agentop has no check for being run by an agent in either integration.

Raised in

Review of #1526 (huang195), from Codex's source. Taken out of that PR so both integrations are handled the same way.

Possible approach

Detect that agentop is running as an agent's tool call. If it is, still write the settings but skip the restart, and print the restart command to run from a terminal.

  • Codex: sets CODEX_THREAD_ID in the environment of every command it runs for a turn (codex-rs/core/src/exec_env.rs). This is a one-line check.
  • OpenCode: the equivalent marker still needs to be found.

To do

  • Reproduce on Codex: ask Codex to run agentop configure codex enable with its daemon running, and record the wait and whether a daemon survives.
  • Find out what opencode service restart does to the session that triggered it.
  • Find a reliable marker for "running inside an OpenCode session".
  • Apply one behaviour to both integrations, with tests, and document it in docs/agents/codex.md and the OpenCode guide.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions