Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

access: LANSecret answers "not shared" from settings, before caller-keys.json's lock

yetone23d4dc591a1f
diff --git a/internal/access/access.go b/internal/access/access.go
index 23b93ddef..7921241c7 100644
--- a/internal/access/access.go
+++ b/internal/access/access.go
@@ -206,6 +206,12 @@ func List() ([]Key, error) {
// requests the gateway takes only with a named key; "" while the gateway
// isn't shared, or that key is off.
func LANSecret() string {
+ // not shared, the usual case, is told by the settings alone, before
+ // the lock: taken first, every agent's sync (keeping) made and locked
+ // caller-keys.json.lock, ~100 times in a start's first 20s (#1665)
+ if !settings.Load().LAN {
+ return ""
+ }
mu.Lock()
defer mu.Unlock()
s := settings.Load()
diff --git a/internal/access/lansecret_unlocked_test.go b/internal/access/lansecret_unlocked_test.go
new file mode 100644
index 000000000..722a90952
--- /dev/null
+++ b/internal/access/lansecret_unlocked_test.go
@@ -0,0 +1,38 @@
+package access
+
+import (
+ "testing"
+ "time"
+)
+
+// #1665: with the gateway not shared, LANSecret answers from the settings
+// alone, without taking caller-keys.json's lock (every agent's sync asks
+// it, ~100 times in a start's first 20s, each a lock file opened and
+// locked); shared, it reads the key under the lock, as before.
+func TestLANSecretNotSharedTakesNoLock(t *testing.T) {
+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
+ answer := func() (string, bool) {
+ got := make(chan string, 1)
+ go func() { got <- LANSecret() }()
+ select {
+ case s := <-got:
+ return s, true
+ case <-time.After(5 * time.Second):
+ return "", false
+ }
+ }
+
+ mu.Lock()
+ s, ok := answer()
+ mu.Unlock()
+ if !ok || s != "" {
+ t.Fatalf("not shared, under another's lock: answered=%v %q; want \"\" at once", ok, s)
+ }
+
+ if err := ConfigureLAN(true, false); err != nil {
+ t.Fatal(err)
+ }
+ if s, ok := answer(); !ok || s == "" {
+ t.Fatalf("shared: answered=%v %q; want the key", ok, s)
+ }
+}