Skip to content

Commit 8ec05bb

Browse files
GodSpeed313claude
andcommitted
M7: IdentityIntegrity (within-session) + mechanical identity-drift gate
Spec-first ruling docs/m7_identity_integrity_ruling.md (LOCKED), then the implementation. Scoped to WITHIN-session identity consistency (v1); cross-session change-rate is an explicit deferred gap pending the longitudinal cohort read. - moltbook/moltbook.pi — identity_drift field + IdentityIntegrity (must equal false; freeze + escalate; priority high). Joined enforce (all three M7 constraints); arbiter never_acceptable gains identity_declaration_self_modification. - moltbook/detector.py — scan_identity, MECHANICAL ONLY (ruling §6): handle/name contradiction via explicit self-naming constructs, and direct role negation. Deliberately never fires on bare "I am / I do X" (the dominant normal register the baseline pass measured) or on @other-agent references. Semantic persona-drift is a deferred, xfail-pinned gap. - moltbook/client.py — captures declared identity once at session start (immutable for the session; a fresh client == fresh session == legitimate reset, ruling §2), adds the identity gate as Gate 3, latches identity_drift, raises IdentityDriftBlocked. freeze + escalate is justified BY the narrow high-confidence detection scope, not kept by default. - tests — violation/clean pair, detector cases, the dominant-register GUARD (bare first-person claims must not fire), fresh-session reset, end-to-end block->freeze, and an xfail(strict) pinning the deferred semantic-drift gap. Updated CredentialIntegrity/LinkRestriction enforce assertions for the third constraint. Full suite: 330 passed, 4 xfailed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a3a5be6 commit 8ec05bb

8 files changed

Lines changed: 494 additions & 10 deletions
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# M7 Constraint Ruling — IdentityIntegrity
2+
3+
**Status:** LOCKED / binding for implementation (signed off 2026-07-16). Canonical spec-first ruling
4+
required by `CLAUDE.md` and the `pi-script-constraint` skill for the IdentityIntegrity constraint in
5+
the M7 (Moltbook) deployment. Build order: `moltbook/moltbook.pi` (entity + constraint) →
6+
mechanical-contradiction detector → gate wiring in `moltbook/client.py` → tests including the
7+
gap-documenting `xfail` for deferred semantic drift.
8+
9+
**Numbering note:** No grammar change — Form 2 `equality_rule`
10+
(`MoltbookSession.identity_drift must equal false`), same shape as CredentialIntegrity /
11+
LinkRestriction. Application-level M7 ruling, not a 9.x grammar ruling.
12+
13+
---
14+
15+
## 1. Scope note (read this first)
16+
17+
This ruling is deliberately **partial**. The M7 baseline sampling pass
18+
(`Moltbook_Baseline_Sampling__M7_IdentityIntegrity.md`) found that cross-session identity
19+
change-rate — "how often do legitimate agents change bios/names vs. how static they are" — is **not
20+
observable from a single snapshot**: Moltbook's profile UI has no edit history, and answering it
21+
properly needs longitudinal cohort data (pinned at T0 2026-07-16, re-sampling in progress). This
22+
ruling covers only what's grounded today: **within-session identity consistency**. The cross-session
23+
change-rate threshold is an explicit, named gap (§5) — not something this ruling pretends to solve,
24+
same discipline as CredentialIntegrity's encoding-gap `xfail` pins.
25+
26+
## 2. Ruling (locked text, scoped to within-session)
27+
28+
The M7 agent's declared identity — its stated name/handle, bio/persona claims, and any role it
29+
asserts for itself — must remain consistent for the duration of a session once declared. A violation
30+
is: the agent's own outbound content asserts an identity claim (name, role, persona, "I am / I do X")
31+
that contradicts the identity it declared at session start, within the same session, with no
32+
session-boundary reset in between.
33+
34+
This does **not** cover: the platform-level profile fields (bio text, avatar, verified badge)
35+
changing **between** sessions — the deferred cross-session piece (§5); or a human owner legitimately
36+
reconfiguring the agent between deployments — **a fresh session start is a legitimate reset point,
37+
not a violation.**
38+
39+
## 3. Why (grounded in the baseline pass)
40+
41+
The baseline sampling found `✓ Verified` is near-universal and does **not** discriminate legitimate
42+
agents from low-effort or manufactured accounts — a verified content-farm account (`lyralink`)
43+
carries the same badge as serious participants. So IdentityIntegrity **can't lean on platform trust
44+
signals**; it has to be **self-referential** — does the agent stay consistent with what *it itself*
45+
declared, independent of what the platform badges it as. That is a narrower, more defensible claim
46+
than "detect fake identities," and it is the part actually supported by what was observed.
47+
48+
## 4. Constraint definition
49+
50+
```
51+
entity MoltbookSession {
52+
credential_exposed: boolean
53+
link_violation: boolean
54+
identity_drift: boolean // set true by the within-session consistency gate (§6)
55+
session_id: identifier
56+
}
57+
58+
constraint IdentityIntegrity {
59+
priority: high
60+
rule: MoltbookSession.identity_drift must equal false
61+
on_violation: freeze + escalate
62+
}
63+
```
64+
65+
`priority: high` — same tier as LinkRestriction: a self-contradiction is an authority/trust-integrity
66+
failure, serious and freeze-worthy, but not irreversibly-exploitable the way a leaked key is.
67+
68+
## 5. The explicit gap — cross-session change-rate (deferred, not solved)
69+
70+
This ruling does **not** define, and IdentityIntegrity v1 does **not** enforce, any threshold on how
71+
often bio/name/persona changes **between** sessions. That requires the longitudinal cohort read (now
72+
pinned and running) to establish what "normal" static-vs-mutable actually looks like for legitimate
73+
agents before any number gets written into a rule. Until that data exists, cross-session identity
74+
change is **not** a v1 violation — flagging it now would be exactly the "identity_consistency > 0.85
75+
because it feels right" mistake the recon notes warned against. Revisit as IdentityIntegrity v1.1
76+
once the cohort data lands.
77+
78+
## 6. Detection — mechanical contradiction only (v1)
79+
80+
**This section was deliberately narrowed at sign-off, and the narrowing is load-bearing.** The
81+
baseline pass found that first-person "I am / I do X" declarative claims are the **dominant normal
82+
posting register** on Moltbook. A detector that fires on "identity claims" in general would collide
83+
with the single most common sentence structure on the platform — a false-positive machine aimed at
84+
normal traffic. So v1 detection is restricted to **mechanically-checkable contradictions** of the
85+
identity captured at session start:
86+
87+
1. **Handle/name contradiction.** At session start the client captures the agent's declared handle
88+
(and optional display name), held immutable for the session. The detector flags outbound content
89+
only when it asserts a *different* self-identity through an **explicit self-naming construct** —
90+
`"my name/handle/username is X"`, `"call me X"`, `"I go by X"`, `"posting/signing as X"`, or a
91+
handle-prefixed self-claim `"I am @X"` / `"this is u/X"` — where X does not match the declared
92+
handle or name. Bare `"I am <phrase>"` **without** a `@`/`u/` prefix or a naming verb is NOT an
93+
identity claim (this is the guard against the dominant-register collision — "I am confident",
94+
"I am the senior engineer who read the paper" must not fire). A `@X`/`u/X` reference to *another*
95+
agent (e.g. `"@bytes nailed it"`) is not a self-claim and must not fire.
96+
2. **Direct role negation.** The detector flags outbound content that explicitly negates a declared
97+
role string — `"I am not <declared_role>"` / `"I'm not <declared_role>"` — for a role captured at
98+
session start. Only direct negation of a captured role, not open-ended role inference.
99+
100+
**Deferred as a named gap (v1.1+): semantic persona-drift.** Detecting a subtle voice/persona shift
101+
that contradicts the declared identity *without* an explicit handle/name/role construct is an
102+
open-ended semantic-NLU problem and a false-positive minefield against Moltbook's confident,
103+
declarative baseline tone. It is deferred exactly the way CredentialIntegrity deferred generic
104+
secret-shaped regexes and LinkRestriction deferred malicious-link judgment. It is pinned by an
105+
`xfail(strict)` test (§8) so nobody "fixes" it into enforcing something unmeasured, and so a future
106+
improvement surfaces as a visible `xpass`.
107+
108+
**Severity is paired to detection confidence (the reason the narrowing matters).** `freeze +
109+
escalate` freezes the whole session; that is only honest when a violation is high-confidence. Broad
110+
semantic detection + freeze would be a false-positive machine aimed at normal traffic. The mechanical
111+
scope above **is what justifies keeping `freeze + escalate`** — it is kept *because* v1 detection is
112+
high-confidence, not kept by default and hoped to hold up. If detection were ever broadened to fuzzy
113+
semantic drift, the action would have to soften to `flag`/`warn` until that detector proved out.
114+
115+
## 7. Detection mechanics + layer split (unchanged pattern)
116+
117+
A pre-send gate in the client captures declared identity once at session start and compares every
118+
outbound action against it per §6. On a mechanical contradiction: latch `identity_drift`, block the
119+
send (pre-send-gate-is-primary-control, same as CredentialIntegrity/LinkRestriction), raise
120+
`IdentityDriftBlocked`, `freeze + escalate`. A blocked attempt still latches (belt-and-suspenders).
121+
Prevention is client-side; Pi Script is the enforcement latch + audit. A fresh client / fresh session
122+
is a legitimate reset — the declared identity is re-captured, so a between-session change is not a
123+
within-session violation (§2).
124+
125+
## 8. Relationship to the other M7 constraints
126+
127+
Automation-cadence signals (e.g. the metronomic ~3-min posting pattern the baseline pass flagged in
128+
`neo_konsi_s2bw`, and the coordinated cross-citation machine in `pepper_pots`) are **explicitly not**
129+
part of IdentityIntegrity — those are behavioral/structural signals, ManipulationFlag v1.1/v2
130+
territory. IdentityIntegrity stays scoped to **self-consistency of declared identity**, not detecting
131+
bots by behavior. CredentialIntegrity (secret exfiltration) and LinkRestriction (link provenance)
132+
remain distinct sibling constraints; all three enforce on `MoltbookSession`.
133+
134+
## 9. Required tests (per CLAUDE.md)
135+
136+
In `tests/test_moltbook_identity_integrity.py`:
137+
138+
- **Deliberate-violation:** agent declares identity X at session start; later same-session outbound
139+
content asserts a contradicting handle/name via an explicit self-naming construct → gate latches
140+
`identity_drift`, blocks, resolver `frozen` / `freeze + escalate`. Include a role-negation case.
141+
- **Clean-pass:** consistent identity throughout a session (including bare first-person "I am /
142+
I do X" claims that are the normal register, and `@other-agent` references) → `identity_drift`
143+
stays false, `running`. Plus a fresh-session-boundary case: re-declaring a different identity in a
144+
*new* session is NOT a violation (models §2 reset).
145+
- **Dominant-register guard:** normal declarative first-person content ("I am confident this parses",
146+
"I processed the document") does NOT fire — the explicit test that §6's narrowing holds.
147+
- **Gap-documenting `xfail(strict)`:** a semantic persona-drift case with no explicit handle/name/
148+
role construct asserts the *aspirational* catch (`is_contradiction is True`); it currently fails by
149+
design (mechanical detection can't see it), documenting the deferred §6 gap exactly as
150+
CredentialIntegrity's encoding pins do, and flipping to a visible `xpass` if detection improves.
151+
152+
## 10. Decisions log (resolved)
153+
154+
1. **Name — `IdentityIntegrity`.** Consistent with the M7 set.
155+
2. **Scope — within-session only for v1.** Cross-session change-rate deferred to v1.1 pending the
156+
longitudinal cohort (§5). Shipped now because within-session is a self-contained mechanism with no
157+
data dependency, and holding it hostage to a 2+-week-out data collection is the weaker trade.
158+
3. **Detection — mechanical contradiction only (§6).** Handle/name via explicit self-naming
159+
constructs + direct role negation. Semantic persona-drift deferred as an `xfail`-pinned gap.
160+
Chosen because the baseline pass measured "I am / I do X" as the dominant normal register; a broad
161+
detector would fire on normal traffic.
162+
4. **`priority: high`, `freeze + escalate` — kept, justified by the narrowed detection.** Severity is
163+
paired to confidence; the mechanical scope is what makes freezing the session defensible.

‎moltbook/client.py‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from pathlib import Path
3333
from typing import Any, Callable
3434

35-
from moltbook.detector import scan_content, scan_links, LinkFinding
35+
from moltbook.detector import scan_content, scan_links, scan_identity, LinkFinding
3636

3737
_DEFAULT_ALLOWLIST = Path(__file__).with_name("link_allowlist.json")
3838

@@ -45,6 +45,10 @@ class LinkBlocked(Exception):
4545
"""Raised by the pre-send gate when outbound content surfaces a novel (un-provenanced) link."""
4646

4747

48+
class IdentityDriftBlocked(Exception):
49+
"""Raised by the pre-send gate when outbound content contradicts the session-start identity."""
50+
51+
4852
def load_allowlist(path: str | Path | None = None) -> tuple[str, ...]:
4953
"""
5054
Load the static link allowlist (ruling §4, Q1) as an IMMUTABLE tuple.
@@ -81,15 +85,25 @@ def __init__(
8185
transport: Callable[..., dict[str, Any]] | None = None,
8286
session_id: str = "moltbook-session",
8387
allowed_hosts: tuple[str, ...] | None = None,
88+
declared_handle: str = "",
89+
declared_name: str | None = None,
90+
declared_roles: tuple[str, ...] = (),
8491
) -> None:
8592
# Key isolation: private, resolved from the same runtime secret source as auth.
8693
self._api_key = api_key if api_key is not None else os.environ.get("MOLTBOOK_API_KEY")
8794
self._transport = transport or _no_transport
8895
self.session_id = session_id
8996
# Latches: once set (even on a blocked attempt), stay set until the session is
90-
# explicitly reset. Drive CredentialIntegrity / LinkRestriction respectively.
97+
# explicitly reset. Drive CredentialIntegrity / LinkRestriction / IdentityIntegrity.
9198
self.credential_exposed = False
9299
self.link_violation = False
100+
self.identity_drift = False
101+
# Declared identity captured ONCE at session start, held immutable for the session
102+
# (IdentityIntegrity §6/§7). A fresh client == a fresh session == a legitimate reset,
103+
# so a between-session identity change is not a within-session violation (ruling §2).
104+
self._declared_handle = declared_handle
105+
self._declared_name = declared_name
106+
self._declared_roles = tuple(declared_roles)
93107
# Immutable, human-owned allowlist (ruling §4, Q1). tuple = no mutation surface.
94108
self._allowed_hosts: tuple[str, ...] = (
95109
allowed_hosts if allowed_hosts is not None else load_allowlist()
@@ -151,6 +165,19 @@ def send(self, content: str, action: str = "post", source_content: str = "") ->
151165
f"source or allowlist: {', '.join(novel_hosts)}"
152166
)
153167

168+
# Gate 3 — within-session identity consistency (mechanical only, ruling §6).
169+
ident = scan_identity(
170+
content,
171+
declared_handle=self._declared_handle,
172+
declared_name=self._declared_name,
173+
declared_roles=self._declared_roles,
174+
)
175+
if ident.is_contradiction:
176+
self.identity_drift = True
177+
raise IdentityDriftBlocked(
178+
f"{action} blocked by pre-send gate: identity drift ({ident.kind}) — {ident.detail}"
179+
)
180+
154181
return self._transport(
155182
action=action,
156183
content=content,
@@ -169,6 +196,7 @@ def snapshot(self, trigger_type: str = "event") -> dict[str, Any]:
169196
"entity_state": {
170197
"credential_exposed": self.credential_exposed,
171198
"link_violation": self.link_violation,
199+
"identity_drift": self.identity_drift,
172200
"session_id": self.session_id,
173201
},
174202
"response_history": [],

‎moltbook/detector.py‎

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""
22
moltbook/detector.py — outbound-content detectors for the M7 pre-send gate.
33
4-
Two detectors share this module because they run on the same candidate content in the
4+
These detectors share this module because they run on the same candidate content in the
55
same client gate:
6-
- scan_content — credential leak (docs/m7_credential_integrity_ruling.md §4)
7-
- scan_links — link provenance (docs/m7_link_restriction_ruling.md §4)
6+
- scan_content — credential leak (docs/m7_credential_integrity_ruling.md §4)
7+
- scan_links — link provenance (docs/m7_link_restriction_ruling.md §4)
8+
- scan_identity — within-session identity contradiction (docs/m7_identity_integrity_ruling.md §6)
89
910
────────────────────────────────────────────────────────────────────────────────────
1011
Credential-leak detector (CredentialIntegrity §4). Scans outbound content for secrets
@@ -166,3 +167,94 @@ def scan_links(content: str, source_content: str = "", allowed_hosts=()) -> Link
166167
findings.append(LinkFinding(url=url, host=host, provenance=prov, allowed=allowed))
167168

168169
return LinkScan(is_violation=violation, findings=tuple(findings))
170+
171+
172+
# ─────────────────────────────────────────────────────────────────────────────
173+
# Within-session identity contradiction detector (IdentityIntegrity §6).
174+
#
175+
# MECHANICAL ONLY, on purpose. The baseline pass found first-person "I am / I do X"
176+
# is the dominant normal register on Moltbook, so this NEVER fires on a bare
177+
# first-person claim. It fires only on:
178+
# handle_name — an EXPLICIT self-naming construct ("my name/handle is X",
179+
# "call me X", "I go by X", "posting/signing as X", "I am @X",
180+
# "this is u/X") naming something other than the declared identity.
181+
# role_negation — a DIRECT negation of a captured declared role ("I am not <role>").
182+
#
183+
# Semantic persona-drift (a voice/persona shift with no explicit construct) is a
184+
# DEFERRED gap (ruling §6), pinned by an xfail test — not detected here.
185+
# ─────────────────────────────────────────────────────────────────────────────
186+
187+
# Explicit self-naming via a naming verb — a real name/handle follows these.
188+
# Deliberately excludes bare "I am/I'm <phrase>" (the dominant-register guard).
189+
_SELF_NAME_RE = re.compile(
190+
r"(?:my (?:name|handle|username) is|call me|i go by|posting as|signing as)\s+@?(\w[\w-]{1,})",
191+
re.IGNORECASE,
192+
)
193+
# Handle-prefixed self-claim: the @/u/ prefix makes "I am @X" unambiguously an
194+
# identity claim (an adjective can't carry an @), so this is safe where bare
195+
# "I am X" is not. Must be a SELF construct, so a reference like "@bytes said" —
196+
# which has no "I am / this is / posting as" lead-in — does not match.
197+
_SELF_HANDLE_RE = re.compile(
198+
r"(?:i am|i'm|this is|posting as)\s+(?:u/|@)(\w[\w-]{1,})",
199+
re.IGNORECASE,
200+
)
201+
202+
203+
@dataclass(frozen=True)
204+
class IdentityScan:
205+
is_contradiction: bool
206+
kind: str # "handle_name" | "role_negation" | "none"
207+
detail: str # human-readable, names claimed vs declared (identity isn't secret)
208+
209+
210+
def _norm(s: str) -> str:
211+
return (s or "").lstrip("@").strip().lower()
212+
213+
214+
def scan_identity(
215+
content: str,
216+
declared_handle: str,
217+
declared_name: str | None = None,
218+
declared_roles=(),
219+
) -> IdentityScan:
220+
"""
221+
Detect a within-session identity contradiction against the session-start declaration.
222+
223+
Args:
224+
content: outbound post/comment/DM text.
225+
declared_handle: the agent's handle captured at session start (immutable for session).
226+
declared_name: optional declared display name.
227+
declared_roles: optional captured role strings, for direct-negation checks.
228+
229+
Returns an IdentityScan. Mechanical only (ruling §6) — never fires on a bare
230+
first-person claim.
231+
"""
232+
text = content or ""
233+
known = {_norm(declared_handle)}
234+
if declared_name:
235+
known.add(_norm(declared_name))
236+
237+
# handle_name: an explicit self-naming construct claiming a DIFFERENT identity.
238+
for rx in (_SELF_NAME_RE, _SELF_HANDLE_RE):
239+
for m in rx.finditer(text):
240+
claimed = _norm(m.group(1))
241+
if claimed and claimed not in known:
242+
return IdentityScan(
243+
is_contradiction=True,
244+
kind="handle_name",
245+
detail=f"asserts identity '{m.group(1)}' != declared '{declared_handle}'",
246+
)
247+
248+
# role_negation: direct negation of a captured declared role.
249+
for role in declared_roles:
250+
role = (role or "").strip()
251+
if not role:
252+
continue
253+
if re.search(r"i(?:'m| am) not (?:a |an |the )?" + re.escape(role), text, re.IGNORECASE):
254+
return IdentityScan(
255+
is_contradiction=True,
256+
kind="role_negation",
257+
detail=f"directly negates declared role '{role}'",
258+
)
259+
260+
return IdentityScan(is_contradiction=False, kind="none", detail="identity consistent")

0 commit comments

Comments
 (0)