[BUG] `cocoindex update` exits 0 and prints ✅ when every mounted component fails, so by default a scheduled run cannot detect a failed index by exit status
Describe the bug
When every background component created through coco.mount or mount_each fails, cocoindex update still exits 0 and displays a green check on the failing group. Cron, CI, and other schedulers cannot detect the failure by exit status.
Errors normally appear in logs and statistics, but --quiet hides the statistics. Installing a handler that re-raises, without awaiting mount handles, also removes the default error logs. Combining those settings produces exit 0 with empty stdout and stderr.
Background failures intentionally do not propagate through handle.ready() by default. This issue concerns CLI reporting and should preserve that documented library behavior.
To reproduce
# failapp.py
import cocoindex as coco
@coco.fn
async def boom(i: int) -> None:
raise ValueError(f"item {i} is poison")
@coco.fn
async def app_main() -> None:
for i in range(3):
await coco.mount(coco.component_subpath("boom", str(i)), boom, i)
app = coco.App("failapp", app_main)COCOINDEX_DB=./db python -m cocoindex.cli update failapp.py
echo $?Relevant output, with timestamps and tracebacks omitted:
ERROR cocoindex._internal.component_ctx: component build failed: item 0 is poison
ERROR cocoindex._internal.component_ctx: component build failed: item 2 is poison
ERROR cocoindex._internal.component_ctx: component build failed: item 1 is poison
[Stats] (terminated)
✅ app_main: 1 total | 1 added
✅ boom: 3 total | 3 ⚠️ errors
0All three components fail, but the command exits 0. A root exception already produces exit 1, although its stats row also displays ✅.
Expected behavior
- Exit non-zero when components fail, with an opt-out for pipelines that tolerate errors.
- Show a warning icon for completed groups with errors.
- Include component identity in fallback logs, so users can identify the failing item.
- Preserve the existing in-process exception propagation contract.
Execution path and root cause
- CLI:
python/cocoindex/cli.py:1113-1115awaits completion without checkinghandle.stats(). The public stats API exposesnum_errors, but it does not affect exit status. - Display:
rust/core/src/engine/progress_display.rs:47-88chooses the icon solely from the in-flight count. Before #1804, it usedhas_errors()to select ⚠️. The replacement test explicitly expects ✅ with errors, so this appears to be a regression requiring confirmation. - Attribution:
python/cocoindex/_internal/component_ctx.py:172logs the exception and traceback without the availablestable_pathandprocessor_name. A traceback identifies the function, but usually not the mounted item.
Checking root stats alone is insufficient: errors inside coco.stats_group are excluded from that report, and LiveComponentOperator.report_exception logs errors without counting them. Root orphan-delete failures can also bypass Python handlers. A complete run outcome needs to cover these paths.
Existing workarounds require application changes. A raising handler plus awaiting every mount handle's ready() produces exit 1. An explicit stats-group check can do the same. A raising handler alone does not work.
Proposed direction
- Report failed non-live runs through the CLI exit status. Add
--fail-on-error / --no-fail-on-error, proposed default on. Exit 1 when components failed and print a short stderr summary that survives--quiet. Address the counter gaps above; readinghandle.stats()alone is only a partial fix. - Include truthful component attribution in fallback logs. Include stable path and processor name where available. The Python callback also handles descendant deletion failures, so wording such as
component failed at or under {stable_path} ({processor_name})avoids claiming an exact failing path. Exact descendant attribution requires additional core plumbing. - Make completion icons reflect errors. Use ⚠️ when
in_flight == 0 && num_errors > 0, and updatetest_format_component_line_with_errorsaccordingly.
Policy decisions:
num_errorsincludes errors swallowed by handlers anduse_mountfailures caught by the parent. Decide whether these should fail the CLI run; counting only unhandled errors requires additional tracking.- Exclude
--liveinitially, since cumulative errors do not describe current health. Decide how--previewand cancellation should affect exit status. - Counts represent failed components, not unique underlying exceptions, because propagation can count both a child and its parent.
Persistence and scope
Keep state storage and retry behavior unchanged. Failed components remain eligible for retry on the next run.
Changing the default CLI exit status requires a release note and a documented --no-fail-on-error escape hatch. Library propagation defaults must remain unchanged. App.update_blocking() returns no handle or stats, so equivalent library outcome reporting is separate work.
Error classification, retry policies, quarantine, and persisted failure records are out of scope.
Tests
- CLI exit codes for clean runs, failed runs, and
--no-fail-on-error. - Reporting under
--quiet, including a raising handler with unawaited mount handles. - The chosen policy for swallowed errors and caught
use_mountfailures. - Counter coverage for stats groups and
report_exceptionbeforemark_ready()in catch-up mode. - Icons for running, successful, and failed groups.
- Fallback logs with component identity and accurate wording for descendant deletion failures.
- Compatibility:
handle.ready()remains non-raising without an installed handler.
Related
- #2406 explicitly deferred child-failure reporting:
app.update()still returns normally when a child fails. - #2279 proposes a Rust CLI with an exit-code protocol; coordinate the contract.
- Document exit status in
cli.py'supdate()docstring or outside the generated block indocs/src/content/docs/cli.mdx. Update the exception-handling documentation to agree. - Fix the monitoring examples in
advanced_topics/exception_handlers.mdx: they usenum_erroredinstead ofnum_errors, and the polling example checks stats before the handle has started.
CocoIndex version and verification
The original draft records verification against main at e24ead9333ae381243773cd90e6309d530f19c81. Coverage included the reproduction, handlers, quiet mode, stats groups, live-component reporting, orphan deletion, and deliberately handled errors. No implementation changes were made during that verification.
Classification: confirmed bug.
I'd like to work on the three proposed fixes.
Before implementation, please confirm the CLI default, the treatment of deliberately handled errors, and whether the ✅-with-errors behavior is an unintended regression.
Source: cocoindex-io/cocoindex