fix(pier): reap stateful sessions whose store record expired

- a reaper started at Mount checks every local session against the store
  every min(idle_ttl/2, 1m) and closes each copy whose record is gone,
  logging the expired step (A-CR-01, A-IN-06)
- the GET stream re-check ends the stream when the record is gone (A-IN-01)
- tool calls served without a session on the stateful path log the
  session as ephemeral (A-IN-06)
- TestPierReaperSmoke and the ReapNow, LocalSessions, StopReaper seams
This commit is contained in:
Jakub Zych
2026-10-23 15:50:04 +02:00
parent d18d8f0dc2
commit 2bf9dca603
6 changed files with 190 additions and 8 deletions

View File

@@ -57,6 +57,12 @@ type Pier struct {
appName string
version string
instance string
// stopReap ends the session reaper Mount starts. backpack.App has no
// shutdown hook yet, so in production the reaper runs for the life of
// the process, like the store subscription; when backpack gains one,
// Mount registers stopReap there.
stopReap context.CancelFunc
}
// Mount reads the mcp.* keys and, when mcp.enabled is true, compiles every
@@ -130,6 +136,9 @@ func Mount(host Host, app *backpack.App, plugins []party.Plugin) error {
if err := app.Publish(p); err != nil {
return fmt.Errorf("pier: publishing the endpoint: %w", err)
}
reapCtx, stop := context.WithCancel(context.Background())
p.stopReap = stop
go p.sessions.reap(reapCtx, reapInterval(cfg.IdleTTL))
return nil
}