Skip to content

web(drafts): preserve edits through stale saves and navigation - #67

Merged
TusanHomichi merged 11 commits into
mainfrom
codex/34-draft-refused-text
Oct 2, 2026
Merged

TusanHomichi merged 11 commits into
mainfrom
codex/34-draft-refused-text

Conversation

@TusanHomichi

@TusanHomichi TusanHomichi commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Problem and behavior

A stale autosave reloaded the winning draft and erased the losing writer’s edits. The draft workspace now keeps divergent narratives, deletions, and ratings in a read-only, copyable recovery panel. The writer chooses what to copy back and save, or discards it. Buffers stay in memory and clear on deliberate navigation.

Saves serialize against the accepted revision. SPA departure waits for pending ordinary saves with the editor mounted; failed saves offer Retry save, and native unload warns while edits or fresh recovery are pending. Reload latest draft retries only the GET and preserves recovery text. Origin guards keep late loads and workflow replies tied to their draft and controller.

When submission or finalization freezes a queued save, local fields remain labeled and selectable while the authoritative copy loads. A typed refusal is distinguished from an unconfirmed transport outcome. The server copy then returns as the main content, with local differences kept separately. Review, finalize, and amend actions wait until recovery is resolved.

Fields pause during workflow requests and accepted navigation; interrupted navigation can resume without clearing buffers. Invalid numeric draft/version URLs show an error before fetching and allow valid SPA reentry.

Scope and issue

Closes #34. Recovery follows ADR 0008: buffers stay in memory, with no persistence or automatic merge. Existing service, API, schema, and record-integrity contracts are unchanged. The primary issue owns the execution graph and historical evidence.

Verification

Final candidate b515cb92f18de119ca56592c0289213d3ded3150, tree 67a472a327a9821df872cead15fa08bbfad2a420, includes main e0679bc.

  • All nine required local commands passed: web install/check/build, Rust format/Clippy/tests/build, Chromium installation, and browser tests. 176 Rust tests and 56 browser tests passed; exact-revision local receipt.
  • Hosted CI passed all nine gates with the same 176 Rust and 56 browser results. Its checked-out merge tree equals the candidate tree; original logs and API records were independently verified.
  • The final focused run passed 13/13 cases, including all seven predecessor failures and six frozen-save controls. The editable-stale Finalize control stays visible with its existing refusal guard; frozen pending/unresolved recovery holds the control. The failed predecessor receipt remains preserved.
  • Independent source review accepted the exact final four file hashes. All 14 existing review threads are resolved. The latest automated review summary still names predecessor 678b6fe; no new automated approval is claimed for this head.

Fixtures use invented data. Debug browser checks read built assets from disk and do not prove release embedding. Synthetic stranded-history coverage is qualified separately from natural navigation overlap. Hosted binary/static outputs were not downloaded; no hosted output hashes are claimed.

Merged to main as 03cc8c77af26183dd7a0a61870152d21757dcb85. The merged tree equals the tested candidate tree; local main was fast-forwarded and task-owned branch/worktree cleanup was verified. Merge verification receipt.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T21:44:30.503919Z 678b6fe New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c955ce220

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/lib/drafts/editor.svelte.ts Resolved
Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved
Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved
Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved

@TusanHomichi TusanHomichi left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Merge review at 0c955ce: hold this PR. I inspected the controller/route lifecycle and agree with the four existing, unresolved Codex findings; this summary does not create duplicate findings. pr-gate run 34661983530 is green, but it does not cover these boundaries.

