Review the prerequisites
Suitable for: Backend developers learning Agent applications.
- Delivery conditions and shared deadlines for parallel results
- Parallelism only shortens independent waiting and does not change task dependencies and success conditions. Global deadlines constrain all attempts and backoffs; the cancellation of a local task does not prove that the remote side effects have stopped, and the results must be retained and classified item by item.
How does the mechanism work?
Step-by-step explanation
- What's the problem with calling the synchronous HTTP library in the async function?
Concurrent execution requires yielding control; function syntax alone does not guarantee this.
- Are other tasks still running after aggregation wait encounters an exception?
Error handling changes the lifecycle of concurrent tasks, so check the library's actual semantics.
- Why does the tool retry reusing the remaining time?
Local retries must obey the global delivery budget.
Debugging · Diagnose failures
Diagnose failures · Delivery conditions and shared deadlines for parallel results
Objectives of this level: Ability to select cancellation strategies and clean up resources based on delivery conditions.
Visual guide · One deadline governs every branch
Required failures block; optional failures may yield partial. Cleanup must run on exceptions too, and local cancellation proves no remote noncommit. Select the figure to open it at full size.
Public repair exercise: partial success misreported and exception cleanup missing
Save this faulty implementation as deadline_bad.py. It treats any success as batch success and has no cleanup or protected exception path. The fault cause is disclosed here. Record your observations and execution before opening the optional explanation. Label this exercise guided_repair; it cannot establish independent diagnosis of an unseen fault.
def run_batch(runtime, jobs, deadline):
for job in jobs:
runtime.start(job["id"])
runtime.advance(deadline)
rows = []
for job in jobs:
seen = runtime.poll(job["id"])
if seen["state"] == "pending":
seen = {"state": "timeout", "value": None, "error": "deadline"}
rows.append(dict(id=job["id"], **seen))
status = "succeeded" if any(r["state"] == "succeeded" for r in rows) else "blocked"
return {"status": status, "finished_at": runtime.now, "results": rows}
Run the fixed incident, then grade the actual faulty module and keep deadline-before.json. Both commands should exit 1. Grader failures include contract mismatches and leaked resources; poll_fault also exercises propagation and cleanup. cp creates the working copy; make your own repair in deadline_debug.py.
python3 deadline_lab.py incident --out deadline-incident.json
python3 deadline_lab.py grade --module deadline_bad.py --out deadline-before.json
cp deadline_bad.py deadline_debug.py
Save these unchanged assertions as deadline_probe.py. Repair the module without changing the assertions or grader inputs. Hanging required c must block delivery, a must retain its evidence, and exception cleanup must leave no pending work or handles.
from deadline_lab import BASE, LogicalRuntime, LabFault
from deadline_debug import run_batch
from copy import deepcopy
jobs = deepcopy(BASE)
jobs[2]["required"] = True
rt = LogicalRuntime(jobs)
result = run_batch(rt, jobs, 5)
assert result["status"] == "blocked"
assert [r["state"] for r in result["results"]] == ["succeeded", "failed", "timeout"]
assert result["results"][0]["value"] == "evidence-A"
assert rt.now == 5 and not rt.pending_ids() and not rt.opened_ids()
rt = LogicalRuntime(jobs, fault_id="a")
try:
run_batch(rt, jobs, 5)
except LabFault as exc:
assert str(exc) == "poll_failure"
else:
raise AssertionError("LabFault was swallowed")
assert not rt.pending_ids() and not rt.opened_ids()
print("required_gate_and_exception_cleanup_passed")
Rerun the same inputs after your repair. The probe should print required_gate_and_exception_cleanup_passed and exit 0; the grader should pass 12/12 and exit 0. Compare actual events, open_handles, and module_sha256 across before/after. Execution evidence validates behavior; it does not establish authorship or independent work.
python3 deadline_probe.py
python3 deadline_lab.py grade --module deadline_debug.py --out deadline-after.json
Optional explanation: repair the fixed scenario
After recording your public repair, use explain to inspect the two-job repair: successful a plus pending required c at the deadline means blocked; cancel c, then close a/c. The general function must aggregate required results and use finally for pending cancellation and handle release while preserving the original exception. Retain all outcomes and keep required unchanged. explain covers two fixed jobs; the general learner module still needs all 12 grader cases.
python3 deadline_lab.py explain --out deadline-explained.json
code example
A failing run and unchanged assertions
Calling deadline_bad causes contract failures and leaked handles. Unchanged probes test the required gate and LabFault cleanup; a repaired module should pass 12/12.
Acceptance task for this level
Public repair exercise: run deadline_bad, keep probe/grader unchanged, repair deadline_debug.py, and submit before/after reports and a diff; label optional explanation as reference.
Reading this browser’s record…
Hide the answer and check your understanding
Why can closing immediately before a normal return still leak?
Expand reference derivation
poll can raise LabFault before the return cleanup executes. finally must cancel pending work and close started handles while preserving the original exception.
Further explanations and practice
When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.
All linked explanations and exercises (1 )
Sources and verification scope
The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.