FORGE-85: assign deployment_events.seq as max(seq) + 1 #713
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gmackie/ForgeGraph!713
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "FORGE-85-seq-max-plus-one"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part 7b of FORGE-85 (D1 Phase 2, parent FORGE-69). Stacked on #745 (D1 constraint-message fix). #712's index is applied and valid in production (migration 0121).
appendDeploymentEventassigns seq in the insert:INSERT … SELECT coalesce(max(seq), 0) + 1 FROM deployment_events, retried with jittered backoff (bound 100) on a collision withdeployment_event_seq_unique_idx. No writer uses the serial sequence; the PG default stays until the D1 schema replaces it.getDeploymentEvents(…, afterSeq)never skips a late-committing event, which a sequence allowed. On D1 each statement runs alone on the single writer, so the retry never fires.appendDeploymentEventsappends a batch in order. The agent report route uses it instead ofPromise.all, whose parallel appends would only collide and whose order was arbitrary.payloadandcreated_atare bound through the column encoders and typed by the INSERT target (no::jsonb), so the identical statement runs on D1;deployment-events-seq-indexleaves d1-known-failures.txt.created_atvia the encoder also matters because; a raw Date insqlisn't serialised by postgres-js once the server infers a timestamp.Verification
deployment-events-seq.concurrency.test.ts(real Postgres): 80 concurrent appends across two deployments over a 20-connection pool, with a cursor reader polling throughout. It asserts distinct, gap-free seqs and that the reader saw every event exactly once, in order. With retries disabled it fails ondeployment_event_seq_unique_idx, so the contention is real. CI caught that a fixed 20-attempt bound could starve one writer under 80-way contention; the jittered backoff fixes it. Passes repeatedly on PG16, including a 300-writer stress run.deployment-events-seq.database.test.ts: ordered appends, payloads, cursor reads (PGlite + PG16). 7a's lag test passes against the new writer.test:d1) green including both seq test files; api/web tsc clean; agent and deploy route suites (142) green.🤖 Generated with Claude Code
Preview environment is live: https://pr-713-forgegraph.forgegraf.com
Deployed
034d9c7dwith the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.Preview environment is live: https://pr-713-forgegraph.forgegraf.com
Deployed
034d9c7dwith the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.034d9c7d3aa4ec761370a4ec7613708ee8c5617c8ee8c5617ce69fea2b56e69fea2b5697531688cbPreview environment is live: https://pr-713-forgegraph.forgegraf.com
Deployed
97531688with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.97531688cb1f6e651329Preview environment is live: https://pr-713-forgegraph.forgegraf.com
Deployed
1f6e6513with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.Preview environment is live: https://pr-713-forgegraph.forgegraf.com
Deployed
1f6e6513with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.