Skip to content

fix(hooks): honor session-memory hook model override for LLM slug generation [AI-assisted] - #89561

Closed
luyao618 wants to merge 1 commit into
openclaw:mainfrom
luyao618:fix/session-memory-hook-model-override
Closed

luyao618 wants to merge 1 commit into
openclaw:mainfrom
luyao618:fix/session-memory-hook-model-override

Conversation

@luyao618

@luyao618 luyao618 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

🤖 AI-assisted (built with Hermes orchestration; reviewer = 麻酱, code review = Codex CLI). Test level: fully tested. Prompt summary available on request.

Summary

  • Problem: hooks.internal.entries["session-memory"].model was silently ignored; slug generation always used the agent's default model.
  • Solution: introduce a small pure helper that prefers a parseable hook-level model override and falls back to the agent default; thread it through generateSlugViaLLM.
  • What changed: src/hooks/llm-slug-generator.ts (+ helper + new optional modelOverride param), src/hooks/bundled/session-memory/handler.ts (forwards hookConfig.model), src/hooks/llm-slug-generator.test.ts (regression tests).
  • What did NOT change (scope boundary): no schema change (HookConfigSchema already .passthrough()), no other hooks touched, no behavior change when the override is absent or unparseable, no agent-level model resolution paths modified.

Motivation

Users who set a cheaper / faster model on the session-memory hook (e.g. to keep /reset slug generation off their primary coding model) expect that override to be used. Today the hook config is read but the model field is silently dropped, so the slug call still spends primary-model tokens. This is a behavior bug filed in #89551 and is trivially reproducible with a hook config.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: slug-generation model selection now honors hooks.internal.entries["session-memory"].model.
  • Real environment tested: local OpenClaw checkout @ upstream/main f789081bae123099e5a057ca43d8be35e35c6c48, macOS, Node v22.15.0. Repro drives the real resolveDefaultModelForAgent and resolveSlugGeneratorModelRef source modules via tsx — no mocks, no stubbed providers.
  • Exact steps or command run after this patch:
    1. Constructed a config with agents.defaults.model.primary = "openai/gpt-5.5" and hooks.internal.entries["session-memory"].model = "anthropic/claude-3-5-haiku".
    2. node_modules/.bin/tsx repro-89551.mjs (driver imports source .ts by absolute path).
  • Evidence after fix (redacted terminal capture):
    === BEFORE the fix (current main) ===
    agent default ref: { provider: 'openai', model: 'gpt-5.5' }
    slug-gen ref (BEFORE: simulated current main behavior): { provider: 'openai', model: 'gpt-5.5' }
    hook override requested: anthropic/claude-3-5-haiku
    ❌ Bug #89551 reproduced: slug generator picked openai/gpt-5.5 instead of the hook-level model anthropic/claude-3-5-haiku.
    
    === AFTER the fix (this branch) ===
    agent default ref: { provider: 'openai', model: 'gpt-5.5' }
    slug-gen ref (AFTER fix): { provider: 'anthropic', model: 'claude-3-5-haiku' }
    ✅ Bug #89551 fixed: hook-level model is honored, fallbacks preserved.
    
  • Observed result after fix: the slug generator now resolves to the hook-level provider/model when one is configured, and continues to fall back to the agent default for undefined / empty / whitespace / unparseable overrides.
  • What was not tested: did not exercise a live /reset end-to-end against a real model provider; mocked plugin load warnings (pi-ai/oauth) in the repro environment are unrelated to the change.
  • Before evidence: same BEFORE block above (captured by stashing the fix and rerunning the same driver).

Root Cause (if applicable)

  • Root cause: generateSlugViaLLM in src/hooks/llm-slug-generator.ts unconditionally called resolveDefaultModelForAgent({ cfg, agentId }), and the session-memory handler read resolveHookConfig(cfg, "session-memory") but never extracted or forwarded hookConfig.model to the slug generator.
  • Missing detection / guardrail: no unit test asserted what provider/model is sent to runEmbeddedAgent when a hook-level model override is present.
  • Contributing context: HookConfigSchema is .passthrough(), so the override silently parsed and survived as unknown without ever being consumed.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/hooks/llm-slug-generator.test.ts.
  • Scenario the test should lock in: a hook-level model override is honored end-to-end into runEmbeddedAgent's provider/model; absent / empty / whitespace / unparseable overrides fall back to the agent default.
  • Why this is the smallest reliable guardrail: the new helper is the single decision point; it.each over the override values exhaustively pins behavior without needing a real provider.
  • Existing test that already covers this (if any): N/A.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

  • When hooks.internal.entries["session-memory"].model is set (and parseable), session-memory slug generation now uses that model. When unset, empty, or unparseable, behavior is unchanged (agent default).

Diagram (if applicable)

Before: hookConfig.model ──(ignored)── generateSlugViaLLM ── resolveDefaultModelForAgent ── agent default
After:  hookConfig.model ──► generateSlugViaLLM(modelOverride) ──► resolveSlugGeneratorModelRef
                                                                       │
                                                          parseable ──►├──► hook override ref
                                                          else        ─┴──► resolveDefaultModelForAgent

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No (the routing target may change to a different already-configured provider; no new outbound surface)
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node v22.15.0, pnpm (repo-pinned)
  • Model/provider: N/A (driver does not hit a real provider)
  • Integration/channel (if any): N/A
  • Relevant config (redacted): agents.defaults.model.primary, hooks.internal.entries["session-memory"].{enabled,llmSlug,model}

Steps

  1. git fetch upstream && git checkout fix/session-memory-hook-model-override
  2. node_modules/.bin/vitest run src/hooks/llm-slug-generator.test.ts src/hooks/bundled/session-memory/handler.test.ts → 35 passed
  3. pnpm exec oxfmt --check src/hooks/llm-slug-generator.ts src/hooks/llm-slug-generator.test.ts src/hooks/bundled/session-memory/handler.ts → clean
  4. node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --pretty false --incremental → 0 errors
  5. Repro driver: BEFORE → ❌ (slug-gen picks openai/gpt-5.5), AFTER → ✅ (slug-gen picks anthropic/claude-3-5-haiku).

…eration

The session-memory hook accepts a per-hook `model` config field (used to
route the small slug-generation call to a cheaper model than the agent's
primary). The handler resolved `hookConfig` via `resolveHookConfig()`
but never forwarded `hookConfig.model` to `generateSlugViaLLM`, which
unconditionally called `resolveDefaultModelForAgent()`. Result: the
override was silently ignored and the agent's default model was always
used.

Add a small pure helper `resolveSlugGeneratorModelRef` that prefers the
hook-level override when present and parseable (full `provider/model`
or bare model with the agent's default provider), and falls back to the
agent default for undefined, empty, whitespace, or unparseable inputs.
Wire it through `generateSlugViaLLM` via a new optional
`modelOverride` parameter, and have the session-memory handler pass
`hookConfig.model` through.

Closes openclaw#89551
[AI-assisted]
@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 2, 2026
@clawsweeper

clawsweeper Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 2, 2026, 1:55 PM ET / 17:55 UTC.

Summary
The PR forwards hooks.internal.entries.session-memory.model into LLM slug generation and adds slug-generator tests for override and fallback model selection.

PR surface: Source +44, Tests +80. Total +124 across 3 files.

Reproducibility: yes. from source: current main reads the session-memory hook config but never forwards hookConfig.model, and the slug generator resolves only the agent default model. I did not run the hook locally because this review is read-only.

Review metrics: 1 noteworthy metric.

  • Hook Config Surface: 1 runtime key activated. hooks.internal.entries.session-memory.model changes from ignored passthrough data into provider-routing input, so docs, doctor, and upgrade behavior matter before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦪 silver shellfish
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Use the canonical alias-aware model-selection resolver for the hook override.
  • Document and doctor-check the supported session-memory.model behavior.
  • [P1] Add redacted terminal or live output proving the actual session-memory hook path after the patch.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body includes useful terminal output from a source-level driver, but it does not show the actual /reset or session-memory hook path after the patch; add redacted terminal/live output and update the PR body to trigger re-review.

Risk before merge

  • [P1] A configured model alias, auth-profile-bearing model string, or configured-provider ref can be misinterpreted by the new parseModelRef path, causing slug generation to use the wrong provider/model or fail as unknown.
  • [P1] The PR activates a previously ignored provider-routing config value, so existing configs with hooks.internal.entries.session-memory.model can start sending session snippets to a different configured provider after upgrade.
  • [P1] The PR body's terminal proof exercises a resolver-style driver, but it does not show the real /reset or session-memory hook path after the patch.

Maintainer options:

  1. Fix Resolver And Contract Before Merge (recommended)
    Use the existing alias-aware model-selection resolver for this hook override, then add docs/doctor and handler coverage so the new config key behaves like other supported model surfaces.
  2. Accept A Narrow Simple-String Contract
    Maintainers may intentionally support only literal provider/model or bare model strings, but the PR should document that limitation and the upgrade behavior before landing.
  3. Pause Until Product Contract Is Chosen
    If session-memory.model is not intended as a supported hook config key, pause or close this branch and keep slug generation on the existing configured-model behavior.

Next step before merge

  • [P1] Manual review is needed because the PR requires a maintainer decision on the new hook model config contract and contributor-supplied real hook-path proof; automation cannot supply that proof for the contributor.

Security
Cleared: No new dependency, workflow, permission, secret-handling, or arbitrary code-execution surface was introduced; the provider-routing privacy concern is tracked as merge risk.

Review findings

  • [P1] Use the canonical model resolver for hook overrides — src/hooks/llm-slug-generator.ts:48
  • [P2] Document and validate the new hook model contract — src/hooks/bundled/session-memory/handler.ts:236-237
Review details

Best possible solution:

Resolve the session-memory override through the canonical alias-aware model-selection API, add handler-level forwarding coverage, document and validate the new hook model contract, then require redacted terminal or live output proving the actual hook path.

Do we have a high-confidence way to reproduce the issue?

Yes from source: current main reads the session-memory hook config but never forwards hookConfig.model, and the slug generator resolves only the agent default model. I did not run the hook locally because this review is read-only.

Is this the best way to solve the issue?

No: the proposed fix is plausible for literal provider/model strings, but it is not the best OpenClaw-shaped fix because it bypasses the existing alias-aware model-selection contract and leaves the new config surface undocumented and unchecked.

Full review comments:

  • [P1] Use the canonical model resolver for hook overrides — src/hooks/llm-slug-generator.ts:48
    This new resolver calls parseModelRef directly, so a configured alias such as fast-slug is treated as a raw model on the fallback provider instead of resolving through the alias index like hooks.gmail.model and other model-selection paths. Route the override through the existing alias-aware resolver before passing provider/model to runEmbeddedAgent, otherwise alias-based configs still use the wrong or unknown model.
    Confidence: 0.82
  • [P2] Document and validate the new hook model contract — src/hooks/bundled/session-memory/handler.ts:236-237
    This line makes hooks.internal.entries.session-memory.model affect runtime provider routing, but the session-memory docs list only messages and llmSlug, and doctor currently validates hooks.gmail.model but not this new hook key. Before merge, document the option and add or extend health-check coverage so typos, disallowed models, and missing catalog rows are visible before /reset slug generation fails or silently routes elsewhere.
    Confidence: 0.76

Overall correctness: patch is incorrect
Overall confidence: 0.78

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 1d3cfc4b0168.

Label changes

Label justifications:

  • P2: This is a scoped hook/provider-routing bug fix with limited blast radius but real user-visible model-selection impact.
  • merge-risk: 🚨 compatibility: Merging activates a previously ignored session-memory hook config key and can change behavior for existing configs after upgrade.
  • merge-risk: 🚨 auth-provider: The activated key can route session-memory slug generation to a different provider/model than the agent default.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body includes useful terminal output from a source-level driver, but it does not show the actual /reset or session-memory hook path after the patch; add redacted terminal/live output and update the PR body to trigger re-review.
Evidence reviewed

PR surface:

Source +44, Tests +80. Total +124 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 46 2 +44
Tests 1 81 1 +80
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 127 3 +124

What I checked:

  • Repository policy applied: Root AGENTS.md and scoped src/agents guidance require whole-path review, compatibility scrutiny for config/provider routing, and source-backed review beyond the diff. (AGENTS.md:7, 1d3cfc4b0168)
  • Current main ignores the hook model: Current main reads the session-memory hook config and gates llmSlug, but calls generateSlugViaLLM({ sessionContent, cfg }) without forwarding any hook-level model value. (src/hooks/bundled/session-memory/handler.ts:208, 1d3cfc4b0168)
  • Current slug generation always uses the agent default: Current main's slug generator calls resolveDefaultModelForAgent and passes that provider/model to runEmbeddedAgent, so the reported override cannot influence routing today. (src/hooks/llm-slug-generator.ts:56, 1d3cfc4b0168)
  • PR uses low-level parsing for the new override: The proposed resolver parses the override with parseModelRef(trimmed, fallbackRef.provider), which does not use the alias index or configured-provider resolution used elsewhere. (src/hooks/llm-slug-generator.ts:48, 5afc9356ff25)
  • Canonical model string resolver is alias-aware: resolveModelRefFromString strips auth profiles, checks aliasIndex.byAlias, and then falls back to configured provider/model parsing; this is the model-selection contract the PR bypasses. (src/agents/model-selection-shared.ts:689, 1d3cfc4b0168)
  • Existing hook model surface uses alias-aware resolution: resolveHooksGmailModel builds a model alias index and delegates to resolveModelRefFromString, showing the existing pattern for hook-level model config. (src/agents/model-selection-shared.ts:1311, 1d3cfc4b0168)

Likely related people:

  • vincentkoc: Git blame and -S history show commit 07821e4 added the session-memory hook, LLM slug generator, docs, tests, and the alias-aware model-selection surfaces involved in this review. (role: introduced behavior and adjacent model-routing owner; confidence: high; commits: 07821e4bb829; files: src/hooks/bundled/session-memory/handler.ts, src/hooks/llm-slug-generator.ts, src/hooks/bundled/session-memory/HOOK.md)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 2, 2026
@luyao618

luyao618 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Closing this — ClawSweeper flagged real correctness/compat risks I don't want to ship: the new parseModelRef path can misinterpret alias-aware model strings and silently re-route existing hooks.internal.entries.session-memory.model configs to a different provider after upgrade (P1 auth-provider + compatibility risk). Right approach is to reuse the canonical alias-aware model-selection resolver rather than introduce a parallel parser. Will reopen with a clean rewrite if/when I get to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: session-memory hook model config ignored for LLM slug generation

1 participant