codexswitch

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package codexswitch repoints the account ccdad's codex proxy serves.

It is a package of its own, and a very small one, so that a machine-checkable statement can be made about it: its dependency closure contains neither internal/switcher nor internal/cclink nor internal/store, so nothing reachable from here can install a Claude Code credential, rewrite the credentials file, or read one. That is why Execute takes a uuid STRING rather than a store.Account -- taking the account would put the store in the closure and cost the guarantee for a convenience.

A Codex "switch" is not a credential swap at all. Codex holds no token on this machine; the daemon's proxy holds them and rewrites the bearer per request. So all a switch does is move a pointer, and the pointer is read on every request rather than cached, which is what makes a repoint apply to new threads without disturbing threads already in flight.

Index

Constants

This section is empty.

Variables

View Source
var ErrPointerMovedUnstamped = errors.New("codexswitch: the pointer moved but the switch cooldown was not recorded")

ErrPointerMovedUnstamped marks an Execute failure that happened AFTER the pointer already moved: the proxy is serving the new account, but the anti-flap cooldown for that switch was not recorded, so a poll tick shortly after can re-switch immediately with nothing holding it back. A caller that sees an error satisfying errors.Is(err, ErrPointerMovedUnstamped) cannot conclude the repoint did not happen -- it must re-read ReadServing to learn what is actually being served.

Functions

func Clear

func Clear(root string) error

Clear removes the pointer UNCONDITIONALLY, regardless of what it currently names -- there is no read before the remove, so nothing here can race a concurrent repoint the way a caller that read the pointer first and acted on that reading could.

Reach for THIS only when the decision to clear does not depend on what the pointer used to say -- a full store wipe, say, where every account is going away regardless and there is nothing to race. A caller that means "clear it if it still names the account I am about to remove" wants ClearIfServing instead: `ccdad remove` used to call Clear for exactly that decision, and it raced a daemon that had just repointed codex TO the account being removed, deleting a pointer that had nothing to do with the removal.

Calling it on a machine with no pointer is not a failure -- nothing asks first.

func ClearIfServing

func ClearIfServing(root, uuid string) (cleared bool, err error)

ClearIfServing clears the pointer only if it currently names uuid, and does the read and the remove under the SAME LOCK Execute takes -- so a repoint landing between the two cannot be undone by a decision made before it happened. That is the gap a bare ReadServing-then-Clear at the call site cannot close: the pointer can legitimately move between the read and the remove, and nothing outside this package can serialise against Execute without importing it.

cleared reports whether the pointer was actually removed, which is false both when there was no pointer and when the pointer named a different account -- a caller that must say something different in the two cases needs ReadServing's own answer, not this one.

func Execute

func Execute(root, uuid string) (err error)

Execute repoints codex at one account.

It runs under the SAME LOCK ClearIfServing takes, so a repoint can never interleave with a concurrent check-then-clear on this pointer: the pointer is never observed half-changed by a caller deciding whether to remove it, and a clear that lands after Execute has already moved the pointer to a different account cannot undo that move on the strength of a decision made before it happened.

TWO CRITICAL SECTIONS, IN THIS ORDER, and the order is the whole of the correctness here. The pointer is written first, because it is the thing that changes what the machine spends; the cooldown stamp is written only after that succeeded, because a cooldown earned by a repoint that did not happen would hold the lane off the retry that would have made it happen.

The pointer write is atomic -- a sibling temp file and a rename -- so the proxy, which reads this file on every request, sees one whole uuid or the previous one, never a torn line.

A non-nil error does NOT mean the repoint did not happen. The pointer is written first and the stamp only after, on purpose (see above), so a failure in the stamp step returns an error while the pointer has already moved: the proxy is already serving uuid, and the cooldown that would hold the lane off an immediate re-switch was never recorded. That case wraps ErrPointerMovedUnstamped. A caller that needs to know what is actually being served on any error must re-read ReadServing rather than infer it from Execute's return value.

What it deliberately does NOT do: store.SetActive, switcher.RecordSwitch, releaseManagedAPIKey, SyncGlobalConfigIdentity. None of them is reachable from this package, which is asserted rather than remembered.

func ReadServing

func ReadServing(root string) (string, bool)

ReadServing is the account codex is served from, and whether there is one.

Every failure answers "no pointer" rather than an error, and that is the right degradation for this file: the reader is a request handler, and a pointer that cannot be read means the same thing to it as a pointer that was never written -- fall through to the top-ranked eligible account. An account named by a pointer that no longer exists is the caller's to notice; this function only reports what the file says.

func ServingPath

func ServingPath(root string) string

ServingPath is where the pointer lives under a ccdad store root.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL