Skip to content

Salvage 3 kernels from the optimization-spec review (decay escalation · override audit · traceback de-noise)#7

Merged
templetwo merged 3 commits into
mainfrom
worktree-coupling-decay
Jun 18, 2026
Merged

Salvage 3 kernels from the optimization-spec review (decay escalation · override audit · traceback de-noise)#7
templetwo merged 3 commits into
mainfrom
worktree-coupling-decay

Conversation

@templetwo

Copy link
Copy Markdown
Owner

Three small, contract-safe improvements salvaged from the review of an external
"deep optimization" spec. The spec itself was mostly rejected (server-shaped
proposals grafted onto a per-event fail-open hook plugin; several invariant
violations). These are the defensible kernels, each reframed to fit T2Helix's
real model — folded into existing structure, no new tables, no new write
paths, no row deletion
.

1. feat(coupling) — recency-weighted memory→compass escalation

escalateByMemory decays each outcome-tagged entry by e^(-k·age) (half-life
72h) at recall time instead of flat-counting. Recent evidence arbitrates the
failure-vs-success balance, and a live-failure-mass floor lets a cluster of
purely stale failures fade rather than warn forever.

  • Contract intact: OPEN→PAUSE only, never WITNESS, never downgrade; pure
    function of timestamps; dateless entries weigh 1.0 → byte-identical to the old
    behavior for callers without created_at.
  • One behavior change to note: the weighted ratio can now escalate a
    recent-failure-dominant set whose raw ratio is <0.5 (e.g. 1 fresh failure +
    2 stale successes). Still a soft, overridable PAUSE. Half-life (72h) and mass
    floor (1.0) are exported, tunable constants.

2. feat(compass) — overridden-fire audit signal in compass_log.user_override

The user_override column has existed since phase 1 but was never written. On
an approved PAUSE override the hook now sets it to the consumed approval's row
id
(not the token value), and the two history reads surface it. "This fire was
overridden" becomes queryable; recall_compass exposes it for free. Routed
through the existing logCompass scrub chokepoint.

3. feat(surface) — de-noise pasted tracebacks before recall

New pure lib/query-normalize.js (ReDoS-safe: line splits + linear regexes
only) strips stack frames / paths / line:col / hex from a prompt containing a
traceback, so the error identity leads the FTS query against the v0.10 error-fix
atlas. No-op on ordinary prompts; never returns empty. Not the rejected
sha256 frame-signature store — just a recall-side query normalizer feeding the
matcher that already exists.

Verification

  • Full suite green: 297 tests, exit 0 (smoke 167, regression 52, integration
    19, sse 9, import-atlas 18, atlas-acceptance 15, sync-stack 17). Baseline was
    285 before these changes; +12 new tests (6 decay, 1 override round-trip, 5
    query-normalize incl. a frame-flood linear-time check).
  • An adversarial review pass over the diff was run against the fail-open /
    OPEN→PAUSE-only / append-only / ReDoS invariants.

🤖 Generated with Claude Code

CAF Agent and others added 3 commits June 17, 2026 23:44
escalateByMemory now decays each outcome-tagged entry by e^(-k·age)
(half-life 72h) at recall time instead of flat-counting. Recent evidence
arbitrates the failure-vs-success balance, and a live-failure-mass floor
lets a cluster of purely stale failures fade rather than warn forever.

Contract intact: OPEN→PAUSE only, never WITNESS, no new tables/writes,
no row deletion — pure function of timestamps. Dateless entries weigh
1.0, so behavior is byte-identical for callers passing rows without
created_at (full back-compat).

Salvaged from the external optimization-spec review (the circuit-breaker
section's one defensible kernel), folded into the existing coupling
rather than a parallel failure_chronicle table.

291 tests green (+6 decay tests).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…r_override

The compass_log.user_override column has existed in the schema since
phase 1 but was never written. On an approved PAUSE override the
PreToolUse hook now sets it to the consumed approval's row id (not the
token value), and getCompassHistory / getCompassSince surface it — so
"this fire was overridden" is a queryable signal instead of being buried
in the free-text reason. recall_compass exposes it for free.

Salvaged from the spec review (security section): the one defensible
piece of the proposed audit_compass_trail table, done without a new
table, HMAC, CAS, or cross-process key — and routed through the existing
logCompass scrub chokepoint.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tching)

New lib/query-normalize.js (pure, ReDoS-safe: line splits + linear
regexes only) strips stack-frame lines, file paths, line:col offsets,
and hex addresses from a prompt that contains a traceback, leaving the
error identity (ModuleNotFoundError, sqlite3.OperationalError, ...) to
lead the FTS query. surface.js applies it to the generic-recall query so
a pasted error matches the v0.10 error-fix atlas instead of being
diluted by path noise. No-op on ordinary prompts; never returns empty.

Salvaged from the spec review (traceback section): the one defensible
kernel, reframed as a recall-side query normalizer feeding the existing
matcher — NOT the rejected sha256 frame-signature identity store.

297 tests green (+5).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@templetwo
templetwo merged commit 087123a into main Jun 18, 2026
8 checks passed
templetwo added a commit that referenced this pull request Jun 18, 2026
The leading-identifier run `[\w$]*` before the Error/Exception/Warning
suffix was unbounded, so a long suffix-less word run forced O(n^2)
backtracking from every offset (~21s at 200K chars) — contradicting the
file's own "linear, ReDoS-safe" header. Live exposure was bounded by the
4000-char prompt cap (~10ms), so this was a false-guarantee / correctness
issue, not an exploitable hang. Bound the run to {0,64} (real exception
names are far shorter) → linear; 200K worst case now <100ms.

Also corrects the header claim and adds a smoke test that feeds a single
200K-char suffix-less token under a wall-clock bound — the prior
frame-flood test used short lines and never reached the quadratic path,
so the linear-time claim was asserted but untested.

Found by the post-merge adversarial review of #7.

298 tests green.

Co-authored-by: CAF Agent <agent@caf.cli>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@templetwo
templetwo deleted the worktree-coupling-decay branch July 14, 2026 22:14
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