feat(context): passive window observer + downward-only clamps (phase 5) - #275
Conversation
Odin's normal work is the probe: every emergency rescue already carries the server's own numbers (phase-2 stamping) — the overflow's rejected input size and the compressed retry's accepted usage echo. The observer turns those pairs into per-account, per-model evidence and a temporary DOWNWARD clamp on budget resolution, so a silent serving-window regression stops costing repeated overflow round-trips. No probe traffic, no autonomous upward adjustment (plan of record R2 SS11). - src/llm/window_observer.py: versioned data/context_windows.json evidence store (opaque account keys only), one lock around the whole read-merge-atomic-write transaction, hostile-input-safe reads (O_NONBLOCK/O_NOFOLLOW, fstat shape, size cap), quarantine-never- repair on corrupt material, atomic publication with parent-dir fsync, explicit fd ownership across every failure window. Clamp qualifies only on a same-account, same-model, server-authoritative overflow->acceptance pair; the clamp value IS the acceptance, exact; 24h TTL judged lazily; downward-only merges; active clamp = minimum non-expired across accounts; every public entry point total - evidence-write failure forfeits durability, never the request. - Resolution: snapshot_for_codex_config(observed_clamp=) feeds the phase-1 clamp slot; chat (_maybe_compress + _call_llm ladder), loop (_maybe_compress_loop + _call_loop_llm ladder), and agent (_generation_budget_snapshot) surfaces all pass the active clamp. - Evidence capture at all three rescue-success sites: chat and loop record through the runner's total helper; agents thread an evidence_recorder callable (spawn -> _run_agent -> _call_llm_with_recovery) with a dict-shape adapter beside the callback that produces the shape. - API: GET /api/context/windows (canonical keys, floors, overrides, configured vs effective resolutions, provenance, raw evidence) + POST /api/context/windows/clear (account-scoped manual clear); route parity 188 -> 190. - 41-test battery: hostile store inputs (FIFO/symlink/directory/ oversize/corrupt/off-schema), atomicity under crashed writes, fd discipline under fdopen failure, the full clamp qualification matrix, downward-only + TTL semantics, forfeit invariant, broken- observer guard arms on every surface, resolver integration, all three surface hooks, and the management API.
|
LGTM — approved at |
Campaign phase 5 (plan of record R2 §11–§12, backend half of §12 — the table UI itself is phase 6).
What this adds
src/llm/window_observer.py— the evidence store + clamp authority. Odin's normal work is the probe: every emergency rescue already carries the server's own numbers (phase-2 stamping), and the observer turns each same-request overflow→compressed-retry-acceptance pair into per-(opaque account, canonical model) evidence and a temporary DOWNWARD clamp on budget resolution. No probe traffic, no autonomous upward adjustment.data/context_windows.json: versioned schema, strict validation, opaque account keys only; ONE lock around the whole read–merge–atomic-write transaction;active_clamp()is synchronous, disk-free, lock-free (immutable-state replacement).asyncio.to_thread.Resolution integration —
snapshot_for_codex_config(observed_clamp=)feeds the clamp slot phase 1 built. All five snapshot sites pass the active clamp: chat_maybe_compress+_call_llmladder, loop_maybe_compress_loop+_call_loop_llmladder, agent_generation_budget_snapshot(plan capture + spawn provider).Evidence capture at all three rescue-success sites: chat and loop record through a total runner helper; agents thread an
evidence_recordercallable (spawn →_run_agent→_call_llm_with_recovery) with the dict-shape adapter living beside the callback that produces that shape.API —
GET /api/context/windows(canonical keys, floors, overrides, configured vs effective resolutions side by side, provenance, raw evidence) +POST /api/context/windows/clear(account-scoped). Route parity 188 → 190.One deliberate deviation from the plan text
Plan §11 scopes the active clamp to "currently eligible pool accounts"; this implementation takes the minimum non-expired clamp across ALL accounts holding one — the conservative superset. Rationale: the pool is sticky but failover can seat any account at any moment, pool-membership introspection would couple the observer to
CodexAuthPool, and a departed account's clamp dies with its 24h TTL anyway. Flagging explicitly for your verdict; happy to build pool-eligibility scoping if you judge the plan text binding here.Notes for review
Gates at
9565508Full suite 9,516 passed / 5 skipped; coverage findings=0 (window_observer.py baselined via the 41-test battery: hostile store inputs, crashed-write atomicity, fd discipline under fdopen failure, the full qualification matrix, downward-only + TTL semantics, forfeit invariant, broken-observer guard arms on every surface, resolver integration, all three surface hooks, API); lint new=0; type new=0 (module itself mypy-clean); apply-registry clean; diff-check clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01SHfEwTsEyuS8RUhwdoW66g