codex: the editor extension's bundled Codex version is read, so the threshold is written (HermanHongbb on X)
The background-compaction table is written only when every Codex that reads the config is known to be new enough. The openai.chatgpt extension's reader was always made with no version, so any machine with the extension installed counted as "unknown" and the table, with the threshold, was held out: Codex compacted at its own 65%. The extension ships bin/<target>/codex-package.json beside its codex (checked in the real Open VSX packages of chatgpt 26.51111.21308, Linux x64 and Windows x64: "version": "0.169.0-alpha.11.1"). It is read now, one reader per installed copy, in every dot folder's extensions (VS Code, VS Code Server, Cursor, Windsurf, VSCodium, ...); copies in .obsolete are skipped. A version that can't be read stays unknown, not old. Settings' existing note (codexAsyncHeld) names the editor extension and its version when it is what holds the threshold back. Run: TestExtensionCodexVersionRead (new; red with the version read turned off by hand: got map[:4]), go vet darwin/linux/windows, gofmt, and go test ./internal/agent on mote, ok. Not tried: a live VS Code with the extension; the full suite before the tag. The macOS extension layout is the same package (darwin vsix not unpacked).
This commit is contained in:
@@ -89,12 +89,62 @@ var codexReaders = func(at place) []CodexReader {
|
||||
out = append(out, CodexReader{Kind: "app", Version: installedVersion(filepath.Join(dir, "resources", "codex"))})
|
||||
}
|
||||
}
|
||||
if extensionHere(at.home, "openai.chatgpt") {
|
||||
out = append(out, CodexReader{Kind: "ide"})
|
||||
return append(out, extensionCodexReaders(at.home)...)
|
||||
}
|
||||
|
||||
// extensionCodexReaders are the Codexes the editors' OpenAI extension
|
||||
// (openai.chatgpt) carries, one per installed copy, in VS Code's
|
||||
// ~/.vscode/extensions, VS Code Server's, and each fork's (Cursor,
|
||||
// Windsurf, VSCodium, …). The extension ships its codex at
|
||||
// <ext>/bin/<target>/codex, with the version in the codex-package.json
|
||||
// beside it ("0.169.0-alpha.11.1" in chatgpt 26.51111 on Linux and
|
||||
// Windows alike); one whose version can't be read is "" (unknown, not old).
|
||||
// A copy the editor marked obsolete (.obsolete) is not run any more.
|
||||
func extensionCodexReaders(home string) []CodexReader {
|
||||
var out []CodexReader
|
||||
es, err := os.ReadDir(home)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, e := range es {
|
||||
if !strings.HasPrefix(e.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
root := filepath.Join(home, e.Name(), "extensions")
|
||||
xs, err := os.ReadDir(root)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var obsolete map[string]bool
|
||||
if b, err := os.ReadFile(filepath.Join(root, ".obsolete")); err == nil {
|
||||
json.Unmarshal(b, &obsolete)
|
||||
}
|
||||
for _, x := range xs {
|
||||
n := strings.ToLower(x.Name())
|
||||
if !x.IsDir() || !strings.HasPrefix(n, "openai.chatgpt-") || obsolete[x.Name()] {
|
||||
continue
|
||||
}
|
||||
out = append(out, CodexReader{Kind: "ide", Version: extensionCodexVersion(filepath.Join(root, x.Name()))})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// extensionCodexVersion is the version in an extension copy's
|
||||
// codex-package.json (bin/<target>/, or bin/), "" when none is readable.
|
||||
func extensionCodexVersion(dir string) string {
|
||||
paths, _ := filepath.Glob(filepath.Join(dir, "bin", "*", "codex-package.json"))
|
||||
paths = append(paths, filepath.Join(dir, "bin", "codex-package.json"))
|
||||
for _, p := range paths {
|
||||
if b, err := os.ReadFile(p); err == nil {
|
||||
if m := codexPackageVersionRe.FindSubmatch(b); m != nil {
|
||||
return strings.TrimSpace(string(m[1]))
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var codexPackageVersionRe = lazyre.New(`"version"\s*:\s*"([^"]+)"`)
|
||||
|
||||
// bundledCodexVersion is the version of the codex a Codex app bundle
|
||||
|
||||
@@ -363,3 +363,55 @@ func TestCodexAsyncConfigLoadsInRealCodex(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The editor extension carries its own codex, with its version in the
|
||||
// codex-package.json beside it (#X: HermanHongbb on X, Fedora, the
|
||||
// extension in VS Code and Cursor, both newer than the gate). The reader was
|
||||
// made with no version, so it was always "unknown" and held the table (and
|
||||
// the threshold) out. A version that is newer passes; one that can't be
|
||||
// read stays unknown, not old.
|
||||
func TestExtensionCodexVersionRead(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
put := func(rel, body string) {
|
||||
p := filepath.Join(home, rel)
|
||||
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(p, []byte(body), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
pkg := func(v string) string {
|
||||
return `{"layoutVersion": 1, "version": "` + v + `", "entrypoint": "bin/codex"}`
|
||||
}
|
||||
put(".vscode/extensions/openai.chatgpt-26.51111.21308-linux-x64/bin/linux-x86_64/codex-package.json", pkg("0.164.0-alpha.11.1"))
|
||||
put(".vscode-server/extensions/openai.chatgpt-26.5908.1-linux-x64/bin/linux-x86_64/codex-package.json", pkg("0.167.0-alpha.4.1"))
|
||||
put(".cursor/extensions/openai.chatgpt-26.1-win32-x64/bin/windows-x86_64/codex-package.json", pkg("0.169.0"))
|
||||
put(".windsurf/extensions/openai.chatgpt-26.2-linux-x64/bin/linux-x86_64/codex", "binary only")
|
||||
put(".vscode-oss/extensions/openai.chatgpt-25.1-linux-x64/bin/linux-x86_64/codex-package.json", pkg("0.100.0"))
|
||||
put(".vscode-oss/extensions/.obsolete", `{"openai.chatgpt-25.1-linux-x64": true}`)
|
||||
put(".vscode/extensions/other.ext-1/bin/x/codex-package.json", pkg("0.1.0"))
|
||||
|
||||
got := map[string]int{}
|
||||
for _, r := range extensionCodexReaders(home) {
|
||||
if r.Kind != "ide" {
|
||||
t.Errorf("kind %q", r.Kind)
|
||||
}
|
||||
got[r.Version]++
|
||||
}
|
||||
want := map[string]int{"0.164.0-alpha.11.1": 1, "0.167.0-alpha.4.1": 1, "0.169.0": 1, "": 1}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
for v, n := range want {
|
||||
if got[v] != n {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// what the gate makes of them: only the unreadable one holds the table
|
||||
blocked := codexAsyncBlocked(extensionCodexReaders(home))
|
||||
if len(blocked) != 1 || blocked[0].Version != "" {
|
||||
t.Errorf("blocked %v, want only the one of unknown version", blocked)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user