One-command make codex-login that refreshes the local worker's Codex credentials #168
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
P1
P2
P3
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Creatidy/scarcity-router#168
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Refreshing the OpenAI/Codex credentials of the local execution worker currently
requires the operator to know and type the host-specific source id:
On ROG the source id may differ. The authorization machinery itself already
exists and is correct (
run_official_codex_login→ officialcodex login --device-authagainst the source-controlledCODEX_HOME); whatis missing is a one-command UX layer that works unchanged on both hosts.
Desired UX
Same command on ROG and Precision. No
.dev/.prdvariants, no host-specificarguments, no source id typed by the operator.
Constraints (from the task)
scarcity-router-worker codex-loginmachinery — no newauthorization mechanism, no second credential store, no Codex installation.
persisted home of that selection is the generated systemd user unit's
ExecStart(service install --codex-source <id>renders it); read it backinstead of hard-coding
precision-codex-live.--state-dir) so thecontrolled
codex-sources/<source_id>/home is exactly the one the workerprobes.
~/.codex.configured — never guess.
make help.Notes
eligibility check, so a completed login requires no worker restart.
--codex-bin(if the unit pins one) is passed through to thelogin as well.
--source,--state-dir,--codex-bin) keep their currentsemantics; discovery only fills what was omitted.
make codex-loginreading the configured source from the installed worker unit (#168) #169Completion report (implemented in PR #169, HEAD
7430d89— open, not merged)task/168-codex-login-make-target→develop, single commit7430d89,origin/develop..HEADcontains only this change)7430d8931c27e1b4b5c223183f781803daf8f112How the local Codex source is discovered. The generated systemd user unit is the persisted home of the operator's adapter selection (D-065), so the new
read_installed_service_configuration()inworker_service.pyparses the installed unit'sExecStartback into executable + state dir +ServiceSelection(parse_exec_startis the exact inverse ofrender_unit::prefix, systemd quoting,%%unescaping). Read-back is marker-gated and fail-closed: missing unit, foreign unit, unknown flag, wrong shape or a dangling value prints the exact remediation (service install --codex-source SOURCE_ID) — never a guess, and nothing outside the unit is consulted.scarcity-router-worker codex-loginwith--sourceomitted requires exactly one configured source (zero/several → refusal listing the ids); the unit's--state-dirand pinned--codex-binpass through so the login addresses exactly the controlled home the worker probes. Explicit flags keep their prior semantics. Decision recorded as D-066.Exact existing auth mechanism reused.
run_official_codex_login(unchanged) → officialcodex login --device-authwithCODEX_HOMEpointed at<state_dir>/codex-sources/<source_id>/(D-053). No new authorization mechanism, no second credential store, no Codex installation, and~/.codexis never read, copied or adopted.Worker restart required: No — the adapter re-probes account auth from the controlled home on every eligibility check, so the running worker picks up fresh credentials on its next check.
Verification:
uv run basedpyright0 errors/0 warnings,git diff --checkclean.ExecStartReadBackTests(9, incl. exact round-trip of hostile paths and agreement with the independentsystemd_wordsoracle) andCodexLoginDiscoveryTests(6, incl. explicit---sourcebackwards compatibility and every refusal path).make helplists the target;make -n codex-loginprints the singleuv run scarcity-router-worker codex-loginline; reading the real installed unit resolvesstate_dir=/home/adrian/.local/share/scarcity-router/workerand zero configured codex sources — the command correctly refuses with the install recipe, because the ROG service currently runs without a Codex source. After one-timescarcity-router-worker service install --codex-source <id>(+service restart), the same command resolves it.--codex-source precision-codex-live(the documented install form); that exact flag shape — source pass-through, state-dir reuse, quoting — is pinned by the round-trip and discovery tests against the samerender_unitoutput.codex-loginpath, the source-controlledCODEX_HOMEis preserved,~/.codexis untouched, and no second Codex installation or credential store exists (the write-confinement guardrail scan is unaffected — the new code only reads).Final operator command (both hosts):
Fix for the Precision field-test failure — commit
d90f450ondevelopWhat your test exposed. Precision's worker runs under a HAND-WRITTEN unit at
~/.config/systemd/user/scarcity-router-worker.service— the retired copied-example shape (%h-anchored paths), not a tooling-generated unit. The merged read-back (PR #169) refused to interpret it ("missing managed marker"), so discovery failed on exactly the host the target must serve.The fix (amends D-066). Discovery is now tiered:
--codex-source,--state-dir,--codex-bin), resolves the documented user specifiers exactly (%h= the invoking user's passwd home — the same source systemd uses; the retired example unit anchored every path at%h;%%literal), toleratesenv/prefix wrappers, and refuses anything it cannot model exactly —$variables and shell syntax, unsupported specifiers (%S,%E,%t, …), continuation lines, a relative--state-dir, or a line that doesn't invokerun— each refusal carrying the migration recipe.runwithout--state-diruses the platform default (derivable, never a guess).service install/uninstallstill never touch a unit they did not generate. A successful hand-written-unit login prints a one-line note naming theservice installregeneration path.Verified against a faithful simulation of your unit shape (
ExecStart=%h/.local/bin/scarcity-router-worker run --codex-source precision-codex-live, with and without--state-dir %h/...): resolvesprecision-codex-liveand the right state directory, prints the caution, and invokes the login with the correct controlled home. Full gate green (2655 tests, basedpyright clean).Process disclosure (important). While I was preparing this fix, PR #169 was merged (by you, 22:46 UTC) and the local checkout ended up on
developwith the feature branch deleted. I committed the fix without re-checking the branch first, sod90f450went directly todevelopinstead of through an issue-branch-PR cycle. That violates the repository workflow; the content itself is gate-green and scoped to this issue's files (verified: exactly 6 files, this issue's change only). It cannot be cleanly undone (a revert would add further directdevelopcommits; history rewrite is forbidden). I've reopened this issue since the acceptance gate is your re-test on Precision. If you'd rather keep the record strict, the options are a revert commit plus a fresh PR (your call — both need directdevelopwrites or your authorization).Please re-test on Precision (the unit there is read as-is; no restart needed for the login itself):
Expected:
codex-login: using configured source 'precision-codex-live' (read from the installed worker service), a note that the unit was written by hand with the one-timeservice installmigration recipe, then the official device-auth URL/code. If your unit differs from the assumed shape (e.g.sh -cwrapper or$-variables), paste theExecStart=line and I'll extend the exact-resolution set.Root cause of the residual
openai status=unknownfound and fixed in PR #170 (branchtask/168-capacity-controlled-home, commit866abb5, awaiting review).The login itself worked — but the OpenAI capacity collector spawns its app-server with the inherited environment, so it authenticated from
~/.codex, a second credential location your login never touched. The fix points the collector at the same controlled homemake codex-loginrefreshes (discovered via the same unit read-back; an explicitCODEX_HOMEenv still wins; worker-less hosts unchanged). After merge +make install,scarcity-router statusshould show the openai windows from the freshly logged-in account. D-066 amended (point 5).