sessionscale

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 15 Imported by: 0

README

sessionscale: long-lived session memory and per-prompt cost

sessionscale writes synthetic Pi session files with the shape of a long-lived session and measures a runtime that resumes them: resident memory after the resume, after N prompts and during a streaming soak, and the CPU and wall time of each prompt. Pi and PiG resume the same bytes, and the scripted model records a hash of each request's conversation, so the two can be checked to send the same context.

The default shape is the one reported for a five-day session (2026-10-10): 299 MB, 46,100 entries (25,171 tool results, 20,138 assistant messages, 700 user messages), 63 compactions, 17 leaves, a longest line of 1.06 MB. Only those counts and sizes are used. The content is pseudo-random from a seed.

go build -o sessionscale ./bench/sessionscale/cmd/sessionscale
go build -o pigprobe ./bench/sessionscale/cmd/pigprobe      # cmd/pig plus SIGUSR1 heap and SIGUSR2 CPU profiles
./sessionscale gen -out f299 -bytes 299M                      # 150k-token active context
./sessionscale gen -out f1g -bytes 1G
./sessionscale gen -out c1m -bytes 299M -context 1000000      # 1M-token active context (also 2000000, 4000000)
./sessionscale gen -out p1 -profile p1                        # real-session profile (handoffs P1): 314 MB, priced prompt caching with misses on two models, /tree rows about 61% of entries
./sessionscale run -arm pig -cmd "./pigprobe -ne" -fixture f299 -prompts 5,50 -heap -cpu -out runs/pig.jsonl
./sessionscale run -arm pi -cmd "node .../pi-coding-agent/dist/cli.js -ne" -fixture f299 -prompts 5,50 -out runs/pi.jsonl
./sessionscale run ... -soak 6m -soak-every 1m                 # slow streaming answers with idle gaps

run copies the session file into a scratch directory, starts the runtime in a pseudo-terminal (or -mode rpc) with --session and a scratch HOME and agent directory, and writes one JSON line per point: RSS, PSS, anonymous and private dirty memory and peak RSS of the process tree (KiB, from /proc), CPU and wall time, per-prompt CPU and wall time, and the model requests (bytes, message count, conversation hash). With -heap and -cpu (pigprobe only) it also writes inuse_space heap profiles at each point and a CPU profile of each checkpoint's prompts.

sessionscale k8s seed and sessionscale k8s sample are bench/k8s's adapter: the profiles session-scale-context and session-scale-entries run them in a Kubernetes pod (docs/site/docs/benchmarking.md). seed writes one fixture and k8s-<size>.json with its fingerprint. sample runs run once, interactive, on a copy with five prompts, and prints one k8sbench sample line.

Documentation

Overview

Package sessionscale writes synthetic long-lived Pi session files and the agent directory that resumes them, so the memory and per-prompt cost of a resumed session can be measured on Pi and PiG with the same bytes.

The default shape is the one reported for a five-day session (owner, 2026-10-10): 299 MB, 46,100 entries, of which 25,171 tool results (130 MB) and 20,138 assistant messages (166 MB), 700 user messages, 63 compactions, 17 leaves and a longest line of 1.06 MB. Only those shape statistics are used; the content is pseudo-random prose, code and base64 from a fixed seed, so a shape and seed always produce the same bytes.

Tokens are estimated as Pi's compaction.ts estimateTokens does: a quarter of the characters of message text, thinking, tool-call names and JSON arguments, and tool-result text, rounded up. Signatures and tool-result details are on disk but not in the estimate.

Index

Constants

View Source
const (
	OwnerBytes           = 299 << 20
	OwnerEntries         = 46100
	OwnerToolResults     = 25171
	OwnerToolResultBytes = 130 << 20
	OwnerAssistants      = 20138
	OwnerAssistantBytes  = 166 << 20
	OwnerUsers           = 700
	OwnerCompactions     = 63
	OwnerLeaves          = 17
	OwnerMaxLine         = 1_060_000
)

Owner shape statistics (2026-10-10 report). Only counts and sizes; no content.

View Source
const (
	P1Bytes       = 314_175_691
	P1Users       = 706
	P1Assistants  = 20_305
	P1ToolResults = 25_339
	P1Systems     = 2
	P1Compactions = 63
	// P1CompactionBytes is the size of the profiled compaction records.
	P1CompactionBytes = 13 << 20
	P1ModelChanges    = 19
	P1CustomMessages  = 3
	P1ThinkingLevels  = 2
	P1BranchPoints    = 15
	// P1TreeRows is the default-filter /tree row count; the assistant messages that are not rows carry no text.
	P1TreeRows = 28_442
	// P1MissEvery is one prompt-cache miss per this many assistant responses.
	P1MissEvery = 40
)

