Skip to content
Merged
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
9 changes: 7 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ and `lib/utils/canonical_json.dart`, plus `AppReport` and `PluginReportRecord`.
by Otzaria's own code (commit named in the fixture); a change there must be re-ported
and the vectors regenerated, or the server receives a body Otzaria would never send.

**Never write to a DB we do not understand.** A `reportsQueueFormat` other than 1 in
**Never write to a DB we do not understand.** A `reportsQueueFormat` other than 1 or 2 in
`otzaria_capabilities.json` (or, without that file, `PRAGMA user_version` above
`UserStateReportQueue.knownSchemaVersion`), a missing `pending_reports` table, or a
book report's `schemaVersion` above 2 all mean "no offer" and no write. A leftover
Expand Down Expand Up @@ -2420,7 +2420,12 @@ new id (`report_id` / `reportId`), is rewritten in the outbox under it, and is r
once. A 503 `{"error":"shabbat"}` stops the run with its own message. A drive
file can come from anywhere, so the endpoint is checked before any POST — and before
the rate-limit wait, since it is not a request. Rejection reasons go to the log only.
One exception, as in Otzaria: an app report carrying the consented crash `minidump`
Schema 2 app reports retain their full outbox file on server rejection and stop with
a visible message; their 10 MiB per attachment / 20 MiB total policy never strips a
minidump or truncates diagnostics/logs. Validation precedes sending, and the 128 MiB
request envelope covers JSON escaping. Existing schema 1 behavior remains below.

One legacy exception, as in Otzaria: a schema 1 app report carrying the consented crash `minidump`
that gets a 413, or a 422 naming `attachments.minidump`, is re-sent once without the
dump (after the window wait), and only that answer decides the file's fate. If the
run stops after the dump was dropped (a transient answer, a timeout, a network error or
Expand Down
36 changes: 32 additions & 4 deletions error_reports_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Flutter), במקביל ל-`custom_apps_manager`.

נוסף על נשיאת הדיווחים של אוצריא, החבילה שולחת גם דיווחים על **הלאנצ'ר
עצמו** — פורט של "דיווח על התוכנה" של אוצריא (`lib/app_report/`), עם אותו
חוזה (`POST https://otzaria.org/api/app-reports`, schema 1) ועם שדה אחד
חוזה (`POST https://otzaria.org/api/app-reports`, schema 2; דיווחים ישנים שומרים schema 1) ועם שדה אחד
נוסף: `"product": "offline-update"`. האתר מנתב לפיו את הדיווח ל-issue בריפו
`Otzaria/Otzaria_Offline_update`. דיווח בלי השדה הוא של אוצריא, ולכן
`UserStateReportQueue` מוחק אותו מכל דיווח שנאסף מהתור של אוצריא.

| | |
| --- | --- |
| `AppReportService` | שליחה, תור והיסטוריה. 2xx עם `success:true` — נשלח (עם `issueNumber`/`issueUrl`/`merged`/`issuePending`); 409 — מזהה חדש ושליחה חוזרת; 400/413/422 — דחייה סופית; 429/5xx/רשת/זמן קצוב — לתור. שליחה מיידית, ושליחת התור בעלייה ואחת ל-5 דקות (עד 4 בקשות בסבב ברקע ו-8 ב"שלח עכשיו"; עוצרת בכשל הזמני הראשון; `FlushOutcome` נושא גם `failed` — שגיאה מקומית — ו-`dropped` — נדחו והוסרו). נעילה לפי מזהה דיווח, וההיסטוריה נכתבת בטור |
| `AppReportService` | שליחה, תור והיסטוריה. 2xx עם `success:true` — נשלח (עם `issueNumber`/`issueUrl`/`merged`/`issuePending`); 409 — מזהה חדש ושליחה חוזרת; 400/413/422 — דחייה: בגרסה 2 התוכן נשמר לתיקון, ובגרסה 1 התור נשאר עם ההתנהגות הישנה; 429/5xx/רשת/זמן קצוב — לתור. שליחה מיידית, ושליחת התור בעלייה ואחת ל-5 דקות (עד 4 בקשות בסבב ברקע ו-8 ב"שלח עכשיו"; עוצרת בכשל הזמני הראשון; `FlushOutcome` נושא גם `failed` — שגיאה מקומית או דיווח חדש שנדחה ונשמר — ו-`dropped` — נדחו והוסרו). נעילה לפי מזהה דיווח, וההיסטוריה נכתבת בטור |
| איפה | `<stateDir>/reports/launcher/pending/<queuedAt>.<id>.json` לכל דיווח בתור (כולל הצרופות; הסדר והספירה נקראים משם הקובץ בלבד, בלי פענוח), ו-`sent.json` להיסטוריה: 100 האחרונים בלי צרופות, ומונה כולל. כתיבה לקובץ זמני ואז `rename`, וקבצי `.tmp` שנשארו מנוקים בעלייה; קובץ פגום מועבר ל-`.bad` ואינו נספר |
| רקע | סבב אחד לכל היותר (קריאה בזמן סבב מצטרפת אליו), עד 4 בקשות בסבב ברקע ו-8 ב"שלח עכשיו" — השרת מאפשר 8 בדקה, והמכסה משותפת להעלאת דיווחי אוצריא. כל רשומה עטופה: שגיאת דיסק נרשמת ב-`log` בלבד, כי שורת שגיאה שלא נתפסה היא ראיה לקריסה. ב-409 חוזר 3 פעמים הדיווח מוסר |
| סדר הכתיבה | בהצלחה — קודם ההיסטוריה ורק אז מחיקת קובץ התור; `submitPendingReport` מוחק רק אחרי תוצאה סופית. כשל קריאה זמני של `sent.json` (למשל אנטי-וירוס) מנוסה שוב ואז מבטל את הכתיבה — לעולם אינו נחשב "היסטוריה ריקה"; קובץ פגום באמת מועבר ל-`.bad` |
Expand Down Expand Up @@ -95,9 +95,9 @@ Flutter), במקביל ל-`custom_apps_manager`.

| | |
| --- | --- |
| קריאה | `pending_reports` בסוגי `error_reports_queue/pending_reports`, `app_reports_queue/pending_reports`, `plugin_reports_queue/pending_reports`, עם `busy_timeout=5000` |
| קריאה | `pending_reports` בסוגי `error_reports_queue/pending_reports`, `app_reports_queue/pending_reports`, `app_reports_queue/pending_reports_v2`, `plugin_reports_queue/pending_reports`, עם `busy_timeout=5000` |
| איפה זה רץ | כל עבודת ה-SQLite — פתיחה, בדיקת הסכמה, פענוח, ה-digest והסימון — ב-`Isolate.run` (מוזרק: `runIsolated`); רק כתיבת הקבצים לתיבה נשארת ב-isolate הראשי, אסינכרונית. FFI סינכרוני ב-isolate של הממשק מקפיא אותו בעלייה (AGENTS §5.9) |
| שמירת סכמה | `reportsQueueFormat` מ-`otzaria_capabilities.json` (C1) שאינו 1, או בלי הטבלה — לא נוגעים, אין הצעה. בלי הקובץ (אוצריא ישנה): `PRAGMA user_version` גבוה מ-`knownSchemaVersion` (1) |
| שמירת סכמה | `reportsQueueFormat` מ-`otzaria_capabilities.json` (C1) שאינו 1 או 2, או בלי הטבלה — לא נוגעים, אין הצעה. בלי הקובץ (אוצריא ישנה): `PRAGMA user_version` גבוה מ-`knownSchemaVersion` (2) |
| קריאה בזיכרון | המעבר הראשון שומר לכל שורה רק מזהה ו-SHA-256 של ה-payload; כל דיווח נקרא ומקודד שוב ב-isolate משלו רק לפני כתיבתו לתיבה |
| ההיסטוריה | הרשומה שעוברת ל-`sent_reports` מקבלת `carriedBy: "offline-update"` ו-`carriedAt` (C3), ואוצריא מציגה אותה "הועבר לשליחה דרך עדכוני אוצריא" |
| דיווח שלא יישלח | `schemaVersion` חדש מ-2, `fromJson` שנכשל, surrogate בודד (אין digest), גוף מעל 256KB — נשאר בתור |
Expand Down Expand Up @@ -150,6 +150,34 @@ Flutter), במקביל ל-`custom_apps_manager`.
`source` של `test/fixtures/api_payload_golden.json`. גרסת סכמה חדשה (3) פירושה
שהפורט אינו מכיר את הדיווח, והוא נשאר בתור.


## תאימות ומגבלות צרופות

`AppReport.schema` נשמר גם ברשומה המקומית וגם בגוף הבקשה. רשומה בלי השדה היא
דיווח ישן עם schema 1; אין לשכתב את הסכמה בזמן איסוף או ניסיון שליחה חוזר.
דיווחים חדשים הם schema 2: עד 10 MiB לקובץ ועד 20 MiB לכל הצרופות יחד,
כאשר 1 MiB הוא 1,048,576 בתים. גם אבחון ולוג מוגבלים ל־10 MiB כל אחד, ללא קיצוץ שקט. הסכום כולל תמונות, dump לפני דחיסת gzip,
אבחון ב־JSON קומפקטי ב־UTF-8 ויומן ב־UTF-8 אחרי הקיצוץ הקיים. GIF נשמר כמו שהוא.
תקציב גוף הבקשה כולל את הרחבת base64, את תקורת gzip ואת שדות הדיווח.

הלקוח מציין `reportsQueueFormat: 2`. המעדכן תומך בפורמטים 1 ו־2. רשומות התור החדשות נשמרות בסוג
`app_reports_queue/pending_reports_v2`, שאוסף ישן אינו בוחר אפילו כאשר
קובץ היכולות חסר או נדרס בלקוח ישן. האוסף החדש קורא את שני סוגי התור
ושומר את הסכמה המקורית ואת יעד ההיסטוריה.
סדר ההפצה: שרת שמקבל schema 1 ו־2, אחריו גרסת המעדכן הזאת, ואחריה לקוח
שמייצר schema 2. שרת תואם ממשיך לקבל תורים ישנים עם מדיניות הצרופות הישנה.
תקרת גוף הבקשה היא 128 MiB כדי לכלול גם הרחבת תווי בקרה ב־JSON; גבולות הצרופות נבדקים בנפרד. דחיית שרת בגרסה 2 משאירה את הדיווח וכל הצרופות בתור, ומוצגת למשתמש; אין הסרה אוטומטית של dump.

`test/fixtures/app_report_schema2.json` הופק מ־`AppReport.toApiPayload` בחבילת
`otzaria_report_contract`; אותו וקטור נבדק גם באוצריא ובאתר.

מסד הנתונים בגרסה 2 מוסיף טבלאות טיוטה בלבד; המעדכן קורא גם את מסד גרסה 1 הישן.
טיוטות נמצאות בטבלאות `report_drafts` ו־`report_draft_attachments` המקומיות.
האוסף קורא רק את סוגי תור השליחה המפורשים (כולל סוג התוכנה החדש); גם טיוטה ישנה
מסוג `app_reports_queue/draft` אינה נבחרת. רק העברה מכוונת של דיווח לתור
יוצרת רשומה שנאספת. בדיקות SQLite מאמתות שהטיוטות והצרופות אינן מועתקות
ואינן משתנות, ושדיווחים ממתינים קיימים ממשיכים להיאסף.

## תיבת היציאה

`<stateDir>/reports/outbox` — **לא** תחת `mirror/`. ניקוי המראה
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ class AppReportService {
);
case _AttemptKind.permanent:
case _AttemptKind.idConflict:
await _deletePendingFile(originalId);
if (current.schema == 1) {
await _deletePendingFile(originalId);
} else {
await _keepQueued(originalId, current, idChanges);
}
_notify();
return AppReportDeliveryResult(
status: AppReportDeliveryStatus.failed,
Expand Down Expand Up @@ -238,13 +242,24 @@ class AppReportService {
int idChanges,
) async {
final existing = await _findPending(originalId);
if (existing != null && report.reportId == originalId) return;
if (existing != null) await _deletePendingFile(originalId);
if (existing != null && report.reportId == originalId) {
if (report.schema == 1) return;
await _writePending(report,
queuedAt: existing.stamp, idChanges: idChanges);
_notify();
return;
}
if (existing != null && report.schema == 1) {
await _deletePendingFile(originalId);
}
await _writePending(
report,
queuedAt: existing?.stamp,
idChanges: idChanges,
);
if (existing != null && report.schema != 1) {
await _deletePendingFile(originalId);
}
_notify();
}

Expand Down Expand Up @@ -355,6 +370,7 @@ class AppReportService {
);
if (step == _FlushStep.sent) sent++;
if (step == _FlushStep.dropped) dropped++;
if (step == _FlushStep.retained) failed++;
if (step == _FlushStep.skipped) skipped++;
if (step == _FlushStep.transient) {
transient = true;
Expand Down Expand Up @@ -396,6 +412,7 @@ class AppReportService {
return _FlushStep.sent;
case _AttemptKind.idConflict:
if (read.idChanges + 1 >= maxIdChanges) {
if (queued.schema != 1) return _FlushStep.retained;
log?.call('App report id conflict kept recurring, removed');
await _deleteQuietly(File(meta.path));
return _FlushStep.dropped;
Expand All @@ -410,6 +427,10 @@ class AppReportService {
await _deleteQuietly(File(meta.path));
return _FlushStep.skipped;
case _AttemptKind.permanent:
if (queued.schema != 1) {
log?.call('App report rejected, retained: ${attempt.httpStatus}');
return _FlushStep.retained;
}
log?.call('App report rejected, removed: ${attempt.httpStatus}');
await _deleteQuietly(File(meta.path));
return _FlushStep.dropped;
Expand Down Expand Up @@ -739,7 +760,7 @@ class AppReportService {
final body = payload.bytes;
if (body == null) {
log?.call('App report payload invalid: ${payload.error}');
return const _Attempt(_AttemptKind.permanent);
return _Attempt(_AttemptKind.permanent, rejectedField: payload.error);
}
if (body.length > AppReport.maxRequestBytes) {
return const _Attempt(
Expand Down Expand Up @@ -867,9 +888,15 @@ class _EncodedBody {
_EncodedBody _encodeForSending(AppReport report) {
try {
final stamped = report.copyWith(product: AppReport.offlineUpdateProduct);
if (stamped.schema != 1) {
final invalidField = stamped.validate();
if (invalidField != null) return _EncodedBody.failed(invalidField);
}
return _EncodedBody(
utf8.encode(jsonEncode(stamped.toApiPayload())),
heavy: report.images.isNotEmpty || report.minidump != null,
heavy: report.images.isNotEmpty ||
report.minidump != null ||
report.otherAttachmentBytes > AppReport.maxBodyBytes,
);
} catch (error) {
return _EncodedBody.failed('$error');
Expand Down Expand Up @@ -916,7 +943,7 @@ _PendingDecoded _decodePendingFile(String path, _PendingDecode mode) {
}
}

enum _FlushStep { sent, skipped, dropped, transient }
enum _FlushStep { sent, skipped, dropped, retained, transient }

class _SentHistory {
_SentHistory(this.total, this.reports);
Expand Down
Loading
Loading