Skip to content

bug(analytics): a killed analysis run's partial findings are shown as the complete result #21003

Open

Description

@mrveiss

Problem

When a codebase analytics or indexing run is killed (exit -9: OOM, a signal, or a time limit), the findings it had already stored are shown afterwards as if they were the complete result. Nothing records that the run did not finish, so the UI cannot say so.

Evidence

From the owner's evidence comment on #20493 (2026-11-02, read-only observation of stored data and task records; timestamps UTC):

Cause of the top-level-only results, for the whole-repo source: an indexing run was killed partway, and its partial findings are shown as if they were the result.

Evidence Value
Findings stored for that source 2,300
Written between 14:43:43 and 14:54:51 UTC on 2026-11-01
Latest task record failed, started 14:25:50, ended 14:54:53, Indexing subprocess crashed (exit code -9)
Previous task record the same failure, 10:54:21 to 11:23:31
Stats document for that source none; the other source, whose run completed, has one
autobot-backend files with findings 88, none below its top level (the repo has 5,187 Python files there, 169 at the top level)

The kill came 2 seconds after the last finding was written. Files were analysed first and stored in walk order, so a run cut off during storing leaves mostly shallow paths.

Why the run was killed isn't established: both failed runs lasted about 29 minutes, which suggests a limit, and _wait_with_watchdog and the hard timeout both return -9. No log line for it survives. The kernel log showed nothing, but that's weak evidence here.

The task records do not name their source, so tying the failed record to this source rests on timing. The owner's comment states that the page "shows results from a failed run with nothing saying so".

Impact

  • Code-smell and other analytics results from a killed run look like a whole-repo result. bug(analytics): code smell results look limited to top-level files, and counts disagree with their cards #20493 reports findings confined to top-level files, and card counts that disagree with the JSON.
  • Users and maintainers act on incomplete findings (triage, sizing, "is this file clean?") without any signal that coverage was partial.
  • The same gap hides a failed run's status: there is no stats document for the failed source, so the reader falls back to whatever findings exist.

Related

Acceptance criteria

  • A run records a terminal status (completed, failed or killed), with the reason, on every exit path, and the UI labels any result from a non-completed run as partial.
  • A run with no completed status is never presented as the latest complete result; the last completed run is shown instead, with a visible note that a newer run did not finish.
  • A test simulates a killed run (subprocess exits -9 after storing some findings) and asserts the recorded status is killed and the UI or API response marks the results partial.
  • The reason for the kill is investigated (memory limit or time limit, using the watchdog and hard-timeout values and the process exit path) and the determined reason is recorded in the run record and in this issue.

Notes

  • Fix one defect in one place: the run-status record and the read path that chooses "latest result". Do not patch each analytics panel separately.
  • The cause investigation is open per the evidence comment; the AC is to determine and record it, not to assume it.

Activity

  1. added
    needs-structureMissing goal milestone, matching phase label or native parent (#19522)
    on Nov 7, 2026
  2. github-actions commented on Nov 7, 2026

    @github-actions
    Contributor

    needs-structure cleared: goal milestone, matching phase label and native parent (or sub-issues) are all present (#19522).

  3. removed
    needs-structureMissing goal milestone, matching phase label or native parent (#19522)
    on Nov 7, 2026
  4. mrveiss commented on Nov 7, 2026

    @mrveiss
    OwnerAuthor

    Progress on #21003: backend half done locally, kill cause not established

    The backend half is committed locally as c7603b3f74 (not pushed). The UI banner and the stats/report wiring are not done yet.

    Lifecycle trace (paths under autobot-backend/api/codebase_analytics/)

    • Start: endpoints/indexing.py (around line 250) calls _run_indexing_subprocess in subprocess_runner.py, which launches indexing_worker.py.
    • Task record: Redis indexing_task:<id> with a 24h TTL (progress_tracker.py, _TASK_REDIS_TTL). Status is written by _create_initial_task_state, _mark_task_completed and _mark_task_failed. After 24h the failed run's record is gone.
    • Findings: problem_storage.py (_store_problems_batch_to_chromadb) upserts in chunks. The codebase_stats_<source> document is written in chromadb_storage.py before the run finishes.
    • Reads: endpoints/stats.py, report.py and charts.py query {"type": "problem"} and the stats document. None looks at run status.
    • Crash path: subprocess_runner.py _handle_subprocess_crash only marked the task failed. No durable record was kept.
    • No stale-task sweep exists for analytics. task_routes.add_clear_stuck_route is a no-op (security(api): routes with no auth beside gated siblings — public /api/redis-service/status, analytics task status and clear-stuck, batch-jobs load/chat-init #18718), so there was nothing to reuse.

    Design (in the local commit)

    • New run_status.py: one durable record per source (codebase_run_<source_id>) in the same ChromaDB collection as the findings, which is the system of record for codebase_analytics.
    • The record holds latest_* (run id, status, reason, times) and a last_completed_* pointer. Only a completed finish advances the pointer. A failed, killed or abandoned run never moves it.
    • A terminal status is never overwritten, so a late crash report cannot replace completed.
    • Statuses: running, completed, failed, killed, abandoned, cancelled. Exit -9 (SIGKILL) maps to killed; any other non-zero exit maps to failed.
    • scanner.py records completed or failed from the worker. subprocess_runner.py records running at start and killed or failed on a crash, with the reason.
    • Both supervisor kills now write a distinct reason into the record: "killed by the progress watchdog: no progress for Ns (limit Ms)" or "killed by the hard timeout: run exceeded Ns".
    • A run left running past the hard timeout plus 300s is marked abandoned on read.
    • New GET /api/analytics/codebase/index/run-state?source_id= returns the status, a partial flag, the reason and the last completed run.
    • Tests (run_status_21003_test.py): killed run keeps the previous completed pointer and is partial; killed first run has an empty pointer; completed advances the pointer; abandoned sweep with a not-yet-overdue control; exit -9 maps to killed end to end through the crash handler. Result: 13 passed (with progress_tracker_test.py).

    Kill cause: not established

    Two code paths can send SIGKILL (-9); both return -9, so before this change the history could not tell them apart:

    • Hard timeout: _SUBPROCESS_HARD_TIMEOUT, default 1800s (indexing_executor.py:44, env AUTOBOT_INDEXING_HARD_TIMEOUT), enforced by asyncio.wait_for in subprocess_runner.py _run_indexing_subprocess, which calls proc.kill().
    • Progress watchdog: _SUBPROCESS_PROGRESS_TIMEOUT, default 300s (indexing_executor.py:47, checked every 30s), enforced in subprocess_runner.py _wait_with_watchdog, which calls proc.kill().

    Both failed runs lasted about 29 minutes, which fits the 1800s hard timeout but does not prove it. An OOM kill cannot be excluded from code. I found no Celery hard time limit on this path.

    Host evidence that would settle it:

    • The backend log lines "Subprocess stale for N seconds" or "Subprocess exceeded hard timeout of N seconds" around 14:54 UTC on 2026-11-01.
    • The effective values of AUTOBOT_INDEXING_HARD_TIMEOUT and AUTOBOT_INDEXING_PROGRESS_TIMEOUT in the running backend.
    • dmesg or journalctl -k for oom-kill entries around 14:54 UTC on 2026-11-01.

    From now on each kill records its cause in the run record.

    Remaining scope (follows once #21008 lands, rebased onto it)

    • The i18n "partial results from an interrupted run" banner in the analytics view, driven by /index/run-state.
    • partial and the last completed run wired into the stats and report responses.

    Proposals (not applied)

  5. mrveiss commented on Nov 12, 2026

    @mrveiss
    OwnerAuthor

    Owner decision, 2026-11-12 — how a killed run is presented

    Every per-source reindex first deletes that source's previous findings, so after a killed run there is no earlier complete result left to show. Asked which way to go, the owner chose: show the partial findings clearly marked as partial, with the time of the last completed run (banner), rather than tagging findings with a run id so the previous complete run survives.

    Consequences for the fix:

    • AC2 is delivered as "a non-completed run is never presented as complete, and the note says when the last completed run was"; keeping the previous run's findings readable is not part of this fix.
    • Found while reading the unpushed backend half (commit c7603b3f74, 7 files): (1) the run record carries source_id in its metadata, so the next run's per-source delete removes the record and its last-completed pointer — the record needs a key the delete does not match; (2) the new GET /index/run-state route takes an optional source with a default, which the source-scoping rule forbids — it must require the source.
    • AC4 (the kill cause) still needs host evidence and stays open.
  6. mrveiss commented on Nov 13, 2026

    @mrveiss
    OwnerAuthor

    Residual noted by the review of PR #21478 (non-blocking, recorded here so it is not lost): the page remembers the first run it knew when a wait began. In the sequence queued → that request is tracked as a job → a second request queues without the polling being restarted, the remembered run stays the first one; if the second request then never runs, the earlier tracked job's own outcome is announced once more, late. It is a real outcome of a real job — nothing wrong is announced and nothing right is suppressed — but the announcement is redundant. Fix direction: re-capture the remembered run when a job id is set.

  7. github-actions commented on Nov 13, 2026

    @github-actions
    Contributor

    Landed via the merge train (#21500, merge 470d3627d8) via #21478

  8. mrveiss commented on Nov 13, 2026

    @mrveiss
    OwnerAuthor

    Landed in #21478 (merge 470d362)

    Criterion Evidence (main) Ticked
    Terminal status with reason on every exit path; UI labels non-completed results partial autobot-backend/api/codebase_analytics/run_status.py:94-101 (statuses, PARTIAL_STATUSES); scanner.py:432,440 (completed, failed); subprocess_runner.py:208,217 (cancelled, start failure) plus supervisor kills; autobot-frontend/src/components/analytics/RunStateNotice.vue:16 (v-if="run && run.partial") yes
    Non-completed run never shown as latest complete; last completed run shown with a note Not met as written. By the owner decision on this issue (2026-11-12) the partial findings are shown marked partial with the time of the last completed run, because the per-source reindex deletes the earlier findings first no
    Killed-run test (exit -9, status killed, results marked partial) run_status_21003_test.py:79-86 asserts ("killed", True, "exit -9"); run_status_21003_test.py:92 for a first run yes
    Kill cause investigated and recorded not verifiable from code: needs host evidence for the historical runs. The code now records which limit fired (distinct supervisor-kill reasons) no

    Remaining

  9. mrveiss commented on Nov 22, 2026

    @mrveiss
    OwnerAuthor

    Branch closed: its content is on main, see #22071.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't workingphase:M4.11Safety net: tests and analysers reach the whole treepriority: high

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions