status: a truncated ACTIVE_GOAL_STATE.md reports healthy with zero Todos
What happens
ACTIVE_GOAL_STATE.md truncated at a section boundary (e.g. everything from
## Agent Todo onward removed) is read as a goal with no Todos:
healthy: {"status_exit":0,"status_ok":true,"todo_index_total":2,"attention":"[P1] implement the thing","todo_total":2}
wounded: {"status_exit":0,"status_ok":true,"todo_index_total":0,"attention":"run the first read-only adapter tick and save a compact run record","todo_total":0}
Both loopx status --format json and loopx todo list --format json exit 0
with ok:true, and the attention line silently degrades from the real P1 item
to the generic first-tick advice. 5/5 runs.
Why this path is taken
parse_active_state_todos iterates only the regions it finds
(loopx/control_plane/todos/active_state_todo_parser.py:36), and a missing
section is legal — only unterminated frontmatter or malformed/orphan markers
raise (machine_region.py:53-58,86,103). A present-but-truncated file is
therefore indistinguishable from a goal that genuinely has no Todos.
Trigger honesty
The state writer is atomic (runtime/document_io.py, temp + fsync + replace),
so this is not a same-version torn write. It models disk corruption after a
crash, a partial backup/restore, or a bad manual/merge edit of a file that is
present.
Relationship to #6799
#6799 is about a missing state file letting the quota gate authorize turns. This is the sibling case: the file exists, its earlier sections parse, and the Todo section is simply gone — so a missing-file guard would not fire, and the quota gate sees a goal with no open work.
Expected
A state file that parses but lost a section it used to have should not read as
"no open work". Options: require the ## Agent Todo region; compare a revision
or section inventory against the last known good state; or surface a
state_incomplete warning on status/todo list.
Reproduced
Snapshot 105c4bc1; unchanged on main at 1c7b258cb. Fixture: one goal with
exactly two Agent Todos; the wounded copy is the same fixture with the state
file cut at 377 → 235 bytes (before ## Agent Todo). The script asserts the
healthy control first (2 Todos, P1 attention) and fails if the wounded side does
not match.
Claiming this issue. I'll verify the truncated-state path on current main, implement the narrowest fail-closed/readback fix, and open a PR that references this issue. Any AI-assisted change will be disclosed in the PR.
Opened a fix in #6921: https://github.com/loopx-project/loopx/pull/6921
Final head: fa29f297e50e3066376ef0d77516947a33240723; base is loopx-project/loopx:main.
The change treats a readable legacy Markdown active state without the required ## Agent Todo heading (or an accepted alias) as state_incomplete instead of a healthy zero-Todo goal. On a synthetic truncated fixture:
statusnow exits1withstate_incompleteand restore guidance instead of exit0with generic first-tick advice.todo listnow exits1witherror_code=state_incompleteinstead ofok:truewith zero Todos.quota should-runreturnsshould_run:false,state:blocked_health, and the same restore guidance.- Restoring an Agent Todo section returns all three commands to success with the Todo visible.
- Present-but-empty Agent Todo sections remain valid; canonical provider authority is unaffected.
Validation on the final head:
tests/control_plane/test_truncated_active_state_todos.py: 6 passed, including direct CLI regression coverage forstatus,todo list, andquota should-run.tests/control_plane/test_canonical_status_todos.py: 156 passed; 4 pre-existing Windows GBK subprocess-decoding failures, and those same 4 cases pass withPYTHONUTF8=1.- Ruff and
git diff --checkpassed; semantic inventory found no supported new vocabulary carriers. - Independent review found no P0/P1. Its documentation and CLI-coverage notes were addressed in
fa29f297e; truncation after the heading but before its items remains outside the selected heading-presence strategy and is documented as a residual boundary.
AI disclosure: this change was drafted with AI assistance at my request, under my direction and review.
Follow-up on the version boundary: #6921 merged on 22 October. Current main uses canonical authority for ordinary Todo reads; the legacy heading check alone no longer describes that path.
I checked an installed 2.1.0 snapshot whose three Todo reader modules match 385771e, using disposable synthetic SQLite fixtures:
- With two canonical Todos, cutting the Markdown before
## Agent Todo, or leaving that heading empty, preserved both exact Todo IDs intodo listandstatus. These reads did not rewrite the display file. - A missing SQLite provider returned
local_authority_provider_missing; restoring that fixture provider restored both Todos. A genuinely empty canonical collection returned a valid zero-Todo result. - Both intact and truncated unmigrated fixtures returned
canonical_authority_required. Their quota checks returnedshould_run:falseandblocked_health.
The current canonical-reader regression records these authority/display distinctions. This check covers the installed SQLite path, not general corruption detection or a rerun of the historical legacy runtime.
中文补充:旧版的缺失标题修复已合并;当前版本需先区分权威存储与 Markdown 展示。展示被截断不应把权威任务清空,存储不可用也不能解释成“没有任务”。若仍复现,版本及 Todo 读回中的 authority_read.source_authority / legacy_fallback_used 会有助于定位路径,无需提供私有任务正文。
Suggested area label: control-plane
The truncated-state false-healthy report is in loopx/control_plane/todos/active_state_todo_parser.py — runtime state management. Note: #6921 (merged 2026-10-22) made the legacy read path fail closed on truncated state (exiting with state_incomplete instead of reporting healthy), and @loopx-agent noted on 2026-10-23 that the legacy heading check alone no longer describes the current read path for ordinary Todo reads.
Re-verified the reported path on main at 31ff0569, because the reader changed after #6921.
The reported symptom (exit 0, ok:true, zero Todos, generic first-tick attention) no longer reproduces. What the three readers actually do now:
| Fixture | status |
todo list |
|---|---|---|
Legacy goal, Markdown cut before ## Agent Todo |
exit 1, canonical_authority_required, write_admitted=false, legacy_fallback_used=false |
exit 1, same payload |
| Canonical goal, same Markdown cut after promotion | exit 0, attention queue still carries the exact canonical todo_fix P1 row |
exit 0, todo_count=1, todo_id=todo_fix |
| Canonical store file truncated mid-JSON | exit 1, provider_protocol_violation |
exit 1, same |
Canonical store edited so head.todos: [] while the rest stays valid |
exit 1, provider_protocol_violation |
exit 1, same |
So the three suggested directions are effectively in place: the legacy heading check fails closed (#6921), ordinary reads require canonical authority instead of treating the display as a work source, and the authority store validates its own structure, so a truncation that reaches it is a protocol violation rather than an empty collection. quota should-run on the same legacy fixture returns should_run:false with state:blocked_health.
The existing coverage is tests/control_plane/test_truncated_active_state_todos.py (legacy heading, present-but-empty headings, CLI fail-closed) and tests/control_plane/test_canonical_status_todos.py (display parametrised over missing/truncated/invalid_utf8/invalid_user_todo).
One gap I did not find a Python regression for: truncating or structurally editing the authority store itself and asserting the CLI refuses rather than reporting an empty read. That is covered at the TypeScript store layer only. If the truncated-store case is worth pinning at the CLI boundary, I can send that as a small test-only change; otherwise I think this issue can be closed as fixed by #6921 plus canonical authority.
Verified on macOS with the real File provider through the CLI. Not verified: Windows and any other provider than the local File store.