diff --git a/.github/native/hosted_native.py b/.github/native/hosted_native.py index faee713c1..b8d09829f 100644 --- a/.github/native/hosted_native.py +++ b/.github/native/hosted_native.py @@ -166,14 +166,14 @@ def private_log_prefix(path): return payload.decode(errors='replace'), truncated -def ios_startup_diagnostics(payload, executable): +def ios_startup_diagnostics(payload, executable, started_ms=None, ended_ms=None, input_partial=False): # Pure fixed-vocabulary classifier; no source message, stack or path leaves # the fresh owned simulator's private compact-log query. spec = importlib.util.spec_from_file_location( 'ios_startup_errors', Path(__file__).with_name('ios_startup_errors.py')) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) - return module.classify(payload, executable) + return module.classify(payload, executable, started_ms, ended_ms, input_partial) def startup_hierarchy_signals(directory): @@ -305,10 +305,14 @@ def maestro_preflight_diagnostics(directory=None, command_label='Assert startup return result -def record_startup_failure(report, device): +def record_startup_failure(report, device, startup_started_ms=None): """Collect bounded diagnostics before destroying this job's fresh app state.""" details = {'scope': 'Fresh startup only; no account or persisted PIN created.', 'collection_errors': []} + try: + startup_ended_ms = int(time.time() * 1000) + except Exception: + startup_ended_ms = None def collect(name, action): try: @@ -377,9 +381,9 @@ def ios_details(): predicate = ('process == "%s" AND (messageType == "error" OR messageType == "fault" ' 'OR eventMessage CONTAINS[c] "error" OR eventMessage CONTAINS[c] "exception" ' 'OR eventMessage CONTAINS[c] "fatal")') % executable - # RN0.83.9 forwards a single console.info string unchanged to - # RCTDefaultLogFunction / OS_LOG_TYPE_INFO. Request that level in the - # existing bounded query; persistence/routing still need native proof. + # Retain INFO for existing bounded diagnostics. The single new + # direct-hook failure marker uses RN's OS_LOG_TYPE_ERROR sink; + # actual marker routing still needs exact-source native proof. args = ['xcrun', 'simctl', 'spawn', device, 'log', 'show', '--info', '--style', 'compact', '--last', '10m', '--predicate', predicate] path = PRIVATE / 'ios-startup-errors.log' @@ -393,11 +397,15 @@ def ios_details(): code = 124 result = {'command': args, 'exit_code': code, 'errors': [], 'query_status': 'SUCCESS' if code == 0 else 'TIMEOUT' if code == 124 else 'FAILED', - 'parse_status': 'UNKNOWN', 'cause': 'UNDETERMINED', 'input_truncated': None} + 'parse_status': 'UNKNOWN', 'cause': 'UNDETERMINED', 'input_truncated': None, + 'startup_failure_receipt': {'schema': 1, 'status': 'UNKNOWN', 'records': [], + 'cause': 'UNDETERMINED', 'reasons': ['QUERY_UNAVAILABLE'], + 'scope': 'OPTIONAL_ORIGINAL_STARTUP_MARKERS_NOT_CAUSE_OR_ACCEPTANCE'}} if code == 0: try: payload, truncated = private_log_prefix(path) - result.update(ios_startup_diagnostics(payload, executable)) + result.update(ios_startup_diagnostics(payload, executable, startup_started_ms, + startup_ended_ms, input_partial=truncated)) result['input_truncated'] |= truncated if truncated: result['parse_status'] = 'PARTIAL' if result['matching_process_records'] else 'UNKNOWN' @@ -1107,7 +1115,7 @@ def smoke(suite='startup'): startup_error = original_error try: if not (is_probe or is_features): - record_startup_failure(report, device) + record_startup_failure(report, device, getattr(startup_capture, 'started_ms', None)) else: data = read() data[result_key] = 'FAIL' diff --git a/.github/native/ios_startup_errors.py b/.github/native/ios_startup_errors.py index 76cbe09de..845dfdce3 100644 --- a/.github/native/ios_startup_errors.py +++ b/.github/native/ios_startup_errors.py @@ -6,7 +6,9 @@ """ from datetime import datetime +import importlib.util import io +from pathlib import Path import re @@ -48,18 +50,9 @@ _ERROR_SEVERITIES = {'e', 'er', 'error', 'f', 'ft', 'fault'} _ERROR_MARKER = re.compile( r'\b(?:error|exception|fatal)\b|\b[\w.$]*(?:Exception|Error)\b', re.IGNORECASE) -STARTUP_STAGES = ('READ_CALL', 'STATE_READ', 'SERVICE_SELECT', 'KEYCHAIN_READ', - 'CREDENTIAL_PARSE', 'NAVIGATE_LOGIN', 'NAVIGATE_CREATE_PIN') -STARTUP_CATEGORIES = ('NATIVE_CODE_NEG34018', 'NATIVE_CODE_NEG25308', 'NATIVE_CODE_NEG25291', - 'NATIVE_CODE_NEG25293', 'NATIVE_CODE_NEG26275', 'NATIVE_CODE_NEG50', - 'ERROR', 'TYPE_ERROR', 'SYNTAX_ERROR', 'RANGE_ERROR', 'REFERENCE_ERROR', 'UNKNOWN') -_STARTUP_MARKER = re.compile( - # Exact RN0.83.9 OSLog subsystem/category in the compact message envelope. - r'(?:\[com\.facebook\.react\.log:javascript\] )?KEEPER_STARTUP_ERROR stage=(' + '|'.join(STARTUP_STAGES) + - r') category=(' + '|'.join(STARTUP_CATEGORIES) + r')') -def classify(payload, executable): +def classify(payload, executable, started_ms=None, ended_ms=None, input_partial=False): """Return fixed positive observations only; an empty result proves no pass. Invalid selectors/types raise fixed errors. Oversized input is classified @@ -71,6 +64,23 @@ def classify(payload, executable): raise ValueError('Unsafe iOS executable selector.') if not isinstance(payload, str): raise TypeError('Expected compact log text.') + receipt, receipt_failed, receipt_frame_partial = None, False, False + try: + spec = importlib.util.spec_from_file_location( + 'startup_failure_receipts', Path(__file__).with_name('startup_failure_receipts.py')) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + receipt = module.Collector(executable, started_ms, ended_ms) + except Exception: + receipt_failed = True + + def note_invalid_marker(line): + nonlocal receipt_failed + if receipt is not None and 'KEEPER_STARTUP_FAILURE_V1' in line: + try: + receipt.invalid_record(True) + except Exception: + receipt_failed = True # Slice characters before encoding so even an arbitrarily large argument # creates at most a bounded four-byte-per-character temporary buffer. @@ -88,8 +98,6 @@ def classify(payload, executable): 'scan_limit_reached': False, 'record_limit_reached': False, 'parse_status': 'UNKNOWN', 'cause': 'UNDETERMINED', 'scope': 'PREFIXED_OWN_PROCESS_MARKERS_ONLY_NOT_CAUSE_OR_ACCEPTANCE', - 'startup_failure_facts': [], 'startup_failure_fact_limit_reached': False, - 'startup_failure_scope': 'FIXED_DEVELOPMENT_STAGE_MARKERS_NOT_AUTHENTICATED_CAUSE', } for index, raw in enumerate(io.StringIO(prefix)): if index >= MAX_SCAN_LINES: @@ -101,12 +109,14 @@ def classify(payload, executable): line = raw.removesuffix('\n').removesuffix('\r') if len(line) > MAX_RECORD_BYTES or len(line.encode('utf-8')) > MAX_RECORD_BYTES: result['oversized_record_lines'] += 1 + note_invalid_marker(line) continue match = _RECORD.fullmatch(line) if not match: # Headers, notices and unprefixed multiline continuations are not # attributed. Timestamp-shaped malformed records remain visible. result['malformed_record_lines'] += int(bool(re.match(r'^\d{4}-', line))) + note_invalid_marker(line) continue try: datetime.fromisoformat(match['timestamp'].replace('Z', '+00:00')) @@ -117,19 +127,26 @@ def classify(payload, executable): valid = False if not valid: result['malformed_record_lines'] += 1 + note_invalid_marker(line) continue + if receipt is not None: + try: + if any(ord(char) > 127 for char in line[:match.start('message')]): + receipt_frame_partial = True + note_invalid_marker(line) + elif ('KEEPER_STARTUP_FAILURE_V1' in match['message'] and + match['severity'].lower() not in _ERROR_SEVERITIES): + receipt.invalid_record(True) + else: + receipt.observe(match['timestamp'], match['process'], match['pid'], match['message']) + except Exception: + receipt_failed = True if match['process'] != executable: continue result['matching_process_records'] += 1 - marker = _STARTUP_MARKER.fullmatch(match['message']) - if marker: - if len(result['startup_failure_facts']) < 32: - result['startup_failure_facts'].append({'stage': marker[1], 'category': marker[2]}) - else: - result['startup_failure_fact_limit_reached'] = True categories = [name for name, pattern in _CATEGORY_PATTERNS.items() if pattern.search(match['message'])] - error = (bool(marker) or bool(categories) or match['severity'].lower() in _ERROR_SEVERITIES or + error = (bool(categories) or match['severity'].lower() in _ERROR_SEVERITIES or bool(_ERROR_MARKER.search(match['message']))) if error: result['error_records'] += 1 @@ -138,10 +155,20 @@ def classify(payload, executable): result['unclassified_error_records'] += int(not categories) if result['error_records']: result['errors'] = ['IOS_STARTUP_ERROR'] + partial = any(result[name] for name in ( + 'input_truncated', 'scan_limit_reached', 'record_limit_reached', + 'malformed_record_lines', 'oversized_record_lines', + 'replacement_character_observed')) if result['matching_process_records']: - partial = any(result[name] for name in ( - 'input_truncated', 'scan_limit_reached', 'record_limit_reached', - 'malformed_record_lines', 'oversized_record_lines', - 'replacement_character_observed')) result['parse_status'] = 'PARTIAL' if partial else 'PARSED' + result['startup_failure_receipt'] = { + 'schema': 1, 'status': 'UNKNOWN', 'records': [], 'cause': 'UNDETERMINED', + 'reasons': ['COLLECTOR_UNAVAILABLE'], + 'scope': 'OPTIONAL_ORIGINAL_STARTUP_MARKERS_NOT_CAUSE_OR_ACCEPTANCE'} + if receipt is not None and not receipt_failed: + try: + result['startup_failure_receipt'] = receipt.result( + input_partial=partial or receipt_frame_partial or input_partial is not False) + except Exception: + pass return result diff --git a/.github/native/startup_failure_receipts.py b/.github/native/startup_failure_receipts.py new file mode 100644 index 000000000..d2dac5be5 --- /dev/null +++ b/.github/native/startup_failure_receipts.py @@ -0,0 +1,201 @@ +"""Bounded optional startup markers from already validated compact records. + +This module performs no native operation or raw compact-log parsing. The marker's +epoch is used only for relation to the supplied capture window; neither it nor +the compact timestamp, PID, process, or message is exported. Positive markers +are observations, never a cause, a successful read, or an acceptance predicate. +""" + +import re + + +MARKER = 'KEEPER_STARTUP_FAILURE_V1' +COMPACT_PREFIX = '[com.facebook.react.log:javascript] ' +MAX_RECORDS = 32 +MAX_MESSAGE_CHARS = 16 * 1024 +MAX_EPOCH_MS = 10 ** 14 +PHASES = ('ACCOUNT_STATE', 'NATIVE_CREDENTIAL_READ', 'CREDENTIAL_JSON', 'NAVIGATION') +OUTCOMES = ('THREW', 'REJECTED') +ERROR_NAMES = ('Error', 'TypeError', 'SyntaxError', 'ReferenceError', 'RangeError', + 'EvalError', 'URIError', 'AggregateError', 'OTHER', 'UNKNOWN') +_REASONS = ('MISSING_WINDOW', 'INVALID_WINDOW', 'NO_MARKER_OBSERVED', + 'INVALID_COMPACT_RECORD', 'INVALID_RECORD_FIELDS', 'MALFORMED_MARKER', + 'UNSUPPORTED_FRAMING', 'FOREIGN_PROCESS_MARKER', 'OUTSIDE_WINDOW', + 'MULTIPLE_OWN_PIDS', 'DUPLICATE_MARKER', 'MULTIPLE_MARKERS', + 'OBSERVATION_LIMIT', 'PARTIAL_INPUT') + + +def _integer(value, minimum, maximum): + return type(value) is int and minimum <= value <= maximum + + +def _pid(value): + if isinstance(value, str) and re.fullmatch(r'[1-9][0-9]{0,9}', value): + value = int(value) + return value if _integer(value, 1, 2147483647) else None + + +class Collector: + """Collect fixed facts; observe() accepts the caller's validated fields. + + Supported grammar is an exact standalone marker or that marker after the + fixed React JavaScript subsystem/category prefix. This grammar does not + establish that either form has actually reached the hosted log query. + Each counter and retained collection is bounded. + """ + + def __init__(self, executable, started_ms=None, ended_ms=None): + if (not isinstance(executable, str) or + not re.fullmatch(r'[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}', executable)): + raise ValueError('Expected a validated executable selector.') + self._executable = executable + if started_ms is None or ended_ms is None: + self._window = 'UNKNOWN' + elif (not _integer(started_ms, 0, MAX_EPOCH_MS) or + not _integer(ended_ms, 0, MAX_EPOCH_MS) or ended_ms < started_ms): + self._window = 'INVALID' + else: + self._window = 'BOUNDED' + self._started_ms, self._ended_ms = started_ms, ended_ms + self._rows, self._seen, self._pids = [], set(), set() + self._pid_count_capped = False + self._reasons = set() + self._counts = {name: 0 for name in ( + 'marker_records_seen', 'duplicate_records', 'malformed_markers', + 'invalid_compact_markers', 'invalid_record_fields', + 'foreign_process_markers', 'outside_window_markers')} + + def _count(self, name): + if self._counts[name] < MAX_RECORDS: + self._counts[name] += 1 + else: + self._reasons.add('OBSERVATION_LIMIT') + + def _marker(self): + if self._counts['marker_records_seen'] >= MAX_RECORDS: + self._reasons.add('OBSERVATION_LIMIT') + return False + self._count('marker_records_seen') + return True + + def _track_pid(self, pid): + if len(self._pids) < 2: + self._pids.add(pid) + elif pid not in self._pids: + self._pid_count_capped = True + if len(self._pids) > 1: + self._reasons.add('MULTIPLE_OWN_PIDS') + + def invalid_record(self, marker_present): + """The existing compact parser found a marker in an invalid record.""" + if type(marker_present) is not bool: + self._reasons.add('INVALID_RECORD_FIELDS') + self._count('invalid_record_fields') + elif marker_present and self._marker(): + self._reasons.add('INVALID_COMPACT_RECORD') + self._count('invalid_compact_markers') + + def observe(self, timestamp, process, pid, message): + # The compact timestamp is not interpreted as an epoch: compact output + # may omit its timezone. The marker supplies its own bounded epoch. + if not isinstance(message, str) or len(message) > MAX_MESSAGE_CHARS: + self._reasons.add('INVALID_RECORD_FIELDS') + self._count('invalid_record_fields') + return + if MARKER not in message: + # The caller supplies all validated compact records, not just + # markers. An ordinary record from another own PID also prevents + # single-process attribution. Do not infer its timezone or export it. + own_pid = _pid(pid) + if (isinstance(timestamp, str) and timestamp and len(timestamp) <= 64 and + process == self._executable and own_pid is not None): + self._track_pid(own_pid) + return + if not self._marker(): + return + if (not isinstance(timestamp, str) or not timestamp or len(timestamp) > 64 or + not isinstance(process, str)): + self._reasons.add('INVALID_RECORD_FIELDS') + self._count('invalid_record_fields') + return + if process != self._executable: + self._reasons.add('FOREIGN_PROCESS_MARKER') + self._count('foreign_process_markers') + return + pid = _pid(pid) + if pid is None: + self._reasons.add('INVALID_RECORD_FIELDS') + self._count('invalid_record_fields') + return + self._track_pid(pid) + if message.startswith(COMPACT_PREFIX): + message = message[len(COMPACT_PREFIX):] + if not message.startswith(MARKER + '|'): + self._reasons.add('UNSUPPORTED_FRAMING') + self._count('malformed_markers') + return + parts = message.split('|') + if len(parts) != 6: + self._reasons.add('MALFORMED_MARKER') + self._count('malformed_markers') + return + _, epoch, phase, outcome, name, code = parts + valid_epoch = bool(re.fullmatch(r'(?:0|[1-9][0-9]{0,14})', epoch)) + if (not valid_epoch or int(epoch) > MAX_EPOCH_MS or phase not in PHASES or + outcome not in OUTCOMES or name not in ERROR_NAMES or + (outcome == 'REJECTED' and phase != 'NATIVE_CREDENTIAL_READ')): + self._reasons.add('MALFORMED_MARKER') + self._count('malformed_markers') + return + status_code = None + if code != 'NONE': + if (phase != 'NATIVE_CREDENTIAL_READ' or outcome != 'REJECTED' or + not re.fullmatch(r'(?:0|-?[1-9][0-9]{0,9})', code)): + self._reasons.add('MALFORMED_MARKER') + self._count('malformed_markers') + return + status_code = int(code) + if not -2147483648 <= status_code <= 2147483647: + self._reasons.add('MALFORMED_MARKER') + self._count('malformed_markers') + return + epoch = int(epoch) + identity = (epoch, phase, outcome, name, status_code) + if identity in self._seen: + self._reasons.add('DUPLICATE_MARKER') + self._count('duplicate_records') + return + self._seen.add(identity) + if self._window != 'BOUNDED': + return + if not self._started_ms <= epoch <= self._ended_ms: + self._reasons.add('OUTSIDE_WINDOW') + self._count('outside_window_markers') + return + self._rows.append({'phase': phase, 'outcome': outcome, 'error_name': name, + 'code': status_code, 'window_relation': 'IN_WINDOW'}) + + def result(self, input_partial=False): + reasons = set(self._reasons) + if self._window == 'UNKNOWN': + reasons.add('MISSING_WINDOW') + elif self._window == 'INVALID': + reasons.add('INVALID_WINDOW') + if type(input_partial) is not bool or input_partial: + reasons.add('PARTIAL_INPUT') + if not self._counts['marker_records_seen']: + reasons.add('NO_MARKER_OBSERVED') + if len(self._rows) > 1: + reasons.add('MULTIPLE_MARKERS') + status = 'OBSERVED' if len(self._rows) == 1 and not reasons else ( + 'AMBIGUOUS' if self._rows else 'UNKNOWN') + return { + 'schema': 1, 'status': status, 'cause': 'UNDETERMINED', + 'window': self._window, 'records': [dict(row) for row in self._rows], + **self._counts, 'own_process_count': len(self._pids), + 'own_process_count_capped': self._pid_count_capped, + 'limit_reached': 'OBSERVATION_LIMIT' in reasons, + 'input_partial': type(input_partial) is not bool or input_partial, + 'reasons': [reason for reason in _REASONS if reason in reasons], + 'scope': 'OPTIONAL_ORIGINAL_STARTUP_MARKERS_NOT_CAUSE_OR_ACCEPTANCE', + } diff --git a/.github/tests/test_ios_startup_errors.py b/.github/tests/test_ios_startup_errors.py index c062262e8..6cf2b338e 100644 --- a/.github/tests/test_ios_startup_errors.py +++ b/.github/tests/test_ios_startup_errors.py @@ -20,28 +20,31 @@ def record(message, process=APP, severity='Df', timestamp='2026-10-22 09:22:33.1 class IOSStartupErrorsTest(unittest.TestCase): - def test_precise_development_marker_uses_only_the_shared_fixed_vocabulary(self): + def test_precise_development_marker_uses_the_shared_final_vocabulary(self): source = (Path(__file__).resolve().parents[2] / - 'src/storage/startup-credential-diagnostics.ts').read_text() - stages = re.search(r'STARTUP_FAILURE_STAGES = \[(.*?)\] as const', source, re.S)[1] - self.assertEqual(tuple(re.findall(r"'([^']+)'", stages)), ios.STARTUP_STAGES) - categories = [] - for name in ('NATIVE_CODES', 'ERROR_NAMES'): - block = re.search(r'const ' + name + r' = \{(.*?)\} as const', source, re.S)[1] - categories.extend(re.findall(r":\s*'([^']+)'", block)) - self.assertEqual(tuple(categories + ['UNKNOWN']), ios.STARTUP_CATEGORIES) - for stage in ios.STARTUP_STAGES: - for category in ios.STARTUP_CATEGORIES: - self.assertIn("'" + category + "'", source) - marker = f'KEEPER_STARTUP_ERROR stage={stage} category={category}' - for envelope in ('', '[com.facebook.react.log:javascript] '): - result = ios.classify(record(envelope + marker, severity='I'), APP) - self.assertEqual(result['startup_failure_facts'], [{'stage': stage, 'category': category}]) + 'src/storage/startup-failure-observer.ts').read_text() + phases = re.search(r"const PHASES = \[(.*?)\];", source, re.S)[1] + names = re.search(r"const NAMES = \[(.*?)\];", source, re.S)[1] + spec = importlib.util.spec_from_file_location('receipt_vocab', + Path(__file__).resolve().parents[1] / 'native/startup_failure_receipts.py') + receipts = importlib.util.module_from_spec(spec) + spec.loader.exec_module(receipts) + self.assertEqual(tuple(re.findall(r"'([^']+)'", phases)), receipts.PHASES) + self.assertEqual(tuple(re.findall(r"'([^']+)'", names)), receipts.ERROR_NAMES) + for phase in receipts.PHASES: + for name in receipts.ERROR_NAMES: + marker = f'KEEPER_STARTUP_FAILURE_V1|1500|{phase}|THREW|{name}|NONE' + for envelope in ('', receipts.COMPACT_PREFIX): + result = ios.classify(record(envelope + marker, severity='E'), APP, 1000, 2000) + observed = result['startup_failure_receipt'] + self.assertEqual(observed['status'], 'OBSERVED') + self.assertEqual(observed['records'], [{'phase': phase, 'outcome': 'THREW', + 'error_name': name, 'code': None, 'window_relation': 'IN_WINDOW'}]) self.assertEqual(result['error_records'], 1) self.assertEqual(result['cause'], 'UNDETERMINED') - def test_foreign_malformed_and_private_marker_variants_supply_no_fixed_facts(self): - marker = 'KEEPER_STARTUP_ERROR stage=KEYCHAIN_READ category=NATIVE_CODE_NEG34018' + def test_foreign_malformed_and_private_marker_variants_cannot_claim_one_fixed_fact(self): + marker = 'KEEPER_STARTUP_FAILURE_V1|1500|NATIVE_CREDENTIAL_READ|REJECTED|Error|-34018' for payload in [record(marker, process='OtherApp'), marker, record('prefix ' + marker), record(marker + ' PRIVATE_SENTINEL'), record('[com.facebook.react:javascript] ' + marker), @@ -49,20 +52,20 @@ def test_foreign_malformed_and_private_marker_variants_supply_no_fixed_facts(sel record('[com.facebook.react.log:javascriptX] ' + marker), record('[com.facebook.react.log:javascript] ' + marker), record('[com.facebook.react.log:javascript] ' + marker + ' suffix'), - record('[com.facebook.react.log:javascript] ' + marker, process='OtherApp'), - record(marker.replace('KEYCHAIN_READ', 'PRIVATE_SENTINEL')), - record(marker.replace('NATIVE_CODE_NEG34018', 'PRIVATE_SENTINEL')), - record(marker.replace('KEEPER_STARTUP_ERROR', 'keeper_startup_error'))]: - with self.subTest(payload=payload[:15]): - result = ios.classify(payload, APP) - self.assertEqual(result['startup_failure_facts'], []) - self.assertNotIn('PRIVATE_SENTINEL', json.dumps(result)) + record(marker.replace('NATIVE_CREDENTIAL_READ', 'PRIVATE_SENTINEL')), + record(marker.replace('Error', 'PRIVATE_SENTINEL'))]: + result = ios.classify(payload, APP, 1000, 2000) + self.assertNotEqual(result['startup_failure_receipt']['status'], 'OBSERVED') + self.assertEqual(result['startup_failure_receipt']['records'], []) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(result)) def test_marker_observations_remain_bounded_and_never_establish_native_cause(self): - marker = 'KEEPER_STARTUP_ERROR stage=READ_CALL category=UNKNOWN' - result = ios.classify('\n'.join([record(marker)] * 40), APP) - self.assertEqual(len(result['startup_failure_facts']), 32) - self.assertTrue(result['startup_failure_fact_limit_reached']) + marker = 'KEEPER_STARTUP_FAILURE_V1|1500|ACCOUNT_STATE|THREW|UNKNOWN|NONE' + result = ios.classify('\n'.join([record(marker, severity='E')] * 40), APP, 1000, 2000) + observed = result['startup_failure_receipt'] + self.assertEqual(len(observed['records']), 1) + self.assertTrue(observed['limit_reached']) + self.assertEqual(observed['status'], 'AMBIGUOUS') self.assertEqual(result['error_records'], 40) self.assertEqual(result['cause'], 'UNDETERMINED') self.assertNotIn('PASS', json.dumps(result)) diff --git a/.github/tests/test_startup_failure_integration.py b/.github/tests/test_startup_failure_integration.py new file mode 100644 index 000000000..b1c0a8676 --- /dev/null +++ b/.github/tests/test_startup_failure_integration.py @@ -0,0 +1,131 @@ +"""Optional receipt integration; subprocesses are fake and no native app runs.""" +import importlib.util +from contextlib import redirect_stdout +import io +import json +from pathlib import Path +import subprocess +import tempfile +import unittest +from unittest import mock + +spec = importlib.util.spec_from_file_location('startup_failure_integration', + Path(__file__).resolve().parents[1] / 'native/hosted_native.py') +native = importlib.util.module_from_spec(spec) +spec.loader.exec_module(native) +MARKER = 'KEEPER_STARTUP_FAILURE_V1|1500|NATIVE_CREDENTIAL_READ|REJECTED|Error|-34018' + + +def record(message=MARKER, process='hexa_keeper_dev', pid='123', severity='E'): + return '2026-10-22 20:00:00.123 %s %s[%s:abc] %s\n' % (severity, process, pid, message) + + +class StartupFailureIntegrationTests(unittest.TestCase): + def receipt(self, payload, **kwargs): + return native.ios_startup_diagnostics(payload, 'hexa_keeper_dev', 1000, 2000, + **kwargs)['startup_failure_receipt'] + + def test_one_validated_own_error_marker_has_only_fixed_fields_and_no_cause_claim(self): + result = self.receipt(record('[com.facebook.react.log:javascript] ' + MARKER)) + self.assertEqual(result['status'], 'OBSERVED') + self.assertEqual(result['records'], [{'phase': 'NATIVE_CREDENTIAL_READ', 'outcome': 'REJECTED', + 'error_name': 'Error', 'code': -34018, 'window_relation': 'IN_WINDOW'}]) + self.assertEqual(result['cause'], 'UNDETERMINED') + encoded = json.dumps(result) + for private in ('hexa_keeper_dev', '2026-10-22', '1500', '123', MARKER): + self.assertNotIn(private, encoded) + + def test_invalid_compact_info_foreign_and_multiple_process_records_cannot_claim_one_failure(self): + for payload in (MARKER, record(severity='Info'), record(process='OtherApp'), + '2026-02-31 20:00:00 E hexa_keeper_dev[123:abc] ' + MARKER, + record() + record('ordinary startup', pid='124')): + with self.subTest(payload_shape=len(payload)): + self.assertNotEqual(self.receipt(payload)['status'], 'OBSERVED') + self.assertEqual(self.receipt(record() + record())['status'], 'AMBIGUOUS') + self.assertEqual(self.receipt(record(), input_partial=True)['status'], 'AMBIGUOUS') + missing = native.ios_startup_diagnostics(record(), 'hexa_keeper_dev')['startup_failure_receipt'] + self.assertEqual(missing['status'], 'UNKNOWN') + self.assertEqual(missing['records'], []) + + def test_optional_import_failure_does_not_change_existing_error_classification(self): + original = native.importlib.util.spec_from_file_location + def optional_only(name, path): + if name == 'startup_failure_receipts': + raise OSError('PRIVATE_SENTINEL') + return original(name, path) + with mock.patch.object(native.importlib.util, 'spec_from_file_location', side_effect=optional_only): + result = native.ios_startup_diagnostics(record('TypeError PRIVATE_SENTINEL'), 'hexa_keeper_dev') + self.assertEqual(result['category_record_counts']['JS_TYPE_ERROR'], 1) + self.assertEqual(result['startup_failure_receipt']['status'], 'UNKNOWN') + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(result)) + + def test_unsupported_unicode_header_spacing_cannot_supply_one_fixed_failure(self): + for separator in ('\u0085', '\u2028', '\u00a0'): + for payload in ('2026-10-22 20:00:00.123' + separator + 'E hexa_keeper_dev[123:abc] ' + MARKER, + '2026-10-22 20:00:00.123 E' + separator + 'hexa_keeper_dev[123:abc] ' + MARKER, + '2026-10-22 20:00:00.123 E hexa_keeper_dev[123:abc]' + separator + MARKER): + with self.subTest(separator=ord(separator), position=len(payload)): + result = self.receipt(payload) + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['records'], []) + self.assertIn('INVALID_COMPACT_RECORD', result['reasons']) + + def test_original_query_deadline_and_failed_smoke_are_unchanged_and_window_is_supplied(self): + with tempfile.TemporaryDirectory() as directory: + private = Path(directory) + with mock.patch.multiple(native, PRIVATE=private, EVIDENCE=private / 'metadata.json', PLATFORM='IOS'): + native.save({'commands': [], 'smoke': 'FAIL', 'built_artifact': {'executable': 'hexa_keeper_dev'}}) + def query(args, stdout, stderr, **kwargs): + self.assertEqual(args, ['xcrun', 'simctl', 'spawn', 'owned-simulator', 'log', 'show', + '--info', '--style', 'compact', '--last', '10m', '--predicate', + 'process == "hexa_keeper_dev" AND (messageType == "error" OR messageType == "fault" ' + 'OR eventMessage CONTAINS[c] "error" OR eventMessage CONTAINS[c] "exception" ' + 'OR eventMessage CONTAINS[c] "fatal")']) + self.assertEqual(kwargs, {'timeout': 25, 'check': False}) + stdout.write(record().encode()) + return subprocess.CompletedProcess(args, 0) + with mock.patch.object(native.subprocess, 'run', side_effect=query), \ + mock.patch.object(native.time, 'time', return_value=2), redirect_stdout(io.StringIO()): + native.record_startup_failure(private / 'missing.xml', 'owned-simulator', 1000) + data = native.read() + self.assertEqual(data['smoke'], 'FAIL') + self.assertEqual(data['startup_diagnostics']['ios_errors']['startup_failure_receipt']['status'], 'OBSERVED') + + def test_failed_query_discards_valid_looking_marker_output(self): + with tempfile.TemporaryDirectory() as directory: + private = Path(directory) + with mock.patch.multiple(native, PRIVATE=private, EVIDENCE=private / 'metadata.json', PLATFORM='IOS'): + native.save({'commands': [], 'smoke': 'FAIL', 'built_artifact': {'executable': 'hexa_keeper_dev'}}) + def query(args, stdout, stderr, **kwargs): + stdout.write(record().encode()) + return subprocess.CompletedProcess(args, 2) + with mock.patch.object(native.subprocess, 'run', side_effect=query), redirect_stdout(io.StringIO()): + native.record_startup_failure(private / 'missing.xml', 'owned-simulator', 1000) + result = native.read()['startup_diagnostics']['ios_errors']['startup_failure_receipt'] + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['records'], []) + self.assertEqual(result['reasons'], ['QUERY_UNAVAILABLE']) + + def test_optional_clock_failure_keeps_original_query_and_failure_unknown(self): + with tempfile.TemporaryDirectory() as directory: + private = Path(directory) + with mock.patch.multiple(native, PRIVATE=private, EVIDENCE=private / 'metadata.json', PLATFORM='IOS'): + native.save({'commands': [], 'smoke': 'FAIL', 'built_artifact': {'executable': 'hexa_keeper_dev'}}) + def query(args, stdout, stderr, **kwargs): + stdout.write(record('TypeError PRIVATE_SENTINEL').encode()) + return subprocess.CompletedProcess(args, 0) + with mock.patch.object(native.subprocess, 'run', side_effect=query) as called, \ + mock.patch.object(native.time, 'time', side_effect=OSError('PRIVATE_SENTINEL')), \ + redirect_stdout(io.StringIO()): + native.record_startup_failure(private / 'missing.xml', 'owned-simulator', 1000) + called.assert_called_once() + data = native.read() + result = data['startup_diagnostics']['ios_errors'] + self.assertEqual(result['category_record_counts']['JS_TYPE_ERROR'], 1) + self.assertEqual(result['startup_failure_receipt']['status'], 'UNKNOWN') + self.assertEqual(data['smoke'], 'FAIL') + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(data)) + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/tests/test_startup_failure_receipts.py b/.github/tests/test_startup_failure_receipts.py new file mode 100644 index 000000000..944b9e804 --- /dev/null +++ b/.github/tests/test_startup_failure_receipts.py @@ -0,0 +1,296 @@ +"""Pure fixed-marker controls; no native query, launch, or credential operation.""" + +import importlib.util +import json +from pathlib import Path +import unittest + + +SPEC = importlib.util.spec_from_file_location( + 'startup_failure_receipts', + Path(__file__).resolve().parents[1] / 'native/startup_failure_receipts.py') +receipts = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(receipts) +APP = 'hexa_keeper_dev' +EPOCH = 1792710000000 +STAMP = '2026-10-22 20:41:18.941' + + +def marker(epoch=EPOCH, phase='NATIVE_CREDENTIAL_READ', outcome='REJECTED', + name='Error', code='-34018'): + return '%s|%s|%s|%s|%s|%s' % ( + receipts.MARKER, epoch, phase, outcome, name, code) + + +class StartupFailureReceiptsTests(unittest.TestCase): + def collector(self): + return receipts.Collector(APP, EPOCH - 100, EPOCH + 100) + + def observe(self, collector, message=None, process=APP, pid='123', timestamp=STAMP): + collector.observe(timestamp, process, pid, marker() if message is None else message) + + def assert_private_and_optional(self, result): + encoded = json.dumps(result) + for private in ['PRIVATE_SENTINEL', 'https://private.invalid/', '/private/seed.js', + APP, STAMP, str(EPOCH), 'service-name', 'username', 'password']: + self.assertNotIn(private, encoded) + self.assertEqual(result['cause'], 'UNDETERMINED') + self.assertNotIn('PASS', encoded) + self.assertNotIn('selected_failure', result) + self.assertLessEqual(len(result['records']), 32) + + def test_one_exact_original_read_rejection_exports_fixed_facts_only(self): + collector = self.collector() + self.observe(collector) + result = collector.result() + self.assertEqual(result['status'], 'OBSERVED') + self.assertEqual(result['window'], 'BOUNDED') + self.assertEqual(result['records'], [{ + 'phase': 'NATIVE_CREDENTIAL_READ', 'outcome': 'REJECTED', + 'error_name': 'Error', 'code': -34018, 'window_relation': 'IN_WINDOW', + }]) + self.assertEqual(result['marker_records_seen'], 1) + self.assertEqual(result['own_process_count'], 1) + self.assertEqual(result['reasons'], []) + self.assert_private_and_optional(result) + + def test_supported_compact_prefix_is_grammar_not_a_hosted_transport_claim(self): + collector = self.collector() + self.observe(collector, receipts.COMPACT_PREFIX + marker()) + result = collector.result() + self.assertEqual(result['status'], 'OBSERVED') + self.assertEqual(result['records'][0]['code'], -34018) + self.assert_private_and_optional(result) + for prefix in [' ', 'sender: ', '[OTHER:javascript] ', receipts.COMPACT_PREFIX + ' ']: + with self.subTest(prefix_kind=prefix.split(':')[0]): + collector = self.collector() + self.observe(collector, prefix + marker()) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['records'], []) + self.assertIn('UNSUPPORTED_FRAMING', result['reasons']) + self.assert_private_and_optional(result) + + def test_each_phase_and_fixed_error_name_preserves_failure_scope(self): + for phase in receipts.PHASES: + for name in receipts.ERROR_NAMES: + with self.subTest(phase=phase, name=name): + collector = self.collector() + self.observe(collector, marker(phase=phase, outcome='THREW', name=name, code='NONE')) + result = collector.result() + self.assertEqual(result['status'], 'OBSERVED') + self.assertEqual(result['records'][0], { + 'phase': phase, 'outcome': 'THREW', 'error_name': name, + 'code': None, 'window_relation': 'IN_WINDOW', + }) + self.assert_private_and_optional(result) + + def test_code_is_canonical_int32_only_at_native_rejection_boundary(self): + for code in ['-2147483648', '2147483647', '0', '-25300', 'NONE']: + with self.subTest(code=code): + collector = self.collector() + self.observe(collector, marker(code=code)) + result = collector.result() + self.assertEqual(result['status'], 'OBSERVED') + self.assertEqual(result['records'][0]['code'], None if code == 'NONE' else int(code)) + self.assert_private_and_optional(result) + invalid = ['-2147483649', '2147483648', '+1', '01', '-0', '1.0', + 'NaN', '1e3', '1\u0662', '', 'PRIVATE_SENTINEL'] + for code in invalid: + with self.subTest(code_kind=code[:4]): + collector = self.collector() + self.observe(collector, marker(code=code)) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['records'], []) + self.assertIn('MALFORMED_MARKER', result['reasons']) + self.assert_private_and_optional(result) + for phase, outcome in [('ACCOUNT_STATE', 'THREW'), ('CREDENTIAL_JSON', 'THREW'), + ('NAVIGATION', 'THREW'), ('NATIVE_CREDENTIAL_READ', 'THREW')]: + collector = self.collector() + self.observe(collector, marker(phase=phase, outcome=outcome, code='-34018')) + self.assertEqual(collector.result()['status'], 'UNKNOWN') + for phase in ['ACCOUNT_STATE', 'CREDENTIAL_JSON', 'NAVIGATION']: + collector = self.collector() + self.observe(collector, marker(phase=phase, outcome='REJECTED', code='NONE')) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertIn('MALFORMED_MARKER', result['reasons']) + + def test_missing_invalid_and_partial_capture_cannot_establish_attribution(self): + for start, end, reason in [(None, None, 'MISSING_WINDOW'), (EPOCH, None, 'MISSING_WINDOW'), + (EPOCH + 1, EPOCH, 'INVALID_WINDOW'), + (True, EPOCH, 'INVALID_WINDOW'), (-1, EPOCH, 'INVALID_WINDOW')]: + with self.subTest(reason=reason): + collector = receipts.Collector(APP, start, end) + self.observe(collector) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['records'], []) + self.assertIn(reason, result['reasons']) + self.assert_private_and_optional(result) + collector = self.collector() + self.observe(collector) + for partial in [True, 'PRIVATE_SENTINEL']: + result = collector.result(input_partial=partial) + self.assertEqual(result['status'], 'AMBIGUOUS') + self.assertIn('PARTIAL_INPUT', result['reasons']) + self.assert_private_and_optional(result) + + def test_marker_epoch_selects_window_without_guessing_compact_timezone(self): + for epoch in [EPOCH - 100, EPOCH + 100]: + collector = self.collector() + self.observe(collector, marker(epoch=epoch), timestamp='2026-10-22 20:41:18.941') + result = collector.result() + self.assertEqual(result['status'], 'OBSERVED') + self.assertEqual(result['records'][0]['window_relation'], 'IN_WINDOW') + self.assert_private_and_optional(result) + for epoch in [EPOCH - 101, EPOCH + 101]: + collector = self.collector() + self.observe(collector, marker(epoch=epoch)) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['outside_window_markers'], 1) + self.assertEqual(result['records'], []) + self.assertIn('OUTSIDE_WINDOW', result['reasons']) + self.assert_private_and_optional(result) + + def test_foreign_process_and_multiple_own_pids_never_select_one_failure(self): + collector = self.collector() + self.observe(collector, process='OtherApp') + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['foreign_process_markers'], 1) + self.assertEqual(result['own_process_count'], 0) + self.assertEqual(result['records'], []) + self.assert_private_and_optional(result) + collector = self.collector() + for pid, epoch in [('123', EPOCH), ('124', EPOCH + 1), ('125', EPOCH + 2)]: + self.observe(collector, marker(epoch=epoch), pid=pid) + result = collector.result() + self.assertEqual(result['status'], 'AMBIGUOUS') + self.assertEqual(result['own_process_count'], 2) + self.assertTrue(result['own_process_count_capped']) + self.assertIn('MULTIPLE_OWN_PIDS', result['reasons']) + self.assertEqual(len(result['records']), 3) + self.assert_private_and_optional(result) + + def test_duplicate_and_distinct_markers_remain_ambiguous(self): + collector = self.collector() + self.observe(collector) + self.observe(collector, receipts.COMPACT_PREFIX + marker()) + result = collector.result() + self.assertEqual(result['status'], 'AMBIGUOUS') + self.assertEqual(result['duplicate_records'], 1) + self.assertEqual(len(result['records']), 1) + self.assertIn('DUPLICATE_MARKER', result['reasons']) + self.assert_private_and_optional(result) + collector = self.collector() + self.observe(collector) + self.observe(collector, marker(epoch=EPOCH + 1, phase='NAVIGATION', outcome='THREW', code='NONE')) + result = collector.result() + self.assertEqual(result['status'], 'AMBIGUOUS') + self.assertEqual(len(result['records']), 2) + self.assertEqual(result['duplicate_records'], 0) + self.assertIn('MULTIPLE_MARKERS', result['reasons']) + self.assert_private_and_optional(result) + + def test_ordinary_own_process_records_also_constrain_pid_attribution(self): + for ordinary_first in [True, False]: + with self.subTest(ordinary_first=ordinary_first): + collector = self.collector() + if ordinary_first: + self.observe(collector, 'ordinary startup PRIVATE_SENTINEL', pid='124') + self.observe(collector, pid='123') + if not ordinary_first: + self.observe(collector, 'ordinary startup PRIVATE_SENTINEL', pid='124') + result = collector.result() + self.assertEqual(result['status'], 'AMBIGUOUS') + self.assertEqual(result['own_process_count'], 2) + self.assertIn('MULTIPLE_OWN_PIDS', result['reasons']) + self.assertEqual(len(result['records']), 1) + self.assert_private_and_optional(result) + + def test_malformed_or_invalid_compact_markers_poison_single_marker_certainty(self): + malformed = [marker() + '|PRIVATE_SENTINEL', marker(name='PrivateError'), + marker(phase='PRIVATE_SENTINEL'), marker(outcome='PASS'), + marker(epoch='NaN'), marker(epoch='-1'), marker(epoch='01'), marker(epoch='17\u0661'), + marker(epoch=str(receipts.MAX_EPOCH_MS + 1)), marker() + '\n', + marker(code='-34018\x00PRIVATE_SENTINEL')] + for message in malformed: + with self.subTest(message_length=len(message)): + collector = self.collector() + self.observe(collector, message) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['records'], []) + self.assertEqual(result['malformed_markers'], 1) + self.assert_private_and_optional(result) + collector = self.collector() + self.observe(collector) + collector.invalid_record(marker_present=True) + result = collector.result() + self.assertEqual(result['status'], 'AMBIGUOUS') + self.assertEqual(result['invalid_compact_markers'], 1) + self.assertIn('INVALID_COMPACT_RECORD', result['reasons']) + self.assert_private_and_optional(result) + + def test_field_validation_is_fixed_and_does_not_reparse_raw_record_content(self): + for fields in [dict(pid='0'), dict(pid='2147483648'), dict(pid='1\u0662'), dict(pid=True), + dict(timestamp=None), dict(timestamp=''), dict(process=None), + dict(message=None), dict(message='x' * (receipts.MAX_MESSAGE_CHARS + 1))]: + collector = self.collector() + values = dict(timestamp=STAMP, process=APP, pid='123', message=marker()) + values.update(fields) + collector.observe(**values) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertIn('INVALID_RECORD_FIELDS', result['reasons']) + self.assert_private_and_optional(result) + for executable in ['', '../PRIVATE_SENTINEL', 'app\nPRIVATE_SENTINEL', 'a' * 129, None]: + with self.assertRaisesRegex(ValueError, '^Expected a validated executable selector\\.$'): + receipts.Collector(executable) + + def test_storage_and_export_counts_are_bounded_and_never_choose_cap_tail(self): + collector = self.collector() + for index in range(100): + self.observe(collector, marker(epoch=EPOCH - 50 + index)) + result = collector.result() + self.assertEqual(result['status'], 'AMBIGUOUS') + self.assertEqual(result['marker_records_seen'], 32) + self.assertEqual(len(result['records']), 32) + self.assertTrue(result['limit_reached']) + self.assertIn('OBSERVATION_LIMIT', result['reasons']) + self.assertLess(len(json.dumps(result)), 7000) + self.assert_private_and_optional(result) + collector = self.collector() + for _ in range(100): + collector.invalid_record(marker_present=True) + result = collector.result() + self.assertEqual(result['status'], 'UNKNOWN') + self.assertEqual(result['invalid_compact_markers'], 32) + self.assertTrue(result['limit_reached']) + self.assert_private_and_optional(result) + + def test_noise_absence_and_result_copy_do_not_invent_or_mutate_observations(self): + collector = self.collector() + self.observe(collector, 'PRIVATE_SENTINEL https://private.invalid/ /private/seed.js') + collector.invalid_record(marker_present=False) + absent = collector.result() + self.assertEqual(absent['status'], 'UNKNOWN') + self.assertEqual(absent['records'], []) + self.assertIn('NO_MARKER_OBSERVED', absent['reasons']) + self.assert_private_and_optional(absent) + self.observe(collector) + first = collector.result(input_partial=True) + first['records'][0]['phase'] = 'PRIVATE_SENTINEL' + first['reasons'].append('PRIVATE_SENTINEL') + second = collector.result() + self.assertEqual(second['status'], 'OBSERVED') + self.assertEqual(second['records'][0]['phase'], 'NATIVE_CREDENTIAL_READ') + self.assertEqual(second['reasons'], []) + self.assert_private_and_optional(second) + + +if __name__ == '__main__': + unittest.main() diff --git a/docs/r5-startup-credential-failure-observation.md b/docs/r5-startup-credential-failure-observation.md new file mode 100644 index 000000000..3ef89946c --- /dev/null +++ b/docs/r5-startup-credential-failure-observation.md @@ -0,0 +1,108 @@ +# Optional original-startup failure receipt + +This offline diagnostic preparation starts from frozen source +`1bc34890cb8618b2fffd446a63924974e0fe15b5`. It implements no credential, +navigation, dependency, signing, simulator-service or acceptance correction. +The app-source changes add observability only; the original failure behavior stays. +It has not run on hosted iOS or Android. The original native source remains unchanged. Its run completed naturally; +this observer has not run on a native candidate. Actual future native status is required before proposing +a correction. + +The1bc iOS receipt contains the fixed credential-error and Retry public flags. +Its guarded Splash catch covers both `hasPin` and navigation. The native +Keychain status was not retained. Historical source +`d865ca9c4f91532a1524443cc6da42d8d7b07e1a` swallowed every `hasPin` exception and +returnedfalse; its CreatePin pass did not establish a successful Keychain read. +RNKeychain10.0.0's original query rejects status other than0/-25300 with a +decimal-string `error.code`, and performs no library error logging. A successful +false return is not proof of exact-25300. + +## Original failure boundaries + +`hasPin` accepts an optional second callback. Existing callers retain their +arguments and legacy false-on-error behavior. Startup registers the observer; +its original native query, service choice, call count, return and original thrown +error are retained. No extra read, write, reset or Retry is introduced. Failures +are classified only where they occur: + +- `ACCOUNT_STATE`: Redux/account selection throws. +- `NATIVE_CREDENTIAL_READ`: a synchronous call throws, or its original awaited + result rejects. Only the latter may retain a canonical ASCII decimal signed + int32 `error.code`; other code values remainnull. +- `CREDENTIAL_JSON`: credential-property access or JSON parsing throws. +- `NAVIGATION`: the existing Login/CreatePin navigation call throws, after a + completed credential decision. This separate catch prevents attributing a + navigation error to a native read or duplicating its failure receipt. + +The callback receives fixed phase/outcome/error-name values and the optional +numeric code. It never receives an error object, message, stack, service, +username, password, account identifier or credential value. Error getters and +observer failures are contained; no observer means no error-property inspection. +Only failures emit markers. Successful and empty reads emit nothing, and a +missing marker does not establish that a read succeeded. + +## Source-supported transport, not hosted proof + +The development-only sink checks `__DEV__` and the direct +`global.nativeLoggingHook`, then emits a fixed Error-level3 marker. It does not +call `console.log`, `console.error`, ExceptionsManager or LogBox. Missing hooks, +invalid clock/receipt data and sink failures are quietly ignored. The public +epoch milliseconds are used solely to relate a receipt to the original Maestro +command's capture window; neither that value nor raw log content is exported. +This relation uses the simulator and host's shared Unix-epoch clock convention, +not a performance measurement or an inferred compact-log timezone. Missing, +invalid or outside-window relations remain unknown; multiple own PIDs or markers +prevent selecting one unambiguous failure. + +Pinned React Native0.83.9 source establishes the path: + +- js-polyfills `console.js` uses level1 for log/info and3 for error; its + `console.error` wrapper can invoke ExceptionsManager/LogBox. +- `RCTInstance.mm:452` binds `nativeLoggingHook` to + `_RCTLogJavaScriptInternal`; `RCTLog.mm:328` calls the configured log function. +- `RCTLog.mm:74` maps level3 to `OS_LOG_TYPE_ERROR`; the default function at107 + uses `os_log_with_type` with public fixed text, subsystem + `com.facebook.react.log` and category `javascript`. The app has no custom + logging override. This direct path bypasses the console-error wrapper. + +RN tarball SHA1: `61d2a4ccd89e06b98992c9b9781856ad88a09d39`; +`RCTLog.mm` SHA256: +`a72a020e0047026a8b6710fb3942fc638a7b87bda1f78f06655598793b5e97a7`. +The separate js-polyfills0.83.9 tarball SHA1 is +`8178d55abcb6ffdf3b4afe69ea4dc76051e43408`; `console.js` SHA256: +`3446f28d3f79e91ed37f40f56faf520fc9f914e30566879b4605db05cacfa9f2`. +Both tarballs matched the frozen lock's SHA512 integrity. These are source facts; +actual hosted transport remains NOT RUN. + +## Existing collection only + +The reconciled own-process compact `log show` query retains #7129's --info +option, last10m selection, predicate and25s deadline. There is no new query. Its already validated records feed a pure bounded +collector. The marker's epoch is compared with the capture start immediately +before the original Maestro command and the end before failure collection. +Compact timestamps are not guessed into a timezone. Exact marker messages and +the fixed React JavaScript subsystem/category prefix are recognized grammar; +other framing stays unknown. This grammar is not a claim about an observed +hosted renderer. + +The optional `startup_failure_receipt` exports at most32 fixed records and +bounded counts. Missing/malformed/partial input, missing or invalid windows, +outside-window markers, foreign processes, multiple own PIDs, duplicates and +limits remain explicit UNKNOWN/AMBIGUOUS states. Process and timestamp values, +raw text and marker epochs are not exported. Import/collector/query failure +leaves UNKNOWN and preserves the original startup failure. Rendered log markers +are observations, not authenticated provenance or failure-cause proof. + +No acceptance predicate consumes this optional receipt. App selectors, actions, +deadlines, installed-byte requirements and all cleanup remain unchanged. Current +#7068 head `4bef0b78581ccaf4acc89053d3c7d30b04fa1338` has no `src`, iOS, Android, +dependency or patch delta from1bc and supplies no observed Keychain/PIN fix. + +## Reconciliation with #7129 + +The separately reviewed full-ancestry child selects this one direct hook and +removes the earlier console.info helper. It adds #7129's current-attempt guard +to suppress late callbacks after unmount. Its canonical pure compact parser +remains the single framing/category implementation and feeds this collector; +the older inline parser is not restored. Source controls from both producers +remain, adapted to the selected V1 grammar. See [the current source contract](r5/STARTUP-FAILURE-BOUNDARIES.md). diff --git a/docs/r5/STARTUP-FAILURE-BOUNDARIES.md b/docs/r5/STARTUP-FAILURE-BOUNDARIES.md index d269e34a2..d41a49326 100644 --- a/docs/r5/STARTUP-FAILURE-BOUNDARIES.md +++ b/docs/r5/STARTUP-FAILURE-BOUNDARIES.md @@ -1,52 +1,73 @@ -# Startup observation reconciliation A: app transport - -This package preserves both producer ancestries: [#7129](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7129) -`cd9d50a80bdd9035b532604bd10bcfeb21fe484e` and [#7131](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7131) -`e34331083959c94b5f0a17603d8c1f578305c474`. Its fixed source-review baseline -`4b6cabc55a82d4f9d200a97db137202d01236e82` has those two parents and exactly -the already reviewed #7129 tree. That join is not a native/release candidate; -selected #7131 work is exposed across this app package A and successor B. -Full new changed code/test text across both packages is approximately18.3k -characters/4 tokens before final formatting; per-package estimates and exact -commits belong in their handoffs. Existing producer PRs remain review links. - -A selects exactly one development-only direct native hook from #7131 and adds -#7129's current-attempt/unmount guard. The old console.info emitter is removed. -Its old pure classifier remains temporarily because the unchanged canonical -parser's source-vocabulary controls still use it. It emits no log and is not -called by the app. Successor B removes it and connects the V1 collector to the -canonical parser; A alone does not claim V1 fixed-receipt collection. - -The original1bc iOS window built/installed successfully and failed Create a -passcode. [The exact artifact readout](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7123) -retained credential-error and Retry flags in one snapshot. Its616 own-process -error records contain18 CONNECTION markers and598 unclassified records. Neither -the snapshot nor those categories identify a Keychain/navigation cause. The -original source and evidence remain immutable; no pass transfers to this source. - -The optional second `hasPin` callback receives only fixed phase/outcome/error-name -values and an optional numeric code. Only the original native-read rejection may -retain a canonical ASCII decimal-string signed int32 code. Guarded getters never -forward the original error, message, stack, credential, service/account identifier -or native response. No observer means no error-property inspection. Original -rejection identity, legacy false-on-error semantics, read count/service choice, -modal, Retry, success navigation and cleanup remain intact. Navigation failures -have their own phase after the original read. Abandoned attempts emit nothing. - -A current development failure emits one direct Error-level3 hook call, such as: +# Reconciled startup failure observations + +This source-only reconciliation preserves the full ancestry of [#7129](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7129) +(`cd9d50a80bdd9035b532604bd10bcfeb21fe484e`) and [#7131](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7131) +(`e34331083959c94b5f0a17603d8c1f578305c474`). It selects one development-only +direct `nativeLoggingHook` emitter and retains the current-attempt/unmount guard. +App package A is `04be52e61569b88597ccc24504993247cd33ac48` on the fixed +mechanical join `4b6cabc55a82d4f9d200a97db137202d01236e82` (tree exactly #7129). +This successor B exposes the canonical collector bridge separately. Both packages +retain explicit full new-source and cumulative size estimates in their handoffs. +It replaces the earlier console.info marker; the two emitters never run together. +The original producer branches and their review evidence remain unchanged. + +The exact `1bc34890cb8618b2fffd446a63924974e0fe15b5` iOS window built and +installed successfully, then failed its first Create a passcode assertion. +[The pinned artifact readout](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7123) +found credential-error and Retry flags in one retained snapshot. The flags do +not establish the current route, tap delivery or failure cause. Its 616 +own-process error records contain 18 CONNECTION markers and 598 unclassified +records. No native Keychain status was retained. These observations cannot be +transferred to this new source or the combined candidate. + +The original Splash catch spans both `hasPin` and navigation. `hasPin` spans +Redux/account selection, native credential reading and JSON parsing. Empty +fresh credentials ordinarily resolve false and select CreatePin. No Keychain, +entitlement, SDK or navigation cause has been established. This package makes +those original failure boundaries observable; it supplies no app correction. + +`hasPin` accepts an optional second callback. It receives only a fixed phase, +THREW/REJECTED outcome, whitelisted error name and optional numeric code. Only a +native-read rejection may retain a canonical ASCII decimal-string signed int32 +code. Guarded property access never forwards the original error, message, stack, +credential, account/service identifier or native response. Original rejection +identity and legacy false-on-error behavior survive observer faults. No callback +means no error-property inspection. + +A current development attempt emits at most one direct Error-level3 hook call +for its failure. It calls no console or LogBox wrapper. For example: ```text KEEPER_STARTUP_FAILURE_V1|1500|NATIVE_CREDENTIAL_READ|REJECTED|Error|-34018 ``` -This is illustrative grammar, not an observed native code. No console/LogBox call -or production observer is introduced. Pinned RN0.83.9 source supports the direct -Error sink. Actual hosted transport and marker visibility remain UNVERIFIED. -There is no SDK, selector, query, deadline, dependency or acceptance change in A. - -Source controls cover original results/errors, every read boundary, hostile -getters, observer/sink faults, production silence, navigation, Retry and late -unmount. A does not correct the observed app failure or establish native, -backend, physical-device or release acceptance. No native window is queued. -The complete collection/privacy/ambiguity controls are a separate successor B, -which must be reviewed and integrated before the next combined diagnostic source. +This is illustrative grammar, not an observed native status. Production startup +supplies no observer. Abandoned attempts emit nothing. Existing modal, Retry, +read count, service selection, success navigation and cleanup behavior remain. +Navigation exceptions have their own fixed phase after the original read. + +The existing canonical pure compact-log parser validates framing and exact own +executable attribution. It retains its generic category/count contracts and +feeds already validated fields to #7131's pure bounded receipt collector. A +complete standalone V1 marker, optionally preceded by exactly +`[com.facebook.react.log:javascript] `, is supported. Other framing cannot supply +one observed receipt. The collector relates its bounded epoch to the original +startup command's start and failure-collection end; raw epoch, timestamps, PID, +process and message are never exported. Missing/invalid windows, partial input, +foreign processes, duplicate markers, multiple own PIDs and limits stay explicit +UNKNOWN/AMBIGUOUS. At most32 fixed records are retained. Rendered markers are +observations, not authenticated provenance, a failure cause or acceptance. + +The same own-process log query keeps --info, its last10m selection, predicate +and25s deadline. There is no additional query, SDK/configuration/selector change, +new native operation or acceptance-predicate relaxation. Pinned RN0.83.9 source +supports the direct Error sink and fixed React prefix; actual marker visibility +on hosted native remains UNVERIFIED. No native run has exercised this source. + +App source controls cover original results/errors, hostile getters, observer and +sink faults, production silence, Retry/navigation and late unmount. Pure parser, +collector and fake-query controls cover exact envelopes, window/PID ambiguity, +bounds and privacy. These tests do not establish native feature, backend, +physical-device or release acceptance. No personal Mac or release operation is +required by this source preparation. See [the transport source record](../r5-startup-credential-failure-observation.md) +for the original #7131 source analysis. diff --git a/src/storage/startup-credential-diagnostics.ts b/src/storage/startup-credential-diagnostics.ts deleted file mode 100644 index eae2e746a..000000000 --- a/src/storage/startup-credential-diagnostics.ts +++ /dev/null @@ -1,81 +0,0 @@ -// Fixed development observations only. Never retain or forward an Error object. -export const STARTUP_FAILURE_STAGES = [ - 'READ_CALL', - 'STATE_READ', - 'SERVICE_SELECT', - 'KEYCHAIN_READ', - 'CREDENTIAL_PARSE', - 'NAVIGATE_LOGIN', - 'NAVIGATE_CREATE_PIN', -] as const; -export type StartupFailureStage = (typeof STARTUP_FAILURE_STAGES)[number]; - -const NATIVE_CODES = { - '-34018': 'NATIVE_CODE_NEG34018', - '-25308': 'NATIVE_CODE_NEG25308', - '-25291': 'NATIVE_CODE_NEG25291', - '-25293': 'NATIVE_CODE_NEG25293', - '-26275': 'NATIVE_CODE_NEG26275', - '-50': 'NATIVE_CODE_NEG50', -} as const; -const ERROR_NAMES = { - Error: 'ERROR', - TypeError: 'TYPE_ERROR', - SyntaxError: 'SYNTAX_ERROR', - RangeError: 'RANGE_ERROR', - ReferenceError: 'REFERENCE_ERROR', -} as const; -export const STARTUP_FAILURE_CATEGORIES = [ - ...Object.values(NATIVE_CODES), - ...Object.values(ERROR_NAMES), - 'UNKNOWN', -] as const; -export type StartupFailureCategory = (typeof STARTUP_FAILURE_CATEGORIES)[number]; -export type StartupFailureFact = Readonly<{ - stage: StartupFailureStage; - category: StartupFailureCategory; -}>; - -export const startupFailureFact = ( - stage: StartupFailureStage, - error: unknown -): StartupFailureFact => { - let category: StartupFailureCategory = 'UNKNOWN'; - // Accessors may themselves throw. No dynamic value is returned or logged. - try { - if (error && (typeof error === 'object' || typeof error === 'function')) { - const { code } = error as { code?: unknown }; - if ( - stage === 'KEYCHAIN_READ' && - (typeof code === 'string' || typeof code === 'number') && - Object.prototype.hasOwnProperty.call(NATIVE_CODES, code) - ) { - category = NATIVE_CODES[String(code) as keyof typeof NATIVE_CODES]; - } else { - const { name } = error as { name?: unknown }; - if (typeof name === 'string' && Object.prototype.hasOwnProperty.call(ERROR_NAMES, name)) { - category = ERROR_NAMES[name as keyof typeof ERROR_NAMES]; - } - } - } - } catch { - // Unknown is more accurate than letting diagnostics replace the failure. - } - return { - stage: STARTUP_FAILURE_STAGES.includes(stage) ? stage : 'READ_CALL', - category, - }; -}; - -export const reportStartupFailure = (fact: StartupFailureFact) => { - if (!__DEV__) return; - try { - const { stage, category } = fact; - if (STARTUP_FAILURE_STAGES.includes(stage) && STARTUP_FAILURE_CATEGORIES.includes(category)) { - // One info line adds no LogBox warning/error and exports no raw details. - console.info(`KEEPER_STARTUP_ERROR stage=${stage} category=${category}`); - } - } catch { - // Logging never changes credential, navigation, Retry or unmount semantics. - } -};