#5491 names a dsh fork's completed requests by the reply id dsh writes with them, over the conversation's opening only where the two agree: the reply's session owns the opening, or is a fork of its owner, which the fork header's parentSession says (Session.ForkOf). dsh 0.2.2's ordinary fork writes isSeeded and session/end-seed but no parentSession. ForkOf is empty, the guard refuses the reply id's own session, and the fork's requests stay under its source on Routing and Context; the fork's own row never appears (Flandern1211: 7 of 17 top-level seeded sessions on one computer are such forks). end-seed now keeps the conversation ids its copied events opened (SeedConvs) instead of dropping them with the seed's counts. That is the fork's own file saying it copied that opening, and forkedFrom accepts it when the fork names no parent, only to admit a reply id that is already one session's. A route with no reply id still goes by the opening, and a reply id two sessions share stays ambiguous. dsh's parse version rises so kept parses are read again; the Routing integration fixture leaves parentSession out, as current dsh does. Flandern1211's fix/dsh-fork-without-parent @ ead1abcce, as written; one conflict taken (parseVersions has antigravity 2 on main). ggbdpq's port on #5542 (0d7e18d1e) is the same change. Not ported: the follow-up fix/dsh-fork-unmatched @ 1bce689ed (Context page leaves a fork-shared opening's unread route out of both cards). Review findings are on #5542. Run at aca932bf7 (this change on5c5160c94), on mote; the pushed head adds onlye20517a88under it, a one-line Qoder mover min: - go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./..., GOOS=windows go build ./...: all ok. - go test -tags nogui -count=1 ./internal/sessions/ ./internal/gui/ ./internal/gateway/: ok (18.8s, 82.8s, 783.9s). - gofmt -l on the six files: nothing. Broken by hand (mote, -run 'Dsh|Fork|Routing|Context'): - end-seed dropping SeedConvs: TestDshForkWithoutAParentKeepsItsSeedOpenings red ("seed openings [], want [magpie-e2f7b8e6… …]") and TestRoutingTellsAForkByItsReply red ("route 1: session \"session-source\", want \"session-fork\""). - forkedFrom ignoring the seed: TestDshForkWithoutAParentIsNamedByItsReply red ("reply \"chatcmpl-fork\", opening \"magpie-open\": \"source\", want \"fork\"") and TestRoutingTellsAForkByItsReply red. - assembleListed not carrying SeedConvs onto the Session: TestRoutingTellsAForkByItsReply red. - Review check: the source's routes from before reply ids were kept (no ResponseID) still make the source's Context card, 3 of 3 requests. Not tried: a replay of real dsh session files (the reporter's numbers are on #5542; ~/.dsh here is a live config and was not read); dsh's parse version bump is not pinned by a test of its own (the generic re-read on a raise is, in cache_decode_test.go). Reported-by: Flandern1211 Co-authored-by: Flandern1211 <163982805+Flandern1211@users.noreply.github.com>
86 lines
3.3 KiB
Go
86 lines
3.3 KiB
Go
package gui
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
)
|
|
|
|
// A dsh fork copies its source's conversation, so the hash of the opening
|
|
// names both sessions and names neither: Routing showed the source for the
|
|
// fork's own requests too, or nothing at all. The reply's id is the fork's
|
|
// own — dsh keeps the one magpie's gateway put on it — and names it
|
|
// (Route.ResponseID, sessions' ResponseIDs).
|
|
func TestRoutingTellsAForkByItsReply(t *testing.T) {
|
|
sandboxHome(t)
|
|
home := t.TempDir()
|
|
t.Setenv("DSH_HOME", home)
|
|
sessions.Reset()
|
|
t.Cleanup(sessions.Reset)
|
|
resetRouteConvs := func() {
|
|
routeConvs.Lock()
|
|
routeConvs.of, routeConvs.at = nil, time.Time{}
|
|
routeConvs.Unlock()
|
|
}
|
|
resetRouteConvs()
|
|
t.Cleanup(resetRouteConvs)
|
|
defer func(f, k time.Duration) { convsFresh, convsKept = f, k }(convsFresh, convsKept)
|
|
convsFresh = 0
|
|
|
|
const opening = `{"type":"user/message","seq":1,"time":1000,"data":{"source":{"kind":"user"},"content":[{"type":"text","text":"same first prompt"}]}}`
|
|
const endSeed = `{"type":"session/end-seed","seq":2,"time":1000,"data":{"inherited":true}}`
|
|
reply := func(seq int, id string) string {
|
|
return `{"type":"assistant/message","seq":` + strconv.Itoa(seq) + `,"time":1000,"data":{"message":{"source":{"provider":"magpie","model":"group/flash","replayState":{"response":{"provider":"magpie","responseId":"` + id + `"}}}}}}`
|
|
}
|
|
write := func(name, header string, lines ...string) {
|
|
dir := filepath.Join(home, "sessions", "proj", name)
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b := header + "\n"
|
|
for _, l := range lines {
|
|
b += l + "\n"
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "session.v4.jsonl"), []byte(b), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
write("session-source", `{"type":"session","version":4,"id":"session-source","cwd":"/w","createdAt":1000,"delegationDepth":0,"isSeeded":false}`,
|
|
opening, reply(2, "reply-source"))
|
|
write("session-fork", `{"type":"session","version":4,"id":"session-fork","cwd":"/w","createdAt":1000,"delegationDepth":0,"isSeeded":true}`,
|
|
opening, reply(2, "reply-source"), endSeed, reply(4, "reply-fork"))
|
|
|
|
var openingHash string
|
|
for _, s := range sessions.List(0) {
|
|
if s.ID == "session-source" && len(s.Convs) > 0 {
|
|
openingHash = s.Convs[0]
|
|
}
|
|
}
|
|
if openingHash == "" {
|
|
t.Fatal("the fixture session names no conversation id")
|
|
}
|
|
routes := []gateway.Route{
|
|
{ID: 1, Agent: "dsh", Conv: openingHash, ResponseID: "reply-fork"}, // the fork's own turn
|
|
{ID: 2, Agent: "dsh", Conv: openingHash}, // the opening alone: its source's
|
|
{ID: 3, Agent: "dsh", Conv: openingHash, ResponseID: "reply-source"}, // the source's
|
|
{ID: 4, Agent: "dsh", ResponseID: "reply-fork"}, // the reply alone
|
|
}
|
|
got := map[int64]string{}
|
|
for _, r := range pricedRoutes(routes) {
|
|
got[r.ID] = r.Session
|
|
}
|
|
// 2 is the opening alone: the fork's inherited copy of it is its
|
|
// source's (the seed ends before its own turns), so it names the source
|
|
want := map[int64]string{1: "session-fork", 2: "session-source", 3: "session-source", 4: "session-fork"}
|
|
for id, w := range want {
|
|
if got[id] != w {
|
|
t.Errorf("route %d: session %q, want %q", id, got[id], w)
|
|
}
|
|
}
|
|
}
|