Skip to content

feat(web): mark and lock documents managed from a repository - #758

Merged
pikann merged 3 commits into
Paca-AI:masterfrom
msammu07:feat/web-managed-doc-copies
Nov 14, 2026
Merged

pikann merged 3 commits into
Paca-AI:masterfrom
msammu07:feat/web-managed-doc-copies

Conversation

@msammu07

Copy link
Copy Markdown
Contributor

Summary

Fourth part of #747 (docs pull / push / content check for coding agents), on top of #754. The web app shows which documents are managed copies of a repository file and stops people from editing a locked one by accident.

Stacked on #756. This branch contains the realtime fix from #756 (commit 118bc8a), so the diff shows services/realtime/src/collab.ts and its test until that PR is merged. The two can be merged in either order. The change of this PR is the one commit feat(web): mark and lock documents managed from a repository.

  • Banner. A document with a source shows where it comes from above the editor: repository, file path and, when recorded, the commit.
  • Lock and unlock. Someone with docs:write can lock or unlock a managed copy from the banner (PATCH /docs/{docId} with source_locked). The button is disabled while a save is pending.
  • Read-only when locked. The editor is not editable while source_locked is true. Locking a document someone has open takes effect in their page without a reload: the existing rule that refetches a document on doc.updated already covers it, so there is no new realtime code in the web app.
  • A save that loses to a lock. A save answered with 409 DOC_LOCKED is dropped and not retried, the page shows one message that the change was not saved, and the document is marked locked at once.
  • Doc tree. A managed copy has a marker in the sidebar tree. Rename is disabled for a locked one; moving it stays allowed, as on the API.
  • Translations. The new strings are in all 9 locales. The 8 that are not English were machine-written and would benefit from a native speaker's look.

Decisions, listed so they can be challenged

  1. The editor is remounted when the lock state changes, so an edit that was refused does not stay on screen as if it had been saved.
  2. A save carries the id of the document it was made for. Without it, a 409 that arrives after the person switched documents would mark the wrong one locked.
  3. The lock is a guard rail, as in feat(api): read and write documents by path, with managed-copy metadata and change notes #754: anyone with docs:write can unlock.

Known gaps

  • A push that changes only source.commit raises no event (by design in feat(api): read and write documents by path, with managed-copy metadata and change notes #754), so an open page keeps showing the previous commit in the banner until the document is next fetched.
  • An edit refused with 409 stays in the shared editing room for a short time. If someone unlocks the document within 30 seconds and nothing else is written in between, that edit can come back and be saved. It is the person's own edit, not someone else's content, but it contradicts the "not saved" message. Not covered by a test.
  • Browser saves still send no If-Match for documents; that is unchanged here.

Type of Change

  • Other (feature, web)

Testing

  • apps/web: tsc clean; biome reports no errors; vitest 1673 of 1674 pass. The one failure, GitSettings.test.tsx ("shows the platform's reason on error and keeps the form usable", 5 s timeout), fails 3 of 3 on unmodified master, and this PR does not touch that area. New unit tests: managed-copy-banner.test.tsx, doc-lock.test.ts.
  • services/realtime (the fix(realtime): drop an empty collab room when the stored content changes #756 commit): bun run lint, bun run check, bun test (151 pass).
  • Browser specs (apps/e2e, chromium, tests/docs and tests/realtime) on a stack built from this branch: 210 passed, 6 skipped, 2 failed, 1 passed on retry.
    • New tests/docs/managed-copies.spec.ts, all 5 pass:
      • a managed copy shows where it comes from
      • a locked managed copy is read-only and can be unlocked
      • locking a document that is open stops further edits
      • a save that races a lock is dropped and not retried
      • a locked document cannot be renamed from the tree but can be moved
    • docs.spec.ts:350 (rename from the sidebar) and docs.spec.ts:640 (edit own comment, uses Control+a on macOS) fail the same way on master.
    • collaborative-editing.spec.ts:395 failed once and passed on retry. The whole file run 4 times without retries failed 13 of 28 on this branch and 19 of 28 on unmodified master, so these specs are racy under parallel load today; run one at a time, spec 395 passed 15 of 15 on this branch.
  • The new specs are in their own file because docs.spec.ts does not pass lint on master today.

Checklist

  • The change is focused and scoped.
  • Related documentation is updated: none needed.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — two low-stakes suggestions below.

Reviewed changes

  • Managed-copy banner — managed-copy-banner.tsx + test: repository, file path and short commit, the locked/unlocked explanation, and a Lock/Unlock button only for docs:write, disabled while a change is pending.
  • Lock handling — doc-lock.ts + route: a save answered with 409 DOC_LOCKED is dropped, the cached document is marked locked and refetched, and the page shows one "not saved" message.
  • Read-only editor — editable = canWrite && !locked; the editor remounts when the lock flips, and a remote lock while dirty raises the single toast.
  • Doc tree — app-sidebar.tsx: a managed-copy marker (icon + accessible label) and Rename disabled for locked copies, while move and delete stay available.
  • API surface — DocSource/source_locked on Document, source_locked on the update payload, and ApiErrorCode.DocLocked.
  • Translations — 7 docs.managedCopy.* keys in all 9 locales.
  • e2e — new feature + spec covering the banner/marker, unlock, lock-while-open in two browsers, the 409 race, and rename/move.
  • Realtime (stacked from #756, 118bc8a) — an empty post-grace collab room is dropped when the stored content changes, so the next editor re-seeds instead of being handed pre-write content. Reviewed; the drop is synchronous after the access-check await, the timers are cleared in destroy, and cluster leases simply stop being renewed.

ℹ️ Revert from the activity pane still writes to a locked copy

With docs:write, a locked managed copy still renders the activity pane's Revert action, and handleRevert PATCHes title/content. The API refuses that with 409 DOC_LOCKED, so the action always fails with the pane's generic "revert failed" message, while rename from the tree now explains why it is unavailable. Gating the revert on the lock (leaving comment editing enabled) would close the last content-write affordance this PR left open.

Technical details
# Gate the activity-pane revert on the document lock

## Affected sites
- `apps/web/src/components/projects/docs/doc-activity-pane.tsx:130-159` — `handleRevert` calls `updateDocument(projectId, docId, {title?, content?})`.
- `apps/web/src/components/projects/docs/doc-activity-pane.tsx:210-212` — `onRevert`/`isRevertable` are gated only on `canEdit` (= `canWrite`).
- `apps/web/src/routes/_authenticated/projects/$projectId/docs/$docId.tsx:364-369` — `DocActivityPane` receives `canEdit={canWrite}` with no lock information.

## Required outcome
- A locked managed copy does not offer an enabled Revert that the server will always reject; either hide it or disable it with the same reason the tree's Rename item uses (`docs.managedCopy.locked`).
- Comment add/edit/delete must stay available: the lock only covers content and title.

## Suggested approach (optional)
- Pass the lock state (or a `canRevert` boolean) from the doc page and combine it with `canEdit` for `onRevert`/`isRevertable` only, not for the comment props.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

…s locked

Clicking Lock blurs the editor, which starts a save. The button was
disabled while a save was pending, so the click that caused the save was
dropped. The lock request now waits for the save in flight instead.

The activity pane offered Revert on a locked copy, which the API always
refuses. It is offered only while the copy is unlocked; comments stay
available.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Re-reviewed the delta since the last pullfrog review (1c50823 → 5a82ac8, 4 files). Both prior findings are addressed:

  • Lock waits for the blur-save — the banner button is disabled only by lockMutation.isPending, and lockMutation.mutationFn awaits the content save tracked in saveInFlightRef before sending the lock, so the save still reaches the server first without the click being dropped. The ordering holds in Chromium, Firefox and WebKit, where focus leaves the editor on mousedown and the save is dispatched before click.
  • Revert gated on the lock — DocActivityPane takes a canRevert prop (defaulting to canEdit) that gates only onRevert/isRevertable; the page passes canWrite && !locked, so a locked copy hides Revert while comments stay editable and View diff remains offered.
  • Coverage for both — two browser specs plus matching feature scenarios: locking with an unsaved edit takes one click and keeps the edit, and a locked copy offers no Revert until it is unlocked.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 3833513 into Paca-AI:master Nov 14, 2026
4 checks passed
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.

[Feature] Docs: efficient pull/push/content-check for coding agents (change feed, ETags, upsert by path, partial reads)

2 participants