feat: conditional bootstrap file loading for heartbeat vs DM sessions#13524
feat: conditional bootstrap file loading for heartbeat vs DM sessions#13524tarun131313 wants to merge 1 commit into
Conversation
Add session-type-aware filtering to filterBootstrapFilesForSession(): - Heartbeat runs: load only HEARTBEAT.md, AGENTS.md, IDENTITY.md - Normal DM sessions: load all files EXCEPT HEARTBEAT.md - Subagent sessions: unchanged (AGENTS.md + TOOLS.md) This saves ~1,400+ tokens per DM message by excluding heartbeat instructions that are only relevant during heartbeat polls, and saves tokens during heartbeat runs by excluding files the heartbeat poller doesn't need (SOUL.md, TOOLS.md, USER.md, MEMORY.md). The isHeartbeat flag is threaded from the auto-reply layer through the embedded runner to the bootstrap file resolver. Related: openclaw#9157 (workspace file injection token waste) Related: openclaw#1594 (heartbeat context overhead)
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/auto-reply/reply/followup-runner.ts
Line: 117:122
Comment:
**Heartbeat runs misclassified**
`registerAgentRunContext()` here doesn’t include `isHeartbeat`, so followup heartbeat runs won’t be marked as heartbeat in the run context. This breaks consumers that gate behavior on `getAgentRunContext(runId)?.isHeartbeat` (e.g. webchat heartbeat broadcast suppression in `src/gateway/server-chat.ts:12-25`). Consider passing `isHeartbeat: opts?.isHeartbeat === true` in this call.
How can I resolve this? If you propose a fix, please make it concise. |
bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Problem
Workspace bootstrap files (AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, USER.md, HEARTBEAT.md, MEMORY.md) are injected into every agent run regardless of session type. This wastes tokens:
For users with multiple agents and detailed HEARTBEAT.md files, this adds up to 1,400+ wasted tokens per DM message.
Solution
Extend
filterBootstrapFilesForSession()to support session-type-aware filtering:The
isHeartbeatflag is threaded from the auto-reply layer through the embedded runner to the bootstrap file resolver.Changes
workspace.ts: AddedHEARTBEAT_BOOTSTRAP_ALLOWLIST,DM_BOOTSTRAP_EXCLUDELIST, andFilterBootstrapOptionstype. ExtendedfilterBootstrapFilesForSession()with optionaloptsparameter.bootstrap-files.ts: ThreadisHeartbeatthroughresolveBootstrapFilesForRunandresolveBootstrapContextForRun.run/types.ts+run/params.ts: AddedisHeartbeat?to embedded run params.run/attempt.ts+run.ts: PassisHeartbeatto bootstrap context resolver.followup-runner.ts+agent-runner-execution.ts: PassisHeartbeatto embedded runner.Testing
workspace.test.ts: 4/4,bootstrap-files.test.ts: 2/2)optsparameter is optional, existing behavior unchanged when not providedRelated Issues
Greptile Overview
Greptile Summary
This PR adds session-type-aware bootstrap file filtering to reduce token waste: subagent runs continue to load a minimal allowlist, heartbeat runs load only HEARTBEAT.md + core identity/agent files, and normal DM sessions load everything except HEARTBEAT.md. The new
isHeartbeatflag is threaded from the auto-reply layer through the embedded runner into the bootstrap resolver, which then calls the updatedfilterBootstrapFilesForSession().Main issue to address before merge: followup runs don’t register
isHeartbeatin the agent run context, which can break downstream behavior that relies ongetAgentRunContext(runId)?.isHeartbeat(notably webchat broadcast suppression for heartbeats).Confidence Score: 3/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!