Skip to content

fix: surface unsustainable warning on all gradient return paths#351

Merged
BYK merged 1 commit into
mainfrom
fix/unsustainable-warning-visibility
May 15, 2026
Merged

fix: surface unsustainable warning on all gradient return paths#351
BYK merged 1 commit into
mainfrom
fix/unsustainable-warning-visibility

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 15, 2026

Summary

  • Bug fix: The unsustainable flag on TransformResult 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, line 1833) never set it because the sticky layer guard pins effectiveMinLayer >= 1, bypassing the tier gate entirely. Sessions like 0P8Jt4Th6iGN would accumulate 5+ consecutive busts without the warning ever reaching the model.
  • Proactive meta-distillation: When 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

File Change
packages/core/src/gradient.ts Add unsustainable flag to return paths 1 (layer 0 passthrough) and 3 (layers 1/2/3 compression loop); export getConsecutiveBusts()
packages/core/src/index.ts Re-export getConsecutiveBusts
packages/core/src/distillation.ts Add metaThresholdOverride param to run()/runInner()
packages/gateway/src/idle.ts Bust-aware meta-distillation threshold (20 → 5 when busts >= 3)
packages/gateway/src/pipeline.ts Pass metaThresholdOverride in urgent distillation path
packages/gateway/test/helpers/idle-worker.ts Add getConsecutiveBusts to @loreai/core mock

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.
@BYK BYK force-pushed the fix/unsustainable-warning-visibility branch from c8914a4 to 6a4c326 Compare May 15, 2026 18:12
@BYK BYK merged commit 3ce14a5 into main May 15, 2026
12 of 13 checks passed
@BYK BYK deleted the fix/unsustainable-warning-visibility branch May 15, 2026 18:17
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 |
@craft-deployer craft-deployer Bot mentioned this pull request May 15, 2026
6 tasks
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