mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-19 23:14:25 +01:00
python -m diet_guard claude-worker serves the phone's meal requests from RTDB (rtdb_relay RequestServer, one SSE stream, reconnects with backoff): validate, estimate with Claude, log through the signed log with source=claude under the oldest due slot (normal mode: nearest slot of the phone's hint), write the sealed result, delete only the request payload, then publish in the background. diet-guard-claude.service (Restart=on-failure, WantedBy=default.target) is installed by install.sh and started once the worker's own Firebase session exists. Nothing is deployed by this commit. Failure paths: - narrow peer pull fails (sync locked/unreachable): fail closed, no claim, no answer, no model call; the request stays pending, retried every 30 s - e2e key locked, no passphrase, no session: fail closed, nothing read or written; the worker waits and retries every 60 s - bad body, request older than 24 h (or no created): fail closed, an error result, nothing logged - Claude failure/timeout/invalid JSON: fail closed, an error result with retry, nothing logged - crash between log and result, or a duplicate event: idempotent, the entry id is uuid5 of the rid and is looked up (tombstones included) before the model call - request payload delete, old-answer cleanup and the post-answer publish failing: fail open on purpose (logged only); the answer and the local entry are already durable - due mode with nothing due: falls back to slot_for_log, not an error New log helpers log_meal_as / find_entry; log_meal's body is split into _entry_fields / _store_entry with the same output. The gate and CLI import none of the worker's dependencies at load time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZHWP4KZ6x5TcXDBFC
237 lines
8.0 KiB
JSON
237 lines
8.0 KiB
JSON
{
|
|
"version": 1,
|
|
"root": "diet-guard-sync/claude-e2e",
|
|
"header_path": "diet-guard-sync/e2e",
|
|
"key_hex": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
|
|
"rid": "01JD5Z8K3M7Q2W9XH4TBN6VR0E",
|
|
"entry_id_namespace": "5d9c1a40-6f0e-5c3e-9b57-d1e7a3c0b2f4",
|
|
"entry_id": "90729b3a-5202-5ade-824b-f17949d93890",
|
|
"layout": {
|
|
"clear": [
|
|
"requests/*/claim"
|
|
],
|
|
"units": {
|
|
"requests/*/req": [
|
|
"created"
|
|
],
|
|
"requests/*/result": [
|
|
"at"
|
|
]
|
|
}
|
|
},
|
|
"limits": {
|
|
"text_max": 2000,
|
|
"photo_b64_max": 600000,
|
|
"slot_max": 1439,
|
|
"expiry_hours": 24,
|
|
"estimate_timeout_s": 45
|
|
},
|
|
"request": {
|
|
"path": "requests/01JD5Z8K3M7Q2W9XH4TBN6VR0E/req",
|
|
"node": {
|
|
"_e2e": "ARptgd1om/yDg1f7fxoTEDGTYmtYGbzOLbVOyEBtvqnXA+vzMYiZxfyI5pklwS6zxQfPh//X0Saxx27Ae+/NoFZWY1yE6iR+ok73tvMpXl/n687UM1inV6nJe6+9ItOtlNFP6f55RowkbLMopAGFEyeXr+De4L4yz6iYofOxLGV2kVU62Kj+8apl5qNbxY+IcqR4pt6dOwb1Jdn4s0vuQp6geftXf7Ewv2mML0Ubp1MP24x+BuuS6H+OVb68x0idSWyAwRcmS2uUPd44rmcKqec0cPjbQGP00DIGMghASzyHx23iDDT1W9K9Ca5QR+V4HT88zC7mr0YPRTqYNXyYGkttmaMoADx61Uagtdh2QI/9W1PxUQlWESuIb6/kpzyZ5ecpStp3z/vCdfxYUXG1Cqasrv3d3fJfVhJitXNxVsYRkPghHXKcimU2nkGraCdxHbt3qustc/TLKGRF+nE=",
|
|
"created": 1795000000000
|
|
},
|
|
"plain": {
|
|
"kind": "meal",
|
|
"dev": "6f1f0c1e-5b0a-4a3e-9f57-2c1d6f0e9a11",
|
|
"sent_at": 1794999999960,
|
|
"body": {
|
|
"text": "2 jajka sadzone i kromka chleba",
|
|
"photo_jpeg_b64": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/",
|
|
"client_slot_min": 720,
|
|
"mode": "due"
|
|
}
|
|
},
|
|
"clear": {
|
|
"created": 1795000000000
|
|
}
|
|
},
|
|
"claim": {
|
|
"path": "requests/01JD5Z8K3M7Q2W9XH4TBN6VR0E/claim",
|
|
"node": {
|
|
"by": "pc-worker",
|
|
"lease_until": 1795000300000,
|
|
"attempt": 1,
|
|
"phase": "claimed",
|
|
"at": 1795000000010
|
|
}
|
|
},
|
|
"results": {
|
|
"logged": {
|
|
"path": "requests/01JD5Z8K3M7Q2W9XH4TBN6VR0E/result",
|
|
"node": {
|
|
"_e2e": "AcnCnUL+sLfDhgsuRt2bOTVbrRzZlNtm3FupBPJr8/1kQjIV0xPk3fPgRfL4HIQBR9E1ttO18lwVJEn7b5fTPFcpO+oKfIQUDdRxJl5Lzg86UtTGizhk4UU7Qdhq/g6IXoe8HzapQ+JBW6ivOsd+KFCtUFJ42cQyuol7K33K2j2PnFNHM2ADmGnTz8K5mUoWTrxkdXa/jHnCJaDEoQx8wiYXtffq6shiXNa/47V/oe6uorNzzDS8TpVw6fMhDBsCAG6LFEVSxfpG/yVuRg6BuqI8/yiP6yDyqFMK7EmAvpw22PJa9350+FXcL8fLe7fDyV6idRcmttfFvIeOCP4V614Nrnc9aJz8FIFPtbeBK+JYcxH//qcwbi7aDxGLRV8oKMI8JUUI8PC5mEe6nqPla46KgNSLvVBG1CBamL2KAB7ovCQ=",
|
|
"at": 1795000009000
|
|
},
|
|
"plain": {
|
|
"ok": true,
|
|
"kind": "meal",
|
|
"status": "logged",
|
|
"id": "01JD5Z8K3M7Q2W9XH4TBN6VR0E",
|
|
"entry_id": "90729b3a-5202-5ade-824b-f17949d93890",
|
|
"desc": "2 jajka sadzone i kromka chleba",
|
|
"grams": 190,
|
|
"kcal": 410,
|
|
"protein_g": 17.5,
|
|
"carbs_g": 22,
|
|
"fat_g": 26,
|
|
"slot_min": 720,
|
|
"time": "2026-11-17T12:03:41+01:00"
|
|
},
|
|
"clear": {
|
|
"at": 1795000009000
|
|
}
|
|
},
|
|
"error": {
|
|
"path": "requests/01JD5Z8K3M7Q2W9XH4TBN6VR0E/result",
|
|
"node": {
|
|
"_e2e": "AWmFLu+Iov25GLdTDVfnRYwy5g+01YwnhpIa0ThJu+GWHla5swvNo+He9EcH8U2Rft15ZUePS8DrapBih7xD51kCsNYKBl5xXiAQUxgmcCIr45/9maYXFynxoQLOwkzp3tTy6kB4I6MZko3JWyRd+KSa8YEV5Rlt279uOZd1dF9wxc4iN+QO2jVwoWtuYED152vTQAhrPep5DpQ3/nkSto4yGCxWn6N05KpHNSqRx5YUrK12eEWw/wflM8ZA7TXsF291Unnq5FLX0KBsdvOO6Wp770FUvxGhwwwuf9K70bw/Gw==",
|
|
"at": 1795000009000
|
|
},
|
|
"plain": {
|
|
"ok": false,
|
|
"kind": "meal",
|
|
"status": "error",
|
|
"id": "01JD5Z8K3M7Q2W9XH4TBN6VR0E",
|
|
"error_code": "estimate_failed",
|
|
"code": "estimate_failed",
|
|
"error": "model returned no valid JSON",
|
|
"retry": true
|
|
},
|
|
"clear": {
|
|
"at": 1795000009000
|
|
}
|
|
},
|
|
"expired": {
|
|
"path": "requests/01JD5Z8K3M7Q2W9XH4TBN6VR0E/result",
|
|
"node": {
|
|
"_e2e": "AdbyPhYZMItxxH+1gHmCfJ6jpWfzhTaSqKA7HE6CceNsyQRR80AREbfMbJcnKj4ExJU28MFP7AjqAGldaqzC8PJTldXOymupascUvVHXIQ8MZJy07Wzb5XxtdkaSL26YWAwIu1Kbz6fyqoI4xBRcTNIz5xAEzW++656co/dETMZe8mfnj1tFuGGjZLGoDm8d3lxbnXWU8Z+uCEHmGjKGYaAwFKEUASzX9tdZgbnnyYhnnbFf3eOqwrjEBdE6dpoj2yow1DnH2h06Fx2VgnM=",
|
|
"at": 1795000009000
|
|
},
|
|
"plain": {
|
|
"ok": false,
|
|
"kind": "meal",
|
|
"status": "error",
|
|
"id": "01JD5Z8K3M7Q2W9XH4TBN6VR0E",
|
|
"error_code": "expired",
|
|
"code": "expired",
|
|
"error": "request older than 24 h",
|
|
"retry": false
|
|
},
|
|
"clear": {
|
|
"at": 1795000009000
|
|
}
|
|
}
|
|
},
|
|
"body_cases": [
|
|
{
|
|
"name": "text only",
|
|
"valid": true,
|
|
"body": {
|
|
"client_slot_min": 480,
|
|
"mode": "normal",
|
|
"text": "banan"
|
|
}
|
|
},
|
|
{
|
|
"name": "photo only",
|
|
"valid": true,
|
|
"body": {
|
|
"client_slot_min": 0,
|
|
"mode": "due",
|
|
"photo_jpeg_b64": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/"
|
|
}
|
|
},
|
|
{
|
|
"name": "both",
|
|
"valid": true,
|
|
"body": {
|
|
"text": "2 jajka sadzone i kromka chleba",
|
|
"photo_jpeg_b64": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/",
|
|
"client_slot_min": 720,
|
|
"mode": "due"
|
|
}
|
|
},
|
|
{
|
|
"name": "nothing to estimate",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": 480,
|
|
"mode": "due"
|
|
}
|
|
},
|
|
{
|
|
"name": "blank text",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": 480,
|
|
"mode": "due",
|
|
"text": " "
|
|
}
|
|
},
|
|
{
|
|
"name": "text too long",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": 480,
|
|
"mode": "due",
|
|
"text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
}
|
|
},
|
|
{
|
|
"name": "bad mode",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": 480,
|
|
"mode": "now",
|
|
"text": "a"
|
|
}
|
|
},
|
|
{
|
|
"name": "slot out of range",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": 1440,
|
|
"mode": "due",
|
|
"text": "a"
|
|
}
|
|
},
|
|
{
|
|
"name": "slot not int",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": "480",
|
|
"mode": "due",
|
|
"text": "a"
|
|
}
|
|
},
|
|
{
|
|
"name": "missing slot",
|
|
"valid": false,
|
|
"body": {
|
|
"text": "a",
|
|
"mode": "due"
|
|
}
|
|
},
|
|
{
|
|
"name": "photo not jpeg",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": 480,
|
|
"mode": "due",
|
|
"photo_jpeg_b64": "aGVsbG8="
|
|
}
|
|
},
|
|
{
|
|
"name": "photo not base64",
|
|
"valid": false,
|
|
"body": {
|
|
"client_slot_min": 480,
|
|
"mode": "due",
|
|
"photo_jpeg_b64": "@@@"
|
|
}
|
|
}
|
|
]
|
|
}
|