Mobiusi commited on
Commit
c1334e8
·
verified ·
1 Parent(s): 5b073e5

sync sample package

Browse files
record_239d80f8-4213-4d92-90ab-38c55593bfef.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source_code": "type Channel = 'email' | 'sms';\ntype JobStatus = 'queued' | 'retry_wait' | 'sending' | 'delivered' | 'failed';\ntype SendResult = { ok: true } | { ok: false; retryable: boolean };\n\ninterface DeliveryJob {\n id: string;\n channel: Channel;\n attempts: number;\n recipient: string;\n payload: string;\n}\ninterface JobRepository {\n // Atomically claims a due queued or retry_wait job and moves it to sending.\n claimDue(jobId: string): Promise<boolean>;\n schedule(jobId: string, update: { status: 'retry_wait' | 'queued'; channel: Channel; attempts: number; runAt: number }): Promise<void>;\n complete(jobId: string, status: 'delivered' | 'failed'): Promise<void>;\n}\ninterface Provider {\n send(recipient: string, payload: string): Promise<SendResult>;\n}\n\nclass QueueWorker {\n constructor(private jobs: JobRepository, private providers: Record<Channel, Provider>) {}\n\n async process(job: DeliveryJob): Promise<void> {\n if (!(await this.jobs.claimDue(job.id))) return;\n const result = await this.providers[job.channel].send(job.recipient, job.payload);\n if (result.ok) {\n await this.jobs.complete(job.id, 'delivered');\n return;\n }\n\n if (result.retryable && job.attempts < 2) {\n await this.jobs.schedule(job.id, {\n status: 'retry_wait',\n channel: job.channel,\n attempts: job.attempts + 1,\n runAt: Date.now() + 1000 * 2 ** job.attempts\n });\n return;\n }\n\n if (job.channel === 'email') {\n await this.jobs.schedule(job.id, {\n status: 'queued',\n channel: 'sms',\n attempts: 0,\n runAt: Date.now()\n });\n return;\n }\n await this.jobs.complete(job.id, 'failed');\n }\n}",
3
+ "state_transitions": [
4
+ {
5
+ "from_state": "queued or retry_wait",
6
+ "to_state": "sending",
7
+ "condition": "The job is due and claimDue successfully claims it."
8
+ },
9
+ {
10
+ "from_state": "sending",
11
+ "to_state": "retry_wait",
12
+ "condition": "The provider returns a retryable failure and attempts is less than two; the repository stores the incremented attempt count and future runAt."
13
+ },
14
+ {
15
+ "from_state": "sending",
16
+ "to_state": "queued",
17
+ "condition": "An email job has a non-retryable failure or has exhausted retries; it is scheduled immediately on SMS with attempts reset to zero."
18
+ },
19
+ {
20
+ "from_state": "sending",
21
+ "to_state": "delivered",
22
+ "condition": "The selected provider returns success and the repository completes the job as delivered."
23
+ },
24
+ {
25
+ "from_state": "sending",
26
+ "to_state": "failed",
27
+ "condition": "The SMS provider fails non-retryably or after its retry budget is exhausted."
28
+ }
29
+ ],
30
+ "idempotency_analysis": "The repository's documented claimDue operation atomically claims a due job and moves it to sending, which can prevent two workers from processing the same eligible job concurrently if the repository honors that contract. The job ID serves as the claim identifier, but no provider-side idempotency key is passed. If a provider accepts a message and the worker crashes before complete or schedule is persisted, a later recovery may send it again; exactly-once delivery is not established by this code.",
31
+ "control_flow_analysis": {
32
+ "main_flow": "QueueWorker first asks the repository to claim the due job; if the claim fails, it does nothing. It sends through the job's current channel. Success completes the job as delivered. A retryable failure within the retry budget is persisted for a later attempt. Once that budget is exhausted, or after a non-retryable failure, an email job is queued immediately on SMS with its attempt count reset; a failing SMS job is completed as failed.",
33
+ "branch_conditions": [
34
+ "A false result from claimDue stops processing before a provider call.",
35
+ "A successful provider result completes the job as delivered.",
36
+ "A retryable result with attempts less than two schedules another attempt on the same channel.",
37
+ "Retry scheduling uses a delay of 1,000 ms when attempts is zero and 2,000 ms when attempts is one.",
38
+ "A non-retryable failure or a retryable failure at attempts two skips same-channel retrying.",
39
+ "After same-channel retries stop, email switches to SMS immediately; SMS failure completes the job as failed."
40
+ ]
41
+ },
42
+ "component_dependencies": [
43
+ {
44
+ "component_name": "QueueWorker",
45
+ "responsibility": "Claims due jobs, invokes the selected provider, and chooses retry, fallback, or completion behavior.",
46
+ "dependencies": [
47
+ "JobRepository",
48
+ "Provider",
49
+ "Date.now"
50
+ ]
51
+ },
52
+ {
53
+ "component_name": "JobRepository",
54
+ "responsibility": "Atomically claims eligible jobs, persists scheduled work, and records terminal status.",
55
+ "dependencies": []
56
+ },
57
+ {
58
+ "component_name": "Provider",
59
+ "responsibility": "Sends a job's recipient and payload through a particular channel and reports retryability on failure.",
60
+ "dependencies": []
61
+ }
62
+ ],
63
+ "delivery_behavior_impact": "Persisted exponential backoff limits rapid repeat attempts and can absorb transient provider failures, while the email-to-SMS switch provides an alternate channel after email's retry budget is exhausted. The fallback resets the attempt count, giving SMS its own retry budget and potentially increasing eventual delivery at the cost of latency. Atomic job claiming limits concurrent processing, but a crash between provider acceptance and persistence can still cause duplicate delivery because provider-side idempotency is absent. Exceptions can also leave a claimed job without a recorded retry or terminal state.",
64
+ "retry_and_fallback_analysis": {
65
+ "retry_trigger": "Only a returned failure marked retryable triggers a same-channel retry, and only while the job's attempts value is less than two. Non-retryable results proceed directly to fallback or terminal failure. Thrown exceptions are not caught.",
66
+ "retry_policy": "The worker allows up to two scheduled retries per channel, for three total attempts when the initial job has attempts zero. Backoff is exponential: 1,000 ms before the next attempt when attempts is zero, then 2,000 ms when it is one. Retry timing is persisted as runAt; execution of due jobs is outside this code.",
67
+ "fallback_behavior": "After email fails permanently or exhausts its retry budget, the job is scheduled immediately on SMS with attempts reset to zero. SMS has the same retry policy, but there is no further fallback after SMS stops retrying; the job is marked failed."
68
+ }
69
+ }
record_2f77056f-f111-48ca-9d11-23cde57dd985.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source_code": "type DeliveryStatus = 'sending' | 'sent' | 'failed';\ntype SendResult = { ok: true } | { ok: false; retryable: boolean; error: string };\n\ninterface Provider {\n send(recipient: string, body: string): Promise<SendResult>;\n}\ninterface NotificationStore {\n getStatus(key: string): Promise<DeliveryStatus | undefined>;\n setStatus(key: string, status: DeliveryStatus): Promise<void>;\n}\nconst delay = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms));\n\nclass DeliveryService {\n constructor(private primary: Provider, private backup: Provider, private store: NotificationStore) {}\n\n async deliver(key: string, recipient: string, body: string): Promise<DeliveryStatus> {\n const current = await this.store.getStatus(key);\n if (current === 'sent' || current === 'sending') return current;\n\n await this.store.setStatus(key, 'sending');\n for (let attempt = 1; attempt <= 3; attempt++) {\n const result = await this.primary.send(recipient, body);\n if (result.ok) {\n await this.store.setStatus(key, 'sent');\n return 'sent';\n }\n if (!result.retryable) break;\n if (attempt < 3) await delay(500 * 2 ** (attempt - 1));\n }\n\n const fallback = await this.backup.send(recipient, body);\n const finalStatus: DeliveryStatus = fallback.ok ? 'sent' : 'failed';\n await this.store.setStatus(key, finalStatus);\n return finalStatus;\n }\n}",
3
+ "state_transitions": [
4
+ {
5
+ "from_state": "absent or failed",
6
+ "to_state": "sending",
7
+ "condition": "The stored status is neither sent nor sending, and delivery begins."
8
+ },
9
+ {
10
+ "from_state": "sending",
11
+ "to_state": "sent",
12
+ "condition": "The primary provider succeeds, or the backup provider succeeds."
13
+ },
14
+ {
15
+ "from_state": "sending",
16
+ "to_state": "failed",
17
+ "condition": "The primary attempts do not succeed and the backup attempt fails."
18
+ }
19
+ ],
20
+ "idempotency_analysis": "The store status check suppresses a repeated call when the key is already sent or sending. However, the read and subsequent setStatus are separate operations, so concurrent callers can both pass the check; atomic claiming or a unique-key constraint is not shown. A crash after marking sending can leave the key in that status, which future calls return without recovery. No provider-side idempotency key is passed.",
21
+ "control_flow_analysis": {
22
+ "main_flow": "DeliveryService first reads the stored status and returns immediately for a notification already marked sent or sending. Otherwise it marks the notification sending, tries the primary provider up to three times, and records sent on success. A non-retryable failure or exhausted retry budget leads to one attempt through the backup provider; its result determines the final stored status.",
23
+ "branch_conditions": [
24
+ "If the stored status is sent or sending, no provider is called.",
25
+ "A successful primary result records sent and ends delivery.",
26
+ "A non-retryable primary failure exits the retry loop immediately.",
27
+ "A retryable primary failure is retried while fewer than three attempts have been made; delays before the second and third attempts are 500 ms and 1,000 ms.",
28
+ "After the primary loop exits, the backup is called once; its success records sent and its failure records failed."
29
+ ]
30
+ },
31
+ "component_dependencies": [
32
+ {
33
+ "component_name": "DeliveryService",
34
+ "responsibility": "Coordinates status checks, primary-channel retries, backup-channel delivery, and final status updates.",
35
+ "dependencies": [
36
+ "Provider",
37
+ "NotificationStore",
38
+ "delay"
39
+ ]
40
+ },
41
+ {
42
+ "component_name": "Provider",
43
+ "responsibility": "Sends a notification and returns a success result or a failure with a retryability flag.",
44
+ "dependencies": []
45
+ },
46
+ {
47
+ "component_name": "NotificationStore",
48
+ "responsibility": "Reads and writes the notification delivery status.",
49
+ "dependencies": []
50
+ }
51
+ ],
52
+ "delivery_behavior_impact": "The three-attempt primary loop can improve delivery when failures are transient, at the cost of added latency from its two backoff delays. A permanent primary failure avoids unnecessary primary retries but still incurs one backup attempt. Because the status check and write are not atomic and no provider idempotency key is used, concurrent calls or a crash around provider acceptance can still produce duplicate delivery. Uncaught provider exceptions can exit before a final status is recorded.",
53
+ "retry_and_fallback_analysis": {
54
+ "retry_trigger": "Only a primary-provider result with ok false and retryable true triggers another primary attempt. A non-retryable result skips remaining primary attempts and proceeds to the backup. Thrown exceptions are not caught in this code.",
55
+ "retry_policy": "The primary is called at most three times. Delays are 500 ms and 1,000 ms before attempts two and three, respectively. There is no delay between the final primary attempt and the backup. The backup is attempted once, with no retry policy shown.",
56
+ "fallback_behavior": "The backup provider is called after a non-retryable primary failure or after all three primary attempts fail. The code has one configured backup and does not show channel selection beyond that. Backup success records sent; backup failure records failed."
57
+ }
58
+ }
record_eafc2c43-479c-4b56-b0e3-71f01f460432.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source_code": "type SendResult = { ok: true } | { ok: false; retryable: boolean };\ntype ClaimResult = 'acquired' | 'delivered' | 'busy';\ntype StoredStatus = 'delivered' | 'failed';\n\ninterface Provider {\n send(recipient: string, body: string): Promise<SendResult>;\n}\ninterface IdempotencyStore {\n // claim atomically reserves a key unless it is already delivered or in flight.\n claim(key: string): Promise<ClaimResult>;\n mark(key: string, status: StoredStatus): Promise<void>;\n}\ninterface Notice { key: string; recipient: string; body: string; route: string[]; }\nconst sleep = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms));\n\nclass RoutedSender {\n constructor(private providers: Record<string, Provider>, private idempotency: IdempotencyStore) {}\n\n async send(notice: Notice): Promise<string> {\n const claim = await this.idempotency.claim(notice.key);\n if (claim !== 'acquired') return claim === 'delivered' ? 'delivered' : 'in_flight';\n\n for (const channel of notice.route) {\n const provider = this.providers[channel];\n if (!provider) continue;\n for (let attempt = 1; attempt <= 2; attempt++) {\n const result = await provider.send(notice.recipient, notice.body);\n if (result.ok) {\n await this.idempotency.mark(notice.key, 'delivered');\n return 'delivered';\n }\n if (!result.retryable) break;\n if (attempt < 2) await sleep(250);\n }\n }\n\n await this.idempotency.mark(notice.key, 'failed');\n return 'failed';\n }\n}",
3
+ "state_transitions": [
4
+ {
5
+ "from_state": "unclaimed",
6
+ "to_state": "in_flight",
7
+ "condition": "The store returns acquired from the atomic claim operation."
8
+ },
9
+ {
10
+ "from_state": "in_flight",
11
+ "to_state": "delivered",
12
+ "condition": "Any provider on the ordered route succeeds and the sender records delivered."
13
+ },
14
+ {
15
+ "from_state": "in_flight",
16
+ "to_state": "failed",
17
+ "condition": "All route entries are unavailable or their attempts fail, and the sender records failed."
18
+ }
19
+ ],
20
+ "idempotency_analysis": "The sender relies on IdempotencyStore.claim to atomically distinguish acquired, delivered, and busy keys before any provider call. This prevents concurrent sends only if the store fulfills the documented atomic-claim contract. The key is not passed to providers, so provider-side deduplication is not shown. Exceptions after a claim are uncaught, and no claim release or recovery path appears in this code.",
21
+ "control_flow_analysis": {
22
+ "main_flow": "RoutedSender first atomically claims the notice key. It returns without sending if the key is already delivered or in flight. For an acquired key, it walks the requested route in order, skips channels without a configured provider, and makes up to two attempts per available provider. A successful send marks the key delivered and stops; exhausting the route marks it failed.",
23
+ "branch_conditions": [
24
+ "A delivered claim returns delivered, while a busy claim returns in_flight; neither invokes a provider.",
25
+ "A route entry with no configured provider is skipped.",
26
+ "A successful provider result marks the notice delivered and ends processing.",
27
+ "A non-retryable failure moves directly to the next route entry.",
28
+ "A retryable failure gets one retry after a 250 ms delay; after the second failed attempt, processing advances to the next route entry.",
29
+ "If no route entry succeeds, the store is marked failed."
30
+ ]
31
+ },
32
+ "component_dependencies": [
33
+ {
34
+ "component_name": "RoutedSender",
35
+ "responsibility": "Claims the idempotency key and coordinates ordered channel attempts and status updates.",
36
+ "dependencies": [
37
+ "Provider",
38
+ "IdempotencyStore",
39
+ "sleep"
40
+ ]
41
+ },
42
+ {
43
+ "component_name": "Provider",
44
+ "responsibility": "Sends a notice over a configured channel and reports success or whether a failure is retryable.",
45
+ "dependencies": []
46
+ },
47
+ {
48
+ "component_name": "IdempotencyStore",
49
+ "responsibility": "Atomically claims a notice key and records delivered or failed status.",
50
+ "dependencies": []
51
+ }
52
+ ],
53
+ "delivery_behavior_impact": "Ordered routing makes channel preference explicit and allows later channels to recover from an unavailable or failing earlier channel. Limiting each channel to two attempts bounds per-channel delay, while the 250 ms retry can help with transient failures. A longer route can increase total latency. Atomic claiming reduces concurrent duplicate sends, but provider acceptance followed by a process failure before mark can still lead to a later redelivery if the store permits recovery; provider-side deduplication is not shown.",
54
+ "retry_and_fallback_analysis": {
55
+ "retry_trigger": "A provider result with ok false and retryable true triggers a retry on the same channel. Non-retryable failures advance immediately to the next route entry. Thrown exceptions are not caught.",
56
+ "retry_policy": "Each configured provider receives at most two attempts. The only retry delay is 250 ms between those attempts. No further retry is made on that provider after the second failure; no persistent retry scheduling is shown.",
57
+ "fallback_behavior": "The route array determines channel order. After a channel fails or is unconfigured, the sender proceeds to the next entry. It stops at the first successful provider. If all entries are unavailable or fail, it marks the notice failed. The code does not define a default route or select channels outside the supplied array."
58
+ }
59
+ }