Skip to content

Keep the cancellation test waiting on an unfinished write - #932

Merged
zlareb1 merged 1 commit into
mainfrom
fix/sdk-close-test-inflight
Nov 18, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
fix/sdk-close-test-inflight

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The SDK close cancellation test waits on an unfinished write even when its coalescing window expires.

Why

The test gates bulk writes, but the first calls in a coalescing window are point writes. If the window expires during setup, the bulk gate alone does not keep close() pending. Gating the first point write establishes that precondition, and asserting cancel() succeeds checks it explicitly.

Scope and risk

Two lines in one SDK unit test. The test still requires CancelledError, successful results for all nine writes and a closed transport. No SDK implementation, timeout, batching window or assertion is weakened.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: reverting removes the test precondition; no stored data changes.

Tests

Existing CI records this exact test failing because awaiting close() did not raise CancelledError. Static source review shows that point writes enter the coalescer's tracked in-flight set before their callers wait, so the shared gate keeps close() pending independently of bulk formation. The failure log does not record the incident's clock or task state.

Local checks cover Python AST syntax, whitespace and public prose only. The small scheduling witness and corrected test remain unrun: the resource guard refused the witness before execution because available memory was below its admission floor. No retry or dependency change followed. Full CI on the final commit is required.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated: Codex wrote the two-line test edit. Static review checked point-write tracking, cancellation propagation and the unchanged write assertions.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: no generated files are affected.
  • A new migration is additive and numbered after the latest on main; no migration changes.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version; no plugin files change.
  • The frontend builds and its tests pass, if frontend/ changed; no frontend files change.
  • Docs describe the system as it is; no operator steps or wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

A bulk-only gate does not hold point writes when the batching window
expires. Hold the first point write too and assert cancellation is
accepted before checking that close preserves every pending write.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 06ebfb3 into main Nov 18, 2026
44 checks passed
zlareb1 added a commit that referenced this pull request Nov 18, 2026
Related: #855
Related: #932

### Changelog category (leave one):

- Build/Testing/Packaging Improvement

### Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The first-set cancellation test controls the clock so its writes share one coalescing window.

### Why

The test requires a bulk flush behind an unfinished point write. Yielding a fixed number of event-loop turns does not establish that all three calls fit inside one 200 ms window. If the window expires before the third call submits, that call can become a point write in a new window and finish while the earlier write waits.

The existing manual clock holds this test in the window it intends to exercise. Explicitly closing the window still starts the flush, and the test still requires the cancelled caller's write to land before that flush.

### Scope and risk

One test gains the existing clock fixture. Its cancellation, gates, both ordering assertions and scheduling yields remain unchanged. The SDK implementation and 200 ms window are unchanged. The separate close-cancellation test is unaffected.

### Compatibility, rollout and rollback

- Wire: none.
- Operator steps: none.
- Rollback: reverting removes the clock control; no stored data changes.

### Tests

- The exact changed test passes: `python -m pytest -q tests/unit/test_sdk_set_coalescer.py::test_a_first_set_its_caller_cancels_still_lands_before_the_windows_flush` — 1 passed in 1.64s.
- A bounded witness invokes the original test with the actual SDK and existing fake transport. A frozen-clock control passes; advancing the clock by 0.21s before the third submission reproduces the failed assertion, with the newer value landing first. The hosted failure records no window ages, so its exact scheduling cause remains unproven.
- Ruff format/check and whitespace checks pass for the changed file. AST comparison preserves the entire original file after removing only the clock setup and added fixture parameter, including both original assertions.
- All 44 checks and all three applicable workflows pass in GitHub CI on this head, including the unit, integration, Postgres-authority, coverage and offline benchmark gates.

### AI assistance in the code (leave one; writing this description with AI is fine):

- AI-generated: Codex wrote the clock setup. Source review checked the coalescer's window and cancellation behavior; a bounded witness checked the scheduling premise, and AST comparison checked the preserved assertions.

- [x] I can explain every line of this diff and how it interacts with the rest of Loom.

### Checklist

- [x] `make format-check`, `make lint`, `make typecheck` and `make test-unit` pass; the integration suite passes if server behaviour changed.
- [x] Generated files are unaffected.
- [x] No migration changes.
- [x] No shipped plugin files change.
- [x] No frontend changes.
- [x] No operator steps or wire changes.
- [x] Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
- [x] Commits are signed off (`git commit -s`).
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
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