Real-session profile statistics (handoffs/P1-real-session.md, 2026-10-11): the owner's session as profiled for open and /tree. Only counts; no content.

View Source
const (
	Provider = "sessionscale"
	Model    = "scripted"
	// ModelB is the second model a ProfileP1 session switches to; its cache-read price differs from Model's.
	ModelB = "scripted-b"
)

Provider and Model name the scripted model the agent directory declares and the assistant messages carry.

View Source
const ProfileP1 = "p1"

ProfileP1 selects the real-session profile.

Variables

This section is empty.

Functions

func WriteAgentDir

func WriteAgentDir(agentDir string, window int, baseURL string) error

WriteAgentDir writes models.json declaring the scripted model at baseURL with the window, and settings.json selecting it.

Types

type Meta

type Meta struct {
	Shape            Shape            `json:"shape"`
	Bytes            int64            `json:"bytes"`
	Entries          int              `json:"entries"`
	ByType           map[string]int   `json:"byType"`
	BytesByType      map[string]int64 `json:"bytesByType"`
	MaxLine          int              `json:"maxLine"`
	Compactions      int              `json:"compactions"`
	Leaves           int              `json:"leaves"`
	PathEntries      int              `json:"pathEntries"`
	ContextEntries   int              `json:"contextEntries"`
	ContextTokens    int              `json:"contextTokens"`
	ContextBytes     int64            `json:"contextBytes"`
	Window           int              `json:"window"`
	SHA256           string           `json:"sha256"`
	Session          string           `json:"session,omitempty"`
	AgentDir         string           `json:"agentDir,omitempty"`
	LeafID           string           `json:"leafId"`
	LastCompactionID string           `json:"lastCompactionId"`
}

Meta describes a written fixture.

func Generate

func Generate(w io.Writer, shape Shape) (Meta, error)

Generate writes the session file for shape to w.

func Write

func Write(dir string, shape Shape, baseURL string) (Meta, error)

Write creates dir/session.jsonl, dir/agent/models.json, dir/agent/settings.json, dir/meta.json and dir/work. baseURL is the scripted model's OpenAI-compatible endpoint.

type Shape

type Shape struct {
	// Bytes is the file size to reach. Generation stops at the first turn boundary at or above it, then writes the active tail.
	Bytes int64
	// Compactions and Leaves are the counts for the whole file. Zero scales the owner's counts by Bytes.
	Compactions int
	Leaves      int
	// ContextTokens is the estimated size of the active context the file resumes to: the last compaction's summary, its kept messages and everything after it. Zero means 150,000.
	ContextTokens int
	// KeepRecentTokens is how much each compaction keeps (Pi's compaction.keepRecentTokens default, 20,000, when zero).
	KeepRecentTokens int
	// Window is the scripted model's context window. Zero means the smallest of 272,000 and ContextTokens*100/85 rounded up to a multiple of 1,000 that is at least ContextTokens + 32,768.
	Window int
	// Seed selects the content.
	Seed uint64
	// Cwd is the header's working directory.
	Cwd string
	// Profile "" is the 2026-10-10 report's shape. ProfileP1 is the real-session profile: its entry mix, model changes, priced
	// prompt caching with misses, system and custom messages, and assistant messages without text that the /tree default filter hides.
	Profile string
}

Shape selects a fixture.

func (Shape) Normalize

func (s Shape) Normalize() Shape

Normalize fills the zero fields of a shape.

Directories

Path Synopsis
cmd
pigprobe command
Command pigprobe is cmd/pig with two additions for measurement: SIGUSR1 writes a heap profile (after a collection) to $SESSIONSCALE_HEAP_DIR/heap-<n>.pprof, then an empty heap-<n>.pprof.done marker; SIGUSR2 starts a CPU profile to $SESSIONSCALE_HEAP_DIR/cpu-<n>.pprof and the next SIGUSR2 stops it (then cpu-<n>.pprof.done).
Command pigprobe is cmd/pig with two additions for measurement: SIGUSR1 writes a heap profile (after a collection) to $SESSIONSCALE_HEAP_DIR/heap-<n>.pprof, then an empty heap-<n>.pprof.done marker; SIGUSR2 starts a CPU profile to $SESSIONSCALE_HEAP_DIR/cpu-<n>.pprof and the next SIGUSR2 stops it (then cpu-<n>.pprof.done).
sessionscale command
Command sessionscale writes and measures long-lived session fixtures (see package sessionscale).
Command sessionscale writes and measures long-lived session fixtures (see package sessionscale).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL