agora.fleet.error_router

Scope-bounded error routing — v2.5.

When a test task fails because an upstream task’s output is broken (e.g. implement_tests fails with ModuleNotFoundError: No module named 'src.url_shortener' pointing at a file owned by implement_core_module), the framework should return the failure to the owning task instead of letting the tester keep cycling on something it can’t fix.

This module is the pure-helper layer that the orchestrator composes with the retry machinery. Two functions, no I/O:

  • extract_failing_paths() — parse a pytest / import failure string and return workspace-relative paths referenced by ImportError / ModuleNotFoundError entries. Test modules (the file pytest was trying to load) are excluded because those are owned by the tester, not an upstream.

  • find_owning_task() — given a file path and the project’s task list, return the task whose output is that file. Matches against both task.output_path and file_exists(rel=...) postconditions.

The orchestrator wires them together: on a failed pytest_passes postcondition, extract the broken paths, look up the owning task, flip it back to PENDING with structural feedback in its next system prompt.

Functions

extract_failing_paths(failure_reason)

Parse a pytest failure string; return workspace-relative paths of modules referenced by ImportError / ModuleNotFoundError in the traceback.

find_owning_task(file_path, tasks)

Return the task whose output claims file_path, or None.

agora.fleet.error_router.extract_failing_paths(failure_reason)[source]

Parse a pytest failure string; return workspace-relative paths of modules referenced by ImportError / ModuleNotFoundError in the traceback.

Returns an ordered, de-duplicated list. Empty list means: no routable import error was found in this reason string, caller falls back to the normal failure path.

The returned paths include both foo/bar.py and foo/bar/__init__.py candidates for each dotted module so the owning-task lookup can match whichever form the project actually uses.

Test-module import failures (pytest couldn’t load the test file itself — the tester’s own problem) are excluded from the output.

agora.fleet.error_router.find_owning_task(file_path, tasks)[source]

Return the task whose output claims file_path, or None.

Matching rules (in order — the first hit wins):
  1. task.output_path equals file_path (normalized slashes).

  2. Any postcondition in task.spec.postconditions whose name encodes the same relative path (e.g. the predicate factory file_exists(rel="src/foo.py") registers a predicate named artifact_contains_src_foo.py — we re-derive the rel from the name for matching).

Tasks in tasks are walked in their natural list order, which mirrors the plan’s declared task order. Self-owned lookups (a task routing to itself) are the caller’s responsibility to filter.