Required repairs and regression evidence:

  1. DraftEditorController::destroy() cancels the only pending autosave inside the 600 ms debounce window. Preserve/flush legitimate working-copy edits against their original draft identity before allowing navigation, or explicitly warn/block navigation. Do not mistake the requirement to discard refused recovery buffers on navigation for permission to silently discard unsaved ordinary edits. Add a real navigation-before-debounce regression.
  2. received() ignores successful saves, so following the offered copy-back-and-save recovery path leaves refusalUnresolved set. Make successful resolution clear the matching guard without requiring an additional discard action, and without allowing unrelated/failed saves or a first attempted workflow action to clear other unresolved text. Test copy-back -> successful save -> submit/finalize without discard.
  3. The identity-change cleanup replaces the controller but leaves the page-level refusal guard set. Keep all refusal/guard state in the same draft lifetime, and prove that client-side navigation to another [id] does not leave it blocked with no recovery panel capable of resolving it.
  4. recoverFromRefusal() resumes after await load() using the current editor, even when load() returned null because the route changed. Capture the originating controller and generation/draft identity and invalidate the complete continuation before it updates buffers, errors, or guards. Distinguish obsolete navigation results from actual reload failures. Hold the refusal-triggered GET, navigate to another draft using SPA navigation (not a full page reload), then release it; assert no old content, error, or guard appears in the destination. A different-form destination and an A -> B -> A navigation are useful checks against field-ID coincidences and identity-only guards.

Keep the existing recovery text memory-only and read-only; no automatic merging/resubmission. Retain the existing failed-reload, late-typing, and repeated-refusal coverage. Revalidate against current main, which now includes #68, and rerun the full repository/browser gates. #59 remains open.

Verification limitation: this review used source inspection and GitHub CI/review evidence; no independent local Rust/browser run was performed.

