Skip to content

fix(learning): align durable reflection admission with exact-source replay and request budgets #2599

Open

Description

@jbeda

Problem

Durable reflection admission validates a bounded selected evidence input, but the background/recovery worker reconstructs the full exact source run independently. The queued attempt does not persist the selected evidence manifest. Admission and execution therefore do not necessarily evaluate the same evidence or enforce the same byte/count budgets.

This affects automatic completed-session learning and manual /reflect when configured with a durable attempt repository. It is separate from the synchronous manual reflection size-fitting fix in #2598 and from the /reflections browser UI in #2595.

The operator explicitly chose to fix synchronous manual reflection first and defer this work. Preserve this issue for follow-up; the synchronous fix must leave automatic/durable admission behavior unchanged rather than claiming these cases resolved.

Confirmed source paths

  • internal/app/reflection_observer.go: evidence selection and request validation precede durable attempt creation; durableAttemptMaterial binds the source using automaticTrajectoryDigest of the selected current span (or selected input when no current span is set).
  • internal/app/learning_digest.go: canonical digest is computed from the input's current span when valid.
  • internal/app/source_evidence.go: the durable worker reconstructs the exact recorded run, validates provenance/current-prompt/source digest, then projects that reconstructed evidence. It does not replay the admission-time selected manifest.
  • internal/app/attempt_recovery.go: the reconstructed projection is passed to EvidenceReflector.ReflectProjection.

Failure cases

  1. Selected current evidence differs from replayed source. Explicit selection can omit part of the current run to meet local limits. The resulting source digest can differ from the worker's reconstructed full-current-run digest, so queued work later fails closed as evidence unavailable.
  2. Replay exceeds local limits. Even when the source digest matches, the full reconstructed projection may exceed the reflector's serialized-byte or event-count limits although the admission-time selected input fit. Selector/domain event limits and default reflector event limits also differ.
  3. Admission accounting precedes an inevitable failure. The automatic path may consume cadence/reserve count and token budgets for work that cannot execute solely because admission and replay use inconsistent local evidence/budget calculations. Estimates for selected input need not describe the replayed request.

These are fail-closed failures, not evidence of silently accepting altered evidence or approving the wrong proposal.

Why an early replay check is not enough

Ordinary automatic observation currently receives neither a run-event snapshot nor an event source. Its callback can precede durable recording of the terminal event. An early EventLog read therefore cannot prove the complete worker input fits; treating incomplete evidence as rejection would disable valid pending-work/recovery behavior.

Do not solve this by weakening digests, silently reselecting evidence after a queued attempt is bound, increasing arbitrary limits, or dropping every automatic admission lacking a terminal record.

Design decision and desired outcome

Choose an explicit consistent contract, for example:

  • Conservative admission: validate the complete exact-run input that execution will use and abstain/skip before admission when it cannot fit; requires a complete snapshot or appropriately deferred admission.
  • Selected-evidence replay: persist an evidence-selection manifest, reconstruct exactly those original source coordinates after restart, and verify their content digests/ownership before execution. Assess stored-data compatibility and existing attempts deliberately.

Whichever design is selected:

  • An admitted attempt must not later fail solely because local admission and execution disagree on selected evidence, bytes, or collection counts.
  • Preserve exact principal/run/current-prompt binding, canonical ordering, atomic tool-call/result units, compaction/archive handling, and fail-closed source verification.
  • Preserve incomplete-evidence waiting and restart recovery; keep genuine unavailable/changed evidence and operational failures distinct from normal bounded abstention.
  • Align automatic reservations with the actual executed request while preserving cooldown/deduplication/count policy.
  • Assess wire, public Go API, and stored-data compatibility before changing contracts; do not assume unchanged protobuf fields imply compatibility.

Offline verification

Add tests through admission and the real loader/reflector seam, not admission-only or a replacement loader:

  • oversized current run requiring selected-message omission;
  • full-run event count exceeding the reflector while a selected subset fits;
  • escaping/evidence-reference/structural overhead crossing the serialized-byte limit;
  • automatic and manual durable admission;
  • pending terminal evidence, restart/resume, compaction, and changed/missing evidence;
  • exact source/selection replay, one intended provider execution, and correct reservation accounting;
  • absence of attempt/reservation/cadence mutation when the selected policy requires a pre-admission skip.

Use isolated in-memory/test-owned stores and mock providers. No live models, operator transcripts, memory values, or credentials are needed.

Read-only/local fixture probes during #2598 reproduced queued work for selected/current digest divergence and 400 full worker events failing the real reflector limits. The separate synchronous-only fix intentionally does not change these paths.

Activity

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