Skip to content

fix(memory): resample unthrottled after allocator trim - #2859

Merged
ScriptedAlchemy merged 2 commits into
masterfrom
devin/1790908997-trim-resample
Oct 2, 2026
Merged

ScriptedAlchemy merged 2 commits into
masterfrom
devin/1790908997-trim-resample

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

// register_process_allocator_pressure_reclaimer_v1
- pressure.sample_for_checkpoint();      // throttled (~10ms); may return the standing OverBudget state
+ pressure.resample_after_reclaim();     // canonical sampler, unthrottled, no reclaimer re-entry

fn resample_after_reclaim(&self) -> Option<ResidentMemoryPressureStateV1> {
    let sample = (self.sampler)()?;
    self.publish_observation(sample.admission_bytes());
    self.publish_over_budget_gauge();
    Some(self.state())
}

Motivation

The pressure latch only clears once memory drops below the low watermark. Suppose an indexing checkpoint sampled within the last RESIDENT_MEMORY_CHECKPOINT_SAMPLE_INTERVAL_V1. The post-trim call then returns the standing state without reading memory again. run_pressure_reclaimers doesn't resample afterwards either, so the latch stays OverBudget even though memory has recovered. Admissions keep being refused until the maintenance sampler next runs.

Changes

  • crates/tracedecay-runtime-core/src/resident_memory.rs: adds a private resample_after_reclaim and calls it from the allocator trim reclaimer. It publishes the cgroup-aware admission bytes and the gauge. It does not call run_pressure_reclaimers, so the reclaimers can't re-enter.
  • crates/tracedecay-runtime-core/src/resident_memory/tests.rs: adds allocator_trim_readmits_growth_when_memory_recovers_inside_checkpoint_throttle. The test checks the behavior through ProcessResidentMemoryV1::reserve, the API admission callers actually use, with literal inputs:
    1. Memory is at the 1 GiB limit. A checkpoint sample starts the throttle window, and a 16 MiB reserve is refused with ObservedOverBudget.
    2. Memory drops to 64 MiB and the pressure pass runs.
    3. The same reserve now succeeds, and the ledger records 16 MiB used.

Test plan

  • cargo nextest run --workspace --no-fail-fast passes (left to CI)
  • cargo clippy -p tracedecay-runtime-core --all-targets -- -D warnings clean
  • cargo test -p tracedecay-runtime-core --lib resident_memory: 52 passed. With the old sample_for_checkpoint() call restored, the new test fails at the post-recovery reserve, which is still refused.
  • cargo fmt --all -- --check

Checklist

  • CHANGELOG.md updated (under [Unreleased] if no version bump)
  • No secrets, credentials, or .env files included
  • Breaking changes documented (if any): none

Link to Devin session: https://app.devin.ai/sessions/9f41edacea9a4fffb64bd90be9914a12
Open in Devin Desktop: https://app.devin.ai/desktop/session/9f41edacea9a4fffb64bd90be9914a12?variant=devin
Requested by: @ScriptedAlchemy


Devin Review

Local verification (land-open-prs)

On the head rebased onto master 9d24792:

  • Fails before: with the reclaimer reverted to pressure.sample_for_checkpoint(), resident_memory::tests::allocator_trim_readmits_growth_when_memory_recovers_inside_checkpoint_throttle fails 10/10 (tests.rs:1202, growth refused).
  • Passes after: cargo test -p tracedecay-runtime-core --lib -- resident_memory --test-threads=16: 52 passed.
  • Runtime journey: cargo test -p tracedecay-cli --features alloc-mimalloc --test refresh_memory_journey (shipped daemon cold-indexing and refreshing a 300-file heavy corpus under a 6 GiB limit): 2 passed in 149 s.
  • cargo clippy -p tracedecay-runtime-core --all-targets -- -D warnings clean; cargo fmt --all -- --check clean. No cfg-gated code touched.

This carries the remaining part of #2596 (closed); #2851 landed its first two commits.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5b65159

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@ScriptedAlchemy
ScriptedAlchemy merged commit cdf251a into master Oct 2, 2026
16 of 26 checks passed
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.

1 participant