Skip to content

AI-2146: fix stale notes.md and silent permission errors in init_task_record.py#7

Draft
RachelXiaolan wants to merge 1 commit into
mainfrom
linear/ai-2146-init-task-record-stale-notes
Draft

AI-2146: fix stale notes.md and silent permission errors in init_task_record.py#7
RachelXiaolan wants to merge 1 commit into
mainfrom
linear/ai-2146-init-task-record-stale-notes

Conversation

@RachelXiaolan

Copy link
Copy Markdown
Owner

What this fixes

scripts/init_task_record.py had two related footguns when run twice on the same issue id (or when --root pointed at a read-only directory):

  1. Stale notes.md. A second run with new --title / --repo / --branch would rewrite task.json while preserving notes.md from the previous issue. The result was a folder whose task.json (title, repo, branch) and notes.md (Scope, Progress, Links) disagreed about which Linear issue they belonged to.
  2. Silent crash on permission errors. Path.mkdir(parents=True, exist_ok=True) swallows FileExistsError but lets PermissionError propagate as a raw traceback, with no actionable hint and a partial folder left behind.

Changes

  • Refuse to create a task artifact in an existing folder unless --force is passed (exit code 2, clear stderr message).
  • --force reuses the folder and rewrites both task.json and notes.md atomically so they always describe the same issue.
  • PermissionError / generic OSError from mkdir are caught and turned into a clean non-zero exit with an actionable message; no partial folders are left behind.

Tests

tests/test_init_task_record.py covers:

  • First-run creation of both task.json and notes.md.
  • Repeat-run refusal: notes.md and task.json preserved unchanged.
  • --force refresh: both files rewritten atomically.
  • Permission-error: non-zero exit, no partial folder, clean stderr.
$ python3 tests/test_init_task_record.py
  ✅ test_first_run_creates_both_files
  ✅ test_repeat_run_refuses_without_force
  ✅ test_force_overwrites_atomically
  ✅ test_permission_error_exits_cleanly
4 passed, 0 failed

Linear

Tracked under AI-2146 (parent AI-2145). No code behavior change for the existing happy path — only the failure / repeat-run cases are tightened.

…task_record.py

The old init_task_record.py would silently partial-overwrite a task folder:
- task.json was always rewritten with the new title/repo/branch
- notes.md was preserved if it existed, leaving '## Scope' referencing the
  previous issue's context while the new run's metadata sat next to it.

It also crashed with a raw PermissionError traceback when --root pointed at
a read-only directory.

Changes:
- Refuse to create a task artifact in an existing folder unless --force is
  passed (with a clear error message and exit code 2).
- --force rewrites both task.json and notes.md atomically (folder reused).
- PermissionError and other OSErrors during mkdir are caught and turned
  into a clean non-zero exit with an actionable message.
- Add tests/test_init_task_record.py covering: first-run creation,
  repeat-run refusal, --force refresh, and permission-error handling.
@RachelXiaolan

Copy link
Copy Markdown
Owner Author

🔗 Synced from Linear

🤖 Codex

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.

2 participants