c1652e2bc6
Pure move: split the three multi-feature server files into per-concern files, with no behaviour change - same package, same exported and unexported identifiers, same call graph, same tests. - internal/server/chat.go -> chat.go (broker seam, client token, dispatcher), chat_hub.go, chat_claims.go, chat_permissions.go, chat_sessions.go, chat_stream.go, chat_commands.go - internal/stage/model.go -> model.go, model_run.go, model_failure.go, model_validation.go - internal/pipeline/runs.go -> runs.go (read side), runs_schema.go, runs_create.go, runs_mutate.go, runs_sessions.go Checked before committing: - Packaged templates and internal/author/skill/references: neither refers to internal/server/chat.go, internal/stage/model.go or internal/pipeline/runs.go, so nothing there needed updating (the change is a move with no behaviour change). - gofmt -l on the three packages: clean. go build ./..., go vet ./... and go test ./... pass. go.mod/go.sum unchanged. - No test, docs, android/, install or Docker files touched. Known stale path pointers deliberately left to the single docs writer (shared docs) and out of scope (android/): docs/chat-verification.md and android/README.md name the old file paths.
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package server
|
|
|
|
// chatPermissionRetainedLimit bounds the dedup set of already-pushed permission
|
|
// request ids one session retains, so a long turn cannot grow it without limit.
|
|
const chatPermissionRetainedLimit = 256
|
|
|
|
// seenPermission records requestID as pushed for the session and reports whether
|
|
// it is newly seen (true) or a duplicate (false). The retained ids are bounded:
|
|
// the oldest is dropped once the session exceeds chatPermissionRetainedLimit, so
|
|
// the same pending request is pushed at most once while the state stays bounded.
|
|
func (h *chatHub) seenPermission(sessionID, requestID string) bool {
|
|
if sessionID == "" || requestID == "" {
|
|
return false
|
|
}
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
turn := h.turnLocked(sessionID)
|
|
if turn.permissions == nil {
|
|
turn.permissions = map[string]struct{}{}
|
|
}
|
|
if _, ok := turn.permissions[requestID]; ok {
|
|
return false
|
|
}
|
|
turn.permissions[requestID] = struct{}{}
|
|
turn.permissionOrder = append(turn.permissionOrder, requestID)
|
|
if len(turn.permissionOrder) > chatPermissionRetainedLimit {
|
|
oldest := turn.permissionOrder[0]
|
|
turn.permissionOrder = turn.permissionOrder[1:]
|
|
delete(turn.permissions, oldest)
|
|
}
|
|
return true
|
|
}
|
|
|
|
// forgetPermission releases a request id reserved by seenPermission when its
|
|
// frame could not be written, so a later poll re-pushes it instead of the id
|
|
// staying "seen" while the phone never received the request.
|
|
func (h *chatHub) forgetPermission(sessionID, requestID string) {
|
|
if sessionID == "" || requestID == "" {
|
|
return
|
|
}
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
turn := h.turns[sessionID]
|
|
if turn == nil {
|
|
return
|
|
}
|
|
delete(turn.permissions, requestID)
|
|
for i, id := range turn.permissionOrder {
|
|
if id == requestID {
|
|
turn.permissionOrder = append(turn.permissionOrder[:i], turn.permissionOrder[i+1:]...)
|
|
break
|
|
}
|
|
}
|
|
}
|