SONA trajectories persist but are not consumed by hooks_route or indexed when steps are present · Issue #3662 · ruvnet/ruflo · GitHub
Skip to content

SONA trajectories persist but are not consumed by hooks_route or indexed when steps are present #3662

Open

Description

@Tigon32

Summary

In Ruflo 3.51.1, a successful hooks_intelligence_trajectory-end reports that SONA learned a pattern and persists it to .swarm/sona-patterns.json, but the normal hooks_route path does not consult that persisted SONA optimizer. In addition, trajectory feedback is only promoted to the semantic pattern store when the trajectory has no steps. The common start → step → end path therefore records SONA state without making the feedback searchable through hooks_intelligence_pattern-search.

This was reproduced against the installed 3.51.1 package before applying a local compatibility shim. The shim is not part of this report; this issue describes the vendor behavior and the integration test expected upstream.

Environment

  • Ruflo / bundled @claude-flow/cli: 3.51.1
  • Node.js: 26.10.0
  • OS: macOS on Apple Silicon
  • Embeddings status: ONNX, semanticGrounded: true

Reproduction

  1. Call hooks_intelligence_trajectory-start with a task and agent.
  2. Record at least one step with hooks_intelligence_trajectory-step.
  3. Call hooks_intelligence_trajectory-end with success: true and non-empty feedback.
  4. In a fresh process, inspect SONA state / query the same task through the public routing path, and search feedback with hooks_intelligence_pattern-search.

Actual behavior

  • trajectory-end returned sonaUpdate: true and a SONA pattern key; the pattern was written to .swarm/sona-patterns.json and reloaded by a fresh SONAOptimizer process.
  • hooks_route returned its AgentDB or local semantic/keyword route instead of a SONA-pattern route. The hooksRoute implementation tries bridgeRouteTask and then routeTaskLocal; it does not call SONAOptimizer.getRoutingSuggestion().
  • hooks_intelligence_pattern-search did not find the trajectory feedback. In hooksTrajectoryEnd, feedback promotion is gated on !hasSteps, so feedback from a trajectory that recorded steps is not indexed in the pattern namespace.
  • A single success increases SONA confidence from 0.50 to 0.55, below getRoutingSuggestion()'s 0.60 threshold. The response can therefore say “learned” even though one successful outcome is not yet eligible to affect routing; please clarify/document this evidence threshold or make the response explicit.

Relevant implementation areas in the published package:

  • @claude-flow/cli/dist/src/mcp-tools/hooks-tools.js: hooksTrajectoryEnd, hooksRoute, routeTaskLocal, hooksPatternSearch
  • @claude-flow/cli/dist/src/memory/sona-optimizer.js: processTrajectoryOutcome, getRoutingSuggestion, saveToDisk, loadFromDisk

Expected behavior

  • A qualifying persisted SONA routing pattern is considered by the normal hooks_route inference path, with an explicit confidence/valid-agent gate and an identifiable result source; otherwise, trajectory-end should not imply that routing was improved.
  • Non-empty feedback is promoted to a durable, searchable pattern whether or not trajectory steps were recorded, with trajectory metadata and outcome confidence preserved.
  • Add a fresh-process regression test proving both that an eligible persisted SONA pattern affects hooks_route and that feedback from a stepful trajectory is found by semantic pattern search.
  • Keep process-local counters distinct from persisted counters in telemetry; hooks_intelligence_unified-stats already documents their different scopes.

Related issues

Acceptance criteria

  • Successful, supported SONA patterns above the documented threshold can affect hooks_route after a process restart.
  • trajectory-end with non-empty feedback and one or more recorded steps makes that feedback retrievable through hooks_intelligence_pattern-search.
  • Response fields and metrics distinguish “recorded/persisted” from “eligible and used for inference.”
  • Integration tests cover a fresh process, threshold behavior, and both stepful and step-less trajectories.

Activity

  1. ruvnet commented on Oct 11, 2026

    @ruvnet
    Owner

    Nightly triage — 2026-10-11

    Status: fixed tonight (partial): draft PR #4051; remainder needs human input
    Verified both claims directly in v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts on current main (3.52.1). (1) hooksRoute/routeTaskLocal never call SONAOptimizer.getRoutingSuggestion() — confirmed getSuggestion/getRoutingSuggestion (src/memory/sona-optimizer.ts) have zero callers anywhere outside that file, so persisted SONA patterns never reach routing. This is real but architectural (precedence vs. the AgentDB pre-route and local semantic/keyword router, the confidence threshold the reporter also flags as ambiguous, and new response fields distinguishing "persisted" from "eligible for inference") — needs a human design call, not a guess from an unattended run. (2) hooksTrajectoryEnd's feedback promotion was gated on !hasSteps (line 3469), exactly as reported — #2351 only covered step-less trajectories. That half was small and mechanical, so I fixed it: removed the !hasSteps restriction and added __tests__/trajectory-feedback-indexing-3662.test.ts, which drives trajectory-start → trajectory-step → trajectory-end(feedback) → pattern-search end-to-end; confirmed it fails on current main (feedbackDistilled undefined) and passes with the fix, with no regressions in the related trajectory-recovery-3199/self-learning-2245/round-b-wiring-2245/hooks-intelligence-learning suites (25 tests). No duplicate or dream-cycle-labeled issue/PR covers this; #2222 and #1243 are related but closed and don't touch this gap.


    Generated by Claude Code

  2. added 2 commits that reference this issue on Oct 11, 2026
  3. ruvnet commented on Oct 11, 2026

    @ruvnet
    Owner

    The stepful-feedback half is fixed in #4051 (merged, 19c59a2): trajectory-end now promotes non-empty feedback to the pattern namespace even when steps were recorded, with an end-to-end regression test (start, step, end, pattern-search). It ships in the next release. The other half of this issue (hooks_route consulting persisted SONA patterns) is not covered by that PR, so I am leaving this open.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions