Skip to content

Fix: Settle Codex's app-server and updater the same way in every command - #2029

Merged
Alan-Cha merged 3 commits into
mainfrom
refactor/codex-settle
Nov 24, 2026
Merged

Alan-Cha merged 3 commits into
mainfrom
refactor/codex-settle

Conversation

@Alan-Cha

@Alan-Cha Alan-Cha commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

configure codex enable and disable restarted Codex's background processes with one copy of the code, and agentop uninstall's Codex row (#1781) with another. The two copies had drifted, and review on #1781 and #1783 kept finding gaps in one that the other had already closed. This puts the decisions in one place, and fixes the gaps by taking the stricter rule of the two everywhere.

#1781 and #1783 are merged, and this is now based on main.

What changes for users

  • enable and disable stop the auto-updater also when no app-server runs. codex app-server daemon stop leaves the updater running, and the app-server it starts after its next update inherits its environment, so after disable that app-server went back to Cortex's proxy. uninstall already did this.
  • After a failed restart, enable and disable still report the updater. They used to stop there.
  • An updater whose stop failed is named with its fix, unless its environment shows the routing the file now gives. Before, enable and disable printed only the error when its environment could not be read.
  • Their fix commands match uninstall's: kill <pid> && while kill -0 <pid> …; do sleep 1; done && codex app-server daemon restart, which waits for the updater to exit, and CODEX_HOME=<dir> in front of the restart when the file is not the one the shell's codex reads.
  • uninstall settles Codex's processes also when every key changed since enable (CodeRabbit and clawgenti on Fix: Leave a Codex value changed since enable on disable #1783): it stops an updater, and restarts an app-server, that still has Cortex's proxy. One already off Cortex's proxy is left alone.
  • disable with nothing to remove names an updater still on Cortex's proxy, as it names such an app-server (clawgenti on Fix: Leave a Codex value changed since enable on disable #1783). It still acts on nothing, since nothing was asked. configure codex status does not name the updater, as before this PR (review): its "not enabled" means not all five keys are set, and a file with some of them can still route a new updater to Cortex, so the stop-and-restart line would change nothing.
  • uninstall's consent line says "restarts its app-server" only when it will.
  • A relative record's restart line says to run it from the directory enable ran in (clawgenti on Fix: Unroute Codex in agentop uninstall #1781).

Docs: when uninstall leaves the file unchanged, it does not restart an app-server already off Cortex's proxy, so auto-updates pause until that app-server next restarts. docs/agents/codex.md now says so (review).

Everything else prints what it printed before: the existing tests of this output pass unchanged, except one, updated for the new kill command and the not-stopped line.

How

In codex_daemon.go:

  • checkCodexProcs reads the app-server and the auto-updater and judges each against the routing the file gives (codexProcState): agrees, disagrees, environment unreadable, no proxy to compare with, or, for the updater, not confirmed as the recorded process.
  • codexSettles is the one rule for what to act on: when the file changed, stop the updater and restart a running app-server; when it did not, only a process that disagrees.
  • settleCodexProcs acts by that rule and judges again, adding what failed (not restarted, not stopped, gone).
  • Each command words the result: printCodexProcs for enable and disable, codexProcsLeft for uninstall's Left behind, and reportCodexDaemon, which acts on nothing, for status and the no-op cases.

It replaces finishCodexChange, reportRestartedDaemon, reportRestartedUpdater, noteCodexDaemonOnCortex, uninstall's settleCodex closure, codexDaemonLeft and codexUpdaterLeft. codexRestartCmdFor and codexKillThenRestart move to codex_daemon.go, and shellPathIn is shellPath without a setup run. The non-test code is about 90 lines longer: the copies are gone, and the shared judgement is new.

Test plan

  • New:
    • TestCodexDisable_StopsAnUpdaterWithNoAppServer
    • TestCodexDisable_NamesTheUpdaterWhenTheRestartFails
    • TestCodexDisable_NothingToRemoveNamesAnUpdaterOnCortex
    • TestCodexEnable_PrintsTheRestartForItsCodexHome
    • TestUninstallStopsACodexUpdaterStillOnCortexWhenEveryKeyChanged (stop works, stop fails)
    • TestUninstallLeavesACodexOffCortexAloneWhenEveryKeyChanged
    • the relative restart line in TestUninstallKeepsACodexRecordWithARelativePath
    • TestCodexStatus_NamesNoUpdater (review), which fails with status naming the updater
  • Updated: TestCodexDisable_NamesAnUpdaterThatKeptCortex, for the new kill command and the not-stopped line.
  • Mutation-checked, each failing the tests it should: no stop when the file did not change; a stop only with an app-server running; no updater report after a failed restart; no updater in the no-op report; a bare restart command; a restart when nothing changed and the app-server agrees; a consent line that promises a restart whenever an app-server runs; no relative qualifier; a failed stop never named.
  • After merging main: scripts/dev/go-test-shards.sh -race cmd/agentop (1262 tests) and the subpackages under -race; go vet, also for linux; gofmt
  • Not run against a real Codex: every process here is stubCodexDaemon's fake.

Refs #1365

Assisted-By: Claude (Anthropic AI) [email protected]

configure codex enable and disable restarted Codex's background
processes with one copy of the code, and uninstall's Codex row with
another. The two had drifted:

- enable and disable stopped the auto-updater only when an app-server
  was running. Codex's daemon stop leaves the updater running, and the
  app-server it starts after its next update inherits its environment,
  so after disable that app-server went back to Cortex's proxy.
- After a failed restart, enable and disable said nothing about the
  updater, and for one whose stop failed they printed the error but no
  fix unless its environment showed the old proxy.
- Their fix commands neither waited for a killed updater to exit nor
  named a Codex home other than the shell's, as uninstall's do.
- uninstall skipped the updater when every key had changed since enable
  and no app-server ran (#1783 review), and disable, in the same case,
  named only an app-server still on Cortex's proxy.

Now checkCodexProcs judges both processes against the routing the file
gives, and settleCodexProcs stops and restarts them by one rule
(codexSettles): when the file changed, the updater is stopped and a
running app-server restarted; when it did not, only a process still on
the old routing is. enable and disable word the result as sentences,
uninstall as Left behind lines, and reportCodexDaemon, which acts on
nothing, reads the same judgement. uninstall's consent line promises a
restart only when one will happen.

A relative record's restart line now says to run it from the directory
enable ran in (#1781 review).

Refs #1365

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
@Alan-Cha
Alan-Cha requested a review from a team as a code owner November 20, 2026 18:19
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 35 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd521bf3-0721-4db7-aad3-81a5ef083754
Commits

Reviewing files that changed from the base of the PR and between e2645ea and 949fd43.

Files selected for processing: 7

  • cmd/agentop/cmd_codex.go
  • cmd/agentop/cmd_uninstall.go
  • cmd/agentop/cmd_uninstall_test.go
  • cmd/agentop/codex_daemon.go
  • cmd/agentop/codex_daemon_test.go
  • cmd/agentop/setup_runner.go
  • docs/agents/codex.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 20, 2026
Base automatically changed from fix/codex-disable-keeps-edits to main November 20, 2026 18:21

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Moving the stop/restart decisions into checkCodexProcs / codexSettles / settleCodexProcs works, and the stricter rule now applies everywhere. I checked each user-facing claim against the code and the tests: the updater is stopped with no app-server running, it is still reported after a failed restart, a failed stop is named with codexKillThenRestart, CODEX_HOME= is printed for a non-default home, uninstall settles when every key changed and leaves processes already off Cortex alone, the consent line promises a restart only when one will happen, and a relative record gets its "from that directory" qualifier. I found nothing blocking. There are two small notes inline. The main one is that status also gets the new updater line, which the description doesn't mention, and its advice is wrong for a partly enabled file.

CI note: the Go CI workflow (ci.yaml) has not run on this head. Only PR Verifier, DCO and the label/project jobs ran, probably because the PR was retargeted to main after #1781 and #1783 merged. A push or re-run is needed to get real CI before merge. I ran it locally on this head merged with current main: go vet and gofmt -l are clean, and the -run 'Codex|Uninstall' tests pass. In go test ./... for cmd/agentop and its subpackages, the only failure is TestServiceInstall_RefusesABrokenConfig, which fails the same way on main in my environment (no systemd user bus), so it is unrelated.

Author: Alan-Cha (MEMBER — maintainer)
Areas reviewed: Go (cmd/agentop codex/uninstall/setup_runner), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: verifier/DCO passing; Go CI not triggered on this head (see above)

Comment thread cmd/agentop/codex_daemon.go Outdated
" so its next start will not use Cortex.\n", d.PID, filepath.Join(codexHome, ".env"))
case status:
fmt.Fprintf(stdout, "Codex's background app-server (pid %d) is not using Cortex.\n", d.PID)
if !configured && p.updaterState == codexDisagrees {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: reportCodexDaemon is also what configure codex status calls, so status now prints the updater's kill-and-restart line too. That isn't in the PR's list of changes ("Everything else prints what it printed before"), and the advice is wrong when the file is only partly enabled: on is false, but the file still routes HTTPS_PROXY to Cortex. A probe on this head (enable, delete only the SSL_CERT_FILE line, app-server and updater both on Cortex's proxy) prints:

not fully enabled in …/.env (4 of 5 set)
Codex's background app-server (pid 5613) is using Cortex, but …/.env does not route it there,
  so its next start will not use Cortex.
Codex's auto-updater (pid 5600) still uses Cortex's proxy, and the app-server it starts after an update
  inherits that. Stop it, then restart the app-server so a new updater starts:
    kill 5600 && while kill -0 5600 2>/dev/null; do sleep 1; done && CODEX_HOME=… codex app-server daemon restart

The fresh updater would read the same Cortex proxy from the file, so following that line does nothing. The app-server line above it has the same quirk from before this PR, but this PR adds a command to it. Either gate this on !status so only disable's nothing-to-remove case gets it, or, if status should name the updater, judge it against the proxy the file actually holds and mention it in the description and docs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 949fd43, with your first option: status names no updater again, so it prints what it did before this PR, as the description says. TestCodexStatus_NamesNoUpdater is your probe (enable, delete only SSL_CERT_FILE, app-server and updater both on Cortex's proxy), and it fails without the change. disable with nothing to remove still names the updater (TestCodexDisable_NothingToRemoveNamesAnUpdaterOnCortex). I left the app-server line's quirk for a partly enabled file alone, since it predates this PR.

// file only when they start. When it did not, only one that disagrees is: restarting an
// app-server that already agrees would interrupt its turns for nothing.
func codexSettles(p codexProcs, changed bool) (stop, restart bool) {
stop = changed || p.updaterState == codexDisagrees

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: when the file did not change (uninstall with every key edited), an updater on Cortex's proxy is stopped, but an app-server that agrees is not restarted. That app-server then runs with no auto-updater until its next start. A probe with {pid: 4101, env: offCortex, updaterPID: 4103, updaterEnv: onCortex} gives steps == [stop-updater], and nothing in the output says so. Not restarting is probably the right call, since a restart would interrupt turns, but this comment or the uninstall section of docs/agents/codex.md could say that auto-updates pause until Codex's app-server next restarts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that not restarting is the right call. 949fd43 says so in codexSettles' comment and in the uninstall section of docs/agents/codex.md: an updater stopped beside an app-server that is already off Cortex's proxy is replaced only when that app-server next restarts, so auto-updates pause until then.

Alan Cha added 2 commits November 24, 2026 11:54
#2029 was retargeted from #1783's branch to main when #1783 merged, which
does not rerun CI, and it was 308 commits behind. No conflicts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
…pdates pause

reportCodexDaemon now names an updater still on Cortex's proxy, which is
meant for disable with nothing to remove. status calls it too, so status
started printing the updater's stop-and-restart line, which this PR said
it would not do. The advice was also wrong for a file only partly
enabled: status's "not enabled" means not all five keys are set, and
with HTTPS_PROXY still Cortex's the fresh updater reads the same proxy.
status names no updater again.

When uninstall leaves the file unchanged, it stops an updater on
Cortex's proxy but does not restart an app-server that already agrees,
so as not to interrupt its turns. That app-server then runs without an
updater until it next restarts. The code comment and the uninstall
section of docs/agents/codex.md now say so.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
@Alan-Cha
Alan-Cha requested a review from clawgenti November 24, 2026 18:45

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-review at 949fd43. Both notes from my review of 6713e1f are fixed. reportCodexDaemon now names no updater when called from status (!status gate). I mutation-checked TestCodexStatus_NamesNoUpdater: with the gate removed it fails and prints the kill-and-restart line, and TestCodexDisable_NothingToRemoveNamesAnUpdaterOnCortex still passes, so disable's nothing-to-remove case keeps the updater line. The paused auto-updates after uninstall leaves an app-server alone are now stated in the codexSettles comment and in the uninstall section of docs/agents/codex.md. The other reportCodexDaemon callers (enable's nothing-to-change path, disable's nothing-to-remove path) pass status=false, so their behaviour is unchanged. I found nothing blocking. There is one docs nit inline.

Local verification on this head: gofmt -l is clean, and go vet ./cmd/agentop/... passes, also with GOOS=darwin. go test -run 'Codex|Uninstall' ./cmd/agentop/ passes. In go test ./cmd/agentop/... the only failure is TestServiceInstall_RefusesABrokenConfig, which comes from my environment (no systemd user bus) and not from this PR.

Author: Alan-Cha (MEMBER — maintainer)
Areas reviewed: Go (cmd/agentop codex_daemon/cmd_codex/cmd_uninstall/setup_runner), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed-off: yes
CI status: Go CI runs on this head this time. When I posted, DCO, PR title, pre-commit, CodeQL, lint and dependency review had passed, and Go CI (authbridge agentop) and a few other jobs were still pending. Please make sure the agentop job finishes green (and has no let-through test annotations) before merge.

Comment thread docs/agents/codex.md
restarts the app-server only if they still have Cortex's proxy. An app-server that is
already off Cortex's proxy is not restarted, so its turns are not interrupted. If the
updater was stopped beside it, Codex starts a new one only when that app-server next
restarts, so auto-updates pause until then. It does this for the file enable's record names, wherever `--env`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: With the two new sentences in front of it, "It does this for the file enable's record names…" now reads as if "this" means pausing auto-updates, not uninstall's unrouting as a whole. Consider "Uninstall does this for the file…", or moving the two sentences after the --env/CODEX_HOME sentence. Separately, line 569 is much longer than the paragraph's other lines and could be rewrapped.

@Alan-Cha
Alan-Cha requested a review from clawgenti November 24, 2026 19:19
@Alan-Cha
Alan-Cha merged commit c9a35ad into main Nov 24, 2026
60 of 61 checks passed
@Alan-Cha
Alan-Cha deleted the refactor/codex-settle branch November 24, 2026 21:45
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants