Skip to content

ateapi: merge store.OptionalPrecondition into store.Precondition - #4004

Merged
Scott Funkenhauser (sfunkenhauser) merged 4 commits into
agent-substrate:mainfrom
haiyanmeng:single-precondition
Nov 20, 2026
Merged

Scott Funkenhauser (sfunkenhauser) merged 4 commits into
agent-substrate:mainfrom
haiyanmeng:single-precondition

Conversation

@haiyanmeng

@haiyanmeng haiyanmeng commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

store.OptionalPrecondition and store.Precondition have the same uid and version fields. They differ only in whether an unset guard is an error or a skipped check. This keeps one Precondition. Check skips unset guards. Update methods call ValidateRequired first, so they still require both guards. Deletes and marks for deletion call only Check. Store behavior is unchanged.

This reverses the separate optional type, which #3989 renamed from DeletePreconditions. Custom methods such as SuspendActor (#1773) can call Check without ValidateRequired. The trade-off is that the compiler no longer catches optional guards passed to an update method. That mistake now fails at runtime with ErrPreconditionRequired.

Addresses #1773

AI use: I used Claude Code to review the diff and draft the commit message and this description. I reviewed both.

  • Tests pass
  • Docs updated

Comment thread cmd/ateapi/internal/store/store.go Resolved
Comment thread cmd/ateapi/internal/store/store.go Resolved
Comment thread cmd/ateapi/internal/store/store.go Resolved
The two types had the same uid and version fields and differed only in
whether a zero field is an error or a skipped check. Keep one
Precondition and let the store method pick the rule: CheckRequired for
updates, which rejects an unset guard with ErrPreconditionRequired, and
CheckOptional for deletes and marks for deletion.

Update methods still call Validate before any database work. The shared
update helpers now check updates with CheckRequired instead of the
optional check, so the rule holds where the guards are compared. Store
behavior is unchanged.

Signed-off-by: Haiyan Meng <[email protected]>
CheckRequired compares the guards itself instead of calling
CheckOptional. The doc comments now say which errors each check
returns, and the update helpers say when the guards are optional.

Signed-off-by: Haiyan Meng <[email protected]>
Every store method that requires both guards already calls
ValidateRequired before it reads the row. After that call, CheckRequired
and CheckOptional return the same result, so keep one Check that skips
an unset guard. The update helpers no longer take an optionalGuards flag.

Each Update, Delete and MarkForDeletion method in store.Interface now
says whether its precondition guards are required or optional.

Add tests that BindActorToWorker, UpdateActorAndRelease and
UpdateAtespaceAccessPolicy return ErrPreconditionRequired when a guard
is unset. These were the only required methods without one.

Signed-off-by: Haiyan Meng <[email protected]>
Drop the comment in updateActor and updateActorTemplate that repeated
the Check doc comment. TestPreconditionCheck now covers a stale uid
alone and a matching version alone.

Signed-off-by: Haiyan Meng <[email protected]>
Merged via the queue into agent-substrate:main with commit 76f18c0 Nov 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api-machinery kind/cleanup Small fixes that are not bugs, for example a typo in a code comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants