Skip to content

fix(delphi): Clojure-parity math writers + committing write path in PostgresClient#2624

Draft
jucor wants to merge 1 commit into
spr/edge/a861cd87from
spr/edge/6324b652
Draft

fix(delphi): Clojure-parity math writers + committing write path in PostgresClient#2624
jucor wants to merge 1 commit into
spr/edge/a861cd87from
spr/edge/6324b652

Conversation

@jucor

@jucor jucor commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

The four math writers had zero live callers (verified: only commented-out refs
in test_postgres_real_data.py) and did not match the Clojure SQL. Rewrite them
to the verified Clojure statements:

  • write_math_main: caching_tick = COALESCE((select max(caching_tick)+1 from
    math_main where math_env=?), 1) upsert (postgres.clj:323-338). The prod TS
    prefetch (pca.ts:84-151) polls caching_tick > last, so this is fidelity-critical.
  • increment_math_tick: atomic INSERT ... ON CONFLICT ... math_tick+1 RETURNING
    (postgres.clj:292-295), replacing the read-modify-write.
  • add MathBidToPid model + write_math_bidtopid (net-new; participants.ts depends
    on it).
  • write_participant_stats: add the shared math_tick (Clojure writes all three
    data tables with one tick, conv_man.clj:158-169).

Add a committing write path _write_returning (engine.begin()) and route the four
writers through it: query() uses engine.connect() (SQLAlchemy 2.0
commit-as-you-go) which rolls back INSERTs on close. Mocked unit tests could not
catch this; the postgres integration test did. execute() now commits too.

Add global watermark reads for the poll loops: poll_votes_since (WHERE
created > wm ORDER BY zid,tid,pid,created, sign-flipped, postgres.clj:132-145)
and poll_moderation_since (postgres.clj:148-161). Add ORDER BY zid,tid,pid,created
to poll_votes so the full-history rebuild reproduces Clojure's row-insertion
order (base-cluster IDs seed k-means -> parity).

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

commit-id:6324b652


Stack:


⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

@jucor
jucor marked this pull request as draft July 18, 2026 02:43
@jucor
jucor force-pushed the spr/edge/6324b652 branch from b962042 to bb3b05d Compare July 18, 2026 13:28
@jucor
jucor force-pushed the spr/edge/a861cd87 branch from d65c2ef to 55b02d5 Compare July 18, 2026 13:28
@jucor
jucor force-pushed the spr/edge/6324b652 branch from bb3b05d to 9b25900 Compare July 18, 2026 13:32
@jucor
jucor force-pushed the spr/edge/a861cd87 branch from 55b02d5 to 7c607b1 Compare July 18, 2026 13:32
…ostgresClient

The four math writers had zero live callers (verified: only commented-out refs
in test_postgres_real_data.py) and did not match the Clojure SQL. Rewrite them
to the verified Clojure statements:

- write_math_main: caching_tick = COALESCE((select max(caching_tick)+1 from
  math_main where math_env=?), 1) upsert (postgres.clj:323-338). The prod TS
  prefetch (pca.ts:84-151) polls caching_tick > last, so this is fidelity-critical.
- increment_math_tick: atomic INSERT ... ON CONFLICT ... math_tick+1 RETURNING
  (postgres.clj:292-295), replacing the read-modify-write.
- add MathBidToPid model + write_math_bidtopid (net-new; participants.ts depends
  on it).
- write_participant_stats: add the shared math_tick (Clojure writes all three
  data tables with one tick, conv_man.clj:158-169).

Add a committing write path _write_returning (engine.begin()) and route the four
writers through it: query() uses engine.connect() (SQLAlchemy 2.0
commit-as-you-go) which rolls back INSERTs on close. Mocked unit tests could not
catch this; the postgres integration test did. execute() now commits too.

Add global watermark reads for the poll loops: poll_votes_since (WHERE
created > wm ORDER BY zid,tid,pid,created, sign-flipped, postgres.clj:132-145)
and poll_moderation_since (postgres.clj:148-161). Add ORDER BY zid,tid,pid,created
to poll_votes so the full-history rebuild reproduces Clojure's row-insertion
order (base-cluster IDs seed k-means -> parity).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

commit-id:6324b652
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.

1 participant