A refused save reloaded the winning copy and took the writer's own text
with it, turning an honest concurrency refusal into lost work (#34).

The draft working copy, its autosave chain, and the recovery buffers now
have one owner: `web/src/lib/drafts/`, which the route page reads instead
of holding a second copy of every editable value (#59, partial). The
refusal keeps every save the contract refused, newest first, with
anything typed while the request was in flight, shown read-only,
copyable, and field-labelled. Nothing is merged, resubmitted, persisted,
or sent anywhere, and the buffers die with the draft identity.

Recovery state and its guard share the controller's lifetime, which is
what the review's four lifecycle findings needed:

- a queued ordinary edit is saved when the route goes away instead of
  being cancelled with its debounce timer; refused recovery text is not
  resubmitted, and a refusal the page has not answered yet is skipped;
- the workflow-act guard is per refusal, and a save the writer makes
  after seeing a refusal resolves exactly the buffers that save carries —
  copying the text back and saving unlocks submission and finalization
  without an extra discard, while another refusal's uncopied text keeps
  holding the act;
- the guard lives with the buffers in the controller, so a draft identity
  change takes it away instead of leaving a page blocked with nothing to
  dismiss;
- the recovery continuation captures the controller and the route it
  started on, so a refusal whose reload lands after the page moved on
  touches no buffer, no error, and no guard of the draft now on screen.

Browser proof in `web/e2e/draft-recovery.spec.ts` now runs eleven
scenarios over two real writer contexts, synchronized on held requests:
the loser copies their sentence; text typed during a pending request and
text typed while the winner was reloading both stay recoverable and never
reach the server; a failed reload keeps the buffer; a second refusal adds
to the first; a workflow act makes no request until the writer
acknowledges, and then does; copy-back and save lifts the guard without a
discard; an edit made inside the debounce window survives navigation; a
refusal dies with its draft while another draft's acts work; and a
refusal that lands after the page moved on changes nothing. Each fix was
falsified against the behaviour it replaces before it was kept.
@TusanHomichi
TusanHomichi force-pushed the codex/34-draft-refused-text branch from 0c955ce to afed873 Compare September 12, 2026 01:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afed87374b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/lib/drafts/editor.svelte.ts Resolved
Comment thread web/src/lib/drafts/editor.svelte.ts Resolved
@TusanHomichi

Copy link
Copy Markdown
Member Author

Repairs at afed873, rebased onto main (7936a4e, which contains #68)

All four lifecycle findings are fixed, and each fix has a regression that fails against the behaviour it replaces.

1. A queued ordinary edit survives navigation. destroy() now sends the edit the debounce had not yet sent, instead of cancelling it with the timer. It waits for an in-flight save first so it carries the revision the server reached, it never resubmits refused recovery text, and a refusal the page has not answered yet is skipped. Regression: type, navigate to Home inside the debounce window, then assert the server holds the text and exactly one PUT was made. Falsified by removing the teardown save: the test fails.

2. Copy-back plus a successful save resolves the matching refusal. The guard is per buffer now: a save the writer makes after seeing a refusal resolves exactly the buffers whose text that save carries (field by field, ratings included), and nothing else. Regressions: copy the refused text back, wait for Saved, then finalize without any discard (passes); and with two refusals, putting back only the newest one keeps the act held and shows the message, while putting back the older one as well lets it through. Falsified by (a) never resolving on success and (b) resolving every buffer on any success — both fail.

3. Refusal state lives with the draft. The buffers and the guard moved into DraftEditorController: unresolved is derived from that controller's own buffers, so it dies with the draft identity instead of surviving as page state. Regression: refuse on one draft, navigate to another draft (a different form, different field identities) and back, and assert no panel, no refused text, no error, and that each draft's own submit actually goes through. Falsified with guard state declared outside the controller's lifetime: the test fails.

One honesty note on this one: the component-reusing [id] → [id] transition the finding describes has no shipped link — every route into a draft passes through Home, My records, or an enrollment page — so the test drives the reachable client-side navigation and asserts the acts work on both drafts. The state is per controller, so the unreachable transition cannot leak it either; the helper for a direct hop is documented as unused until such a link exists.

4. A late recovery continuation changes nothing. recoverFromRefusal captures the controller, the draft, and the requested version before its await, and returns without touching buffers, error, or guard when any of them changed; an obsolete answer is distinguished from a failed reload, which still reports itself. Regression: hold the refusal-triggered GET, navigate to another draft, release the GET, and assert no old content, error, or guard appears there (and none when returning to the first draft). Falsified by removing the identity check: the test fails.

The existing coverage is retained (failed reload, late typing, repeated refusals, memory-only/read-only buffer, no automatic merge or resubmission), and the browser suite is 21 scenarios green locally. pr-gate run 34664913384 failed in retention::authority_and_policy_failures_leave_no_partial_state — a test this branch does not touch (inject: Database(... "trigger fail_retention_audit already exists")). It passes 12/12 locally, and the same head passed this gate before the rebase; the job has been re-run.

@TusanHomichi

Copy link
Copy Markdown
Member Author

pr-gate on this head: the failure is pre-existing, and filed as #70

The rerun failed at exactly the same place as the first attempt:

thread 'authority_and_policy_failures_leave_no_partial_state' panicked at crates/consolebook-server/tests/retention.rs:607:212:
inject: Database(SqliteError { code: 1, message: "trigger fail_retention_audit already exists" })

That is a test this branch does not touch: git diff --stat 7936a4e..afed873 is docs/development.md plus four web/ files — no Rust at all, so the retention test and the code it exercises are byte-identical to main. Locally on this head, cargo test --workspace is green twice over, the retention binary is 10/10 across six consecutive runs, and the test alone is 12/12. The same branch passed this gate before the rebase.

The failing statement is the test's own second CREATE TRIGGER, after a DROP TRIGGER that reported no error — a fixture-level ordering problem with pooled connections, not an assertion about product behaviour. I filed it as #70 with the exact evidence and three concrete fixes rather than folding a retention-test change into a web-only PR.

Everything this PR changes is verified locally at afed873: npm run check and npm run build clean, cargo fmt --check clean, cargo clippy --workspace --all-targets -- -D warnings clean, cargo test --workspace 27 binaries with 0 failures, and the browser suite 21/21 — including the four new lifecycle regressions described above.

@TusanHomichi TusanHomichi changed the title web(drafts): keep the losing writer's text after a stale save web(drafts): preserve edits through stale saves and navigation Sep 30, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3581462bbd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/lib/drafts/editor.svelte.ts Resolved
Comment thread web/src/lib/drafts/editor.svelte.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e16723500c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/lib/drafts/editor.svelte.ts Resolved
Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9995a61dc6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 526844ff79

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8fbfd69ede

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8477e8941c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved
@TusanHomichi
TusanHomichi merged commit 03cc8c7 into main Oct 2, 2026
1 check passed
@TusanHomichi
TusanHomichi deleted the codex/34-draft-refused-text branch October 2, 2026 02:23
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.

Draft workspace: keep the losing writer's text visible after a stale-save reload

1 participant