Commit Graph
2 Commits
Author SHA1 Message Date
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
yetoneandFlandern1211 e8df78f33e routing: a dsh fork's requests are named by the reply its client was given (#5491)
dsh's chat and messages routes send no session id, so Routing and Context
found a dsh session by the hash of the conversation's opening. A fork
repeats its source's opening, so every request the fork made showed under
the source, and the fork's name never appeared.

Flandern1211's patch, ported:
- The gateway keeps the id of the reply it gave the client
  (Route.ResponseID). It is set from clientResponseID in the same update
  that marks the route done, so a poll that sees Done also sees the id,
  with no race against the usage ledger. When magpie translates, it is
  the id after translation, e.g. chatcmpl-…, not the upstream's msg_….
- sessions reads dsh's replayState.response.responseId into
  Session.ResponseIDs. Only main files are read, only replies served by
  the gateway, and only the fork's own replies after its session/end-seed
  (seedLength for version 1).
- Routing (pricedRoutes) and Context (joinConvs) look up a finished
  request by its reply id first, then by its opening. A request logged
  before this keeps the opening's session.

Changed from the patch:
- A reply id names a session over the opening only when the opening is
  that session's own, or a session it was forked from, or the opening is
  unknown. Vendors' ids can repeat: an encoder keeps the upstream's id,
  and Ollama's is chatcmpl-<0..999>. Without the guard, two unrelated
  conversations could swap names. Session.ForkOf comes from the fork
  header's parentSession, isSeeded and delegationDepth 0, which is how
  dsh's buildForkSeed writes it. ownerOf walks that chain, so a fork of a
  fork works too.
- Poll cost: dsh never writes down some reply ids (a title call, a
  refused turn). Under the patch, each such id made Routing list every
  session again every 2s, for as long as the route was on the page. Now
  an id is waited for only up to a minute (convsKept) after its request
  ended (looseKeys). After that the regular one-minute rebuild covers it.
- A page whose loose routes carry only a reply id still builds the map
  (looseRoute).
- The patch's synthetic fork headers gain parentSession, as dsh writes
  them.
- docs/subsystems/gateway-routing.md describes the reply-id join.

Tests:
- TestDshForkNamedByTheReplyTheGatewayGave sends dsh 0.2.0-rc.2's real
  captured completions request (testdata/dsh-gateway) through
  gateway.New() twice, to an Anthropic-only upstream, so the reply is
  translated. It writes the source's real session file with the first
  client id, and a fork shaped like dsh's buildForkSeed output with the
  second. It then checks that pricedRoutes and contextOf put each request
  under its own session, and an old route without an id under the source.
- TestDshForkOfARealSessionListsItsOwnReplies forks the real fixture
  session: the fork lists only its own reply and ForkOf, the source
  keeps [c1].
- TestDshReplyIDOfAnotherConversationNamesNoOne covers the guard.
- TestRoutingWaitsForAReplyIDOnlyAWhile covers the poll bound.
- The patch's own tests: TestDoneRouteKeepsTheClientResponseID (json and
  stream), TestDshResponseIDs*, TestRoutingTellsAForkByItsReply,
  TestContextTellsAForkByItsReply.

Run on mote (mote-run), at this tree on origin/main be5e8f29f. The vet and
go test lines below were run again after rebasing on e6b9d1199, which
changed only the README and library (ok):
- gofmt -l internal/ printed nothing.
- go vet ./internal/... . is clean.
- GOOS=linux go vet -tags nogui and GOOS=windows go vet of
  internal/{sessions,gui,gateway} are ok.
- go test ./internal/sessions ./internal/gateway ./internal/gui -run
  'Dsh|ResponseID|Fork|Routing|Context|Conv' -count=1: ok.
- GUI: routing-by-key, routing-ctx-sessions, routing-request-metrics,
  routing-sessions, routing-session-folder, sessions-empty-range,
  ctx-route, context-map and panel-routing pass in chromium (120/120)
  and webkit (120/120).

Broken by hand, each red, then restored:
- guard off: TestDshReplyIDOfAnotherConversationNamesNoOne;
- poll bound off: TestRoutingWaitsForAReplyIDOnlyAWhile;
- end-seed keeps the inherited reply ids: TestDshResponseIDsSkipTheSeed,
  TestDshResponseIDsEndSeedAcrossReads and
  TestDshForkOfARealSessionListsItsOwnReplies;
- ForkOf not set: TestDshForkOfARealSessionListsItsOwnReplies,
  TestDshForkNamedByTheReplyTheGatewayGave,
  TestRoutingTellsAForkByItsReply and TestContextTellsAForkByItsReply;
- gateway keeps no id: TestDoneRouteKeepsTheClientResponseID and
  TestDshForkNamedByTheReplyTheGatewayGave.

Not tried:
- a real dsh fork against a running magpie. The session shapes come from
  the real rc.2 fixture and dsh's fork source.
- A request still running, or a failed one, still shows under the source
  until it has a reply id. The patch says the same.
- Delegated subagent files (delegationDepth > 0) are not read for reply
  ids; they stay under their parent as before.
- Not changed: the gateway's turn clock (sessionTurnKey) also falls back
  to the opening's hash, so a fork and its source running at once share
  one. Filed as #5496.

The full suite runs after the push.

Co-authored-by: Flandern1211 <163982805+Flandern1211@users.noreply.github.com>
Reported-by: flandern1211_58540 (Discord)
2026-11-06 17:22:52 +08:00