openclaw - ✅(Solved) Fix session_status leaks stale task context in chat (/status shows old completed jobs) [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58661Fetched 2026-04-08 01:59:34
View on GitHub
Comments
1
Participants
1
Timeline
7
Reactions
0
Author
Participants
Assignees
Timeline (top)
assigned ×1closed ×1cross-referenced ×1locked ×1

/status (session_status) in chat can include stale/noisy task context that feels unrelated to the current conversation state.

In our Telegram topic sessions, the 📌 Tasks: line kept surfacing old completed subagent work (and previously, synthetic internal task text), even when there were no active tasks.

Root Cause

/status (session_status) in chat can include stale/noisy task context that feels unrelated to the current conversation state.

In our Telegram topic sessions, the 📌 Tasks: line kept surfacing old completed subagent work (and previously, synthetic internal task text), even when there were no active tasks.

PR fix notes

PR #58810: fix(status): filter stale task rows from status cards

Description (problem / solution / changelog)

Summary

  • Problem: /status and session_status were reading raw retained task rows, so stale completed tasks could keep showing up as if they were still the relevant session context.
  • Why it matters: users checking current status can miss active work, or see misleading stale task context after cleanup has not swept yet.
  • What changed: added a cleanup-aware task status snapshot, routed both status surfaces through it, preferred active tasks, and only surfaced recent failures when no active work remains.
  • What did NOT change (scope boundary): this does not change task creation, retention policy, or maintenance sweep behavior.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

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

  • Closes #58661
  • Related #54226
  • This PR fixes a bug or regression

Root Cause / Regression History (if applicable)

  • Root cause: both status surfaces built their task line from raw retained registry rows instead of a cleanup-aware view.
  • Missing detection / guardrail: there was no shared status-specific snapshot helper that excluded expired rows and prioritized active tasks.
  • Prior context (git blame, prior PR, issue, or refactor if known): task status surfaces were added before a dedicated status snapshot layer existed.
  • Why this regressed now: task retention and task-linked status became useful enough that stale completed rows were visible to users in normal /status checks.
  • If unknown, what was ruled out: this was not a task maintenance sweep failure alone; the UI path itself was reading the wrong view.

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/auto-reply/reply/commands-status.test.ts, src/agents/openclaw-tools.session-status.test.ts
  • Scenario the test should lock in: stale completed tasks should not headline status when no active visible work remains, and recent failures should only surface when active tasks are absent.
  • Why this is the smallest reliable guardrail: both user-visible status surfaces share the same summary semantics, and these tests assert those semantics directly.
  • Existing test that already covers this (if any): none.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

  • /status prefers active session-linked tasks over stale completed rows.
  • session_status follows the same cleanup-aware task view.
  • Recent failures are still visible, but only when there is no active work to show.
  • Changelog entry included under Unreleased > Fixes. Thanks @vincentkoc.

Diagram (if applicable)

Before:
[/status] -> [raw retained tasks] -> [stale completed row may headline]

After:
[/status] -> [cleanup-aware task snapshot] -> [active tasks first | else recent failure | else recent completion]

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • 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: local worktree
  • Model/provider: N/A
  • Integration/channel (if any): chat /status, session_status
  • Relevant config (redacted): default local dev config

Steps

  1. Create retained completed task rows and at least one active task linked to a session.
  2. Run the chat /status path or the session_status tool.
  3. Compare the task headline before and after the snapshot filtering.

Expected

  • Active task context is shown first.
  • Expired/stale completed rows do not headline status.
  • Recent failures only appear when no active work remains.

Actual

  • Verified by targeted tests below.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: /status active-vs-stale behavior, session_status active-vs-recent-failure behavior.
  • Edge cases checked: expired retained rows excluded even before maintenance sweep; recent failures still visible when there is no active work.
  • What you did not verify: live channel smoke across every chat transport.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: status hides a terminal task a user still wanted to inspect.
    • Mitigation: openclaw tasks remains the full ledger/operator surface; this change only narrows the status summary view.

AI-assisted: yes. Targeted tests and local pnpm check run.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/openclaw-tools.session-status.test.ts (modified, +134/-8)
  • src/agents/tools/session-status-tool.ts (modified, +14/-20)
  • src/auto-reply/reply/commands-status.test.ts (modified, +92/-1)
  • src/auto-reply/reply/commands-status.ts (modified, +18/-18)
  • src/tasks/task-owner-access.ts (modified, +13/-0)
  • src/tasks/task-status.ts (added, +68/-0)
RAW_BUFFERClick to expand / collapse

Summary

/status (session_status) in chat can include stale/noisy task context that feels unrelated to the current conversation state.

In our Telegram topic sessions, the 📌 Tasks: line kept surfacing old completed subagent work (and previously, synthetic internal task text), even when there were no active tasks.

What I observed

  • session_status builds the task line from listTasksForRelatedSessionKeyForOwner(...) and includes latest task context even when there are 0 active tasks.
  • In practice, this keeps old completed subagent jobs visible in /status for that session/topic.
  • Previously, synthetic task rows also appeared in status context:
    • OpenClaw runtime context (internal): ...
    • async followup artifacts (An async command did not run..., An async command the user already approved has completed...)

Exact cleanup I performed (production state DB)

SQLite DB: ~/.openclaw/tasks/runs.sqlite

  1. Removed synthetic terminal task rows across sessions (plus delivery-state rows)
  • Match criteria:
    • runtime='cli'
    • status IN ('succeeded','failed','cancelled','timed_out','lost')
    • task text contains one of:
      • OpenClaw runtime context (internal):
      • An async command did not run.
      • An async command the user already approved has completed.
  • Removed: 15 rows
  • Backup: ~/.openclaw/tasks/runs.sqlite.bak-20260331-214143-synthetic-clean
  1. Removed completed Telegram-topic subagent rows (plus delivery-state rows)
  • Match criteria:
    • runtime='subagent'
    • owner_key LIKE 'agent:main:telegram:group:-1003826723328:topic:%'
    • status IN ('succeeded','failed','cancelled','timed_out','lost')
  • Removed: 10 rows
  • Backup: ~/.openclaw/tasks/runs.sqlite.bak-20260331-215741-tg-subagent-clean
  • Removed task_ids:
    • 12cbc768-b53e-4500-809d-da6dfe0a28a9
    • add11ddf-2545-43f5-91bf-7b8fb7b6bd2a
    • 52c5802c-e81b-48e3-950d-c5980d3c8cfe
    • fabfcae0-ab70-433d-93b9-9659502467ee
    • eed27730-d56c-4559-bb2c-da19d291d32e
    • 686eb40a-add1-4136-8ada-380635110ac3
    • c20898e4-89cc-4566-8d38-0537a0721ed6
    • 674c1529-964f-40d1-b322-79b2aa496cb2
    • fdb4f45b-23e2-4961-a82d-6f9c8aca4d06
    • 3d4e2eef-b86d-41d5-8807-00f09ef74ea0

Why this seems buggy

For chat UX, /status should prioritize current state. Showing old completed task context by default is noisy and misleading when there are no active tasks.

Suggested fix

  • In session_status/buildStatusText task-line logic, prefer:
    1. show task line only when there are active tasks, or
    2. show only recent failures (short window), or
    3. gate “latest succeeded ...” behind an explicit verbose/debug mode.
  • Also ensure synthetic internal followup/runtime-context tasks are never treated as user-facing status context.

extent analysis

TL;DR

Modify the session_status logic to only show the task line when there are active tasks or implement a filtering mechanism to exclude old completed tasks.

Guidance

  • Review the listTasksForRelatedSessionKeyForOwner function to understand how it retrieves tasks and consider modifying it to filter out completed tasks.
  • Implement a check in the buildStatusText function to only include the task line when there are active tasks.
  • Consider adding a verbose/debug mode to gate the display of "latest succeeded" tasks.
  • Ensure that synthetic internal followup/runtime-context tasks are excluded from user-facing status context.

Example

def buildStatusText(session):
    # ...
    tasks = listTasksForRelatedSessionKeyForOwner(session)
    active_tasks = [task for task in tasks if task.status not in ['succeeded', 'failed', 'cancelled', 'timed_out', 'lost']]
    if active_tasks:
        # include task line in status text
        task_line = "📌 Tasks: " + ", ".join([task.name for task in active_tasks])
        # ...
    # ...

Notes

The suggested fix requires modifying the existing code to filter out old completed tasks and synthetic internal tasks. This may involve changing the database queries or adding additional logic to the session_status function.

Recommendation

Apply a workaround by modifying the session_status logic to only show the task line when there are active tasks, as this is a more straightforward solution that can be implemented without significant changes to the existing code.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING