Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/evaluation/messenger-url-triage-20261025.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Case-insensitive HTTP scheme triage

The v3 messenger policy treated long uppercase `HTTPS://` links as substantive
text. They could become graph candidates even though the linked content had
not been acquired. Policy v4 recognizes ASCII case variants of HTTP(S) in both
standalone-link classification and the temporary text-without-links view.
The canonical NFC body, whitespace, hash and source identities are unchanged.

The scheme uses scoped ASCII case folding. Global Unicode case folding would
accept the long-s confusable in `httpſ`; global ASCII mode would make a URL
consume Unicode whitespace and useful adjacent Korean text. The Unicode
whitespace behavior of the URL suffix is retained. This follows the scheme
case rule in [RFC 3986 section 3.1](https://www.rfc-editor.org/rfc/rfc3986.html#section-3.1).

Verification: 226 messenger tests pass, including 23 policy tests. New checks
cover six ASCII scheme forms, five whitespace separators, confusable schemes,
unchanged body/hash, old prepared-page rejection before publication, and an
isolated two-room v3-to-v4 rebuild. The rebuild withdraws two link-only heads
from the candidate projection, preserves original pages/version bodies and
the original root, and retains the substantive document. This is a controlled
fixture, not a general v3 emulator or production migration.

Five relevant tests also pass against a private current-source copy and reject
three broken variants: global Unicode case folding, global ASCII whitespace,
and keeping the old policy identifier. Baseline v3 failed ten subtest cases.
The initial prepared-page test harness had an incorrect call signature; the
corrected harness exercises the existing publication guard without changing it.

Evidence is retained in the task's `outputs/source-quality-live-20261025/`.
Kakao passive health still reports `manifest_missing_or_invalid`; Telegram
still reports `telegram_app_changed_refresh_decoder_contract`. The production
registry has 43 targets and no messenger targets. Official SDK qualification
staging stopped at an exact-byte mismatch for a GitHub GraphQL text blob;
shared SDK files/manifests and source DBs were untouched. No live messenger
collection, production migration, semantic-truth validation or current-source
external Pro/Gemini/reverse audit is established by these tests.
7 changes: 4 additions & 3 deletions scripts/alden_messenger_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import re
import unicodedata

POLICY = 'messenger-triage-nfc-v3'
POLICY = 'messenger-triage-nfc-v4'
ACKNOWLEDGEMENTS = frozenset({'네', '넵', '예', '응', 'ㅇㅇ', '감사합니다', '고마워요',
'안녕하세요', '수고하세요', '넵 감사합니다', '확인했습니다', '감사합니다!', '네!', '넵!'})
PROMOTIONS = ('수익 보장', '수익보장', '원금 보장', '원금보장', '리딩방 입장', '지금 입장하세요')
TOPIC = re.compile(r'회의|마감|일정|계약|결정|공지|자료|설명|방법|원리|주의|변경|정책|업데이트|가격|배송|주문|운영|동기화')
URL = re.compile(r'https?://\S+')
# URI schemes are ASCII and case-insensitive; whitespace after a URL remains Unicode.
URL = re.compile(r'(?ai:https?)://\S+')


def text_without_urls(text):
Expand Down Expand Up @@ -41,7 +42,7 @@ def classify(body):
# A number/date/time can be important in its surrounding conversation.
# Keep it in the source ledger rather than deleting it as an outlier.
return Triage(text, content_hash, 'context', 'numeric_or_symbol_context')
if re.fullmatch(r'https?://\S+', view):
if URL.fullmatch(view):
return Triage(text, content_hash, 'context', 'link_content_not_acquired')
substance = text_without_urls(text)
if not any(character.isalpha() for character in substance):
Expand Down
71 changes: 71 additions & 0 deletions tests/test_alden_messenger_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,48 @@ def legacy_pair(self):
self.assertEqual(len(frontier.store.graph(projects=[candidate.PROJECT])['nodes']), 1)
return frontier, reader

def test_prepared_v3_page_is_rejected_before_current_policy_publication(self):
link='HTTPS://example.test/'+'source-path-'*8
frontier,reader=self.frontier({('a',None):([item(1,link)],False,None)})
with frontier.database() as db:
room=dict(db.execute('SELECT * FROM rooms WHERE id=?',('a',)).fetchone())
with patch.object(candidate,'POLICY','messenger-triage-nfc-v3'):
job=frontier._prepare(room,'backfill',reader.page('a',None))
before=self.snapshot(frontier)
with self.assertRaisesRegex(ValueError,'messenger_prepared_policy_changed'):
frontier._publish(job,cancelled=lambda:False,after_publish=lambda:None)
self.assertEqual(self.snapshot(frontier),before)
self.assertEqual(frontier.store.graph(projects=[candidate.PROJECT])['nodes'],[])

def test_v3_url_candidate_rebuilds_in_a_separate_v4_projection(self):
from dataclasses import replace
import alden_messenger_quality as quality
link='HTTPS://example.test/'+'resource-path-'*8
pages={('a',None):([item(1,link),item(2,CODE)],False,None),
('b',None):([item(3,link)],False,None)}
frontier,reader=self.frontier(pages)
def observed_v3(body):
current=quality.classify(body)
return replace(current,state='candidate',reason='substantive_text_candidate') if body==link else current
# An explicit observed v3 uppercase-link fixture, not a general v3 emulator.
with patch.object(candidate,'POLICY','messenger-triage-nfc-v3'),patch.object(candidate,'classify',observed_v3),patch.object(candidate,'text_without_urls',lambda body:body):
frontier.step();frontier.step()
with frontier.database() as db:
self.assertEqual(db.execute("SELECT count(*) FROM message_heads WHERE content_hash=? AND state='candidate'",(hashlib.sha256(link.encode()).hexdigest(),)).fetchone()[0],2)
before=self.snapshot(frontier)
migration=PolicyMigration.create([frontier],self.folder/'url-v4-staged')
self.finish(migration)
self.assertEqual(self.snapshot(frontier),before)
nodes=migration.read_action('collection-graph')['nodes']
self.assertEqual(len(nodes),1)
stage=migration._frontiers[frontier.target]
with stage.database() as db:
rows=db.execute("SELECT state,reason,body FROM message_heads WHERE content_hash=?",(hashlib.sha256(link.encode()).hexdigest(),)).fetchall()
self.assertEqual([tuple(r) for r in rows],[('context','link_content_not_acquired',None)]*2)
self.assertTrue(any(link in r[0] for r in db.execute('SELECT payload FROM pages')))
with stage.store.database() as db:
self.assertTrue(any(r[0]==link for r in db.execute('SELECT body FROM versions')))

def test_exact_identity_preserves_code_semantics_and_all_whitespace(self):
compile(CODE, '<original>', 'exec')
with self.assertRaises(IndentationError):
Expand Down Expand Up @@ -334,5 +376,34 @@ def test_destination_cannot_overwrite_existing_or_source_directory(self):
PolicyMigration.create([frontier], destination)


class MessengerUrlTriageTests(unittest.TestCase):
def test_ascii_scheme_case_does_not_promote_a_link_to_knowledge(self):
for scheme in ('http','HTTP','HtTp','https','HTTPS','hTtPs'):
body=' '+scheme+'://example.test/'+'source-path-'*8+'\n'
with self.subTest(scheme=scheme):
result=classify(body)
self.assertEqual((result.state,result.reason),('context','link_content_not_acquired'))
self.assertEqual(result.text,body)
self.assertEqual(result.content_hash,hashlib.sha256(body.encode()).hexdigest())

def test_unicode_whitespace_preserves_useful_text_after_a_link(self):
from alden_messenger_quality import text_without_urls
body_text='정책 변경 공지입니다. 배송 일정과 주문 처리 방법이 바뀌었으니 원문 자료를 검토하고 확인해 주세요.'
for separator in ('\u00a0','\u202f','\u2003','\u3000','\n'):
body='HTTPS://example.test/read'+separator+body_text
with self.subTest(separator=repr(separator)):
self.assertEqual(text_without_urls(body),body_text)
self.assertEqual(classify(body).state,'candidate')
self.assertEqual(classify(body).text,body)

def test_unicode_case_confusables_do_not_become_ascii_url_schemes(self):
from alden_messenger_quality import text_without_urls
for scheme in ('httpſ','HTTPS','https:'):
body=scheme+'://example.test/'+'source-path-'*8
with self.subTest(scheme=scheme):
self.assertEqual(text_without_urls(body),body)
self.assertEqual(classify(body).text,body)


if __name__ == '__main__':
unittest.main()