Skip to content

cmd/codeaf: the model warm stops when the process closes - #1179

Merged
santoshkumarradha merged 4 commits into
santos/devfrom
task/c224-model-warm-stops-at-close
Sep 18, 2026
Merged

santoshkumarradha merged 4 commits into
santos/devfrom
task/c224-model-warm-stops-at-close

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Two cmd/codeaf tests failed at cleanup with TempDir RemoveAll cleanup: unlinkat …: directory not empty, only under load, never alone. Neither test starts a goroutine of its own — the first one's
whole body is a t.Setenv("CODEAF_HOME", t.TempDir()), a cache write and a read-only gate — so the
writer was never the test's.

The writer, named

warmV3Models is started fire-and-forget by guard.Go, which joins nothing at shutdown, and it
finishes by writing the picker's cache through tui3.WriteModelCache — which resolves CODEAF_HOME
at the moment it writes, not when the warm started.
On a cold cache the warm is a network
round-trip, so a warm can outlive the conversation that asked for it and land its write in whichever
state root is current when the rows finally arrive: in a package run, the next test's t.TempDir(),
whose clean-up then fails with directory not empty. That is both symptoms at once — only under load
(slow enough to cross a test boundary) and never alone (no earlier test to leak one).

v3Process.closeAll's own header promises that nothing this process started is still writing under
its profile once it closes. For this writer the promise was not true.

The fix, in two parts

Seat the warm on the tracker it should always have been on. poolErrandGoCtx is poolErrandGo
for an errand that must observe cancellation rather than only be waited for; v3Process.warmModels
starts the warm through it, so closeAll cancels the wait and joins the goroutine, exactly as #1124
did for the pool errands. Both call sites move: the chat door (chatv3.go:419) and the engine
(engine.go:708).

Give the warm reads that cannot block. The wait now belongs to Catalog.Warmed(ctx), the one
context-observing door the close can end; after it answers true the rows are in hand, so the two
reads behind it — the context window and FetchedAt — must not ask blocking questions of a catalog
the errand has just stopped waiting on. ContextLengthNow and FetchedAtNow read rowsNow (the
ModelsNow door) and answer zero / the zero time while a lazy catalog is still warming.

ContextLengthNow is byte-for-byte the id matching of its blocking twin — byID[normalizeID(id)],
the same normalisation of the reasoning-effort suffix and a leading ~. That matters: the obvious
cheaper route, reusing the launch's existing non-blocking v3ContextWindow seam, matches with
EqualFold, so a conversation started on model:high would answer a zero window — the exact
number the warm exists to learn. The cell caught that in its own first draft and said so.

Consequence, stated rather than buried

A process that closes before its catalog resolves now writes no picker cache for the next launch,
where before the orphaned warm eventually wrote one. That is the intended trade: the old write was
the bug — it landed in a profile the process no longer owned. The warm runs again at the next launch.

Proof the test bites

A test for a race can pass by asserting nothing, so I checked it by mutation rather than by reading.
In a clone of this branch, unseating the warm back to its old shape —

go func() { warmV3Models(context.Background(), models, agent, started) }()
--- the new test with the seating REMOVED (expect FAIL) ---
        profile's errand tracker lands in whichever root is current when the rows arrive — the
        TempDir clean-up's own "directory not empty". It must be seated on the tracker and joined
        at close (chatv3_process.go, poolindex.go).
FAIL	github.com/Agent-Field/codeaf/cmd/codeaf	0.211s

--- reverted, expect ok ---
ok  	github.com/Agent-Field/codeaf/cmd/codeaf	6.560s   (-count=3)

The test makes the race certain rather than likely: its endpoint holds the catalog fetch open until
the test releases it, so an unseated warm is certainly still waiting at the close, and the test has
already moved CODEAF_HOME to a directory it owns before releasing it. Deterministic, at -count=3.

Evidence

From a fresh clone of this head (c438a8f75b079f7f068d97a55dd289660ee23792) on the Spark
cluster — log ~/src/trees/check-c438a8f75b079f7f068d97a55dd289660ee23792.log, HEAD on its first line:

check result
gofmt -l ./internal ./cmd nothing printed
go vet ./internal/... ./cmd/... clean
go test ./internal/guard ./internal/namelaw ok
go run ./cmd/codeaf-changes check 82 entries, all well formed
go test ./cmd/codeaf -count=1 ok 123.8s
go test ./internal/catalog -count=1 ok 0.15s

The catalog package is in the list because this adds two doors to it.

🤖 Generated with Claude Code

santoshkumarradha and others added 4 commits September 18, 2026 03:22
The model catalog warm was started through guard.Go, which joins nothing at
shutdown, and it writes the picker cache through tui3.WriteModelCache, which
resolves CODEAF_HOME at the moment it writes. A warm that outlived the process
that asked for it landed in whichever state root was current when the rows
arrived — the next test's own TempDir, whose clean-up then failed with
"directory not empty".

It is now seated on the profile's start-up errand tracker (the #1124 machinery)
and observes the tracker's context, so v3Process.closeAll cancels its wait and
joins it before the conversations and stores close.

cmd/codeaf/chatv3_modelswarm_test.go holds the catalog fetch open, moves
CODEAF_HOME, closes the process, releases the fetch, and fails if the write
lands in the moved root (deterministic: fails without the seating, passes with).

Co-Authored-By: codeaf <[email protected]>
…this tree

A review of #1178 caught its own summary claiming that warmV3Models "no longer
resolves the catalog via ContextLength". It does — chatv3.go:2320 still asks
ContextLength for the window. The sentence was wrong and the code is right, so
the note now says what the function actually does and why the obvious way to
make the sentence true would be a regression: the non-blocking v3ContextWindow
seam matches an id with EqualFold where ContextLength normalizes it through
catalog's own index, so a conversation started on model:high would lose the
window it exists to learn; and FetchedAt on the next line reads through the same
waiting door anyway. What moved is the WAIT, to Catalog.Warmed(ctx), and after
it answers the blocking door cannot block, because LoadLazy closes its channel
inside the future's own body.

The note also carries the evidence the brief asked for and it was missing: the
command, and the deterministic failure against the pre-fix fire-and-forget shape
(0.11s, the write landing in the root CODEAF_HOME had already moved to), beside
the pass with the seating in place.

Co-Authored-By: codeaf <[email protected]>
…e catalog

The reported sentence that warmV3Models "no longer resolves the catalog via
ContextLength" was false on the first commit: it still asked
models.ContextLength(started) for the window, and the pull-request check that
reads the sentence held it. The naive fix — read through v3ContextWindow, the
launch's non-blocking seam — is a regression: it matches ids with EqualFold
instead of normalizeID, so a session started on `model:high` answers a zero
window, and it leaves the FetchedAt read on the resolving door behind it.

The warm now reads through two new never-waiting doors on the catalog,
ContextLengthNow and FetchedAtNow, which read rowsNow (the ModelsNow door),
answer zero/nil while a lazy catalog is still warming, and match ids exactly
like the blocking twins. After Warmed(ctx) answers true the rows are always
in hand, so the twins answer the same numbers without counting a blocking
question; the warm's only wait is the context-observing one the close ends.

Co-Authored-By: codeaf <[email protected]>
@santoshkumarradha
santoshkumarradha force-pushed the task/c224-model-warm-stops-at-close branch from 7f4748e to c438a8f Compare September 18, 2026 07:30
@santoshkumarradha
santoshkumarradha merged commit d9b4243 into santos/dev Sep 18, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the task/c224-model-warm-stops-at-close branch September 18, 2026 07:35
AbirAbbas added a commit that referenced this pull request Sep 18, 2026
… custom connections (#1194)

Lands the integration branch santos/dev (#1108, head 6db5125, 152 commits over dev) on dev as one squash, plus two fixes that kept its touched-packages job red: the pool start-up test empties the CI word it is not about (649bb4b), and a zombie leader no longer keeps a job's process group alive on Linux, which had delayed every finished background job by the two-second termination grace since #1155 (053e6a9). #1108 carries the full account; the 94 change entries under docs/changes/unreleased/ are the per-change record.

The commits folded in, oldest first:

5c413ef Keep archived evidence readable while tasks finish
3705a0c Document recovery evidence retrieval change
7834cc7 tui3, manual: a question's own answer box answers to the whole caret vocabulary
99d66e9 task: Add open/all source toggle to crew config
c1e4cb5 docs: the change entry for the crew model family toggle
e63b439 crew: round-1 review fixes
304a5a2 crew: round-2 review fix
65477c0 task: Add open/all selector to /crew TUI picker
9189ef7 Merge branch 'task/add-open-all-selector-to-crew-tu-9e8cc0' into feat/crew-open-all-toggle
ba9c12d crew: reconcile the picker onto config's source helpers
ea05bc0 crew: a chosen family counts as an answered crew
e1a037e Merge remote-tracking branch 'origin/dev' into feat/crew-open-all-toggle
f6c2924 crew: the open table takes the picks we landed on
eff44b5 docs: the change entry carries the open-table move and the family gate
71ce9be crew: the family reaches the fallback, the settings skin, and the row's line
b8ca5f5 crew: round-1 review fixes on the new table
8db5708 crew: round-2 review fixes
ce9759e crew: round-3 review fixes
956e1f5 crew: round-4 review fixes
37ad27f crew: fixes from the first Opus round
6ffb958 crew: the fixes from the Opus confirmation round
72b0274 crew: the comments the atomic write left behind
70d0e20 crew: round-four fixes from the Opus review
234300e Merge branch 'dev' into feat/crew-open-all-toggle
894292f crew: round-five fixes from the Opus review
fba77f9 An answered landing carries its answer's fate when it is raised again, and an in-flight settle holds the question down (#1077)
e694450 Changelog entry for the landing-answer fate (#1086)
64ab7ea crew: round-six fixes from the Opus review
0700164 crew: round-seven fixes from the Opus review
af09aa8 The review round's four findings: claim ownership, decider changes, recordable answers, plain words
c24af02 crew: round-eight fixes from the Opus review
289d372 The tests the landing's answer carries: fate, hold-down, redraw, claim doors
7e38346 The take-down comes before every mint, and the tui3 walk reads the newest card
dbe1be0 The review rounds' last word: the release owns its claim, and the docs say what the code does
4cc4945 The Opus review: a release owns its generation, and every failed round still says its word
a5cce0d The done card says who is deciding, so the clause is a duplication, not the fact
6bd276e Merge fix/1077-landing-reraise into santos/dev
2710169 Merge feat/crew-open-all-toggle into santos/dev
b459399 Merge fix/question-answer-box-caret-keys into santos/dev
a384920 Merge codex/recovery-evidence into santos/dev
dc22e64 cmd/codeaf: the role-door tests read the shipped mastermind instead of a copy of it
39f528f release: the pin-example check reads the guide the examples moved to
6439d3c session, tui3: gofmt the three files santos/dev merged unformatted
8540379 tui3: a question's answer box kills to the end of the line on ctrl+k