Commit Graph
2 Commits
Author SHA1 Message Date
yetoneandFlandern1211 b90e130902 dsh: a fork's call waiting for its reply counts on neither card, not its source's (#5542)
d052fec0e gave a dsh fork without a parentSession its own row, named by
the reply ids it gets. A call whose reply dsh hasn't written down yet
still went by the opening, which the fork copied and only the source
owns, so the source's context line climbed with the fork's turns
(Flandern1211: the source's card showed the fork's 30,778 while its own
last call was 21,944).

routeOwners keeps each opening a fork's seed carried a second time
(ownerCopied). joinConvs leaves a call that names no session out of both
cards (ctxRec.Unmatched) only when its opening is such a shared one, it
has a reply id, and it ended within convsKept: the window Routing's
looseKeys waits in. A call with no reply id (routes from before
e8df78f33, a dsh that writes none) and one past that window go by their
opening as before, so the source keeps its history. An answer that left
a call out stands ctxWhileUnmatched (5s) instead of ctxAgain's minute,
and only while such a call is inside that window. This answers both
review points on 1bce689ed.

Ported from Flandern1211's ad461f7d4, with these changes:
- ctxRec.End time.Time is now Millis int64. The tab keeps one ctxRec
  per route in the range (up to 30 days); End took it from 240 to 264
  bytes, Millis to 248.
- The conflict with #2398's Canceled is resolved by keeping both.
- TestDshForkRouteAwaitingItsReplyIsNeithers also has a long call
  (begun 2m ago, ended 20s ago), and clears Session as well as
  Unmatched before its second join.
- New TestContextHeldAnswerStandsOnlyWhileAReplyIsAwaited covers
  contextFor's cache: an answer without held stands past 6s, one with
  held does not, one with held stands for 1s.

Run (mote, HOME=$(mktemp -d), -tags nogui):
- go test -run 'Dsh|Fork|Routing|Context|Conv' ./internal/gui/, and
  -run 'Dsh|ResponseID' ./internal/gateway/ ./internal/sessions/: ok.
- go test -count=1 ./internal/gui/ ./internal/sessions/: ok (117s, 60s).
- go vet ./internal/gui/ for darwin, linux and windows; gofmt -l: clean.
- node --test internal/gui/tests/context-*.test.cjs and
  compact-one-value.test.cjs (11 files): 474 of 474 pass. No GUI file
  changed; they guard the Context page it draws.
- Benchmark (temporary, not committed), 300k dsh routes over 2000
  sources and 2000 forks: joinConvs 125-135ms per pass with the change,
  140-270ms without; contextOfRecs 130-145ms with, 140-150ms without;
  allocations the same (108MB per pass). mote was at load ~120.

Broken by hand, each red: the age check, the reply-id check, the
Unmatched skip (phantom magpie-… row), held never set, held not
shortening the cache, Millis ignored, sharedOpening always false.

Not tried: a real dsh fork on this side. Flandern1211 measured the pair
on their computer: the source kept its 8 pre-#5491 calls, and a second
/api/context 6s later took 9ms instead of 575ms. Not changed: Routing
still goes by the opening for such a call (its looseKeys retries every
2s), and a fork call whose reply never comes goes back to the source
after a minute.

Reported-by: Flandern1211
Co-authored-by: Flandern1211 <163982805+Flandern1211@users.noreply.github.com>
2026-11-07 20:10:28 +08:00
Flandern1211 d052fec0e3 dsh: a fork without a parent gets its own row, named by its replies (#5542)
#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 on 5c5160c94), on mote; the pushed head
adds only e20517a88 under 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>
2026-11-07 13:54:24 +08:00