Repository navigation
Fix: Settle Codex's app-server and updater the same way in every command - #2029
Conversation
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]>
|
Warning Review limit reachedYou'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. View limit details
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. |
clawgenti
left a comment
There was a problem hiding this comment.
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)
| " 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
#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]>
clawgenti
left a comment
There was a problem hiding this comment.
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.
| 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` |
There was a problem hiding this comment.
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.
Summary
configure codex enableanddisablerestarted Codex's background processes with one copy of the code, andagentop 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
enableanddisablestop the auto-updater also when no app-server runs.codex app-server daemon stopleaves the updater running, and the app-server it starts after its next update inherits its environment, so afterdisablethat app-server went back to Cortex's proxy.uninstallalready did this.enableanddisablestill report the updater. They used to stop there.enableanddisableprinted only the error when its environment could not be read.kill <pid> && while kill -0 <pid> …; do sleep 1; done && codex app-server daemon restart, which waits for the updater to exit, andCODEX_HOME=<dir>in front of the restart when the file is not the one the shell'scodexreads.uninstallsettles Codex's processes also when every key changed sinceenable(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.disablewith 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 statusdoes 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.enableran 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.mdnow 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:checkCodexProcsreads 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.codexSettlesis 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.settleCodexProcsacts by that rule and judges again, adding what failed (not restarted, not stopped, gone).printCodexProcsforenableanddisable,codexProcsLeftfor uninstall's Left behind, andreportCodexDaemon, which acts on nothing, forstatusand the no-op cases.It replaces
finishCodexChange,reportRestartedDaemon,reportRestartedUpdater,noteCodexDaemonOnCortex, uninstall'ssettleCodexclosure,codexDaemonLeftandcodexUpdaterLeft.codexRestartCmdForandcodexKillThenRestartmove tocodex_daemon.go, andshellPathInisshellPathwithout a setup run. The non-test code is about 90 lines longer: the copies are gone, and the shared judgement is new.Test plan
TestCodexDisable_StopsAnUpdaterWithNoAppServerTestCodexDisable_NamesTheUpdaterWhenTheRestartFailsTestCodexDisable_NothingToRemoveNamesAnUpdaterOnCortexTestCodexEnable_PrintsTheRestartForItsCodexHomeTestUninstallStopsACodexUpdaterStillOnCortexWhenEveryKeyChanged(stop works, stop fails)TestUninstallLeavesACodexOffCortexAloneWhenEveryKeyChangedTestUninstallKeepsACodexRecordWithARelativePathTestCodexStatus_NamesNoUpdater(review), which fails withstatusnaming the updaterTestCodexDisable_NamesAnUpdaterThatKeptCortex, for the new kill command and the not-stopped line.main:scripts/dev/go-test-shards.sh -race cmd/agentop(1262 tests) and the subpackages under-race;go vet, also for linux;gofmtstubCodexDaemon's fake.Refs #1365
Assisted-By: Claude (Anthropic AI) [email protected]