Repository navigation
feat(api): read and write documents by path, with managed-copy metadata and change notes - #754
Conversation
… conflict A PUT by path that found the path changed three times answered 500: ErrDocPathChanged had no mapping. It is now 409 DOC_PATH_CHANGED. A document deleted by id between the write's resolve and its row lock made the write answer 404 for a path the caller may create. The repository now reports the path changed when the row is gone before decide runs, so the service resolves again and creates the document.
There was a problem hiding this comment.
Important
The MCP by-path client cannot recognise a server that predates these routes, so its folder-walk fallback never runs and read_doc, delete_doc and move_doc fail against an older API.
Reviewed changes
Read the full 43-file diff (all 8 commits, 0a3a5bd..f2e54e8) plus the routes and IAM guards it builds on.
- By-path endpoints —
PUT/GET /projects/{projectId}/docs/by-pathresolveFolder/Sub/Titlecase-insensitively (exact case first, a document wins over a folder), create missing folders, and reuse the existingETag/If-Matchmachinery. - Serialized writes —
WriteDocumentAtPathruns under the same per-project advisory lock asUpdateFolderAtomic, re-resolves, and compares against the authorized resolution, with the service retrying three times before a retryable 409. - Managed copies —
source/source_lockedcolumns (migration000089), with the lock enforced inside the update decision and source-only/lock-only writes keepingupdated_at,updated_by, the hash and the snapshot history untouched. - Change notes —
note/client/taskon document writes, stored in the activity entry, printed bylist_doc_activities, shown in the web doc activity pane, and echoed in the details of a 412. - Authorization — the route gate checks only the project; the handlers then authorize the resolved document (
docs:read, 404 on deny) or the create target folder, matching theDocCreate/DocChangeexpansion. - MCP tools —
write_doc/read_doc/delete_doc/move_docgo through the new client methods with a folder-walk fallback for older servers.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
A server from before the by-path routes reads GET /docs/by-path as a document whose id is "by-path" and answers 400 "invalid document id". The client looked for "invalid doc id", so it never fell back to the folder walk; the test mocked the same wrong text.
If-Match on a path with no document has no stored version to name. The answer carried an empty content_hash and a zero updated_at; it now carries no error_details.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Re-reviewed the two commits since the previous pullfrog review (f2e54e8), both fixes for that review's findings, and verified each against the API it depends on.
- Older-server detection —
isMissingByPathRoutenow matches theinvalid document idmessage thatparseDocIDactually returns from the pre-PRGET /docs/{docId}route, sogetByPath/putByPathreportunsupportedand the folder-walk fallback runs on an older API; the client test mocks the real message. - 412 with no stored version — the presenter only builds
error_detailswhen theVersionConflictErrornames a stored version, so anIf-Matchon a path with no document answers412with an empty details body;TestUpsertByPath_IfMatchStale412now asserts that viaerrorDetails(raw).
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thanks a lot for your contribution.
Could you please help resolve the merge conflicts so we can get this merged?
The change feed (Paca-AI#753) makes every document and folder write take the project's change counter before any other lock. The by-path write now takes it before the folder advisory lock, and document and folder creates take it around the shared insert helpers. The deadlock test pushes by path against a folder delete.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Re-reviewed the one commit since the prior pullfrog review (dfa64cc): the merge of master (1a98043, the document change-feed PR) into feat/doc-by-path, and checked the conflict resolution against the change-feed machinery it now shares.
- Lock order —
WriteDocumentAtPathnow takes the project change counter (lockDocSeq) before the folder advisory lock, matchingUpdateFolderAtomic,DeleteFolder,CreateDocument,CreateFolder,UpdateDocumentAtomicandDeleteDocument, so the counter is always the first lock and no writer can invert it. - Shared write helpers — the merge keeps master's
insertFolder/insertDocument/updateDocumentLocked/lockDocSeqOfextraction and threadssource/source_lockedthroughdocumentToRecord, the 14-column insert and the update'ssource=$9, source_locked=$10, so by-path and by-id writes no longer diverge on managed-copy metadata;documentCols/documentTreeColscarry the columns into the feed and batch-get queries. - Change-feed wiring —
WithDocChangesadded inbootstrap/app.goand the e2e env, with/changesand/batch-getregistered before/{docId}and after/by-path. - Deadlock coverage — by-path pushes added to
TestDocSeq_ConcurrentWritesAndFolderDeleteDoNotDeadlock, exercising the counter-then-folder-lock order against folder rename/delete (27 sends per round against a4*perFolder+2buffer).
I verified the resolution locally: go build ./... is clean and the doc domain, service, DTO and presenter unit tests pass. Both prior pullfrog threads are resolved, and the merge settles the conflict that blocked the earlier human approval.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Summary
Third part of #747 (docs pull / push / content check for coding agents), on top of #751. A coding agent can write and read a document by its path in one request, mark it as a managed copy of a repository file, and say why it wrote.
PUT /projects/{projectId}/docs/by-pathwith{path, content, source?, lock?, note?, client?, task?}creates the document atFolder/Sub folder/Title(and any missing folder) or updates it:201when created,200otherwise, with the document pluschanged.GET /projects/{projectId}/docs/by-path?path=…reads it.ETag,If-None-MatchandIf-Matchwork as on/docs/{docId}(feat(api): add a document content hash with ETag, If-Match and no-op writes #751).source: {repository, path, commit?}records the repository file a document is a copy of. Documents created in Paca have no source.lock: true(needs a source) marks a managed copy people should not edit in Paca: a content or title write that does not name the samesource.repositorygets409 DOC_LOCKED. Moves stay allowed.PATCH /docs/{docId}acceptssource_lockedso a person withdocs:writecan unlock (or lock again).POST,PATCH, by-pathPUT) acceptnote(at most 500 characters),client(an opaque label, at most 200) andtask(at most 50). They are stored in the document's activity entry and returned in the details of a412, so a writer that lost a conflict can see what the other write was for.clientis never used for authorization.write_doctakes optionalnoteandtask;clientcomes fromPACA_CLIENT.list_doc_activitiesprints the note, client and task.How a by-path write works
docs:writeto change the existing document, or to create one in the deepest folder of the path that exists. The route gate can only check the project.409 DOC_PATH_CHANGED. Two pushes of one path never create two documents or two folders.GETby path answers the same404for a document the caller may not read as for a missing one.Decisions, listed so they can be challenged
docs:writecan name the source repository. It stops accidental edits in the wrong place; permissions stay with roles.updated_at,updated_byand the content hash and takes no snapshot: the document a reader sees is the same. TheETagstill changes, because it covers the whole response. A lock change records adoc.updatedactivity; a source-only change records nothing.changedis true when the document was created or its content, title, folder or position changed. An identical push that only records a new commit ischanged: false.If-Matchon a path with no document is412with empty details (the document moved or was deleted).DOC_LOCKED,DOC_LOCK_NEEDS_SOURCE,DOC_PATH_INVALID,DOC_PATH_IS_FOLDER,DOC_PATH_CHANGED,DOC_SOURCE_INVALID,DOC_NOTE_INVALID.412is read from the activity log, which is written asynchronously, so a conflict right after the other write may not carry its note yet.doc.folder_id == X) is evaluated against the deepest existing folder when the write also creates folders below it.Not in this PR
The web editor does not yet mark a locked managed copy as read-only: a save on one gets
409 DOC_LOCKED. Locked documents only exist once an agent pushes withlock, and the next PR (web UI) handles it.Scope
This PR touches
services/api,apps/mcpandapps/web(one optional prop on the sharedActivityPaneand the doc activity pane). The commits are split by concern; if you prefer, I can raise the MCP and web commits as separate PRs after the API part.Migration
000089_add_documents_source.sql(up only, idempotent):documents.source JSONBanddocuments.source_locked BOOLEAN NOT NULL DEFAULT false.Testing
golangci-lint run: 0 issues.-raceand the full API e2e suite, run in a Linux container (golang:1.26) with CI's commands: pass. New API e2e tests:TestUpsertByPath_*(create with folders, update, no-op,If-Match, lock, concurrent pushes of one path, permissions).apps/mcp: lint and unit tests pass.apps/web:biome check,tscand unit tests pass.apps/e2e, Chromium,tests/docsandtests/realtime, on macOS against a stack built from this branch before the rebase onto currentmaster): 207 passed, 6 skipped, 1 failed. The failure isdocs.spec.ts"User can edit their own comment", which pressesControl+a(not select-all on macOS), as reported in feat(api): add a document content hash with ETag, If-Match and no-op writes #751.Relation to the change feed PR
The change feed (#753) has merged, and
masteris merged into this branch. The by-path write now takes the project's change counter before the folder advisory lock, like every other document and folder write, andTestDocSeq_ConcurrentWritesAndFolderDeleteDoNotDeadlockpushes by path against a folder delete (it fails with a deadlock without that lock). A document created or updated by path appears in the change feed like any other write.Type of Change
Checklist