M11: what the server will actually read

The release-validation milestone, and the thing it had to settle first was
whether any of the earlier evidence meant what it said. M8 measured a deployment
enforcing a 4,096-token input window while the application budgeted 16,384.
Every request returned 200. What Ollama does with the excess is drop the oldest
tokens, and the oldest tokens here are the system block — the narrator's rules
and the campaign canon. A hundred-turn certification against that server would
have looked perfect and proved nothing, which is why this milestone could not
begin with a hundred turns.

So the application asks now. Ollama's window is a property of how a model was
loaded rather than of the request — sending num_ctx is accepted, ignored, and
worse, reloads the model at the server's own default — so the only honest move
is to find out and then tell the truth about it. /api/ps reports what a resident
model is being served with, /api/show what an unloaded one will load with, both
on the same host inference already uses, through the same endpoint policy and
the same TLS trust store. A verified window is a ceiling on the budget; an
unverified one leaves the budget alone and is recorded as unverified in the
turn's own provenance, so an old turn can be asked afterwards whether it was
built against a checked window. There is no third behaviour, and in particular
no hard-coded 4,096: a number the server did not say would be right on one
machine and wrong on the next.

The proof that this is doing something is a campaign whose canon sits at the
front of the prompt, 120 turns of history, and a 4,096-token window. The canon
is still there afterwards and the oldest history is gone. The same campaign
built the old way produces a prompt more than twice the window — the defect,
reproduced, so the fix is measured against it rather than asserted.

Two defects the validation found on its own, and they are the same defect twice:
something was true and nobody was told. A manual state correction of four
changes with one bad reference applied three, returned 201, and said nothing —
while recording the refusal on the audit row nobody reads. It came to light
because the identity diagnostic's own fixture was refused that way and the whole
run proceeded on a campaign with no scene, which would have read as a model
failure. And the narration-length setting moved no number: brief, medium and
long each became one English sentence, while the numeric hint the model actually
reads was derived from the global reply cap and said the same thing for all
three. Both now say what they did.

The other two post-M8 findings are closed as well. The tab said AI D&D, which no
document had ever claimed it did not; it says Interactive Story now, with the
open campaign first, and the name is the owner's decision rather than a
find-and-replace to something narrower than the engine. After an Undo the reader
could not tell where they had landed; the control row now ends with
"Moment 11 · later story ahead", from the server's own answer, in the word the
transcript already uses, with none of head, branch or depth anywhere near it.

The identity diagnostic exists and the root cause does not. That campaign was
destroyed, so no cause can be established — what M11 owes the finding is
something that can classify the next occurrence, and a diagnostic that makes only
the judgements a program can honestly make: duplicate keys, shared names,
protagonist drift, state and context disagreeing. Whether prose misattributed a
line is left to a person reading it beside its prompt, because a regex cannot
read dialogue and one that pretended to would produce exactly the confident wrong
answer this finding is about. Its detectors are proved to fire against a planted
second Alice.

Two entities may still share a display name. That was checked first, as the
finding asked, and left permitted: a mother and a daughter, or a stranger giving
a false name, are ordinary fiction, and refusing them to guard against a model
mistake would refuse the wrong thing. What was missing was that it happened
silently. It is reported now.

Evidence, not inference: a hundred accepted turns against a real narrator with
genuine process restarts; a real browser against the built SPA; a container with
no network at all; a campaign moved into a data directory that never existed.
Each was discarded and re-run whenever the product changed under it, and the runs
that were thrown away are listed in the report with the reason, along with ten
defects in the harnesses themselves — because a harness that has only ever
agreed with itself is not evidence, and two of M8's five harness defects were
masking real ones.

