Tracker Start Values per Greeting — Design Document

Status: ✅ Shipped — S1 and S2 are both built and pushed (kb-audit 2026-10-29). Decided 2026-10-17: the owner chose Option A and took the defaults for Q1–Q4, and added one requirement: a tracker added later must be detectable. The delivery plan, with contracts, milestones and lanes, is docs-internal/architecture/chat-engine/TRACKER_GREETING_START_DELIVERY.md. The Acceptance Criteria boxes below are not ticked on this page; the delivery doc carries the live-pass record.

S1 — shipped (SQL ff1bd3e14 2026-10-17; runtime + authoring d7d649f6b 2026-10-18): the three greeting write doors take trackerJson, the starts read is in, the AI ladder and the manual run screen the values, and all three greeting editors carry the block.

S2 — shipped (9ff12ce50 + 1f8d4c005, live-checked 2026-10-29, fix b96f082d8; pushed with f25b4ad4b): the package keeps its own start values per curated greeting, the package save writes them in its own transaction (checked against the set the save leaves), the resolver lays them over everything else, the cast section falls back to them before the first snapshot, the publish checks screen them, and the builder's greeting step carries the block, with the cast picked from the members' names.

This page builds on Trackers (Phase 1, T1, P1 and C1 shipped) and on Package Cast.

Overview

A tracker has one starting value today. A character can have many greetings, and each greeting opens the story somewhere else: one in the tavern at dusk, another on the road at dawn. The tracker's starting state should match the greeting the reader picked: location, time of day, affection, who is on stage.

The tracker spec already decided what this is. It named the field tracker_overrides_json and gave a greeting's value precedence over every other starting value (trackers.md → Package Integration, and its resolved Open Question 5). This page now calls the field tracker_json, following the owner. The tracker spec also sketched how: store the starting values as the first message's tracker_json (trackers.md, Implementation Map → Conversation Creation Flow). This page maps today's code, compares the ways to build it, records the decision, and adds the detection of trackers added later.

Owner decisions (2026-10-17)

"Tracker greeting start values - it needs to be possible to detect a new addition to tracker. Otherwise agreed. Greeting is basically the first message so it having it's own tracker_json is a good solution"

Today's code

Line numbers are at 7d64d82c5.

What a starting value is now.

Piece Where What it does
The tracker's own start trackers.initial_value (68_tables_trackers.sql:22), 500 chars (CreatorFieldLimits.TrackerInitialValue) The default.
Per-binding start entity_tracker_bindings.override_initial_value (68_tables_trackers.sql:126) A character's or package's own start. Written by the API and agent proposals only; the character's Trackers section shows it read-only (CharacterTrackersSection.tsx:272).
Effective start of a binding TrackerRepository.GetActiveForOwnerAsync, COALESCE(b.override_initial_value, t.initial_value) (TrackerRepository.cs:141) One value per binding.
The conversation's set ConversationTrackerSetResolver.UnionAsync (ConversationTrackerSetResolver.cs:59-84) Cast roster first, then the character's bindings, then the package's; deduped by key, the first definition wins for its start too. Read live every turn.
The cast's start the synthesised roster (ConversationTrackerSetResolver.cs:128-129) InitialValue = the members with present_at_start, in cast order.

Where the greeting is chosen and stored.

The greeting row never gets a snapshot. The first snapshot is written by the first eval, after the reader's first message. It seeds each key the prior state lacks from InitialValue, canonicalised when it fits the type and kept as authored when it doesn't (WebTrackerEvalService.cs:221-241).

Until that first snapshot, four places fall back to InitialValue on their own:

Gaps that exist today:

A tracker added mid-story, today. A tracker bound after a story already has snapshots is picked up by the resolver on the next turn. Then:

Reset. A blank value in the scene save resets the key to the binding's start, else the tracker's (ConversationsEndpoints.cs:2268-2271, InitialTrackerValue at :2367-2378).

Typed values.

Greetings.

Around the edges.

Design Goals

  1. The start matches the greeting picked, for every tracker type and for the cast.
  2. A started story never changes when its greeting is edited later, the same as the greeting's text.
  3. One answer to "what does this tracker start at", for every consumer.
  4. Values are written where the greeting is written, and checked like any other tracker value.
  5. A tracker added later is never mistaken for an authored one: not in the editor, not by the eval.
  6. No new LLM call.

Non-Goals

Options

A, B and D share the authoring block in the greeting editors and the write-time validation described under the design. They differ in storage and in when the start becomes the story's. C has no authoring at all. None of them needs a backfill, and none reaches Discord.

A — Opening snapshot B — Side table C — Eval reads the greeting D — Live layering only
Storage JSON map on the greeting, keyed by tracker key greeting_tracker_values(greeting_id, tracker_id, value) none JSON map on the greeting
The start is fixed at creation, on the greeting row never: read live at the first eval never: read live until the first eval
First reply's prompt has the state yes, through the existing injector no no no
Reader can edit before the first reply yes, through the existing scene save no no no
Cast and package trackers by key: cast and package keys fit cast has no tracker row; needs a second table for packages inferred only by key
New consumer code one write at start, one eval-window rule a join in every resolve an opening eval call one resolver seam
Exact typed values yes yes guessed yes

A — The greeting's values become the story's first snapshot. Chosen (2026-10-17); designed in full below.

B — A side table.

The values are always read and written with their greeting, so rows buy nothing the map lacks.

C — The eval reads the start off the greeting. This is today's baseline, not a new design.

It stays as the complement: whatever a greeting leaves blank, the first eval still infers.

D — Live layering only. The resolver puts the greeting's value into each definition's InitialValue, and every fallback listed above follows with no change of its own. It is small.

D is A's supporting rule, not a design on its own.

Recommendation: A, with D's seam

Why A:

D's seam stays, as A's supporting rule. The resolver layers the greeting's values into InitialValue. So Reset, the scene's starting values, and every "no snapshot yet" fallback give the same answer as the opening snapshot. That covers conversations without one:

The greeting's map is a primary-key read beside the conversation read the resolver already makes. It happens only when the conversation has a greeting.

Two costs, named and designed.

  1. The watermark. A snapshot on the greeting would make it the first eval's anchor, and the greeting text would drop out of the first eval's window. Keys the greeting leaves blank could then no longer be read off its prose: a regression.

    Rule: the opening snapshot is the first eval's prior state, but not its watermark. The eval reads the story's first snapshot and knows whether it is the opening: an assistant row no model wrote, with no row before it (the chat client's own greeting rule). The eval passes over that row when it looks for the anchor. So the first eval still reads the greeting and the first exchange, starting from the authored values.

  2. Where the write runs. The set (roster synthesis, dedupe, binding starts) and the type normaliser live in C#. Writing the snapshot inside the SQL start would copy all of that into plpgsql. The repository can't call WebChat, so the create transaction can't build it either.

    Decision: write it right after the create, in the same request, before the response. Both create paths (ConversationsEndpoints.cs:1094 package, :1307 character) call one WebChat service. The client can't send a first message before the response arrives. The write is guarded: it only lands when the conversation has no snapshot at all. A failed write degrades to the first eval seeding the same values, through D's seam.

No backfill. Stories created before this feature keep today's path. The fallbacks stay for them.

The design

Schema (idempotent, through v1_run_all.sql):

-- S1: the greeting author's starts
ALTER TABLE character_greetings ADD COLUMN IF NOT EXISTS tracker_json JSONB;
-- S2: the package author's starts, per curated greeting
ALTER TABLE package_greeting_bindings ADD COLUMN IF NOT EXISTS tracker_json JSONB;
-- each: CHECK (tracker_json IS NULL OR jsonb_typeof(tracker_json) = 'object')

Values are strings in the same canonical form as a message's tracker_json. A list is a JSON-array string. Example: {"location": "The Rusty Tankard", "time_of_day": "Evening", "mood": "", "cast": "[\"Innkeeper Bran\"]"}.

Three states per key. This is what makes a later addition detectable:

In the greeting's map Meaning The story starts at
"location": "The Rusty Tankard" the author set it that value
"mood": "" the author left it on its default the binding's start, else the tracker's
no weather key never set on this greeting: the tracker was bound after the author last saved the starts the default, and the editor marks it New

Precedence, for each key in the conversation's resolved set:

  1. the package's greeting binding (S2);
  2. the character's greeting;
  3. the winning binding's own start (character first, as P1 ships);
  4. the tracker's initial_value.

The character greeting's values land only on the character's own trackers, never on the cast roster or a package tracker. For cast, step 1 applies, else the present_at_start members.

Write path. The greeting routes take trackerJson, a whole map in three states:

The editor sends every key already in the map that is still bound, plus every row the author touched. A row that was never set and that the author didn't touch stays out, so it stays New.

Each value is checked the way the scene save checks one:

Where the write runs.

Around the write.

Start path. After the create returns, the service:

  1. stops when trackers are off for the conversation, or it has no greeting;
  2. resolves the set, with greeting-aware starts;
  3. takes each non-empty start and canonicalises it with the eval's seed rule, which is extracted into one helper (the eval seed, Reset and the trackers DTO each do it separately today);
  4. writes the result in the set's order with fn_seed_opening_tracker_snapshot(conversation, json).

The function takes the tracker_state lock and says whether it wrote. It writes only onto the conversation's first row, only when that row is an assistant row, and only when no row in the conversation has a snapshot. An empty start writes nothing, so a story with no starting values behaves exactly as today.

Read path.

UI.

Detecting a tracker added later

The owner's requirement (2026-10-17): a tracker added after the starts were written, or after a story started, is told apart from one that was authored.

In the greeting editor.

In a running story.

Limits, by design.

What each case does

Case Behaviour
Character, package and cast trackers By key. S1 names the character's trackers; S2 adds package trackers and cast on the package's greeting binding.
Conversation-bound trackers (T2) No greeting value. They start at their own start, seeded by the first eval.
A greeting edited after a story started The story's opening snapshot is untouched, and the opening shows no stage direction. Reset and keys bound later follow the edit, as they follow tracker edits today.
A tracker bound to the character after the starts were written Every greeting marks it New. It starts at its default until the author sets it.
A tracker bound after a story started The next eval marks it new, with its default or unset, and records what it can. The story prompt, the scene and the bar show it from then on.
A tracker unbound or deleted later The key stays in the opening snapshot. The injector and the eval drop keys outside the set (WebTrackerHistoryInjector.cs:92), and the scene lists a stray key last, as it does today. In the greeting's map the key is ignored, absent from the editor, and dropped on the block's next save.
A tracker re-keyed The new key is New on every greeting; the old key is stale. A running story doesn't mark it new: its binding is old, so the eval shows its default unmarked, as today.
A greeting moved to another character, or detached Its map is cleared. On the new character every bound tracker is New.
A tracker re-typed after the value was saved At start the value is canonicalised when it fits and kept as authored when it doesn't (the seed rule). The editor flags it; saving the block with the value unchanged still works.
The reader's inline edit Works on the opening row like any reply's snapshot, before and after the first reply. Reset puts back the greeting's value. A scene save made while the first eval runs wins key by key.
Branching Copies the opening snapshot with the messages. No change.
Regenerating The greeting can't be regenerated. A regenerated first reply reads the opening snapshot as its prior state and the greeting in its window.
Re-picking a greeting Starts a new conversation with its own opening snapshot.
Start without greeting, or a greeting with empty text No row to carry a snapshot, so no opening is written. Until the story's first snapshot exists, every turn carries the canonical start values (greeting-aware where a greeting is set) as a state block at the head of the reader's turn, on every model leg: Classic, the Hybrid director in both shapes, and the writer. Nothing is written for it; the first eval seeds the same values and the normal path takes over (owner, Relay eod-521, 2026-11-25).
Greeting deleted after the start The story keeps its opening snapshot, and Reset falls back to the binding's start or the tracker's. A hard delete sets greeting_id to NULL. A soft delete keeps greeting_id, but the resolver skips a deleted greeting.
The reader deletes the greeting row Its snapshot goes with it. The no-snapshot fallbacks resume, and the first eval seeds the starts.
Trackers off for the conversation No opening snapshot. Nothing else changes.
Visual-novel runs Their own start path with trackers off: no opening.
Discord Untouched. Trackers are web-only.
Import and export Not exported. Imports never create a map.
Turn cost No new call. The first prompt grows by the state block (tens of tokens). The tracker-eval line is still reserved from the eval's own prompt builder (FeatherlessComputeCostEstimator.cs:565-579), now fed the opening's values and any new-tracker mark. Each eval adds one indexed read (the story's first snapshot).
Public or author-only Creator content, like the scenario. Only the creator's starts read carries it. greeting_view and every reader DTO stay without it: browse greetings, package details, the public character, the conversation greeting re-pick. Readers meet the values in the scene once the story starts. Hidden trackers stay hidden as they are today: a snapshot travels whole, and the scene filters is_visible.
Moderation and all-ages The values join every place that screens the greeting, rendered as key: value lines: the moderator projection, which the all-ages attachment screen also reads (EntityContentExtractionService.cs:347-361, SfwAttachmentTexts.cs:126-139); the AI check's greeting fields (PublishRequestFieldLoader.cs:204-216); the SQL keyword pass over greetings (32_run_content_checks.sql:360-390); the verified-creator scan (26_verified_creator_functions.sql:141-155). They are prompt material, like a tracker's initial_value (26:376-377).
Agent proposals and tools Unchanged in S1. Agent-proposal edits patch named fields, so a patch that doesn't name the new field keeps it, and its undo (an inverse edit) doesn't touch it either. Undoing a greeting an agent proposal created deletes the greeting, map included (68h_composer_undo.sql:856-870). The creation stamp leaves the field out while it is empty, so older undos still match.

Slices

Open Questions

Resolved by the owner (2026-10-17):

For the owner (each with the default the plan builds):

Decided here (overrule if wrong):

Acceptance Criteria

The feature is not done until every box below is verified ✅ against the running product. S2 lines are marked; every other line is S1. The delivery plan maps each line to its milestone and its proof.

User use cases — satisfiable + accessible (verify by driving the UI, not the code):

Behavior:

Invariants that must stay true:

Edges: