Skip to content

issue #116 Phase 1-C: smooth sigmoid read-gate (observability slice)#120

Closed
TSchonleber wants to merge 1 commit into
mainfrom
issue-116-phase-1-sigmoid-gate
Closed

issue #116 Phase 1-C: smooth sigmoid read-gate (observability slice)#120
TSchonleber wants to merge 1 commit into
mainfrom
issue-116-phase-1-sigmoid-gate

Conversation

@TSchonleber
Copy link
Copy Markdown
Owner

Summary

Third and final slice of issue #116 Phase 1. Ships the observability piece of the memo's smooth sigmoid read-gate recommendation (§1.4 Stage 2) — math + per-item weight surface — without changing rank order or dropping any items. Calibration of slope/midpoint from accumulated outcomes is Phase 4 work, intentionally deferred.

Stays on its own branch by request — not auto-merged like Phase 1-A (84c8776) and 1-B (c781043) were. Higher-risk piece even in observability mode because it touches result-item dicts every search, and benchmark fixtures deserve a manual look before merge.

What's in

  • agentmemory.sigmoid_gate — new pure-math module: SigmoidParams (validated frozen dataclass), sigmoid(x, slope, midpoint), normalize_rank(rank, total), weight_for_rank(rank, total), weights_for_results(total), annotate_with_weights(items).
  • Conservative defaults: slope=6.0, midpoint=0.5 per memo §1.4 Stage 2 ("Start with a shallow slope and a conservative midpoint, then tighten as data accumulates").
  • cmd_search hook: one new block before output formatting that calls annotate_with_weights on every result bucket. Items get a new _sigmoid_rank_weight field; existing field if any is preserved (idempotent). Failures swallow.
  • 14 new tests covering math correctness, validation, monotonicity, edge cases, and the annotation contract.

What's NOT in (deliberately)

  • No rank changes. The order of results is identical to pre-PR.
  • No items dropped. `--limit N` still behaves the same.
  • No learning of slope/midpoint. Defaults are conservative + hardcoded; calibration is Phase 4.
  • No enforcement mode. Phase 1-A (pathway log) + 1-B (motivational gate) had `*_ENFORCE` env-var flips; 1-C does not because there's no enforcement to flip — the surface is purely additive.

Live smoke

`brainctl search "cerebellum boundary detection" --limit 3` with the new code, `context` bucket (3 items):

rank normalized weight
1 of 3 1.0 0.9526
2 of 3 0.5 0.5000
3 of 3 0.0 0.0474

Midpoint crossing at the median is the correct shape.

Tests

  • 14 new in `tests/test_sigmoid_gate.py`
  • 145/145 across sigmoid_gate + motivational_gate + retrieval_pathway_log + brain + brain_enhanced + profiles

Test plan

  • Review `agentmemory.sigmoid_gate` for the math itself + defaults
  • Confirm the `cmd_search` hook position is acceptable (right before output formatting, after pathway-log emit)
  • Confirm `_sigmoid_rank_weight` field name doesn't collide with anything in the bench harness fixtures
  • Run `tests/bench/run --check` if there's any concern about ranking output changes (there shouldn't be any — items are mutated additively, not reordered)
  • If green, merge to main

Phase 1 status after this lands

  • Phase 1-A (retrieval pathway log) — shipped `84c8776`
  • Phase 1-B (motivational entry gate, shadow) — shipped `c781043`
  • Phase 1-C (smooth sigmoid read-gate) — this PR

Phase 4 enforcement readiness review is the next planned step, gated on accumulating 4+ weeks of pathway-log data before deciding whether the BG/cerebellum learning loops are calibrated enough to flip from shadow to enforcement.

🤖 Generated with Claude Code

Memo §1.4 Stage 2 argues hard `--limit N` truncation is both noise-
sensitive (items near the boundary flip in and out unpredictably)
and non-learnable (zero gradient at the boundary). The memo's
recommendation is a smooth sigmoid threshold with learnable slope
and midpoint, calibrated from operational data.

This ships the **observability slice** only — the math + a
per-item `_sigmoid_rank_weight` field. Rank order unchanged, no
items dropped, bench output structure identical modulo the new
field. Learning slope/midpoint from outcomes is Phase 4 work and
deliberately deferred.

- agentmemory.sigmoid_gate module: SigmoidParams, sigmoid(),
  normalize_rank(), weight_for_rank(), weights_for_results(),
  annotate_with_weights(). Pure math, no DB access. Conservative
  defaults slope=6.0, midpoint=0.5 per memo §1.4 ("Start with a
  shallow slope and a conservative midpoint, then tighten as data
  accumulates").

- cmd_search hookpoint annotates each surfaced item with
  _sigmoid_rank_weight derived from its 1-based rank in the bucket.
  Failures swallow so a bad gate cannot break search.

- 14 new tests: endpoint behavior, midpoint crossing, monotonicity,
  extreme-overflow handling, SigmoidParams validation, rank
  normalization edges, bucket annotation, idempotence, non-dict
  handling.

Live smoke (context bucket, 3 items):
  rank 1 of 3 → weight 0.9526
  rank 2 of 3 → weight 0.5000  (midpoint exactly)
  rank 3 of 3 → weight 0.0474

145/145 tests green across sigmoid_gate, motivational_gate,
retrieval_pathway_log, brain, brain_enhanced, profiles.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
TSchonleber added a commit that referenced this pull request May 20, 2026
Bumps pyproject.toml and __init__.__version__ to 2.8.0 and promotes
the [Unreleased] CHANGELOG block to [2.8.0] dated 2026-05-20.

This release lands the issue #116 brain-architecture work (16 new
subsystems via migrations 067-082) alongside the v2 MCP tool surface
consolidation (370 registered → 100 visible) and Windows hardening.
Supersedes overnight PRs #120-#137 as a single artifact.

Minor bump rationale: although the v1 tool names are hidden from
list_tools, every one of them remains callable internally through the
consolidated dispatchers — same compatibility shape as 2.7.0's
procedural-memory landing. Clients with stale name allowlists get a
hard-fail at startup pointing at docs/TOOL_MIGRATION_V2.md, never a
silent breakage. A revert is one-line (the _VISIBLE_TOOL_NAMES filter).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TSchonleber
Copy link
Copy Markdown
Owner Author

Superseded by #138 (brainctl-consolidation-v2), which already merged this work into main as part of the v2 tool surface consolidation. Closing as redundant.

@TSchonleber TSchonleber deleted the issue-116-phase-1-sigmoid-gate branch May 21, 2026 08:15
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