No dependency was added, removed or upgraded. No acceptance test was retired,
relaxed or reclassified. M11 is implemented and verified; it is not accepted, and
there is no release tag.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qyn3oRd4D6pi72nKBG725B
This commit is contained in:
JesseMarkowitz
2026-09-07 14:01:20 -04:00
co-authored by Claude Opus 5
parent 1013c94eb1
commit 144406cd48
57 changed files with 7374 additions and 97 deletions
+3
View File
@@ -189,6 +189,9 @@ def create_adventure(
persona_name=payload.persona_name.strip(),
persona_pronouns=payload.persona_pronouns.strip(),
persona_desc=payload.persona_desc.strip(),
# M11: the reader's narration-length choice, kept as data so the prompt
# builder can turn it into a word range (post-M8 finding C).
narration_length=payload.narration_length,
)
db.add(adventure)
db.flush()
+6 -1
View File
@@ -8,6 +8,7 @@ from fastapi import Depends, HTTPException
from sqlalchemy.orm import Session
from ... import derived, memorybank, models, summaries
from ... import contextwindow
from ...context import ContextOverflow, build_context
from ...database import get_db
from ...knowledge import retrieval as knowledge_retrieval
@@ -29,9 +30,13 @@ async def dry_run_context(
# that skipped the library would show a prompt the next turn will not send,
# which is the one thing this panel must never do.
knowledge = await knowledge_retrieval.retrieve(adventure, settings)
# M11: and by the same probe the turn makes, for the same reason — a panel
# that showed a 16,384-token budget while the next turn will be capped to
# 4,096 would be showing a prompt that is not the one about to be sent.
window = await contextwindow.probe(settings.endpoint_url, settings.model)
try:
_, _, report = build_context(
adventure, settings, memories, knowledge=knowledge
adventure, settings, memories, knowledge=knowledge, window=window
)
except ContextOverflow as exc:
# M6: a dry run of a prompt that cannot be built is still an answer, and
+16 -2
View File
@@ -48,6 +48,7 @@ def read_state(
# The raw document, for the correction form to name a key with and for a
# test to assert on without parsing prose.
document=state,
duplicate_names=narrative.model.duplicate_names(state),
)
@@ -95,6 +96,16 @@ def correct_state(
)
if not review.accepted:
raise HTTPException(400, _refusal_message(review))
# M11: a correction can be partly refused — one bad reference among four
# good changes — and until M11 that came back as an unqualified success.
# Partial application is the deliberate behaviour (`validate.py`: losing
# three good changes to one typo is worse), so what M11 adds is the
# telling, not a change of behaviour.
refused = [
{"event": rejection.event, "reason": rejection.reason,
"detail": rejection.detail}
for rejection in review.rejected
]
node = head.node_at(db, adventure, adventure.head_depth)
new_state, _proposal = narrative.store.record(
@@ -120,11 +131,14 @@ def correct_state(
finally:
turns._active_turns.discard(adventure_id)
view = narrative.render.for_inspector(narrative.store.current(adventure))
state_now = narrative.store.current(adventure)
view = narrative.render.for_inspector(state_now)
return schemas.NarrativeStateOut(
groups=[schemas.StateGroup(**group) for group in view["groups"]],
empty=view["empty"],
document=narrative.store.current(adventure),
document=state_now,
duplicate_names=narrative.model.duplicate_names(state_now),
refused=refused,
)
+8
View File
@@ -16,6 +16,7 @@ from ... import (
attempts, head, limits, memorybank, models, narrative, schemas, tree,
worldstate,
)
from ... import contextwindow
from ...context import ContextOverflow, build_context, cursors
from ...knowledge import retrieval as knowledge_retrieval
from ...database import get_db
@@ -202,6 +203,12 @@ async def _generate_turn(
knowledge = await knowledge_retrieval.retrieve(
adventure, settings, exclude_action_id=replacing_id
)
# M11: what this server will actually accept. Asked here rather than inside
# the builder for the same reason retrieval is — the builder makes no
# network calls — and cached per endpoint and model, so it costs one short
# request per session rather than one per turn. An unverified window does
# not block the turn; it is recorded as unverified in the snapshot below.
window = await contextwindow.probe(settings.endpoint_url, settings.model)
try:
system_text, story_text, snapshot = build_context(
adventure,
@@ -209,6 +216,7 @@ async def _generate_turn(
memories,
exclude_action_id=replacing_id,
knowledge=knowledge,
window=window,
)
except ContextOverflow as exc:
# M6: the protected context does not fit in the configured budget, so
+64 -1
View File
@@ -15,7 +15,7 @@ from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from starlette.concurrency import run_in_threadpool
from .. import auth, endpoints, models, schemas, tlstrust
from .. import auth, contextwindow, endpoints, models, schemas, tlstrust
from ..database import get_db
from ..providers.openai_compatible import CONNECT_TIMEOUT
@@ -65,6 +65,15 @@ async def update_settings(
if reason is not None:
raise HTTPException(400, f"That endpoint can't be used — {reason}.")
if any(
field in fields and fields[field] != getattr(settings, field)
for field in ("endpoint_url", "model")
):
# M11: a different server or a different model is a different window.
# What was verified about the old pair says nothing about the new one,
# and a stale ceiling is the one thing this must never apply.
contextwindow.cache_clear()
embedding_model_changed = (
"embedding_model" in fields
and fields["embedding_model"] != settings.embedding_model
@@ -165,6 +174,38 @@ async def list_endpoint_models(endpoint_url: str) -> dict:
return {"ok": True, "models": models_available}
def _window_warning(window: contextwindow.Window, settings: models.Settings) -> str | None:
"""What to tell the reader about the window, or None when nothing is wrong.
Three cases, and they need three different things done about them, so they
say three different things (the same reasoning as the connection test's own
four failure kinds).
"""
budget = settings.context_token_budget
if not window.verified:
return (
f"The context window this server will give '{settings.model}' could not "
f"be checked — {window.detail}. The story budget is {budget:,} tokens; "
"if the server's window is smaller than that it silently drops the "
"oldest part of the prompt, which here is the narrator's rules and the "
"campaign canon. See DEVELOPMENT.md, 'The context window your Ollama "
"actually enforces'."
)
if window.tokens < budget:
ceiling = (
f" The model itself can go up to {window.model_max:,}."
if window.model_max and window.model_max > window.tokens else ""
)
return (
f"This server gives '{settings.model}' {window.tokens:,} tokens, which is "
f"less than the {budget:,}-token story budget. Prompts are being built to "
f"{window.tokens:,} so nothing is silently truncated — the campaign simply "
f"gets less history than the setting asks for.{ceiling} To use the whole "
"budget, load the model with a larger window (DEVELOPMENT.md)."
)
return None
@router.post("/test")
async def test_connection(
db: Session = Depends(get_db),
@@ -173,6 +214,28 @@ async def test_connection(
"""Checks the endpoint the turn engine would use, and lists its models."""
settings = get_settings(db, user)
result = await list_endpoint_models(settings.endpoint_url)
if result.get("ok") and settings.model:
# M11: while we have the server's attention, ask what window it will
# give this model. This is where a reader can act on the answer — the
# model picker is on the same screen as the budget — and it is the
# difference between "your prompts are being truncated" being visible
# here and being invisible until the narrator forgets the canon.
# Cached, deliberately. The model-status badge calls this endpoint on
# every page load, so an uncached probe would be two extra requests to
# the inference host per page view for an answer that changes only when
# an operator reloads a model. Changing the endpoint or the model clears
# the cache (`update_settings`), which covers the case a reader can
# actually cause; the detail line always says where the number came from.
window = await contextwindow.probe(settings.endpoint_url, settings.model)
result = result | {"window": {
"verified": window.verified,
"tokens": window.tokens,
"source": window.source,
"model_max": window.model_max,
"detail": window.detail,
"budget": settings.context_token_budget,
"warning": _window_warning(window, settings),
}}
if result.get("ok") and settings.model and settings.model not in result["models"]:
# Reachable, but pointed at a model that is not installed there — the
# commonest way for a correct endpoint to still fail every turn.