Skip to content

fix(s10): tolerate stray or corrupted task files in TaskStore.list - #662

Open
shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s10-task-store-list
Open

shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s10-task-store-list

Conversation

@shuhuNB515

Copy link
Copy Markdown

Fixes #635

Problem

TaskStore.list (s10_task_system/code.py:194-199) loads every glob match unconditionally:

return [self.load(path.stem)
        for path in sorted(root.glob("task_*.json"))]

One unexpected file in .tasks/ poisons everything downstream. Both modes reproduced against the chapter module before this change:

  1. A hand-created task_notes.json → ValueError: Invalid task ID: 'task_notes' from every list_tasks call.
  2. A truncated task_dead….json → json.JSONDecodeError raised inside complete_task's ready_before scan before the status flip — the target task stayed in_progress and no task on the board could be completed afterwards.

This is not hypothetical: the "Try It" section invites users to inspect .tasks/, and a Ctrl-C mid-write can leave a partial file behind.

Fix

Per-file try/except with a skip + warning, mirroring the policy s12 already applies to saved cron jobs (s12_cron_scheduler/code.py:415-417):

except (ValueError, OSError) as error:
    print(f"  [task] skipped invalid saved task: {error}")

(json.JSONDecodeError subclasses ValueError.) A few lines, same shape as the existing s12 precedent — no new machinery.

Verification

Ran the real chapter module in a temp workspace, before/after:

  • stray task_notes.json + truncated task_….json present → list() returns only the valid tasks with a [task] skipped invalid saved task: … warning each;
  • claim_task + complete_task complete successfully despite the corrupt sibling (previously impossible);
  • valid files load byte-identically.
  • python3 -m pytest tests/ — 503 passed, 118 subtests passed.
  • Embedded s10 source in web/src/data/generated/versions.json synced.

Disclosed AI assistance: found and fixed during an AI-assisted review; both failure modes reproduced and re-verified after the fix, and I stand behind the change.

TaskStore.list loaded every glob match unconditionally, so one
unexpected file in .tasks/ broke everything downstream:

- a hand-created task_notes.json -> ValueError: Invalid task ID from
  every list_tasks call;
- one truncated task_*.json -> json.JSONDecodeError raised from
  complete_task's ready_before scan *before* the status flip, leaving
  the board stuck: no task could ever be completed again.

Skip unparseable files with a warning instead, mirroring the policy
s12 already applies to saved cron jobs
(s12_cron_scheduler/code.py:415-417). Both failure modes were
reproduced against the chapter module before and after the change.

The embedded s10 source in the web registry is synced.

Fixes shareAI-lab#635

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s10: one stray or corrupted task_*.json file makes list_tasks() raise and leaves complete_task() permanently stuck

1 participant