DEV Community

Discussion on: Our AI assistant can write to exactly one table. Postgres enforces it, not our code

Collapse
 
mike-johnstone profile image
Mike Johnstone •

A proposal can go stale in the inbox too. If someone changes a milestone before approval, the reviewer may be looking at a diff against an old value. I'd store the base row version with the proposal and check it atomically when applying, so a stale proposal needs a fresh review. Does apply_pending_change already cover that?

Collapse
 
appwebseo profile image
Viacheslav Bobok •

It did not, and it matters more here than usual because a milestone proposal carries an absolute value. If Claude proposed 55% to 65% and a site manager then entered 70%, approving would write 65%: progress lowered with no note. The inbox showed the live value next to the proposal and the controller got a flag afterwards, but nothing stopped the approve.

Done the way you describe, going out with the next deploy. A BEFORE INSERT trigger stamps the base into the proposal: the milestone’s progress and the number of entries in its journal. It overwrites whatever the client sent, so Claude cannot supply its own base. apply_pending_change locks the milestone row, compares, and refuses the approval if anything moved. Reject still works, so a stale proposal can be thrown away but not approved, and the inbox says so.

The count is there because progress alone misses 70 back to 55 back to 70. One side effect I like: approving one of two pending proposals for the same milestone makes the other one stale. Budget lines and transactions already re-check at apply (unique code, duplicate reference), so only milestones needed this. Thanks, this was a real gap.

Collapse
 
mike-johnstone profile image
Mike Johnstone •

The journal count is a nice touch for a value that changes and then returns to its starting point. Keeping Reject available makes sense too. Thanks for coming back with the implementation details.