Repository navigation
store: implement TaskApplier in memory and postgres backends - #630
Conversation
672cec4 to
ff9a2cd
Compare
|
Have you tried directly stacked on common-ground branch? https://docs.github.com/en/pull-requests/get-started/about-stacked-prs |
ff9a2cd to
72b0cfa
Compare
gh stack only supports same-repo PRs. This PR is created from my fork |
- Add additive runner control columns (generation, actor_uid, runnable, active_run_id, run_seq, runner_token_hash, runner_token_confirmed, claim_nonce, last_acked_runner_seq) to tasks in schema.sql. - Add PrepareTaskRowForApply and OverlayTaskGeneration helpers in internal/store so both backends normalize metadata, scrub Task.Status via StoredStatus, and advance Generation identically. - Implement TaskApplier (Apply and GetTaskRow) on memory.MemoryStore and postgres.Store, preserving saved_at list ordering on updates and retrying concurrent insert races. - Add unit and Postgres integration tests covering concurrent inserts, StoredStatus scrubbing, no-op current returns, saved_at ordering, and DeleteTaskRow sentinel deletion. Signed-off-by: siyuanfoundation <[email protected]>
72b0cfa to
b74ab57
Compare
|
/cc @mayawang |
|
/cc @itssimrank |
mayawang
left a comment
There was a problem hiding this comment.
LGTM, solid locking and the migration is rollout-safe. One thing to fix before the runner handler starts calling Apply: in Postgres, legacy SaveTask/UpdateTaskStatus bump Status.Generation in the JSON but not the generation column, and scanTaskRow then overwrites the JSON value with the column (OverlayTaskGeneration). So a task at gen 3 reads back as 1, and the first Apply writes 2. Taking max(column, json) in scanTaskRow would fix it, plus a test for legacy write then Apply. Memory already gets this right.
Signed-off-by: siyuanfoundation <[email protected]>
Good catch! Fixed in the 2nd commit |
Summary
Implements
store.TaskApplier(ApplyandGetTaskRow) across the PostgreSQL and in-memory store backends (building on #591, Sub-Workstream A of the M0 runner plan) while keeping all existingstore.Storetask methods (SaveTask,GetTask,ListTasks,UpdateTaskStatus,SetTaskDeleteTime,DeleteTask) working unchanged.Key Changes
internal/store/task_row_normalize.go): AddedPrepareTaskRowForApplyandOverlayTaskGenerationso both backends enforce identical metadata defaulting,store.StoredStatusscrubbing (#515), andGenerationadvancement (1on insert,stored.Generation + 1on update).internal/store/postgres):TaskRowcolumns (generation,actor_uid,runnable,active_run_id,run_seq,runner_token_hash,runner_token_confirmed,claim_nonce,last_acked_runner_seq) totasksviaALTER TABLE tasks ADD COLUMN IF NOT EXISTSinschema.sql(schema.goupdated alongside).GetTaskRowand transactionalApply(SELECT ... FOR UPDATE, single retry on concurrent insert23505unique violation so losing creators observe the winner's row, andsaved_atlist-order preservation on updates).internal/store/memory): BackedMemoryStore.taskswith*store.TaskRowand implementedGetTaskRowandApply.internal/store/{memory,postgres}/store_test.go): AddedTestTaskAppliercovering missing-row no-ops, nil-Taskrejection, 8-way concurrent insert races,StoredStatusscrubbing of live vs. AX-owned states, in-placecurrentmutation protection,saved_atlist ordering on updates, andDeleteTaskRowpointer-identity deletion.Testing
make verify(buf format,buf lint,buf generate,go mod tidy,go fmt,golangci-lint—0 issues)go build ./cmd/ax ./cmd/ax-server ./cmd/ax-task-runnerAX_TEST_POSTGRES_URL='postgres://...' go test -v -race -count=1 ./internal/store/postgres/...(postgres:17-alpine— all 9 tests pass)go test -race -count=1 ./...(all test packages pass)