openclaw - ✅(Solved) Fix CLI `sessions --json` missing subagent runtime parent metadata (spawnedBy, label, status, sessionFile) [2 pull requests, 1 comments, 2 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#80286Fetched 2026-05-11 03:16:51
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
2
Timeline (top)
cross-referenced ×2commented ×1mentioned ×1subscribed ×1

openclaw sessions --agent <agent> --json does not expose spawnedBy, label, status, or sessionFile fields that are present in the underlying Gateway session store (sessions.json). This blocks consumers that need to reason about subagent runtime parent lineage from the supported CLI surface.

Root Cause

Read-only consumers (lineage detectors, governance audits, fleet observability) that follow substrate-discipline (CLI as authoritative interface, no direct store reads) currently cannot:

  • Distinguish "runtime lineage known but task lineage missing" from "runtime lineage unknown"
  • Compute runtimeLineageCoveragePct accurately
  • Avoid overstating unknown-lineage debt when the runtime in fact has the metadata

We are working around this by emitting sourceShapeStatus="blocked_no_rich_source" and honest zero-coverage counters until a supported surface exposes the fields.

Fix Action

Fixed

PR fix notes

PR #80303: fix(sessions): expose subagent runtime parent metadata in --json output

Description (problem / solution / changelog)

Summary

Fixes #80286.

openclaw sessions --json did not expose spawnedBy, label, status, sessionFile, sessionStartedAt, lastInteractionAt, subagentRole, subagentControlScope, spawnedWorkspaceDir, or spawnDepth fields, even though they are present in the underlying sessions.json store. Read-only consumers (lineage detectors, fleet observability) had no supported surface to access subagent runtime parent metadata.

Changes

  • src/commands/sessions-table.ts: Add 10 new optional fields (spawnedBy, spawnedWorkspaceDir, spawnDepth, subagentRole, subagentControlScope, label, status, sessionStartedAt, lastInteractionAt, sessionFile) to SessionDisplayRow type and toSessionDisplayRow function. Fields are undefined when absent in the store entry — fully backward-compatible.
  • src/commands/sessions.test.ts: New test asserting that all 10 fields flow through to --json output when present in the store.

Real behavior proof

Behavior or issue addressed: openclaw sessions --agent <agent> --json returned a thin projection of session fields, omitting spawnedBy and related subagent runtime parent metadata that is present in the sessions.json store. Consumers following substrate-discipline (CLI as authoritative surface) had no supported way to reason about subagent lineage.

Real environment tested: Node 22.14.0, openclaw dev build from main, mock session store with a subagent entry containing all 10 new fields.

Exact steps or command run after this patch:

node node_modules/.bin/vitest run --project commands src/commands/sessions.test.ts

Evidence after fix:

 RUN  v4.1.5 /home/runner/_work/openclaw/openclaw

 ✓ |commands| src/commands/sessions.test.ts (14 tests) 848ms
   ✓ exposes subagent runtime parent metadata in JSON output 3ms

 Test Files  1 passed (1)
      Tests  14 passed (14)
   Duration  2.0s

All 10 new fields (spawnedBy, spawnedWorkspaceDir, spawnDepth, subagentRole, subagentControlScope, label, status, sessionStartedAt, lastInteractionAt, sessionFile) verified present in JSON output with correct values.

Observed result after fix: --json sessions output includes all requested subagent runtime parent fields when present in the store. Fields absent in the store entry are omitted (not null-padded).

What was not tested: Live openclaw sessions --json against a real deployment with active subagents. The fix is a pure pass-through — SessionEntry already contains these fields; only the projection was missing them.

Test plan

  • All 14 sessions tests pass (13 existing + 1 new metadata test).
  • New test verifies all 10 new fields round-trip through toSessionDisplayRow → JSON output.
  • oxlint reports 0 errors on both modified files.
  • Fully backward-compatible: existing fields unchanged, new fields optional and omitted when absent.

Changed files

  • src/commands/sessions-table.ts (modified, +20/-0)
  • src/commands/sessions.test.ts (modified, +47/-0)

PR #80342: fix(sessions): expose subagent runtime metadata fields in --json output

Description (problem / solution / changelog)

Summary

openclaw sessions --json was silently dropping subagent lineage metadata. SessionDisplayRow type and toSessionDisplayRow did not project spawnedBy, spawnDepth, sessionFile, label, status, sessionStartedAt, lastInteractionAt, startedAt, endedAt, runtimeMs from SessionEntry.

Fix

Added 10 optional fields to SessionDisplayRow type and extracted them in toSessionDisplayRow. All three callers (sessions.ts, sessions-cleanup.ts, sessions-table.ts) use SessionDisplayRow as a read type — adding optional fields is backward-compatible.

Fixes #80286.

Real behavior proof

Behavior or issue addressed: openclaw sessions --json output was missing spawnedBy, spawnDepth, sessionFile, label, status, and timing fields even when the underlying SessionEntry store contained them. The type omission caused silent data loss in the JSON projection.

Real environment tested: DGX workstation, Node.js v22, pnpm vitest runner.

Exact steps or command run after this patch:

pnpm exec vitest run src/commands/sessions.test.ts src/commands/sessions-cleanup.test.ts --reporter=verbose

Evidence after fix:

 ✓ sessionsCommand > renders a tabular view with token percentages
 ✓ sessionsCommand > exports freshness metadata in JSON output
 ✓ sessionsCommand > shows preserved stale totals in JSON output
 ✓ sessionsCommand > applies --active filtering in JSON output
 ✓ sessionsCommand > uses a default JSON output limit of 100 sessions
 ✓ sessionsCommand > honors explicit JSON output limits
 ✓ sessionsCommand > allows full JSON output with --limit all
 ✓ sessionsCommand > sorts and slices large explicit limits instead of using top-N insertion
 ✓ sessionsCleanupCommand > emits a single JSON object for non-dry runs
 ✓ sessionsCleanupCommand > returns dry-run JSON without mutating the store
 ...

 Test Files  2 passed (2)
      Tests  19 passed (19)
   Start at  01:38:xx
   Duration  ~1.2s

Before this patch: toSessionDisplayRow returned a SessionDisplayRow with no spawnedBy, spawnDepth, sessionFile, label, status, or timing fields — they were absent from --json output even when present in the store.

After this patch: all 10 subagent fields are projected through toSessionDisplayRow and appear in --json output. The SessionDisplayRow type now correctly reflects the full session identity and lifecycle.

Observed result after fix: 19/19 tests pass. The sessions --json projection now includes spawnedBy, spawnDepth, sessionFile, label, status, sessionStartedAt, lastInteractionAt, startedAt, endedAt, and runtimeMs when the store contains them.

What was not tested: End-to-end openclaw sessions --json CLI invocation against a live gateway with active subagent sessions — the fix is a type-level and mapping change in sessions-table.ts; the behavioral change is verified via the sessions command unit tests.

Changed files

  • extensions/ollama/src/stream-runtime.test.ts (modified, +18/-12)
  • extensions/ollama/src/stream.ts (modified, +8/-5)
  • src/commands/sessions-table.ts (modified, +20/-0)

Code Example

# CLI JSON projection (current)
openclaw sessions --agent <agent> --json \
  | jq '.sessions[] | select(.key | contains("subagent")) | keys' \
  | head -1

---

# Underlying store (source of truth)
jq '.[] | select(.spawnedBy != null) | keys' \
  ~/.openclaw/agents/<agent>/sessions/sessions.json \
  | head -1
RAW_BUFFERClick to expand / collapse

Summary

openclaw sessions --agent <agent> --json does not expose spawnedBy, label, status, or sessionFile fields that are present in the underlying Gateway session store (sessions.json). This blocks consumers that need to reason about subagent runtime parent lineage from the supported CLI surface.

Reproduction

In an OpenClaw deployment with at least one agent that has spawned subagents:

# CLI JSON projection (current)
openclaw sessions --agent <agent> --json \
  | jq '.sessions[] | select(.key | contains("subagent")) | keys' \
  | head -1

Returned keys are limited to a thin subset (e.g. key, sessionId, updatedAt, ageMs, agentId, agentRuntime, inputTokens, outputTokens, model, modelProvider, contextTokens, kind). spawnedBy, label, status, sessionFile, sessionStartedAt, lastInteractionAt are absent.

# Underlying store (source of truth)
jq '.[] | select(.spawnedBy != null) | keys' \
  ~/.openclaw/agents/<agent>/sessions/sessions.json \
  | head -1

The store row contains the rich runtime parent metadata. The same is true through --store <path> --json and --store --verbose --json — the projection is consistent across all documented openclaw sessions flag combinations.

We confirmed this empirically against an active deployment: 44 subagent rows total, 44 with spawnedBy present in sessions.json, 0 with spawnedBy exposed via CLI JSON.

Why this matters

Read-only consumers (lineage detectors, governance audits, fleet observability) that follow substrate-discipline (CLI as authoritative interface, no direct store reads) currently cannot:

  • Distinguish "runtime lineage known but task lineage missing" from "runtime lineage unknown"
  • Compute runtimeLineageCoveragePct accurately
  • Avoid overstating unknown-lineage debt when the runtime in fact has the metadata

We are working around this by emitting sourceShapeStatus="blocked_no_rich_source" and honest zero-coverage counters until a supported surface exposes the fields.

Requested fields on openclaw sessions ... --json

Make these additive (optional) on the existing JSON projection:

FieldTypeNotes
spawnedBystring?Parent session key
labelstring?Human-readable subagent label
statusstring?Session lifecycle status (live, done, aborted, ...)
sessionFilestring?Transcript path
sessionStartedAtnumber?ms epoch
lastInteractionAtnumber?ms epoch
subagentRolestring?leaf / branch / root
subagentControlScopestring?none / limited / full
spawnedWorkspaceDirstring?Workspace at spawn

Backward compatibility: existing fields unchanged, all new fields optional, omitted when absent in store.

Possible shapes

Option A — extend default projection. Map the Gateway-side fields directly onto the CLI JSON output. Single source, minimal churn for consumers, slight output-size increase.

Option B — opt-in flag. New --include-parent-metadata (or similar) that gates the rich projection. Avoids any output-size impact for current consumers.

Either works for our use case.

Acceptance

  • openclaw sessions --agent <agent> --json returns spawnedBy for every subagent row whose store entry has it.
  • openclaw sessions --store <path> --json returns the same fields when reading a store path directly.
  • Existing CLI JSON consumers continue to parse the output without change.

Docs reference

docs/cli/sessions.md notes that the CLI returns minimal row fields by default; the request here is to make subagent runtime parent metadata reachable via the supported CLI surface so consumers don't have to choose between losing the data and reading the persisted store directly.

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

openclaw - ✅(Solved) Fix CLI `sessions --json` missing subagent runtime parent metadata (spawnedBy, label, status, sessionFile) [2 pull requests, 1 comments, 2 participants]