Skip to content

fix(client): reconcile external page deletions without losing drafts - #126

Open
HaningZS wants to merge 1 commit into
CopilotKit:mainfrom
HaningZS:fix/page-list-remote-deletion
Open

HaningZS wants to merge 1 commit into
CopilotKit:mainfrom
HaningZS:fix/page-list-remote-deletion

Conversation

@HaningZS

@HaningZS HaningZS commented Oct 9, 2026

Copy link
Copy Markdown

Fixes #125

Workflow

The same owner opens a Space in two tabs. Deleting a page in B succeeds, but A's library keeps its old row indefinitely even though later complete page-list responses omit it. This does not require Intelligence or multi-user collaboration.

mergePageSnapshot previously used a permanent union to protect a locally created document from an older list response. Merely replacing the union with the latest list would lose that protection and could unmount an open unsaved draft.

Change

  • Treat successful complete lists as authoritative for absent rows, except explicitly retained pages. Continue preferring higher revisions and honoring local-deletion tombstones.
  • If a local create/save/delete completed after a poll started, retain existing rows for that response; a later fresh poll can reconcile absence.
  • Keep the selected document mounted when it is deleted elsewhere and show an accessible warning to download the draft before leaving. This does not recreate the server page. Returning to the library reconciles that row normally.
  • Keep one list request in flight per selection, use a 10-second request bound, and abort/ignore obsolete requests when selection changes or the workspace unmounts. This prevents a late older list from undoing a newer result and lets polling recover from a stall.
  • Add 9 workspace component tests and 2 snapshot cases. The existing local-creation regression now explicitly supplies its retention set; its workflow remains covered by the component race test.
  • Document externally deleted-page recovery in the existing setup guide.

Only the client snapshot/polling logic, its tests, and this usage explanation change. No backend, dependency, model configuration, or database migration changes. This branch is based directly on upstream main and does not contain #122. #114 touches the same workspace module but proposes history/trash/import-export; this PR does not add those features.

Verification

On Node 24.16.0, based on upstream main:

  • TDD: before changing production code, the initial snapshot/workspace cases produced 7 failures / 4 passes, including external deletion, eventual removal after a local-create race, open-editor deletion warning, overlapping polls, and recovery after a failed poll. The 3 additional cancellation/timeout cases were added while reviewing the polling fix.
  • Related suites: 23 passed (space-workspace, page-snapshots, autosave, page-document-delete).
  • npm test: 49 files, 313 tests passed.
  • npm run check-format, npm run lint, npm run typecheck, npm run build: passed.
  • git diff --check: passed.

Actual browser and page API checks

An isolated Vite fixture mounted the real SpaceWorkspace, SpaceLibrary, PageDocument, editor, menus and CSS in ReactDOM StrictMode. Two Chrome pages talked to the project's real Hono page routes and SQLite stores, using synthetic in-memory data.

  • Before the fix (1280px): B deleted a parent; its child was reparented correctly on the server. A completed two more list polls but still showed 1 deleted-parent row.
  • After the fix (1280px and 390px): A showed 0 deleted-parent rows after fresh polls; the child remained available at the Space root.
  • In each width, A edited a draft while its save request was pending; B deleted that page. A retained the actual Markdown text, showed the external-deletion warning and the normal failed-save recovery controls.
  • Download was activated with the keyboard and the actual downloaded file contents were checked against the exact draft.
  • After returning to the library and receiving a fresh response, the deleted row was absent.
  • No horizontal document overflow or browser page errors; narrow library/recovery screenshots were inspected locally.

Limits

The component tests mock child views and API responses to control races. The browser checks use real page routes/UI but a small fixture wrapper, not a full deployment; one save request is deliberately held to expose the draft-loss boundary. No live Intelligence/model, voice, Slack or Docker deployment was tested. Temporary browser scripts and screenshots are not committed.

The build retains the existing Vite native-config and large-chunk warnings. No test timeout was raised. AI-assisted investigation and implementation; all reported commands and browser checks were executed locally.

Why:
- A Space library retains pages deleted in another tab despite fresh list responses.
- Blind replacement would regress local creation races and discard open drafts.

What:
- Reconcile absent rows while preserving open pages and local mutations newer than a poll.
- Serialize and bound polling, cancel obsolete requests, and retain revision/tombstone guards.
- Warn when an open page was deleted and document the draft download workflow.
- Add snapshot and component regressions for deletion, races, cancellation, and recovery.

Risk:
- An externally deleted editor stays open for draft recovery, not server restoration.
- Browser verification uses synthetic SQLite data and real page routes, not live AI services.

Tests:
- Initial regressions failed on main before the fix; 23 related tests now pass.
- npm test: 313 tests passed across 49 files on Node 24.16.0.
- npm run check-format; npm run lint; npm run typecheck; npm run build.
- Chrome two-page checks at 1280px and 390px: deletion/reparenting, draft preservation,
  keyboard download with exact content verification, and return-to-library reconciliation.
- git diff --check; living-docs pre/post checks: zero errors and warnings.

Live Docs:
- docs/SETUP.md: externally deleted open-page recovery and server/draft distinction.

Fixes CopilotKit#125
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.

Space library retains pages deleted in another browser tab

1 participant