Skip to content

refactor(sessions): drop client-visible activeRunIds from session rows - #125983

Closed
steipete wants to merge 6 commits into
mainfrom
steipete/remove-active-run-ids
Closed

steipete wants to merge 6 commits into
mainfrom
steipete/remove-active-run-ids

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session rows projected an implementation list of run ids that was never in the protocol schema, never stable-shipped to native clients, had zero plugin consumers, and could be incoherent (hasActiveRun: true with an empty list — its producer only reads chatAbortControllers). Browser exact-run steering was its main consumer and is gone (#125808/#125862/#125921); the rest read it for facts their owners already record.

Why This Change Was Made

Record facts where they happen, read them where needed. Terminal reconciliation uses event-local run ids plus a reload-scoped local run tracker that preserves the stale-terminal defense (unknown terminals ignored; predecessor terminals keep the row running while tracked runs remain — regression-tested, fails pre-fix); history recovery uses chat.history's in-flight identity; token/projection restore uses request-local ids; observer authority uses digest-owned ids; the silent [0] fallbacks are deleted. Android/Apple mirror via their pendingRuns tracking.

User Impact

Behavior-neutral by design; removes a stale-terminal wrong-state window that the old membership check masked only when the list was populated.

Evidence

Production +96/-355 pre-fix pass, final total +557/-927 across gateway/UI/Android/Apple; UI focused 584 + lifecycle/recovery e2e 10, broad UI 9,957 passed, Android full unit matrix passed, Apple ChatViewModel 279 passed, protocol:check/build/ui:build green, autoreview clean (0.96). Local macOS tooling-shard stall documented as env-only (hosted CI judges).

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: android App: android app: macos App: macos labels Aug 18, 2026
@steipete steipete self-assigned this Aug 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts labels Aug 18, 2026
@steipete
steipete marked this pull request as ready for review August 18, 2026 20:06
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 18, 2026, 7:17 PM ET / 23:17 UTC.

ClawSweeper review

What this changes

This PR removes activeRunIds from Gateway session rows and makes web, Android, and macOS clients use locally owned history, request, and lifecycle run identities instead.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: a rejected history predecessor is added to the web client’s authoritative tracker before its adoption guard runs, allowing a later stale observer digest to replace newer session status.

Priority: P1
Reviewed head: e7405d4107d74d370fd6cfece6046fd0cc017d50

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The ownership direction is coherent, but a concrete web session-state race remains.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; repository policy still calls for focused validation and live UI evidence before landing.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; repository policy still calls for focused validation and live UI evidence before landing.
Evidence reviewed 4 items Web ownership race: The history loader adds an active snapshot ID to the shared tracker before the later adoption decision; observer handling accepts any tracked ID when no foreground run is set.
Gateway and documented contract: Gateway now exposes only aggregate activity in session rows; the client documentation says aggregate activity must not establish exact streaming-run identity.
Android sibling repair: The latest Android follow-up rejects an in-flight snapshot when newer local ownership exists and adds the equivalent predecessor-observer regression test.
Findings 1 actionable finding [P2] Fence rejected history snapshots from observer authority
Security None None.

Live Verification

Entry: /chat

Result: FAIL (partial) — step 5 expect_text Opening the focused observer tests: locator.waitFor: Timeout 15000ms exceeded.

Steps:

  • PASS goto /chat
  • PASS wait_for openclaw-chat-page
  • PASS expect_text Session observer demo
  • PASS click text=Session observer demo
  • FAIL expect_text Opening the focused observer tests — locator.waitFor: Timeout 15000ms exceeded.

Live proof recording

Recorded live on the PR head (e7405d4107d7), 27.72s, browser surface.

How this fits together

Gateway session rows expose aggregate activity, while chat clients retain exact run identities from history snapshots and lifecycle events. Those identities control terminal reconciliation and observer-status rendering.

flowchart LR
A[Gateway history snapshot] --> B[Web history loader]
C[Newer lifecycle start] --> D[Local run tracker]
B --> E{Snapshot admitted?}
E -->|Accepted| D
E -->|Rejected| F[Discard predecessor identity]
D --> G[Observer authority check]
G --> H[Visible chat status]
Loading

Before merge

  • Fence rejected history snapshots from observer authority (P2) - inFlightRunId enters activeChatRunIdsBySession before canAdoptInFlightRun decides whether the response is stale. If a successor sessions.changed start arrives while history is pending, the predecessor can fail adoption yet its observer event still passes observerDigestMatchesAuthoritativeRun through the tracker and can replace the successor’s status. Record the snapshot ID only after it is admitted and cover this deferred ordering race; Android now does so.
  • Resolve merge risk (P1) - Without the web fence, a stale predecessor can be treated as locally authoritative and replace visible observer state after a newer run starts.
  • Complete next step (P2) - A narrow Control UI owner-boundary repair and regression test are clear from source; no product decision is needed.

Findings

  • [P2] Fence rejected history snapshots from observer authority — ui/src/pages/chat/chat-history.ts:1767-1769
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test LOC production +557/-927; tests/support +438/-244 (PR-reported production delta and aggregate +995/-1171) The refactor deletes substantial projection code but adds owner-local lifecycle tracking across multiple clients.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server-methods/session-active-runs.test.ts, serialized state: src/gateway/server-methods/session-active-runs.ts, serialized state: src/gateway/server-methods/session-change-event.test.ts, serialized state: src/gateway/server-methods/session-change-event.ts, serialized state: src/gateway/server-methods/sessions-read.ts, serialized state: ui/src/lib/sessions/index.test.ts, and 10 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #125983
Summary: This PR owns the remaining web sibling of the history/observer ownership invariant.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Fence web history ownership (recommended)
    Move tracker admission behind the history snapshot’s ownership/adoption decision and add the deferred predecessor-versus-successor observer regression before merge.
  2. Accept stale observer risk
    Merge while accepting that a rejected predecessor snapshot can still authorize a stale observer digest in the web client.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Apply the Android-equivalent history ownership fence to the Control UI, add a failing-before/fixed-after deferred-history observer test, and rerun the focused Control UI suite.

Technical review

Best possible solution:

Admit a web history snapshot into the local tracker only after it passes the same ownership fence as the Android implementation, with a deferred predecessor/successor regression test.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: start a history request, receive a successor lifecycle start, resolve history with an active predecessor, then deliver that predecessor’s observer digest while no foreground run ID is set.

Is this the best way to solve the issue?

No: the web path needs the same rejected-snapshot ownership fence already applied to Android, otherwise it registers an identity its own adoption decision rejects.

Full review comments:

  • [P2] Fence rejected history snapshots from observer authority — ui/src/pages/chat/chat-history.ts:1767-1769
    inFlightRunId enters activeChatRunIdsBySession before canAdoptInFlightRun decides whether the response is stale. If a successor sessions.changed start arrives while history is pending, the predecessor can fail adoption yet its observer event still passes observerDigestMatchesAuthoritativeRun through the tracker and can replace the successor’s status. Record the snapshot ID only after it is admitted and cover this deferred ordering race; Android now does so.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ffbbb6417871.

Labels

Label justifications:

  • P1: A stale run can replace the visible observer status for a newer active chat run.
  • merge-risk: 🚨 compatibility: The branch removes a session-row field while migrating Gateway, web, Android, and macOS consumers.
  • merge-risk: 🚨 session-state: The changed tracker controls which run may update terminal and observer session state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; repository policy still calls for focused validation and live UI evidence before landing.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs ui/src/pages/chat/chat-history.inflight.test.ts.
  • [P1] node scripts/run-vitest.mjs ui/src/pages/chat/chat-state.test.ts.

What I checked:

Likely related people:

  • steipete: Available PR commits include the ownership refactor and Android’s corresponding history-authority repair; the merged steering refactor is adjacent history context. (role: recent session-lifecycle contributor; confidence: medium; commits: 3d59167135e2, f545bb8fbbd5, e7405d4107d7; files: ui/src/pages/chat/chat-history.ts, ui/src/pages/chat/chat-state-events.ts, apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Move web history tracker admission behind the ownership/adoption fence.
  • Add the deferred history-predecessor versus successor observer regression and run focused Control UI tests.
  • Capture the isolated Control UI lifecycle proof required by repository policy.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-18T20:28:43.493Z sha 3c8f9e4 :: found issues before merge. :: [P1] Preserve a successor during stale-row repair | [P1] Reject observer digests without current-run authority
  • reviewed 2026-08-18T22:02:06.683Z sha 1785f41 :: found issues before merge. :: [P1] Preserve a row when a sibling tracked run remains | [P2] Authorize projected Android digests during reconnect
  • reviewed 2026-08-18T22:35:02.824Z sha 38c05d1 :: found issues before merge. :: [P2] Fence rejected history snapshots from observer authority

…wner facts

Session rows no longer project a run-id list. Consumers migrate to the
facts their owners record: event-local run ids for terminal
reconciliation (with a reload-scoped local run tracker preserving the
stale-terminal defense: unknown terminals are ignored, predecessor
terminals keep the row running while tracked runs remain), chat.history
in-flight identity for snapshot recovery, request-local send/run ids for
token and projection restore, digest-owned ids for observer authority.
The silent activeRunIds[0] fallbacks are gone, as is the incoherent
hasActiveRun:true/empty-list state; resolveVisibleActiveSessionRunState
shrinks to the boolean facts its callers need. Android and Apple mirror
the same migration with their pendingRuns tracking.

The field was never in the protocol schema, never stable-shipped to
native clients, and has no plugin consumers.
@steipete
steipete force-pushed the steipete/remove-active-run-ids branch from caa8102 to 1785f41 Compare August 18, 2026 21:53
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper address review

Please apply the current review finding only: move Control UI history-run tracker admission behind the successful in-flight snapshot ownership/adoption fence, add the deferred predecessor-versus-successor observer regression, and rerun the focused Control UI tests. Do not merge yet; live selected-session proof and final maintainer landing will follow.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🔧
ClawSweeper did not dispatch a repair worker for this one.

Reason: repair commands require a ClawSweeper PR or a PR opted into ClawSweeper autofix or automerge.

Supported re-review commands work on open issues and PRs: /review, /clawsweeper re-review, or @clawsweeper re-review.
Supported issue implementation commands work on open issues: /clawsweeper implement, @clawsweeper fix, /clawsweeper build, @clawsweeper create pr, or @clawsweeper fix issue.
Supported repair commands work on existing ClawSweeper PRs and PRs opted into clawsweeper:autofix or clawsweeper:automerge: /clawsweeper fix ci, /clawsweeper address review, /clawsweeper rebase.
A maintainer can opt a PR in with /clawsweeper autofix or /clawsweeper automerge and I can take another pass.
A maintainer can close unsupported or declined work with /autoclose <reason>.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper stop

Independent owner review found broader active-set and terminal/observer projection gaps beyond the queued web fix. Stop automation; this PR should not merge until the producer contract is reconsidered.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞✅
Got it. ClawSweeper will leave this item for human review.

I added clawsweeper:human-review and paused the automation trail until a maintainer asks again.

@clawsweeper clawsweeper Bot added the clawsweeper:human-review Needs maintainer review before ClawSweeper can continue label Aug 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer decision: closing this refactor rather than continuing to patch the client-local replacement for activeRunIds.

The core premise does not hold under overlapping and cross-client runs. chat.history.inFlightRun intentionally identifies only one current snapshot, while session lifecycle state is aggregate. Removing the Gateway’s run-id set forces web, Android, and Apple to infer negative ownership from incomplete local trackers. The review history has now exposed repeated concrete failures: predecessor terminals hiding successors, rejected history snapshots authorizing stale observer state, inactive/external Android sessions remaining stuck as running, cross-client telemetry loss, and terminal snapshots combining aggregate activity with the wrong run’s terminal fields.

The supported direction is narrower and owner-backed: keep activeRunIds as known exact Gateway facts, remove arbitrary first-run selection in consumers, normalize omission versus completeness, and move any missing liveness/observer ownership facts to the Gateway producer rather than reconstructing them independently in each client.

What would change this decision: an owner-level Gateway contract that supplies a complete active-set generation and run-scoped terminal/observer projection, with web, Android, and Apple boundary proofs for overlap, reconnect, hidden sessions, and cross-client starts. More client-local tracker patches are not sufficient.

@steipete steipete closed this Aug 18, 2026
steipete added a commit that referenced this pull request Aug 19, 2026
Session rows no longer emit activeRunIds: [] while hasActiveRun is
true. Presence now means the complete exact set of direct run ids;
omission means identities are unavailable (projected/embedded owners);
[] only ever represents proven idle. Consumers stop guessing:
soleActiveSessionRunId() replaces the arbitrary [0] fallbacks in the
observer digest, transcript cache key, activity inspector, and
stale-terminal reconciliation, each falling back to its owner fact.

Follows the maintainer direction from #125983: the field stays as
Gateway-owned exact facts; producer-side liveness/observer projections
are a named follow-up.
steipete added a commit that referenced this pull request Aug 19, 2026
#126106)

* fix(gateway): make activeRunIds presence mean a complete exact run set

Session rows no longer emit activeRunIds: [] while hasActiveRun is
true. Presence now means the complete exact set of direct run ids;
omission means identities are unavailable (projected/embedded owners);
[] only ever represents proven idle. Consumers stop guessing:
soleActiveSessionRunId() replaces the arbitrary [0] fallbacks in the
observer digest, transcript cache key, activity inspector, and
stale-terminal reconciliation, each falling back to its owner fact.

Follows the maintainer direction from #125983: the field stays as
Gateway-owned exact facts; producer-side liveness/observer projections
are a named follow-up.

* fix(gateway): clear unavailable active run ids in events

* fix(gateway): preserve idle active run sets

* fix(clients): close active run id cache gaps

* test(android): isolate history run snapshot
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
openclaw#126106)

* fix(gateway): make activeRunIds presence mean a complete exact run set

Session rows no longer emit activeRunIds: [] while hasActiveRun is
true. Presence now means the complete exact set of direct run ids;
omission means identities are unavailable (projected/embedded owners);
[] only ever represents proven idle. Consumers stop guessing:
soleActiveSessionRunId() replaces the arbitrary [0] fallbacks in the
observer digest, transcript cache key, activity inspector, and
stale-terminal reconciliation, each falling back to its owner fact.

Follows the maintainer direction from openclaw#125983: the field stays as
Gateway-owned exact facts; producer-side liveness/observer projections
are a named follow-up.

* fix(gateway): clear unavailable active run ids in events

* fix(gateway): preserve idle active run sets

* fix(clients): close active run id cache gaps

* test(android): isolate history run snapshot
@RomneyDa
RomneyDa deleted the steipete/remove-active-run-ids branch October 22, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android app: macos App: macos app: web-ui App: web-ui clawsweeper:human-review Needs maintainer review before ClawSweeper can continue docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant