Commit Graph
3 Commits
Author SHA1 Message Date
Mansurshakh Japarov 2cbdd22a65 fix(batch): preserve live contexts during capacity cleanup (#4210)
## Description

Closes #4181.

Preserve live batch continuation contexts when replacing an existing
entry at capacity, and reclaim expired entries before evicting the
oldest live entry. The verified fork fix is now normally merged onto
main f1bc260 and published at
`e606a044babeed4913cf6c3ecd9ef940347a3b12`; no reset, force push or hook
bypass.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- Replacing an existing batch refreshes its request context and TTL
without consuming another capacity slot or evicting an unrelated live
batch.
- Inserting a new batch removes expired contexts before applying the
existing oldest-live eviction policy.
- Keep the configured capacity bounded and retain deterministic
public-store regressions for both data-loss transitions.

## Testing

- [ ] Unit tests pass (pytest) — no entire-project Python suite claim.
- [ ] Linting passes (ruff check .) — normal changed-file hooks passed;
no whole-repository Ruff claim.
- [ ] Type checking passes (mypy headroom) — no separate whole-project
mypy claim.
- [x] Manual testing performed

### Test Output

Fresh current-main focused command: `python -m pytest
tests/test_ccr_batch_store.py tests/test_ccr_batch_processor.py
tests/test_proxy_handlers_batch.py -q`.

```text
110 passed in 25.77s
```

Normal current-main merge/push ran Rust workspace checks, rebuilt the
real native extension, and completed commitlint plus:

```text
181 critical Python tests passed
ci-precheck PASSED — safe to push.
```

Original independent real-store proof and failing-before/passing-after
regressions:
https://github.com/headroomlabs-ai/headroom/issues/4181#issuecomment-6148313526
. That older four-file suite was 119 passed, 14 skipped; it is not
relabelled as the current three-file result.

## Real Behavior Proof

- Environment: Linux x86_64, Python 3.13.14, actual public
BatchContextStore.store/get API, synthetic batch requests; no mocked
store or provider credentials.
- Exact command / steps: standalone asyncio script fills a three-entry
store with a,b,c then replaces c; separately fills a two-entry store
with an older live context and a newer expired context, then inserts a
new batch.
- Observed result: before the fix replacement lost a and insertion lost
the live context; after the fix a,b,c remain and the updated c model is
returned, while insertion retains live+new and removes expired. Original
runtime evidence is linked above; the current-main consumer suites and
full push gates also passed.
- Not tested: live provider continuation quality, cloud invoices,
production throughput, Windows/macOS, or hosted CI for this newly opened
PR.

## Runtime Rollout Safety

- Rollout-managed feature(s): none; capacity policy correction within
the existing batch context store.
- Minimum rollout channel: existing batch-store users; no new channel.
- Stable/default behavior changed: updates no longer discard an
unrelated live context; expired entries are reclaimed before live
eviction.
- Kill switch / disable path: existing batch-processing configuration;
no new override.
- Unsafe override required: no.
- Qualification impact: public-store transitions, downstream batch
consumers and normal full push gates verified; provider execution was
not needed for this store defect.
- Rollback path: revert the capacity-policy fix; no persistence
migration or capacity increase.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I did not edit CHANGELOG.md — release-please owns it

## Additional Notes

This publishes an already-verified fix from the earlier Headroom batch
now that an author PR slot is available. It is not counted toward the
newly requested ten Bend issues. AI-assisted without subagents.

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4210"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
2026-10-15 12:53:09 -05:00
GarmandClaude Opus 4.7 efd2ac1ca4 chore: renormalize line endings to LF
`.gitattributes` declares `*.py text eol=lf` and `*.sh text eol=lf`, but
74 files (73 .py, 1 .sh) are stored in the index with CRLF line endings,
violating that contract. Every macOS/Linux clone reports these files as
"modified" on fresh checkout because git's diff engine sees the stored
bytes don't match the attribute contract, even though the working tree
and index match byte-for-byte.

Running `git add --renormalize .` rewrites each affected blob so the
stored form matches the attribute declaration. No semantic changes —
every affected file's diff is "N insertions, N deletions" with inserts
and deletes being the same lines modulo line endings.

Follow-up commit adds `.git-blame-ignore-revs` so `git blame` / GitHub
blame skip this mechanical commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 15:33:30 +02:00
JerrettDavisandCopilot 38bf3e639c test: expand coverage across helper slices
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-23 07:39:52 -05:00