Skip to content

fix(core/server): enforce MAX_NOTES_LENGTH on the total note size when appending - #1301

Open
mccalpink wants to merge 1 commit into
Kohei-Wada:mainfrom
mccalpink:fix/1295-notes-append-limit
Open

mccalpink wants to merge 1 commit into
Kohei-Wada:mainfrom
mccalpink:fix/1295-notes-append-limit

Conversation

@mccalpink

Copy link
Copy Markdown

Description

POST /api/v1/tasks/{task_id}/notes/append (#1294) only validated the appended chunk against MAX_NOTES_LENGTH, while PUT .../notes caps the whole body. Repeated appends could therefore grow a note past the limit. This PR makes the append respect the limit on the resulting note size, atomically.

Related Issue

Closes #1295

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

  • SqliteNotesRepository.append_notes / NotesRepository.append_notes take an optional max_length. The check is part of the append's own UPDATE (WHERE length(content) + :len <= :max), so it stays atomic and does not bring back the read-then-write race fixed in feat(server/client/mcp): atomic append_task_note to prevent lost note-log updates #1094. If no row was updated, an existing note means overflow (NotesTooLargeError, note untouched); a missing note is created as before (rejected if the chunk alone exceeds the limit). The concurrent-create IntegrityError retry uses the same guarded statement.
  • NotesController.append_notes forwards max_length; the router passes the existing MAX_NOTES_LENGTH (the constant is not duplicated in core).
  • New NotesTooLargeError (a TaskValidationError) mapped to 422 in error_handlers.py, the same status PUT returns for an oversized body.
  • Tests: repository on SQLite (exact fit, overflow leaves content and updated_at unchanged, character vs byte length, missing note), controller, and router with the in-memory test repository (two 600k appends -> 200 then 422; exact fit at 1,000,000 -> 200).

Testing

Test Environment

  • OS: Linux
  • Python version: 3.13.13
  • UV version: 0.11.16

Tests Performed

  • Unit tests pass (full pytest tests/ for taskdog-core and taskdog-server; taskdog-ui, client and mcp are untouched and were not run)
  • Added new tests for new features
  • Manual testing completed
  • All affected commands work as expected (notes append endpoint covered by router tests)

Code Quality Checklist

  • Linter passes (make lint)
  • Type checker passes (make typecheck)
  • Code is formatted (make format)
  • No new warnings introduced
  • Code follows project conventions

Documentation

  • Updated README.md (if needed)
  • Updated CLAUDE.md (if architecture changed) - N/A, architecture unchanged
  • Updated CHANGELOG.md - N/A, no CHANGELOG in the repo
  • Added/updated docstrings
  • Updated type hints

Package Affected

  • taskdog-core
  • taskdog-server
  • Multiple packages

Breaking Changes

  • This PR includes breaking changes

append_notes gains an optional max_length parameter (default None, no limit), so existing callers are unaffected.

Screenshots/Output

Before: POST .../notes/append 600000 chars -> 200; again 600000 chars -> 200 (note is now 1,200,000 chars)
After:  first -> 200; second -> 422 {"detail": "Appending would make the notes of task N exceed 1000000 characters"}; note unchanged

Test results: taskdog-core 1210 passed, taskdog-server 378 passed; make lint format typecheck and pre-commit run --files <changed> pass.

Checklist

  • My code follows the coding standards of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

The status is 422 to match PUT and the existing oversized-chunk response on this endpoint.

Known limitation, not new in this PR: SQLite length() stops at the first U+0000, so a note containing a NUL character is under-counted by the guard. Rejecting NUL in notes requests could be a follow-up if you want it.

This PR was prepared with AI assistance (Claude Code). I have reviewed the change and the test results.


For Maintainers:

  • Reviewed for security implications
  • Verified test coverage
  • Checked for breaking changes
  • Updated version number (if needed)
  • Ready to merge

…n appending

POST /tasks/{id}/notes/append only validated the appended chunk, so
repeated appends could grow a note past the limit PUT enforces.

The limit is now checked in the same UPDATE that appends
(WHERE length(content) + :len <= :max), so the check stays atomic with
the append. When no row is updated, an existing note means overflow
(NotesTooLargeError -> 422, note untouched); a missing note is created.

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.

fix(server): repeated notes appends can grow notes past MAX_NOTES_LENGTH

1 participant