Name: [Campaign] Brain v17 Complete: v1.4 + v2.0 Foundation — WI-1..WI-11

State: Failed finished in 19m

PR State: merged

PR Author: David Tran

PR Author Email:

PR: #22

Committer: David Tran

Committer Email: davidtran.hp@gmail.com

Commit: bfce74a14cd125b9f91ecabd7cbfb6926393fec6

Description:

                                            [REF] viin_brain: drop transient sequence field, order collab steps by id (H3+M5)

The previous _append_step read the latest sequence and wrote
last.sequence + 1 with no row lock. Two concurrent transactions
appending to the same page therefore raced — both saw the same
"last" record and both tried to insert the next sequence value,
producing duplicate sequences (and an inconsistent replay order
on reconnect).

Drop the sequence field entirely and rely on the auto-incremented
id column. PostgreSQL id is monotonic per-table, which is exactly
what a relay buffer needs: stable replay order across reconnects.
The buffer is not authoritative history (the source of truth is
viin.brain.page.content_html), so gap-free numbering is not a
requirement; only deterministic ordering is.

Migration: TransientModel column drop is handled by the ORM at
_auto_init during module update — no manual migration script
needed. New code never references sequence so prune logic and
history shape continue to work after the column disappears.

Also move the json import in viin_brain_collab_step.py to the
module top so it does not happen on every _get_history call (M5).

Tests:

  - test_append_step_single: drop sequence assertion.
  - test_append_step_ordering: rewrite to verify id order matches
    the order callers invoked _append_step (and that step_json
    payloads come back in append order).
  - test_rolling_window_trim: verify pruning by inspecting
    surviving step_json values rather than sequence numbers.
  - test_get_history_order_and_shape: drop sequence key assertion;
    add explicit append-order assertion across client_id values.
  - test_history_endpoint_returns_steps: drop sequence key assertion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
                                            

Branch: 17.0

Instance ID: 0

Age:

Up-time: