Skip to content

api: move the create path's sandboxes writes into sandbox-store - #1329

Merged
ac-pplx merged 1 commit into
mainfrom
ac/lifecycle-move-create
Nov 3, 2026
Merged

ac-pplx merged 1 commit into
mainfrom
ac/lifecycle-move-create

Conversation

@ac-pplx

@ac-pplx ac-pplx commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Mechanical move, no functional change. The sandboxes row writes listed below move into pplx-space-sandbox-store with their SQL byte-for-byte; callers keep their locks, transactions and error handling. Everything else is doc comments, plus three store tests that pin the moved statements. Part of the wave-2 stack (1 of 10, on main); it lands with the stack.

Summary

The api controller finalized a created sandboxes row, and deleted a failed create's row, with inline SQL. This moves those six statements into the store's create module (now pub mod). SQL is byte-for-byte except for binds. Callers keep transactions, error handling and logging. The store functions take any executor, and every bind encodes the same Postgres type as before. The api keeps finalize_created_sandbox as a wrapper that converts OperationId.

Moved (old → new):

  • api::controllers::sandbox::queries::finalize_created_sandbox's UPDATE → sandbox_store::create::finalize_created (operation step; the WHERE CAS is the guard).
  • queries::create_with_sandbox_id_inner's UPDATE … SET active_node_id → create::record_created_placement (observed projection; id only).
  • 2× DELETE FROM sandboxes WHERE id = $1 in create_with_sandbox_id_inner and 2× in updates::rollback_created_sandbox → create::delete_failed_create (operation step; no lifecycle predicate).

sql! locators change: the two UPDATEs now carry /*pplx_space_sandbox_store::create:<line>*/ (seen in pg_stat_activity and query monitoring). The DELETE still has none.

Baseline: sandbox_writes drops queries.rs (4 → gone) and lowers updates.rs (4 → 2). queries.rs's file_size cap drops from 2571 to 2527; updates.rs stays at 1008 (already over on main, advisory).

Validation

At ce4ec1989:

  • SQL text vs. old, by script: 6/6 identical.
  • cargo nextest run -p pplx-space-sandbox-store -p pplx-space-api --all-features: 2168 passed, 1 config skip, 0 dependency skips.
  • Mutation (reverted): dropping AND restore_lease_token = $6 fails create_postgres_tests::create_finalization_accepts_operation_leased_restoring_state.
  • cargo clippy --workspace --all-features -D warnings: clean.
  • Kind, fresh cluster, images at this head. Up 24m54s; scripts/tests/smoke-kind-typed.sh all 52m07s: ECW 85 passed, 0 failed, 3 inconclusive; native 35 passed. The cold and warm-pool create scenarios passed rerun with SPACE_SMOKE_KIND_COLD_RECEIPTS; local.restarted_btrfs_send_is_rejected_and_retried needs otel mode (unrelated).

At 3e6c98eb (final), which differs only in store doc comments and new store tests; compiled statements are identical apart from sql! locator line numbers:

  • cargo nextest run -p pplx-space-sandbox-store --all-features: 22 passed, 0 skipped (Postgres ran), incl. the new tests/create_finish_tests.rs: delete_failed_create_removes_the_row_whatever_its_lifecycle, record_created_placement_records_the_node_on_any_lifecycle, finalize_created_records_command_readiness_on_a_creating_row.
  • Mutations, each alone, reverted: M1 AND lifecycle <> 'deleting' fails delete_failed_create_…; M2 dropping placement_changed_at = NOW() fails record_created_placement_…; M3 .bind(command_ready) fails finalize_created_records_….
  • Store clippy (--all-targets --all-features -D warnings), store rustdoc (-D warnings), cargo fmt --check, cargo check -p pplx-space-api --all-features: clean. cargo arch vs. main's baseline: 0 required. No existing test changed.

Severity and risk

Severity: n/a (refactor). Risk: low; statements, binds and caller handling are unchanged. Revert to roll back.

Rollout

Old and new pods issue the same statements bar locator comments. No migration.

Not covered

  • No api test reaches delete_failed_create through a failed create, and the Kind runs were not checked for one. The new store tests pin the statement itself; its four call sites differ from main only in the call.
  • record_created_placement runs in the Direct create tests, but only the new store test asserts its effect, because finalize_created rewrites active_node_id afterwards.

Open PRs that will need to rebase

AI assistance: Claude Code (an AI agent) wrote the code change and this description.

After the wave-2 restack

This PR is one layer of a 10-PR stack, restacked onto main c5fdf0c7 (which includes #826) and then rebased mechanically onto 42a99002, which changed only baseline context lines, in order #1329 → #1336 → #1338 → #1339 → #1342 → #1347 → #1333 → #1335 → #1328 → #1332. The validation earlier in this description ran at pre-restack heads; this layer's head is 4a6d0e9e.

@github-actions github-actions Bot added the triage:pending Waiting for a maintainer to triage label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! A SPACE maintainer will take a look.

CONTRIBUTING.md explains how we review outside contributions.

@ac-pplx
ac-pplx force-pushed the ac/lifecycle-move-create branch from ce4ec19 to 3e6c98e Compare November 2, 2026 20:58
@ac-pplx
ac-pplx force-pushed the ac/lifecycle-move-create branch from 3e6c98e to c0d143f Compare November 2, 2026 23:25
@ac-pplx
ac-pplx added this pull request to stack #1382 November 3, 2026 03:50
@ac-pplx
ac-pplx marked this pull request as ready for review November 3, 2026 03:50
@ac-pplx
ac-pplx marked this pull request as draft November 3, 2026 03:52
@ac-pplx
ac-pplx force-pushed the ac/lifecycle-move-create branch from c0d143f to e26649a Compare November 3, 2026 06:00
@ac-pplx
ac-pplx marked this pull request as ready for review November 3, 2026 06:29
The create path finalized its row and removed the row of a failed create
with inline SQL in the api controller. Move those six statements into
pplx-space-sandbox-store's create module, byte-for-byte except for binds:

- finalize_created: the creating/restoring -> reported-state CAS
  (operation step)
- record_created_placement: the post-create active_node_id write
  (observed projection)
- delete_failed_create: the failed or rolled-back create's row delete,
  shared by the four call sites (operation step)

Callers keep their transactions, error handling and logging. The store
functions take any executor, and every bind encodes the same Postgres
type as before; the api keeps finalize_created_sandbox as a thin wrapper
that converts OperationId. The sql! locators of the two UPDATEs now name
the store module. The DELETE keeps its unlocated text.

Three Postgres-backed store tests characterize behaviour no existing
test pinned: delete_failed_create removes the row and its cascading
dependents in every lifecycle, record_created_placement writes the node
and placement_changed_at whatever the lifecycle, and finalize_created
records command_ready_pending as the inverse of command readiness on a
creating row.

The sandbox_writes ratchet drops queries.rs and lowers updates.rs from
4 to 2; queries.rs's file_size cap drops to 2527.
@ac-pplx
ac-pplx force-pushed the ac/lifecycle-move-create branch from e26649a to 4a6d0e9 Compare November 3, 2026 21:23
@ac-pplx
ac-pplx added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 09c42cd Nov 3, 2026
23 checks passed
@ac-pplx
ac-pplx deleted the ac/lifecycle-move-create branch November 3, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage:pending Waiting for a maintainer to triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants