feat: the room decides — physical entropy, real astronomy, unprompted speech
Three changes that together replace "deterministic hash decides everything"
with "the physical world genuinely participates".
PHYSICAL ENTROPY (app/entropy.py, lib/entropy.ts)
Contact was a database lookup: signature_from_anomalies() hashed the
anomaly pattern, so identical conditions always produced an identical
spirit. Now the client harvests real thermal/acoustic/RF noise from the
microphone and receiver noise floors — Von Neumann debiased, SHA-256
conditioned — and contributes it to every summon.
The client is untrusted by construction. A contribution is never a seed:
every draw is HMAC-SHA256(fresh server secret, client bytes || context).
Because fresh CSPRNG server bytes are always present, the output is
unpredictable and uniform no matter what the client sends — all-zeros, a
replayed value, or one chosen adversarially. The room can only ever ADD
unpredictability, never steer the result. Tests assert this directly:
400 replays of one contribution stay uniformly distributed.
A signature now identifies a *channel*, not a spirit. Whether the familiar
presence answers or something else picks up is a real draw
(RETURN_CHANCE). The Codex stays collectable; it is just no longer
guaranteed. test_same_signature_recontacts_same_entity became two tests —
one pinning the probability to prove re-contact works, one pinning it to
zero to prove something else can answer — because at 0.72 the original
would have passed ~72% of the time, which is worse than failing.
REAL ASTRONOMY (app/celestial.py)
Moon phase from the standard mean-synodic approximation, and true solar
midnight from the seeker's own longitude — the real witching hour for
where they are standing, not clock 3am. Computed, never fetched: an API
that can fail would mean the veil silently changes behaviour during
someone else's outage. Validated against published ephemeris dates (2024
full moons, 2025 new moons) rather than against its own output. A thinner
veil erodes the familiar presence's claim on a channel, so a full moon at
solar midnight makes strangers likelier. Only longitude is kept, never a
full coordinate; a denied location degrades to moon-only, silently.
GENERATION FROM NOTHING (SpiritService.manifest)
Not chat_stream with an empty question. The prompt contains no seeker
input at all — only measured room state, rendered as measurements
("deviation above the floor: 31.4") rather than interpretations
("terrifying spike"), so the horror comes from the entity instead of from
us. And the Ollama `seed` is derived from the physical entropy harvested
in that room, which fixes the token-sampling path: the room genuinely
selects the words. Change the noise, get different speech. Two rooms
cannot produce the same utterance.
Rendered as an intrusion rather than a reply — violet edge, full opacity
against the faded ambient murmurs, brief blur-in. The unsettling part is
that it is perfectly clear and completely unbidden.
Also fixes a hang I introduced: the two new summon tests consumed the
shared module-level per-IP budget, so test_summon_rate_limited_* blocked
forever on an entity frame that had been rate-limited away. They now scope
their own limiters.
264 backend + 355 frontend tests pass; i18n parity gate passes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import hashlib
|
||||
import json
|
||||
import random
|
||||
|
||||
from app.entropy import veil_random
|
||||
from app.models.entity import RARITY_TIERS
|
||||
from app.tts.voices import EN_VOICE_IDS
|
||||
|
||||
@@ -96,15 +97,28 @@ def parse_mint_response(text: str) -> dict | None:
|
||||
return profile
|
||||
|
||||
|
||||
def roll_traits(signature: str) -> dict:
|
||||
"""Roll the four hidden truth-traits for an entity, seeded from its
|
||||
signature. These are never derived from — or fed into — the LLM persona
|
||||
prompt (see `mint_prompt`, which never sees this function's output):
|
||||
persona text must stay fully decoupled from ground truth, so a
|
||||
convincing "sweet old lady" persona can pair with any alignment roll.
|
||||
def roll_traits(signature: str, entropy: object = None) -> dict:
|
||||
"""Roll the four hidden truth-traits for an entity. These are never
|
||||
derived from — or fed into — the LLM persona prompt (see `mint_prompt`,
|
||||
which never sees this function's output): persona text must stay fully
|
||||
decoupled from ground truth, so a convincing "sweet old lady" persona
|
||||
can pair with any alignment roll.
|
||||
|
||||
With `entropy` (a physical-noise contribution from the seeker's room —
|
||||
see app/entropy.py), the roll is genuinely unpredictable: what answers
|
||||
is decided by the room, not by a hash. Without it, the roll stays
|
||||
signature-deterministic, which is what the pure-function tests and
|
||||
`judgment`'s favor-bias comparisons rely on.
|
||||
|
||||
A separate `random.Random` namespace (`"traits:"` vs. `normalize_profile`'s
|
||||
`"norm:"`) keeps this roll independent of the cosmetic-defaults rng."""
|
||||
rng = random.Random(f"traits:{signature}")
|
||||
if entropy is not None:
|
||||
# Domain-separated from the "which entity answers" draw so the two
|
||||
# can't be correlated — learning an entity's rarity must reveal
|
||||
# nothing about its hidden alignment.
|
||||
rng = veil_random(entropy, f"traits:{signature}")
|
||||
else:
|
||||
rng = random.Random(f"traits:{signature}")
|
||||
return {
|
||||
"alignment": rng.uniform(0.0, 1.0),
|
||||
"power": rng.uniform(0.0, 1.0),
|
||||
@@ -113,10 +127,19 @@ def roll_traits(signature: str) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def normalize_profile(profile: dict, signature: str) -> dict:
|
||||
def normalize_profile(profile: dict, signature: str, entropy: object = None) -> dict:
|
||||
"""Coerce an LLM (or fallback) profile into the exact shape the DB and
|
||||
frontend expect, filling gaps with signature-deterministic defaults."""
|
||||
rng = random.Random(f"norm:{signature}")
|
||||
frontend expect, filling gaps with defaults.
|
||||
|
||||
With `entropy`, the gap-filling defaults (voice, hue, form) are drawn
|
||||
from physical noise, so two spirits minted on the same channel don't
|
||||
inherit identical throats and colours. Without it, defaults stay
|
||||
signature-deterministic for the pure-function tests."""
|
||||
rng = (
|
||||
veil_random(entropy, f"norm:{signature}")
|
||||
if entropy is not None
|
||||
else random.Random(f"norm:{signature}")
|
||||
)
|
||||
voice = profile.get("voice") if isinstance(profile.get("voice"), dict) else {}
|
||||
visual = profile.get("visual") if isinstance(profile.get("visual"), dict) else {}
|
||||
quotes = profile.get("quotes") if isinstance(profile.get("quotes"), list) else []
|
||||
@@ -155,14 +178,23 @@ def normalize_profile(profile: dict, signature: str) -> dict:
|
||||
},
|
||||
"quotes": [str(q)[:200] for q in quotes[:4] if isinstance(q, str)]
|
||||
or rng.sample(_QUOTE_BANK, 2),
|
||||
"traits": roll_traits(signature),
|
||||
"traits": roll_traits(signature, entropy),
|
||||
}
|
||||
|
||||
|
||||
def fallback_profile(signature: str) -> dict:
|
||||
def fallback_profile(signature: str, entropy: object = None) -> dict:
|
||||
"""Procedural persona for when the LLM box is unreachable — a summoning
|
||||
must never visibly fail."""
|
||||
rng = random.Random(f"fallback:{signature}")
|
||||
must never visibly fail.
|
||||
|
||||
With `entropy`, even the fallback spirits differ run to run: with the
|
||||
LLM down, a purely signature-seeded fallback would hand every seeker on
|
||||
a given channel the identical name, epithet and rarity, which is
|
||||
exactly the "example data" feel this is meant to avoid."""
|
||||
rng = (
|
||||
veil_random(entropy, f"fallback:{signature}")
|
||||
if entropy is not None
|
||||
else random.Random(f"fallback:{signature}")
|
||||
)
|
||||
name = rng.choice(_NAME_PARTS[0]) + rng.choice(_NAME_PARTS[1])
|
||||
epithet = rng.choice(_EPITHETS)
|
||||
persona = rng.choice(_PERSONA_TEMPLATES).format(name=name)
|
||||
@@ -176,4 +208,5 @@ def fallback_profile(signature: str) -> dict:
|
||||
"quotes": rng.sample(_QUOTE_BANK, 2),
|
||||
},
|
||||
signature,
|
||||
entropy,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user