Repository navigation
fix(openclaw): inject the user profile into automatic context - #5676
Merged
Merged
Conversation
Server context assembly leaves memories/profile.md out because the hook plugins inject it at session start, but OpenClaw never did, so facts the extractor files into the profile never reached the model. Read the user's profile (and the actor peer's under peer_role) through the viking://~ alias and add it as <user-profile> to systemPromptAddition on every main assemble, since that addition is rebuilt each turn. Recall is dropped before the profile when the token budget is tight. Also reword the missing-session log line: it only means session history was not assembled, and recall still runs afterwards.
The capability reference still described OpenClaw recall as /find without a session and listed no profile injection. Update the OpenClaw rows for context-search recall, the system-prompt placement, the profile block and the recall timeout, in English and Chinese.
The profile read used the client default timeout (15 s), so a degraded server could add a full timeoutMs to every main assemble even after recall gave up on its 500 ms health precheck. Give client.read an optional request timeout and cap the profile read at min(autoRecallTimeoutMs, 3 s). When the profile did not fit the token budget, the fallback never tried recall alone, so recall the old code injected was lost. Try recall by itself as the last candidate. Profile read failures other than a missing file (401/403, 5xx, timeouts) were indistinguishable from "no profile.md". Warn on them.
ZaynJarvis
approved these changes
Oct 7, 2026
11 of 14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
OpenClaw now injects the user profile into its automatic context, so facts that memory extraction files only into
memories/profile.mdreach the model in later sessions. On every mainassemble, the plugin readsviking://~/memories/profile.md, plus the actor peer'sprofile.mdwhen an actor peer resolves, and adds it tosystemPromptAdditionas a<user-profile>block next to the session guide and auto-recall. The PR also rewords a misleading log line and fixes the OpenClaw rows in the capability reference.Root cause
Two things combine:
profile.md. OpenClaw auto-recall calls/api/v1/search/searchwithmode: "context",purpose: "coding"and codingquotas. Quotas are always sent, becauserecallLimithas a default. With quotas, gathering runs per bucket, and each memory bucket searches onlymemories/<category>(events, entities, preferences, experiences), somemories/profile.mdfalls under none of them. Flat mode would search the memory root, but_builddrops*/profile.mdexplicitly.buildProfileBlock()at session start, and Hermes has its own reader. OpenClaw'sassembleOpenVikingSessionadded only the archive "Session Context Guide" and the recall block. Nothing in the plugin readprofile.md.How it was introduced
profile.mdexclusion to server recall, on the premise that the hook plugins inject the profile at SessionStart.context_assembler/gather.py.client.findoverviking://~/memories, which could returnprofile.md.mode: "context"without adding the profile injection that the exclusion assumes. This is the regression point. The capability reference was not updated afterwards and still said OpenClaw recall uses/findwith no session field.Why every main turn
OpenClaw's
systemPromptAdditionis not persisted:assemble()rebuilds it on every call, and the Session Context Guide is re-added every turn. Injecting the profile only on the first assemble would drop it from turn 2 onward. Injecting it on every main assemble is the OpenClaw equivalent of a session-start block that stays in the transcript, and pi already rebuilds its profile in the system prompt every turn.Alternatives considered
viking://~alias resolves on the server per request, so it is safe for a multi-user gateway. Cost: one or twoGET /content/readper main turn, run in parallel with recall.buildProfileBlock(). It caches the resolved user space in a module-level variable, which can leak across identities in a long-running multi-user gateway, and it adds 3–4 requests per turn.include_profileflag to/searchcontext mode. This adds public API surface, and the profile would show up only when it scores above the threshold, while the other integrations always inject it.Human Involvement
Related Issue
Fixes #5671
Type of Change
Changes Made
services/context-lifecycle-service.ts:readProfileBlock()reads the user profile and, when an actor peer resolves, the peer profile. Each is capped at 8,000 characters with a truncation marker.autoRecallon, session not bypassed. Short prompts that skip recall still get the profile.min(autoRecallTimeoutMs, 3 s). Failures other than a missing file are logged as warnings, and a recall failure leaves the profile in place.resolveAssembleRouting()so the profile read and recall share it.client.ts:read()takes an optional per-request timeout.16-capability-reference.mdand thesystemPromptAdditiondescription in03-openclaw.md(en and zh) now describe profile injection and the context-search recall (/api/v1/search/search,mode: "context", with the session id).Testing
I have added tests that prove my fix is effective or that my feature works
New and existing unit tests pass locally with my changes
I have tested this on the following platforms:
New tests in
tests/ut/context-engine-assemble.test.tsandtests/ut/client.test.tscover: the issue's scenario for fresh and missing sessions, order across two turns, short prompts, a missing profile, a recall failure, peer profiles, truncation, the budget fallback, the read timeout, failure logging, and no read whenautoRecallis off, the session is bypassed, or duringtransformContext. With the source changes reverted, the tests covering the new behavior fail.npx vitest run: 810 passed, 1 failed. The failure (package-install-contract.test.ts› "ships and registers the canonical Experience skill") also fails onorigin/main, because the two copies of theov-experience-memoryskill already differ there.npm run typecheckis clean.Checklist
Screenshots (if applicable)
N/A
Additional Notes
16-capability-reference.mdstill says OpenClaw and Hermes cap injected recall at 4,000 characters and skip entries that do not fit. OpenClaw now passes that cap to the server asmax_tokens. That line is not changed here.