78 / 90

Day 78: Retry Budgets, Timeouts & Honest Execution Limits

Bound retries with backoff and jitter, enforce finite timeouts, and state exactly which isolation the project does and does not provide.

Agents 480 active minutes (8 hours)
01 120 min

Retry Budgets, Exponential Backoff, and Jitter

Agent-Assisted Engineering Check

Prerequisites

Day 76-77 retry-counter mechanics; basic probability.

Learning Objective

Design a retry policy with a hard attempt budget, exponential backoff, and full jitter; explain how unbounded synchronized retries amplify partial outages into cascading failures.

Instructions

1. The project's policy is deliberately minimal: retries increments on each ok=false observation and the run fails once retries > max_retries=2 - immediate re-issue, no delay.
2. Production policy (AWS Builder's Library): delay = random_between(0, min(cap, base * 2**attempt)); full jitter decorrelates clients and minimizes total work during contention.
3. Cascading-failure model (Google SRE ch.22): retries multiply offered load exactly when the dependency is degraded; a retry budget plus jittered backoff bounds that amplification.
4. Retry only transient faults; permanent faults (invalid_arguments, not_found) need correction - the adapter changes arguments before re-issuing, which is why its retry was productive.

Practice & Prediction Log

Implement retry_with_backoff(fn, attempts=3, base=0.05, cap=0.5) that sleeps a full-jitter interval between tries and re-raises after exhaustion. Drive it with a flaky stub failing twice then succeeding, and a permanent failure that must consume the whole budget.

Independent Mastery Criterion

Explain, with the jitter math, why the project's retry budget (2) and production jittered backoff both bound work - and name the failure each defends (budget exhaustion vs correlated retry storms).

Authoritative Source Resources & Provenance

linking Amazon Web Services site content / linked reference noncommercial

Exponential Backoff And Jitter

Author: Marc Brooker, AWS Architecture Blog | Original Source Link ↗

Relevant Section / Range: Adding Backoff; Adding Jitter (Full Jitter, Equal Jitter, Decorrelated Jitter)

Verified Version & Date: AWS Architecture Blog 2015 (Verified: 2026-10-30)

Selection Rationale:

Detailed practitioner reference proving that full jitter (sleep = random_between(0, min(cap, base*2**attempt))) prevents synchronized retry storms and reduces total work during contention.

Source Prerequisites:

Retries, timeouts, and basic probability of correlated load.

Safe Fallback (Offline Resilience):

The backoff exercise is implemented in pure Python with a local flaky stub; the derivation of jitter benefits is fully reproduced in lesson instructions.

Compared Candidate Sources & Selection Analysis (2)
Google Cloud retry strategy documentation ↗ compared_alternative [CC BY 4.0 / documentation terms]

Product-scoped truncated exponential backoff recipe; Brooker's analysis explains why jitter matters, not just what to configure.

Polly resilience library retry policies (.NET) ↗ compared_alternative [BSD-3-Clause]

Library implementation reference; the AWS article supplies the comparative evidence (with/without jitter) that anchors the lesson.

linking CC BY-NC-ND 4.0 noncommercial no-derivatives

Site Reliability Engineering, Chapter 22: Addressing Cascading Failures

Author: Mike Ulrich, in Site Reliability Engineering (eds. Betsy Beyer, Chris Jones, Jennifer Petoff, Niall Richard Murphy; Google) | Original Source Link ↗

Relevant Section / Range: Preventing Server Overload: Retries

Verified Version & Date: O'Reilly 2016 free online edition (Verified: 2026-10-30)

Selection Rationale:

Primary analysis of how unbounded retries amplify partial outages into cascading failures, motivating hard retry budgets and deadlines in agent runtimes.

Source Prerequisites:

Retries, queueing, and load-shedding basics.

Safe Fallback (Offline Resilience):

The retry-amplification scenario and budget arithmetic are fully reproduced in the lesson's worked example.

Compared Candidate Sources & Selection Analysis (2)
Release It! (Michael Nygard) - Stability patterns ↗ compared_alternative [Commercial book]

Broader stability-pattern catalog (circuit breakers, bulkheads); the SRE chapter is free and directly quantifies retry amplification.

Strong companion article; the SRE chapter frames the failure mode (cascading overload) that the retry budget defends against.

02 120 min

Timeouts, Deadlines, and the Empirical Kill Boundary

Independent Mastery Check (no AI assistance).

Prerequisites

Day 77 evidence pack; subprocess basics.

Learning Objective

Enforce a finite timeout on a child process, then measure the kill boundary empirically: subprocess timeout terminates the direct child but cannot promise cleanup of escaped descendants.

Instructions

1. Timeout controls in this repository: scripts/check_snippets.py sets RUN_TIMEOUT=15.0 with stdin=DEVNULL inside a temp working directory; lab/run_all_tests.py validates the timeout is finite and positive (rejecting bool, 0, negatives, NaN, inf) before subprocess.run(timeout=...).
2. Deadline vs timeout: a timeout bounds one blocking wait; a deadline bounds end-to-end work - agent loops approximate deadlines with step budgets.
3. The kill boundary: subprocess.run kills the child on TimeoutExpired; a descendant that escapes (double-fork or its own session) survives - the lab runner README states exactly this gap: it terminates only the direct child and descendant-tree cleanup remains unimplemented.
4. Process groups are the missing mechanism: setpgid/setsid plus killpg let a runner signal an entire group; without them there is no cleanup guarantee for escaped descendants.

Practice & Prediction Log

Run a child that launches a detached grandchild (subprocess.Popen(['sleep','60']) then sleeps) under timeout=1. Catch TimeoutExpired, then run pgrep -f 'sleep 60' to show the grandchild survived. Record the surviving PID in your evidence log.

Independent Mastery Criterion

Demonstrate with a live process listing that a timeout kills one process, not a process tree; never claim descendant cleanup you have not verified.

Authoritative Source Resources & Provenance

linking PSF License Version 2

Python Standard Library: subprocess - Subprocess Management

Author: Python Software Foundation | Original Source Link ↗

Relevant Section / Range: Using the subprocess Module (subprocess.run timeout) and Notes: Timeout Behavior

Verified Version & Date: Python 3.13 documentation (Verified: 2026-10-30)

Selection Rationale:

Normative reference for subprocess.run(timeout=...), TimeoutExpired, DEVNULL stdin, and the documented kill scope: timeout terminates the child process; it does not define process-tree cleanup semantics.

Source Prerequisites:

Processes, arguments, exit codes, and context managers.

Safe Fallback (Offline Resilience):

The kill-boundary experiment runs entirely in the standard library, so the documented semantics are exercised offline.

Compared Candidate Sources & Selection Analysis (2)
POSIX standard: process creation and termination ↗ compared_alternative [IEEE/Open Group standard]

Formal POSIX semantics; the Python docs map directly onto the commands learners type.

psutil process-tree utilities ↗ compared_alternative [BSD-3-Clause]

Third-party tree enumeration; the exercise deliberately demonstrates the stdlib boundary before reaching for helpers.

linking Linux man-pages license (freely distributable)

Linux man-pages: credentials(7) and setpgid(2) - Process Groups and Sessions

Author: Linux man-pages project (Michael Kerrisk et al.) | Original Source Link ↗

Relevant Section / Range: credentials(7) DESCRIPTION: Process group and session

Verified Version & Date: man-pages 6.x online edition (Verified: 2026-10-30)

Selection Rationale:

Normative reference for process-group semantics (PGID, sessions, killpg): the mechanism a runner must use to signal a whole descendant tree, which the lab runner and subprocess timeout path do not employ.

Source Prerequisites:

POSIX processes, signals, and fork/exec model.

Safe Fallback (Offline Resilience):

Process-group behavior is demonstrated live with os.setsid and process inspection; local man pages cover the same text offline.

Compared Candidate Sources & Selection Analysis (2)
POSIX.1-2017 specification: setpgid ↗ compared_alternative [IEEE/Open Group standard]

Formal standard text; the man page presents the same contract with implementation notes learners can test directly.

Detailed textbook treatment of sessions and job control; the man page is the free, always-current operational reference.

03 120 min

Isolation Layers: Validation Rules, Resource Limits, and OS Sandboxes

Agent-Assisted Engineering Check

Prerequisites

Day 78 Activities 1-2; the project's full control inventory.

Learning Objective

Place every project control on the correct defense layer - AST gates, argument validation, payload/step/retry limits, disposable workspaces, namespaces/cgroups, microVM isolation - and state what each layer cannot stop.

Instructions

1. Layer 1 - static AST gates: scripts/check_snippets.py runs ast.parse on every snippet (rejecting syntax errors) and classify() skips torch imports, interactive input, and training code; AST rules inspect source structure, never runtime behavior.
2. Layer 2 - argument validation: _tool_call rejects unknown tools, non-mapping arguments, and filenames failing Path(filename).name != filename (stops the '../outside.txt' traversal).
3. Layer 3 - resource limits: tool_payload_bytes=4096 (size_limit), max_steps=6, max_retries=2 - they bound consumption but do not isolate.
4. Layer 4 - disposable workspace: TemporaryDirectory per run is convenience hygiene, not a security boundary - absolute paths outside it are still writable.
5. Layers the project never reaches: kernel isolation (namespaces, cgroups, seccomp) and hardware-virtualized boundaries (Firecracker microVMs) - the level multi-tenant runtimes require before executing untrusted code.

Practice & Prediction Log

Draw the five-layer ladder for the summarize-notes run; annotate each layer with one threat it stops and one it does not (e.g., the basename check stops read_note traversal; nothing stops a looping adapter - the step budget only bounds the waste).

Independent Mastery Criterion

For every control in the project, state one threat it stops and one it does not - including the explicit absence of OS-level confinement.

Authoritative Source Resources & Provenance

linking Linux man-pages license (freely distributable)

Linux man-pages: namespaces(7) - Overview of Linux Namespaces

Author: Linux man-pages project (Michael Kerrisk et al.) | Original Source Link ↗

Relevant Section / Range: namespaces(7) DESCRIPTION: Namespace types

Verified Version & Date: man-pages 6.x online edition (Verified: 2026-10-30)

Selection Rationale:

Normative reference enumerating the eight Linux namespace types; establishes what genuine OS-level isolation requires (mount, PID, network, user namespaces plus seccomp and cgroup limits), all of which the learning project deliberately does not provide.

Source Prerequisites:

Processes, mounts, network interfaces, and cgroups basics.

Safe Fallback (Offline Resilience):

Namespace concepts are analyzed against project code, not exercised; unshare(1) examples are optional enrichment.

Compared Candidate Sources & Selection Analysis (2)
Docker Engine security documentation ↗ compared_alternative [Apache-2.0 / documentation terms]

Product view assembling namespaces and cgroups into containers; namespaces(7) supplies the primitive inventory the lesson enumerates.

LWN.net series: Namespaces in operation ↗ compared_alternative [LWN site content]

Strong narrative walkthrough; the man page is the maintained reference surface.

linking USENIX open access

Firecracker: Lightweight Virtualization for Serverless Applications

Author: Alexandru Agache, Marc Brooker, Alexandra Iordache, Anthony Liguori, Rolf Neugebauer, Phil Piwonka, Diana-Maria Popa | Original Source Link ↗

Relevant Section / Range: Section 3.4 Security and Section 3.4.1 Jailer (nsdi20-paper-agache.pdf)

Verified Version & Date: NSDI 2020 / USENIX open access (Verified: 2026-10-30)

Selection Rationale:

Primary literature on production multi-tenant code execution: Firecracker wraps workloads in hardware-virtualized microVMs because containers alone are not a sufficient security boundary, the reference standard for what genuine isolation means.

Source Prerequisites:

Virtualization basics, KVM, process isolation, and threat models.

Safe Fallback (Offline Resilience):

The isolation-layer analysis compares documented properties only; no virtualization is launched in the lesson.

Compared Candidate Sources & Selection Analysis (2)
gVisor architecture documentation ↗ compared_alternative [Apache-2.0]

User-space kernel interception alternative; Firecracker's hardware boundary provides the stronger reference point for the guarantee matrix.

Kata Containers architecture ↗ compared_alternative [Apache-2.0]

VM-backed container runtime; Firecracker's NSDI paper supplies the peer-reviewed threat-model justification.

04 120 min

Assessment: Execution-Limit Guarantee Matrix Audit

Independent Mastery Check (no AI assistance).

Prerequisites

Day 78 Activities 1-3.

Learning Objective

Produce a guarantee matrix auditing every documented control against claimed and non-claimed threats, each cell verified by live evidence or an explicit documentation statement.

Instructions

1. Columns: control | mechanism and location | stops | does not stop.
2. Rows: tool allowlist (ALLOWED_TOOLS frozenset); basename check (_tool_call); 4096-byte payload cap; max_steps=6; max_retries=2; TemporaryDirectory workspace; action/observation-only trace; subprocess timeout (check_snippets.py, lab runner); process-group tree kill (ABSENT); OS sandbox / VM boundary (ABSENT).
3. Evidence rules: a 'stops' claim needs a live demo or unit test; a 'does not stop' claim needs a live counter-example (the surviving sleep PID) or a doc statement (README: resource limits are controls, not an OS sandbox; project.json evidence.resource_limit_note).
4. Reject any row whose claim cannot be tied to evidence - an honest matrix ships zero unverified promises.

Practice & Prediction Log

Fill the 10-row matrix in guarantee_matrix.md; cite line-level mechanisms (e.g., 'Path(filename).name != filename' in agent.py) and the escaped-descendant PID from Activity 2.

Independent Mastery Criterion

Ship a guarantee matrix where every negative claim is corroborated by evidence or documentation - zero unverified promises.

Authoritative Source Resources & Provenance

linking PSF License Version 2

Python Standard Library: ast - Abstract Syntax Trees

Author: Python Software Foundation | Original Source Link ↗

Relevant Section / Range: ast helpers (ast.parse, ast.walk)

Verified Version & Date: Python 3.13 documentation (Verified: 2026-10-30)

Selection Rationale:

Normative reference for ast.parse used by scripts/check_snippets.py as the static admission gate: AST rules inspect source structure before any execution and cannot evaluate runtime behavior.

Source Prerequisites:

Python syntax, parse trees, and compile pipeline basics.

Safe Fallback (Offline Resilience):

Every AST check in the lesson runs in the standard library; no external validator is fetched.

Compared Candidate Sources & Selection Analysis (2)

Production AST linter; the stdlib ast module is the minimal sufficient tool for the admission-gate exercise.

Bandit security linter ↗ compared_alternative [Apache-2.0]

Security-oriented AST rules; deliberately cited as a comparison to show AST gating is necessary but never sufficient for safety.

linking CC BY 4.0

Kubernetes Documentation: Resource Management for Pods and Containers

Author: Kubernetes Documentation Contributors | Original Source Link ↗

Relevant Section / Range: How Kubernetes applies resource requests and limits

Verified Version & Date: Kubernetes documentation (Verified: 2026-10-30)

Selection Rationale:

Primary reference for cgroup-enforced resource limits (CPU throttling, memory OOM-kill): demonstrates that production limits are kernel-enforced accounting, contrasted with the project's application-level counters.

Source Prerequisites:

Containers, CPU/memory accounting, and QoS classes.

Safe Fallback (Offline Resilience):

The lesson contrasts documented cgroup semantics with the project's counters; no cluster is required.

Compared Candidate Sources & Selection Analysis (2)
Linux man-pages: cgroups(7) ↗ compared_alternative [Linux man-pages license]

Kernel-level primitive reference; Kubernetes docs present the enforcement outcome (throttle vs OOM-kill) learners recognize from operations.

Docker resource constraints documentation ↗ compared_alternative [Apache-2.0 / documentation terms]

Single-host flag surface; Kubernetes documentation covers limit semantics plus QoS classification.