Skip to content

[Bug] Crystallized hooks not being integrated into runtime #3

@apoapostolov

Description

@apoapostolov

Bug Report: Crystallized hooks not active

Summary

When using foundry_crystallize to crystallize a pattern into a hook, the hook file is saved to ~/.openclaw/foundry/hooks/ but is not integrated into Foundry's runtime and therefore not being called.

Steps to Reproduce

  1. Run foundry_learnings to see recurring failures
  2. Run foundry_crystallize on a pattern (e.g., `foundry_crystallize patternId="fail_1771767040289_q5n00s"`)
  3. Hook is saved successfully to: `~/.openclaw/foundry/hooks/crystallized_edit_1772232868618.ts`
  4. Gateway is restarted via `foundry_restart`
  5. Hook is not called when the error condition occurs (e.g., using `oldText` instead of `old_string` in edit tool)
  6. Check metrics: `cat ~/.openclaw/foundry/metrics.json` — shows edit tool still has low fitness and failures continue

Expected Behavior

The crystallized hook should be automatically integrated into Foundry's runtime and should intercept `before_tool_call` events for the `edit` tool, injecting guidance when deprecated parameter names are detected.

Actual Behavior

  • Hook file exists in `~/.openclaw/foundry/hooks/` directory
  • Hook is not called during tool execution
  • Pattern continues to repeat (e.g., edit tool failures continue to increment)
  • Metrics show `edit` tool at 36% fitness with recurring failures

Environment

  • Foundry version: Latest from `openclaw plugins install @getfoundry/foundry-openclaw`
  • OpenClaw version: Running from repo at `/home/apoapostolov/git/openclaw`
  • OS: Linux (OpenClaw Gateway)

Hook File Content

The crystallized hook (`crystallized_edit_1772232868618.ts`):
```typescript
api.on("before_tool_call", async (event, ctx) => {
if (event.toolName === "edit") {
// Detects and prevents parameter mismatch
// ...
}
});
```

Additional Context

Looking at Foundry's `index.ts`, there is a `before_tool_call` handler at line 1594, but the crystallized hooks from `~/.openclaw/foundry/hooks/` do not appear to be loaded or integrated into the runtime.

Suggested Fix

Either:

  1. Auto-integration: `foundry_crystallize` should automatically integrate the hook into Foundry's `index.ts` or a hooks loading mechanism
  2. Manual integration: Provide clear documentation on how to manually integrate crystallized hooks into the runtime
  3. Hook loading: Implement a hook discovery/loader that automatically loads all hooks from `~/.openclaw/foundry/hooks/` into the runtime

Impact

  • Crystallization is a core feature of Foundry for converting learned patterns into permanent behavior
  • Without working hook integration, patterns are crystallized but never executed
  • This defeats the purpose of the HexMachina crystallization system

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