Skip to content

Bug: a new Knowledge version closes another session’s editor and loses its draft #3901

Closed

Description

@yannickmonney

Editing a Knowledge entry can silently lose unsaved text when the list refreshes after another writer publishes a new version of the same entry.

Severity: P2 (unsaved work lost without a discard decision).
Source: 9ea59724df24d62729a9360f3902d964dab39b3e.

Reproduction

  1. Open an existing Knowledge entry from its table row, then choose Edit.
  2. Change Content to a distinct unsaved draft; do not save or cancel it.
  3. In another local session, publish changed content for the same entry. When the first session's list next successfully refreshes, the active row has a new version ID and the same document ID.
  4. The first editor immediately disappears. Reopening the entry shows the other writer's content; the unsaved draft is gone.

Expected: keep the editor and draft stable, explain that a newer version exists, and let the user reconcile or explicitly discard their changes.

Actual in the closed component replay: replacing entry-version-1 with entry-version-2 on document-chain-1 unmounts both dialogs, removes Unsaved local work, and exposes the other writer's content. No update mutation was invoked by the draft owner. Reopening contains only the new published text. A control that refetches a fresh object with the same version ID preserves the dirty editor.

Root cause

  • KnowledgeEntriesTable tracks its viewed row with useViewedRecord and mounts KnowledgeEntryViewDialog only while that row is present (services/platform/app/features/knowledge-entries/components/knowledge-entries-table.tsx:42-46,121-129).
  • useViewedRecord identifies records solely by _id; a missing ID immediately returns record: null, then clears the viewed ID after a settled read (services/platform/app/hooks/use-viewed-record.ts:22-35).
  • Knowledge IDs identify versions, not the enduring entry. updateKnowledgeEntry inserts a new active row, supersedes the old row and keeps documentId (services/platform/backend/domains/knowledge_entries/service.ts:549-577). The active-list reader excludes the superseded version.
  • The edit dialog lives inside the view dialog, so losing the old table version unmounts the dirty form even though the underlying entry still exists.

Use the entry's enduring identity for view lifecycle, and preserve the editing session independently of live table membership. Handle true deletion/access loss explicitly as well; retaining stale write access is not required to retain the draft.

Validation and boundaries

Local component replay at the source SHA above: 2/2 tests passed, with the actual table, useViewedRecord, view dialog and edit dialog. Only query/mutation boundaries, ability/org fixtures and indexing badge were replaced. The tests assert both the failure and same-version refetch control. Native source inspection establishes that the substituted list update is the shape produced by a changed-content save. This is not a claim that a full two-session native-backend browser round was executed.

Retained audit evidence: knowledge-functional-next/version-refresh-draft.probe.test.tsx and version-refresh-draft.replay.log. No production testing or writes.

Dedup: distinct from #3602 (backend concurrent writes leave multiple active facts) and #3777 (failed reads masquerade as empty/history missing). This report concerns a successful version replacement unmounting an unrelated unsaved editor. One lifecycle issue, not separate findings for every field.

Activity

  1. yannickmonney commented on Sep 29, 2026

    @yannickmonney
    ContributorAuthor

    Current-main revalidation — b7f8ca0

    Source: b7f8ca02ec249c004652b1ee52e112d9cdfa53ea. The coordinator independently reran two Chromium cases against actual current Knowledge components: unchanged entry identity preserves the dirty draft; another published version changes the viewed record identity and silently removes the editor/draft. Controlled reads/mutations, no real database. A scratch cleanup omission in the initial combined run was corrected, with that initial log retained; the final focused replay passes 2/2.

    Evidence: /Users/yannick/.codex/notes/tale-1000-additional/current-main-reconciliation/components/knowledge-replay.log. Installed external dependencies are reused; app/UI/shared source points at the isolated current tree. Browser runs retain the runner/browser version warning. These revalidations add no findings and include no production testing.

  2. yannickmonney commented on Oct 5, 2026

    @yannickmonney
    ContributorAuthor

    Independent exact-head review receipt for PR #4337 / TALE-322: ACCEPT at fe94746961e4d1d4e0110ee3865d048f5aa836d7. Focused hook regression passed 4/4 with one worker; the same test overlaid on origin/main failed 1/4 as expected. Exact-head CI was read once and all required checks passed (expected skips plus neutral Trivy). PR #4337 was squash-merged with merge commit bfb045985cf4b37f1b0d8ff0fa246aa1a85f0315.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions