Skip to content

feat(sessions): expose label in sessions.list and support label lookup in sessions_send#570

Merged
steipete merged 5 commits into
openclaw:mainfrom
azade-c:feat/sessions-label
Jan 9, 2026
Merged

feat(sessions): expose label in sessions.list and support label lookup in sessions_send#570
steipete merged 5 commits into
openclaw:mainfrom
azade-c:feat/sessions-label

Conversation

@azade-c

@azade-c azade-c commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds proper support for the label parameter in sessions_spawn:

  • Persist the label in the session store
  • Expose it in sessions.list response
  • Display it in the web UI sessions table
  • Allow sessions_send to find sessions by label

Motivation

The label parameter existed in sessions_spawn but was never actually persisted - it was a "phantom parameter". This PR makes it functional, enabling users to:

  1. Identify sub-agents by human-readable names instead of UUIDs
  2. Reconnect to sub-agents using their label via sessions_send

Changes

Core Feature

  • sessions.patch: Accept and store label field
  • sessions.list: Return label in session entries
  • sessions_spawn: Pass label through registry → announce flow → patch
  • sessions_send: New optional label param for lookup (alternative to sessionKey)

UI

  • Add "Label" column to sessions table in web UI

Safety Improvement

  • Session store writes now merge with existing entries ({ ...existing, ...new })
  • Prevents accidental loss of fields like label during concurrent writes

Architecture Note

We initially attempted to persist the label "properly" by passing it through the agent call and storing it during session initialization. However, the auto-reply flow has multiple session write points that overwrite entries, and making them all merge-aware proved unreliable.

Working solution: Patch the label in the finally block of runSubagentAnnounceFlow, after all other writes complete. This is a workaround but robust.

A future refactor could make all session writes consistently merge-based, enabling the cleaner approach.

Usage

// Spawn with label
sessions_spawn({ task: "Implement feature X", label: "feature-x-worker" })

// Later, reconnect by label (no need to remember the UUID!)
sessions_send({ label: "feature-x-worker", message: "Continue with step 2" })

// View labels in sessions list
sessions_list({ activeMinutes: 60 })
// Returns: [{ key: "agent:main:subagent:abc...", label: "feature-x-worker", ... }]

Files Changed (20)

Core:

  • src/config/sessions.ts - Add label to SessionEntry type
  • src/gateway/protocol/schema.ts - Add label to schemas
  • src/gateway/server-methods/sessions.ts - Handle label in patch
  • src/gateway/session-utils.ts - Return label in list mapping
  • src/agents/tools/sessions-spawn-tool.ts - Pass label to registry
  • src/agents/subagent-registry.ts - Store and forward label
  • src/agents/subagent-announce.ts - Patch label in finally
  • src/agents/tools/sessions-send-tool.ts - Label lookup support

Safety (merge writes):

  • src/auto-reply/reply/session.ts
  • src/auto-reply/reply/agent-runner.ts
  • src/auto-reply/reply/directive-handling.ts
  • src/auto-reply/reply/model-selection.ts
  • src/auto-reply/reply/session-updates.ts

UI:

  • ui/src/ui/types.ts
  • ui/src/ui/views/sessions.ts

@steipete steipete force-pushed the feat/sessions-label branch from de99d77 to 09cbca7 Compare January 9, 2026 13:13
@steipete steipete force-pushed the feat/sessions-label branch from 09cbca7 to 7057fc8 Compare January 9, 2026 13:20
azade-c and others added 5 commits January 9, 2026 15:32
…p in sessions_send

- Add `label` field to session entries and expose it in `sessions.list`
- Display label column in the web UI sessions table
- Support `label` parameter in `sessions_send` for lookup by label instead of sessionKey

- `sessions.patch`: Accept and store `label` field
- `sessions.list`: Return `label` in session entries
- `sessions_spawn`: Pass label through to registry and announce flow
- `sessions_send`: Accept optional `label` param, lookup session by label if sessionKey not provided
- `agent` method: Accept `label` and `spawnedBy` params (stored in session entry)

- Add `label` column to sessions table in web UI

- Changed session store writes to merge with existing entry (`{ ...existing, ...new }`)
  to preserve fields like `label` that might be set separately

We attempted to implement label persistence "properly" by passing the label
through the `agent` call and storing it during session initialization. However,
the auto-reply flow has multiple write points that overwrite the session entry,
and making all of them merge-aware proved unreliable.

The working solution patches the label in the `finally` block of
`runSubagentAnnounceFlow`, after all other session writes complete.
This is a workaround but robust - the patch happens at the very end,
just before potential cleanup.

A future refactor could make session writes consistently merge-based,
which would allow the cleaner approach of setting label at spawn time.

```typescript
// Spawn with label
sessions_spawn({ task: "...", label: "my-worker" })

// Later, find by label
sessions_send({ label: "my-worker", message: "continue..." })

// Or use sessions_list to see labels
sessions_list() // includes label field in response
```
- Test finding session by label
- Test error when label not found
- Test error when neither sessionKey nor label provided
@steipete steipete force-pushed the feat/sessions-label branch from 0529ceb to c4c0f13 Compare January 9, 2026 14:40
@steipete steipete merged commit d77dee5 into openclaw:main Jan 9, 2026
16 of 17 checks passed
@steipete

steipete commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main (CI skipped on request).\n\n- Gate (local): pnpm lint && pnpm build && pnpm test\n- Land commit: c4c0f13\n- Merge commit: d77dee5\n\nThanks @azade-c!

@steipete

steipete commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Follow-up landed on main after merge.

  • Gate: pnpm lint && pnpm build && CI=1 pnpm exec vitest run
  • Follow-up commit: 7d518e33c6f632c0df41e941c6a59bd8a92af0ce
  • PR merge commit: d77dee5

Adds sessions.list label filtering, enforces label max length + uniqueness, and unifies sessions.patch normalization (incl. elevated/off semantics). Thanks @azade-c!

lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
feat(sessions): expose label in sessions.list and support label lookup in sessions_send
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
feat(sessions): expose label in sessions.list and support label lookup in sessions_send
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants