Skip to content

fix(http): refuse if and if_absent together instead of dropping if - #303

Closed
japaneseml wants to merge 1 commit into
flop-labs:mainfrom
japaneseml:fix/condition-if-and-if-absent
Closed

japaneseml wants to merge 1 commit into
flop-labs:mainfrom
japaneseml:fix/condition-if-and-if-absent

Conversation

@japaneseml

Copy link
Copy Markdown
Contributor

The bug

_condition() returned on the if_absent branch before if= was ever read,
so a write sent with both (?if=X&if_absent=1) silently dropped if=. When
if= was the condition that could not hold, the request still answered 200
instead of being refused — a caller relying on if= for compare-and-set
(task-state transitions per /interop.md) had no way to know its condition
was never checked.

The fix

The two forms are mutually exclusive by definition: if_absent means the
note is not there, if= means it's there holding exactly that value. There
is no correct value to pick silently, so both are now read and sending both
together raises StoreError, which the existing exception handler renders
as 400 {message} — the same shape every other input refusal already uses,
so no new exception type or wiring was needed for this one call site.

core/app.py grows 981 -> 984 code lines for the extra branch and raise;
sz-baseline.json's baseline and cap move up by the same 3 lines, following
the precedent set by #135.

Test (before/after)

New regression test in tests/http/test_notes.py, covering both directions
plus the POST lane:

  • Before the fix: assert r.status_code == 400 → AssertionError: assert 200 == 400 (the exact issue: unsatisfiable if= silently dropped, note
    created anyway)
  • After the fix: passes

Full suite: 399 passed.

Checks

ruff check .            -> All checks passed!
ruff format --check .   -> 56 files already formatted
ty check                -> All checks passed!
python3 sz.py --check   -> check ok: core code-lines <= baseline (2036)

Fixes #290

🤖 Generated with Claude Code

_condition() returned on the if_absent branch before if= was ever read, so a
write sent with both (?if=X&if_absent=1) silently ignored if=. When if= was
the condition that could not hold, the request still answered 200 instead of
409 or a refusal -- a caller relying on if= for compare-and-set (task-state
transitions per interop.md) could not tell its condition was never checked.

The two forms are mutually exclusive by definition (if_absent: nothing is
there; if=: something specific is there), so there is no correct value to
pick silently. Both are now read, and sending both together raises
StoreError, mapped to the existing 400 handler with a body naming the two
colliding parameters -- matching the shape of every other input refusal
rather than introducing a new exception type for one call site.

core/app.py grows 981 -> 984 code lines for the extra branch and raise;
sz-baseline.json's baseline and cap move up by the same 3 lines, following
the precedent set by flop-labs#135.

Regression test in tests/http/test_notes.py reproduces both directions from
the issue (if= unsatisfiable + if_absent satisfiable, and the reverse) plus
the POST lane, and fails against the pre-fix code (200 instead of 400).

Fixes flop-labs#290

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

sv commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #307, which fixes the same issue (#290) with a smaller, more focused diff — this PR bundles unrelated refactors and touches sz-baseline.json for a fix that doesn't need it. Closing in favor of #307.


Generated by Claude Code

@sv sv closed this Aug 27, 2026
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.

fix: _condition() silently drops if= when if_absent is also present, and answers 200

2 participants