Skip to content

fix(cli): honor systemPromptWhen=always on session resume#35705

Closed
mylukin wants to merge 1 commit into
openclaw:mainfrom
mylukin:pr/cli-backend
Closed

fix(cli): honor systemPromptWhen=always on session resume#35705
mylukin wants to merge 1 commit into
openclaw:mainfrom
mylukin:pr/cli-backend

Conversation

@mylukin

@mylukin mylukin commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Problem

When a CLI backend session (e.g., Claude Code) is resumed with --resume, the system prompt is silently dropped because of this guard:

// Before (broken):
if (!params.useResume && params.systemPrompt && params.backend.systemPromptArg) {
  args.push(params.backend.systemPromptArg, params.systemPrompt);
}

This means resumed sessions lose access to skills, workspace context, and agent instructions — the model operates "blind" without its configured system prompt.

Session flow WITHOUT this fix:

  New session:     claude --system-prompt "skills + context" -p "task"     ✓ has context
  Resumed session: claude --resume <id> -p "follow-up"                    ✗ no context!

Session flow WITH this fix (systemPromptWhen=always):

  New session:     claude --system-prompt "skills + context" -p "task"     ✓ has context
  Resumed session: claude --resume <id> --append-system-prompt "..." -p   ✓ has context

Fix

Remove the !params.useResume guard from the system prompt argument builder. When systemPromptWhen is set to "always" in the CLI backend config, the system prompt is now passed on every invocation, including resumed sessions.

Added a test that verifies --append-system-prompt is included in argv when resuming with systemPromptWhen=always, and that the prompt contains <available_skills>.

Why merge

Without this fix, any multi-turn CLI agent session loses its identity after the first turn. The model forgets its skills, workspace layout, and behavioral instructions on resume. This causes degraded responses, inability to use skills, and effectively breaks multi-turn agent workflows for all CLI backends.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Mar 5, 2026
@greptile-apps

greptile-apps Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Summary

This PR fixes a one-line bug in buildCliArgs where the !params.useResume guard incorrectly suppressed system prompt injection on resumed CLI sessions, even when systemPromptWhen: "always" was configured.

Root Cause:
The systemPrompt value passed into buildCliArgs is already pre-filtered by the upstream resolveSystemPromptUsage function, which correctly evaluates the systemPromptWhen setting ("first"/"always"/"never"). The removed guard was redundant—resolveSystemPromptUsage already returns null for resume sessions when systemPromptWhen === "first" (the default), making the additional !params.useResume check in buildCliArgs unnecessary.

Changes:

  • src/agents/cli-runner/helpers.ts: Removes !params.useResume && from the system prompt condition (line 362). The model-arg and session-ID guards remain correctly gated on !params.useResume to preserve existing behavior.
  • src/agents/cli-runner.test.ts: Adds integration test verifying that a resumed claude-cli session with systemPromptWhen: "always" produces --append-system-prompt in the spawned argv with correct system prompt content.

Safety:
No regressions expected. The default systemPromptWhen: "first" behavior is unaffected because resolveSystemPromptUsage already filters it out for non-new sessions. Users without a custom systemPromptWhen config are unaffected. The fix is narrowly scoped and backed by comprehensive test coverage.

Confidence Score: 5/5

  • This PR is safe to merge. It is a minimal, targeted one-line fix with no regression risk for default configurations.
  • The fix is a single-line removal of a redundant guard. Data flow verification confirms correctness: buildCliArgs receives a systemPrompt value already pre-filtered by resolveSystemPromptUsage, which correctly handles the first/always/never policy. No existing tests break, and the new test exercises the full path end-to-end including skill discovery and system prompt generation. The change correctly handles both the default case (systemPromptWhen: "first" on resume returns null upstream) and the bug case (systemPromptWhen: "always" on resume now includes the prompt). Model and session ID guards remain properly constrained with !params.useResume.
  • No files require special attention

Last reviewed commit: 00cd85b

@mylukin

mylukin commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

/review

@mylukin

mylukin commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing: upstream not accepting merge at this time.

@mylukin mylukin closed this Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant