Skip to content

fix(learning): fit reflection evidence to final request budgets #2598

Closed

Description

@jbeda

Problem

Manual /reflect can reject a long but valid completed conversation before making a model request, while mecatui reports only “reflection service is unavailable.” This blocks exercising the staged-proposal browser in #2595; the UI PR is not the underlying cause.

Confirmed on build v0.0.51-22-g29f794af2, embedded mecatui, automatic learning off. Explicit reflection is supported with automatic learning off. A read-only replay of evidence preparation against the affected saved session (no provider call or proposal writes) produced:

  • Raw-input budget estimate, excluding existing comparison memories: 266,841 bytes.
  • Serialized evidence projection: 278,861 bytes.
  • Application/model input limit: 262,144 bytes (256 KiB).

These numbers identify one replay snapshot; the conversation continues to grow. No transcript, memory values, credentials, or operator configuration are required to reproduce with offline fixtures.

Cause

  • Evidence selection sums JSON sizes of individual message/event units (engine/learning/materializer.go:244), without budgeting the complete downstream input.
  • The application uses a separate raw-input estimate (internal/app/reflection_coordinator.go:171), and the reflector enforces a limit on the assembled serialized projection (engine/agent/evidencereflector.go:152). Evidence references, signals, comparison facts and structural overhead can make selected evidence fail downstream.
  • Automatic reflection retries evidence selection with a smaller budget for the application estimate, while explicit reflection selects once and returns the error (internal/app/reflection_observer.go:353, :394).
  • The error collapses into ErrReflectionFailed, then gRPC Unavailable, then misleading client wording. Existing diagnostics do not identify this stage safely.
  • Related limit alignment to assess: selector/domain allows 512 events and 256 existing facts; the default reflector accepts only 256 events and 128 facts.

Required outcome

  • Explicit reflection safely fits the final model-visible projection and application budget using consistent bounded selection, not a larger arbitrary limit or truncation of evidence/tool components.
  • Respect count limits as well as byte bounds, including comparison facts and serialization overhead. Assess automatic/durable execution so the same candidate cannot pass admission and fail solely from inconsistent local budgets.
  • Preserve exact evidence coordinates/digests, atomic tool-call/result units, source ordering, and fail-closed approval verification. Do not change retained source history or silently alter a persisted proposal's evidence.
  • When no valid evidence fits, return the existing appropriate bounded abstention rather than a generic unavailable failure.
  • Keep genuine provider/persistence failures as failures. Improve safe stage diagnostics if needed without logging raw provider errors, transcripts, memory values or credentials.
  • Add offline regressions at the real application/reflector boundary: near-limit long input, serialization overhead, event/fact count limits, smaller-selection success, and no-provider abstention. Exercise explicit learning-off, automatic, and relevant durable/restart seams.

Scope and compatibility

This is separate backend correctness work from #2595. No learning-policy redesign, increased defaults, new public configuration, provider calls in tests, or unrelated reflection routing/lifecycle fixes.

API compatibility assessment required before implementation: restore bounded-selection/abstention behavior using existing RPCs, response vocabulary, and authorization. Existing conforming clients should require no changes; avoid changing existing wire error mappings without a separate compatibility assessment. Assess exported Go API and stored-data compatibility separately.

Activity

  1. jbeda commented on Oct 29, 2026

    @jbeda
    ContributorAuthor

    Scope split agreed with the operator: fix manual synchronous reflection here first. Automatic/durable admission and replay are tracked separately in #2599.

    The synchronous fix must preserve automatic and durable/queued behavior rather than partially changing their admission semantics. #2599 retains the broader replay/selection, full-run event-count, pending-evidence, restart, and reservation-accounting requirements. No stored-evidence/provenance redesign is part of this synchronous fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions