feat(items): field-level PATCH + conflict envelope + read-only version history (TASK-2022)#876
Merged
Merged
Conversation
Adds three related item-update primitives (TASK-2022 / IDEA-1480): - Field-level merge: PATCH `fields_patch` shallow-merges onto the item's current fields INSIDE the write transaction (null deletes a key), so concurrent single-field updates no longer clobber each other via the full-blob read-modify-write. `pad item update` and the MCP `pad_item.update` action now send only the changed keys. - Optimistic concurrency: optional `expected_updated_at` on update; on mismatch the store returns *UpdateConflictError and the handler emits the pad-structured-error/v1 conflict envelope (HTTP 409, code=update_conflict). Surfaced on CLI (`--expected-updated-at`) and MCP (`expected_updated_at`). - Read-only version history: `pad item history <ref>` (alias `versions`) and MCP `pad_item.history`, reusing the existing item_versions store + versions endpoint (no new store, no schema change). MCP ToolSurfaceVersion bumped 0.9 -> 1.0 (new action + param; update behavior change). No migration required. Claude-Session: https://claude.ai/code/session_019knGmnHcx5rrgWXQ8V8DZS
…ing, date/required guards Round 1+2 review fixes for TASK-2022: - HTTP MCP dispatcher (dispatch_http_advanced.go) now sends fields_patch (only changed keys) instead of a client-side merged full fields blob, and forwards expected_updated_at — remote MCP callers get the same race-free merge + optimistic concurrency the CLI/HTTP paths do. - ValidatePartialFields rejects null-deleting a schema-declared REQUIRED field (would otherwise persist a blob the full-update validator rejects). - Open-children guard on the fields_patch path merges the patch onto the IN-TX locked row inside the precheck (not a stale pre-lock preview), so a priority-only patch can't false-fire the guard. - Optimistic-concurrency check now runs BEFORE the open-children precheck in the store, so a stale expected_updated_at yields update_conflict (not open_children) — single in-tx re-read shared by both. - Date auto-population on the patch path only fills an EMPTY current date; an existing end_date the caller isn't touching is preserved. Tests added for each fix. Claude-Session: https://claude.ai/code/session_019knGmnHcx5rrgWXQ8V8DZS
…patch-conflict-history # Conflicts: # CLAUDE.md # README.md # internal/mcp/instructions.md # internal/mcp/version.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements TASK-2022 (refs IDEA-1480): three related item-update primitives that are a prerequisite for multi-agent coordination.
1. Field-level PATCH (merge, not replace)
PATCH /workspaces/{ws}/items/{slug}acceptsfields_patch: {key: value, key2: null}. The server shallow-merges it onto the item's current fields inside the write transaction (anullvalue deletes a key). Two concurrent single-field updates can no longer clobber each other the way the full-blob read-modify-write did (the lost-write race IDEA-1480 describes).pad item updateand both MCP dispatchers now send only the changed keys.2. Optimistic-concurrency conflict envelope
Optional
expected_updated_aton update. On mismatch (checked under the write lock, before the open-children guard), the store returns*UpdateConflictErrorand the handler emits thepad-structured-error/v1conflict envelope — HTTP 409,code=update_conflict, with{ref, expected_updated_at, actual_updated_at}. Surfaced on CLI (--expected-updated-at) and MCP (expected_updated_atparam); rendered with the versioned stderr marker for MCP stdio lifting.3. Read-only version history
pad item history <ref>(aliasversions) + MCPpad_item.history, reusing the existingitem_versionsstore and/versionsendpoint. Token-light summary shape by default;--fullincludes resolved content.Notes
item_versions,updated_at,fields).ToolSurfaceVersion0.9 → 1.0 (newhistoryaction +expected_updated_atparam + update behavior change). Drift test, README, instructions.md, and CLAUDE.md changelog updated. NOTE: sibling tasks are also bumping this constant; aversion.gomerge conflict is expected and will be resolved by the orchestrator.Tests
ValidatePartialFieldsunit tests.Gates
golangci-lint clean;
go test ./...green (SQLite); full build;go test ./internal/mcp/...green; Postgres suite (store/server/items/mcp + remainder) green. Three Codex review rounds → CLEAN.https://claude.ai/code/session_019knGmnHcx5rrgWXQ8V8DZS