Skip to content

feat(feedback): freeze optional completion copies - #41

Merged
xgame92 merged 4 commits into
mainfrom
devin/frm18-feedback-foundation
Dec 4, 2026
Merged

xgame92 merged 4 commits into
mainfrom
devin/frm18-feedback-foundation

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Part of the optional feedback-copy work in FRM-18. This adds the smallest server-held Forms foundation: a reviewed connector record, a response-scoped preview, and an immutable outbox row that commits with completion in one D1 batch.

Ordinary completion remains available as an authenticated bodyless POST when no copy is chosen; supplied JSON is strictly validated. When a preview is supplied, completion compares the server-derived answer_revision, pinned definition hash, exact frozen projection, connector identity/version/generation, and form inside the batch. A save, connector change, stored-data change, or withdrawal that wins first cannot produce a stale copy. Exact completion retries remain idempotent through the response id key.

The projected copy is limited to the declared choice or rating, the explicitly selected note, and declared static context. Detached answers, response credentials, browser credentials, network addresses and user agents are not projected. New previews supersede earlier previews under the same atomic guard so the response secret cannot accumulate preview rows without bound. Stored preview data is parsed back strictly, and server-owned payload envelope fields cannot be replaced by it.

This slice intentionally does not send anything to Track, provision or activate real grants, rotate keys, or include a sender claim/retry worker. The plaintext connector generation is server-held fixture authority only so the exact frozen payload can be tested; production provisioning and sealing remain later slices.

How it was tested

  • pnpm verify passes on exact head 6df5ad646c2dd4f8835d9a8bafca79060bf1c0cf.
  • pnpm test:e2e passes on the same tree: 174 passed, 8 skipped.
  • Focused feedback-copy fixtures: 18 passed, covering bodyless and strict JSON completion, no connector, no selection, prepared/committed payload equivalence, exact retry, malformed connector data, malformed note, omitted note, detached-answer exclusion, changed answers, connector version changes, invalid generation authority, exact frozen projection/authority losing-order batches, damaged stored preview data, concurrent completion, save-before-preview losing order, preview supersession, and withdrawal ordering.
  • Hand-written SQL guard fixtures: 19 passed together in the focused run.
  • Hosted CI is green: check, e2e, changes, cla and Devin Review.
  • Checked the conditional storage disclosure page manually at 390 px and 320 px; no horizontal scrolling and the feedback sections remain readable.

390 px:

Stored disclosure at 390 pixels

320 px:

Stored disclosure at 320 pixels

  • pnpm verify passes
  • pnpm test:e2e passes
  • Tests cover the change (every bug fix has a test that fails without it)

Deploy notes

  • Adds a generated D1 migration (commit it; never edit one that has been merged)

Keep ordinary completion unchanged while letting a server-held feedback preview commit with completion as one D1 batch. The frozen copy is compared against the response answer revision, pinned definition, connector version and exact projection, so a save, connector change or withdrawal that wins first cannot produce a stale copy.
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Keep bodyless authenticated completion as the explicit no-copy path while strictly validating supplied JSON. Compare the exact frozen projection, connector and generation again inside the completion batch, and reject damaged stored preview data before it can shape the payload.

@xgame92 xgame92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The authenticated bodyless no-copy path and the D1 outbox guards passed independent local checks on Node 24.11.0. All 64 existing feedback-copy, persisted completion, withdrawal, and SQL tests passed.

One completion retry case still fails. An authenticated request reads the open response. An identical request then commits and removes the preview. If the first request resumes and calls completionCopy after that commit, it returns 409 with feedback: stale before completeResponse rechecks the response's completion state. The outbox still contains exactly one row. The same completion request can therefore report failure even though the submission and copy committed.

I reproduced the ordering against the migrated local D1 database using the test Worker. Capture the open response row and pinned definition, complete through the API with the prepared preview, verify one outbox row and no remaining preview, then call completeResponse with the original open row and same preview ID. It rejects where the existing completion contract requires an idempotent success. The current parallel test does not force the preview lookup to lose this ordering.

Please route the preview refusal through a fresh check for the same authenticated response before returning stale, preserving refusal for a still-open response and preserving the withdrawal behavior. Add a deterministic test for that order and assert both the completion result and the single frozen outbox row.

Recheck the authenticated response when a feedback preview has just been cleared so a delayed identical completion can replay the stored success instead of reporting a false stale failure. Keep the stale refusal for a response that is still open and cover the losing order against migrated local D1.
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Addressed at exact head 99e193141de7456474ace692575faaba4a0a01c3 (replying top-level because the finding arrived as one review rather than a line thread).

completeResponse now catches only the feedback-preview stale refusal, freshly rereads the same authenticated response by id and secretSeal, and replays success when that response is already complete. A missing row still returns 404 and a still-open response still receives the original stale-preview refusal, so withdrawal and genuine stale behavior are unchanged.

The new migrated-D1 regression forces the exact losing order: capture the open row and preview, complete the identical request through the Worker, verify the preview is gone, then resume the delayed request with the original open row and same preview ID. It succeeds and the single feedback_outbox row is byte-for-byte unchanged.

Validation at the pushed head:

  • pnpm verify passed
  • focused test/feedback-copy.test.ts: 19/19 passed
  • focused test/auth.test.ts rerun after one transient rate-limit ordering failure in the first full run: 16/16 passed
  • hosted CI green: check, e2e, changes, Secret scan, cla, Devin Review

Current main was merged in for the secret-scan commit; the PR remains draft and unmerged.

@xgame92 xgame92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-reviewed exact head 99e193141de7456474ace692575faaba4a0a01c3 on current main. The earlier stale-preview race is resolved. The delayed identical completion now succeeds after the winning request commits, with exactly one unchanged outbox row. A superseded preview with a different projection still returns 409 while the response stays open. When withdrawal wins the same ordering, the delayed completion returns 404 and the outbox stays empty.

The local Windows run on Node 24.11.0 passed all five selected test files. Three targeted losing-order checks also passed independently on migrated local D1. Hosted workerd checks, Playwright, CLA, and the secret scan passed on this head.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Exact-head independent re-review of 99e193141de7456474ace692575faaba4a0a01c3, scoped to the retry race from the blocking review. Review only; nothing merged or deployed.

Decision: approve-equivalent. The race is closed in exactly the shape the review required, and I independently reproduced the suite: npx vitest run --project worker test/feedback-copy.test.ts at this head passes 19/19 in an isolated worktree (workerd, migrated local D1).

Delayed same-request replay — correct in completeResponse (responses.ts): a feedback: stale refusal out of completionCopy is caught, the same authenticated response is re-read fresh by (id, secretSeal), and only two outcomes follow: completedAt !== null → idempotent success return (the winner's commit is the completion contract fulfilled); otherwise the original stale refusal is rethrown. Any non-stale refusal propagates unchanged. Because the winner's batch sets completed_at and clears previews atomically in one batch, the losing request can never observe one without the other, so the re-read cannot mistake a half-committed state.

Exactly one unchanged outbox row — the deterministic test is the reviewer's reproduction step for step: capture the open row and pinned definition, complete through the API with the prepared preview, assert one outbox row and zero remaining previews, then drive completeResponse with the original open row and same preview id. It resolves, the outbox count stays 1, and the row is deep-equal before and after — the loser writes nothing. The atomic SQL guards behind that were already verified in the first round and are unchanged at this head.

Genuine stale-open refusal intact — when the response is still open and the preview genuinely does not match (including the corrupted-generation case), the refusal survives: 409 with feedback: stale, zero outbox rows, response still incomplete — pinned by the two stale/authority tests.

Withdrawal intact — the withdrawal-wins race still yields [0, 0, 0] with no copy written, and withdrawal of a finished response removes the unclaimed copy row along with the response.

One observation, non-blocking: the replay path returns success to the loser without re-verifying that the committed copy matches the preview id the loser carried. That is correct under the completion contract — the winner was the same authenticated request carrying the same preview, and the outbox row is frozen at commit — but it is worth naming: idempotent replay here means "the completion you asked for happened", not "your exact copy attempt did". No change needed.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Thanks for the exact-head re-review. No further changes are needed from my side; 99e193141de7456474ace692575faaba4a0a01c3 remains draft and unmerged for the orchestrating review/merge step.

@xgame92
xgame92 marked this pull request as ready for review December 4, 2026 00:23
@xgame92
xgame92 merged commit 541e4fb into main Dec 4, 2026
6 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant