fix: surface unsustainable warning on all gradient return paths#351
Merged
Conversation
The unsustainable flag was only set on 2 of 4 return paths in transformInner() — the tier gate (layer 0) and emergency (layer 4). The most common path for unsustainable sessions (layers 1-3 compression loop) never set it because the sticky layer guard bypasses the tier gate. Also lowers the meta-distillation threshold from 20 to 5 gen-0 segments when consecutiveBusts >= 3, triggering earlier consolidation of the distilled prefix under bust pressure to help prevent sessions from becoming unsustainable in the first place.
c8914a4 to
6a4c326
Compare
BYK
added a commit
that referenced
this pull request
May 15, 2026
## Summary Follow-up fixes from self-review of #351: - **`getConsecutiveBusts()` now read-only**: Uses `sessionStates.get()` instead of `getSessionState()` (get-or-create) to avoid creating phantom `SessionState` entries with zeroed calibration fields, which would cause subsequent `transform()` calls to treat the session as uncalibrated. - **`metaThresholdOverride` clamped**: `runInner()` now clamps the override to min 2 — prevents callers from passing 0 or negative values that would trigger meta-distillation unconditionally. - **DRY threshold formula**: Extracted `effectiveMetaThreshold()` helper and `BUST_PRESSURE_THRESHOLD` constant into `@loreai/core`, replacing duplicated `busts >= 3 ? Math.max(3, Math.floor(threshold / 4)) : threshold` logic in `idle.ts` and `pipeline.ts`. ## Files changed | File | Change | |------|--------| | `packages/core/src/gradient.ts` | `getConsecutiveBusts()` uses read-only Map access; new `effectiveMetaThreshold()` helper + `BUST_PRESSURE_THRESHOLD` constant | | `packages/core/src/index.ts` | Re-export new symbols | | `packages/core/src/distillation.ts` | Clamp `metaThresholdOverride` to min 2 | | `packages/gateway/src/idle.ts` | Use shared `effectiveMetaThreshold()` helper | | `packages/gateway/src/pipeline.ts` | Use shared `computeMetaThreshold()` (aliased import) | | `packages/gateway/test/helpers/idle-worker.ts` | Add new exports to mock |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unsustainableflag onTransformResultwas only set on 2 of 4 return paths intransformInner()— the tier gate (layer 0) and emergency (layer 4). The most common path for unsustainable sessions (layers 1-3 compression loop, line 1833) never set it because the sticky layer guard pinseffectiveMinLayer >= 1, bypassing the tier gate entirely. Sessions like0P8Jt4Th6iGNwould accumulate 5+ consecutive busts without the warning ever reaching the model.consecutiveBusts >= 3, lowers the meta-distillation threshold from 20 to 5 gen-0 segments in both the idle handler and urgent distillation paths. This consolidates the distilled prefix earlier under bust pressure, helping prevent sessions from becoming unsustainable in the first place.Changes
packages/core/src/gradient.tsunsustainableflag to return paths 1 (layer 0 passthrough) and 3 (layers 1/2/3 compression loop); exportgetConsecutiveBusts()packages/core/src/index.tsgetConsecutiveBustspackages/core/src/distillation.tsmetaThresholdOverrideparam torun()/runInner()packages/gateway/src/idle.tspackages/gateway/src/pipeline.tsmetaThresholdOverridein urgent distillation pathpackages/gateway/test/helpers/idle-worker.tsgetConsecutiveBuststo@loreai/coremock