Checkpoint: auto-retry after a failed pass; release rate-limit slot on failure
A paste fires exactly one grammar checkpoint, and a failed one never retried until the next keystroke — stranding the writer on "Petal's helper is resting" after a paste. Long docs make it worse: their 15-25s checks have a wide window to catch a transient 502 from the shared Ollama (co-tenant apps load other models and evict the 9B). A failed pass also burned the per-document rate-limit slot, so a retry within 30s hit the throttle path and got an empty set back. - llm.RateLimiter.Release rolls back a slot when its pass fails; Allow now returns the recorded timestamp so Release only frees its own slot. - suggestions.runPass releases the slot on LLM failure before returning 502. - useCheckpoint auto-retries a failed checkpoint with backoff (3/12/35s), keeping the breathing dot up and only flagging "resting" once retries exhaust. Claude-Session: https://claude.ai/code/session_016Yr6jELuRc7hyzYLccQKZd
This commit is contained in:
@@ -65,16 +65,31 @@ func TestParseCheckpoint(t *testing.T) {
|
||||
func TestRateLimiter(t *testing.T) {
|
||||
rl := NewRateLimiter(30 * time.Second)
|
||||
|
||||
if ok, _ := rl.Allow("doc1"); !ok {
|
||||
ok, _, at := rl.Allow("doc1")
|
||||
if !ok {
|
||||
t.Fatal("first call should be allowed")
|
||||
}
|
||||
if ok, retry := rl.Allow("doc1"); ok || retry <= 0 {
|
||||
if ok, retry, _ := rl.Allow("doc1"); ok || retry <= 0 {
|
||||
t.Fatalf("immediate second call should be throttled, got ok=%v retry=%v", ok, retry)
|
||||
}
|
||||
// A different document is independent.
|
||||
if ok, _ := rl.Allow("doc2"); !ok {
|
||||
if ok, _, _ := rl.Allow("doc2"); !ok {
|
||||
t.Fatal("different doc should be allowed")
|
||||
}
|
||||
|
||||
// Releasing doc1's slot (as a failed pass does) lets the next check re-run
|
||||
// immediately instead of waiting out the interval.
|
||||
rl.Release("doc1", at)
|
||||
if ok, _, _ := rl.Allow("doc1"); !ok {
|
||||
t.Fatal("after Release the next call should be allowed again")
|
||||
}
|
||||
// Release only rolls back its own slot: a stale timestamp must not evict the
|
||||
// slot a newer Allow holds (so a late failure can't cancel a fresh in-flight
|
||||
// check). doc2 still holds its slot from above; a zero-time Release is a no-op.
|
||||
rl.Release("doc2", time.Time{})
|
||||
if ok, _, _ := rl.Allow("doc2"); ok {
|
||||
t.Fatal("stale Release must not free doc2's current slot")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncateDoc(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user