226fc8ea3 lists ZCode's sessions for Titles from their rows alone, with
size 0 and the row's time_updated as the file's stamp. Two things followed
from that stamp:
- ZCode writes a message without touching its session's row, so a session
still under its default title, first read before its prompt was in, was
never named by that prompt while only the Routing page polled.
- The cache kept size 0 and the row's time, where the Sessions page's
listing (zcodeFiles) keeps the message count and the last message's
time, so each read the session whole again after the other.
zcodeTitleStamps gives the sessions a poll asks for (their key wanted,
subagents under it too) the same count and last activity, from a
COUNT/MAX over each one's own messages by session_id, not the join over
every session's. A session whose messages can't be read keeps its row's
stamp, as before.
Co-authored-by: Flandern1211 <163982805+Flandern1211@users.noreply.github.com>
Run (mote, via mote-run):
- go test ./internal/sessions -run TestZCode -count=1 at 226fc8ea3 alone:
TestZCodeTitlesSeeNewMessages red (after the prompt: "") and
TestZCodeTitlesKeepTheListingsStamp red (kept size 0 mod
1790496000000000000, listing has size 3 mod 1790496030000000000). With
this change both green. On origin/main 1b0340fdb both pass (the poll
read the join), while 226fc8ea3's TestZCodeSubagentTitlesByRequestID and
TestZCodeTitlesWithoutMessageTable are red there.
- go test -timeout 45m ./internal/sessions ./internal/gui -count=1: sessions
ok; gui ok but TestMainWindowCorners/macOS_26_SDK, #3949 (mote is
macOS 27), untouched here.
- GOOS=linux and GOOS=windows go vet ./internal/sessions: ok. gofmt clean.
Not tried: a real ZCode database (none on this Mac or the Windows box);
the per-session COUNT/MAX is not timed against the reporter's 1 GB one.
It filters message by session_id, as parseOpenCode's own reads do.
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package sessions
|
|
|
|
// zcodeTitleFiles are ZCode's sessions as a title lookup needs them: the
|
|
// session rows alone, without the message join zcodeFiles makes for a
|
|
// session's size and last activity. Titles asks again every 15s, and that
|
|
// join over a large database took ~20s.
|
|
//
|
|
// mu is held by Titles, as openDB's handles expect.
|
|
func zcodeTitleFiles() []file {
|
|
if !Reads("zcode") {
|
|
return nil
|
|
}
|
|
path := zcodeDB()
|
|
if !fileExists(path) {
|
|
return nil
|
|
}
|
|
db := openDB(path)
|
|
if db == nil {
|
|
return nil
|
|
}
|
|
rows, err := db.Query(`SELECT id, COALESCE(parent_id, ''), time_updated FROM session`)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
defer rows.Close()
|
|
parent := map[string]string{}
|
|
var out []file
|
|
for rows.Next() {
|
|
var id, par string
|
|
var updated int64
|
|
if rows.Scan(&id, &par, &updated) != nil {
|
|
continue
|
|
}
|
|
parent[id] = par
|
|
out = append(out, file{agent: "zcode", path: path + "#" + id, mod: ms(updated),
|
|
more: &fileMore{sid: id, oc: zcDB{ocDB{db}}}})
|
|
}
|
|
return ocRoots(out, parent)
|
|
}
|
|
|
|
// zcodeTitleStamps gives the ZCode sessions a name poll asks for the size
|
|
// and last activity zcodeFiles would give them, read from each one's own
|
|
// messages: ZCode writes a message without touching its session's row, so
|
|
// the row's time alone missed a first prompt typed since the last poll, and
|
|
// a stamp unlike the full listing's had the Sessions page and the poll each
|
|
// read the session again after the other. A session whose messages can't
|
|
// be read keeps its row's stamp.
|
|
func zcodeTitleStamps(files []file, want map[string]bool) {
|
|
for i := range files {
|
|
f := &files[i]
|
|
if f.agent != "zcode" || !want[f.key] {
|
|
continue
|
|
}
|
|
zc, ok := f.m().oc.(zcDB)
|
|
if !ok {
|
|
continue
|
|
}
|
|
var n, last int64
|
|
if zc.db.QueryRow(`SELECT COUNT(id), COALESCE(MAX(time_updated), 0) FROM message WHERE session_id = ?`, f.m().sid).Scan(&n, &last) != nil {
|
|
continue
|
|
}
|
|
f.size, f.mod = n, ms(max(f.mod.UnixMilli(), last))
|
|
}
|
|
}
|