Skip to content

fix: avoid repeated naming and regressing session startup progress - #133489

Merged
steipete merged 1 commit into
mainfrom
steipete/duplicate-session-naming-653be6
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/duplicate-session-naming-653be6

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #133488 — repeated naming and regressing startup progress.

Related: #131480 — raw-prompt worktree branch fallback. This change does not alter that fallback policy or rename existing/published branches.

What Problem This Solves

Fixes an issue where users retrying failed worktree setup could pay for session naming again even though an earlier naming request had succeeded. Concurrent startup and discussion opening could also start separate title requests. In Control UI, steering an active run or receiving delayed history could revive an earlier startup label, making completed preparation look as though it was running again.

Why This Change Was Made

Session naming now claims one operation per canonical session generation before inference and saves the existing displayName before checkout/setup. Worktree preparation, dashboard naming, discussion opening, and existing-key creation use that same owner; manual names, replacement generations, and final write authority remain guarded. The eager title preparation/post-setup persistence path is removed.

Control UI reconciles startup status using the already-provided agent sequence, preserves activity while a send is pending, and retires only the previous run when a replacement is adopted. Tools, approvals, and compaction received before the acknowledgement survive adoption. No database schema/version, wire schema/version, configuration, dependency, or migration changes.

User Impact

A retry reuses a successfully saved title instead of repeating naming. Startup progress no longer moves backward after steering or a delayed history response, and incoming tools/approval state remain visible across acknowledgement. Failed naming can still retry from the original first prompt and text attachments. Worktree deadlines, explicit names, and branch fallback behavior remain unchanged.

Evidence

Regression tests failed on the original production code, then passed after repair:

  • A real Git worktree setup failure discarded a successfully generated title; the fixed handler retains it, shares the request with discussion opening, and reuses it on retry.
  • Existing named sessions triggered unnecessary inference; the fixed keyed-create path does not.
  • Controller and real Chromium transport tests reproduced stale-history startup regression and steering activity loss.
  • Independent review found an additional pre-ACK activity-loss race in the first candidate. Three controller orderings and Chromium reproduced it; exact-owner cleanup now preserves incoming tools and approvals.

Local verification:

node scripts/run-vitest.mjs src/gateway/dashboard-session-title.test.ts src/gateway/server.sessions.create.projects.test.ts src/gateway/server.sessions.create.titles.test.ts src/gateway/server-methods/session-discussion.test.ts

74 passed; another 55 focused title/worktree sibling cases passed.

node scripts/run-vitest.mjs run --config test/vitest/vitest.ui.config.ts --configLoader runner ui/src/pages/chat/chat-send.test.ts ui/src/pages/chat/chat-gateway.test.ts ui/src/pages/chat/run-lifecycle.test.ts ui/src/pages/chat/chat-history.inflight.test.ts ui/src/pages/chat/chat-history.startup.test.ts ui/src/pages/chat/tool-stream.startup.node.test.ts ui/src/pages/chat/tool-stream.node.test.ts ui/src/pages/chat/tool-stream-fallback.node.test.ts

657 passed. The three affected Chromium suites passed 17 cases; final focused browser replays covered delayed history, live steering, and pre-ACK tools/approvals. The ordinary complete changed-file gate passed, including core/test/UI types, formatting, lint, dead exports, import cycles, schema and database-first guards. Fresh independent autoreview was clean at its default P0-only threshold.

pnpm build passed, including Control UI. An additional recording drove the normal UI served by a real isolated dev Gateway, with a loopback mock model and a real Git repository: create → generated title → setup failure → reload → correct the owned setup script → retry in the same session → successful reply → reload. The session key, session ID, and title were unchanged; the actual model request log counted exactly one naming request and one agent request, and the successful retry created the session-owned worktree. No naming phase was emitted on retry. The served UI asset matched the built artifact. This is real Gateway/Git/browser proof with a mocked model endpoint, not authenticated external-provider proof.

All captures were inspected and contain only synthetic fixture data and public model names. Mocked-Gateway before/after screenshots remain separate from the real-Gateway recording. No production state or private incident capture is included.

Production LOC: +237/-198 (net +39). Tests/support: +836/-250 (net +586, including fixture moves out of two size-limited suites). Docs: +1/-1. Production growth implements the shared progress/ownership boundary and final-authority checks while deleting duplicate naming paths; no budgets or suppressions were increased.

Before and after (synthetic mocked-Gateway browser fixtures)

Scenario Before After
Delayed history Before: stale history revives Naming worktree After: current Creating worktree phase is retained
Steering Before: steering revives Naming worktree after tool activity After: steering retains active-run progress

Real Gateway retry recording

The following 6.92-second recording shows the built Gateway and normal Control UI retry flow described above, with real Git and a loopback mock model.

attachment-2523764063.mp4

Review follow-up: lifecycle custody and plugin ownership

The ClawSweeper ownership-race finding is not accepted after inspecting the lifecycle owner and testing the proposed concurrent caller. createGatewaySession holds runExclusiveSessionLifecycleMutation for the canonical store/key around the entire createChildSession operation (src/gateway/session-create-service.ts:1474-1506), including the ownership check, awaited title/worktree preparation and final write. The mutation queue and lifecycle lock remain held until completion/finalization (src/sessions/session-lifecycle-admission.ts:202-307). Competing creates, patch, reset and recovery use that owner. The session-accessor callback is not a separate atomic ownership boundary that permits a competing Gateway create to enter during preparation.

Additional boundary probe on the exact PR head: pause plugin A inside actual worktree creation; issue plugin B's sessions.create for the same canonical key; verify B remains pending and no row has been written; release A; verify A succeeds, B rejects with did not create it, the persisted session ID/plugin owner remain A's, and only one real worktree creation occurred. 1 test passed (13.57s Vitest / 20.31s wrapper). The temporary diagnostic fixture reused the normal Gateway handler harness and real Git, with only a preparation barrier; it was removed after the run and retained in local proof artifacts. Production and committed test bytes are unchanged. Existing committed tests also cover concurrent keyed creates and foreign-plugin rejection before naming.

Rank-up disposition: the requested final-effect ownership proof is supplied by that probe and the committed sibling tests. Restoring the duplicate callback check is skipped because the proposed concurrent Gateway interleaving is excluded by the existing lifecycle owner; a raw storage write bypassing that owner would test a different contract. No SQLite schema, storage format, migration, config or wire change is introduced by the test-support extraction or transient UI progress state. The actual stored title uses the existing session displayName field.

Exact-head CI passed on attempt 1: run 33332334661, including openclaw/ci-gate. Landing-side integration reruns passed 74 Gateway and 657 UI tests on 4874083984aab3a04473d2dc40c452c7002b76b2; rebase patch equivalence and repaired production-file hashes were verified.

@steipete steipete self-assigned this Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 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: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 19:58
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 30, 2026, 4:25 PM ET / 20:25 UTC.

ClawSweeper review

What this changes

The PR preserves session titles and Control UI startup activity across retries, delayed history loading, and follow-up sends.

Regression provenance

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

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 7 items remain

Keep open: the PR introduces an ownership-boundary race by moving validation before awaited preparation without retaining it at the final write boundary.

Priority: P1
Reviewed head: 4874083984aab3a04473d2dc40c452c7002b76b2

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Substantial behavior coverage exists, but the introduced ownership-boundary race blocks correctness.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied retry and UI evidence does not demonstrate rejection of a direct plugin SDK ownership replacement during the new awaited preparation window before final commit. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied retry and UI evidence does not demonstrate rejection of a direct plugin SDK ownership replacement during the new awaited preparation window before final commit. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Introduced ownership check move: The PR adds an ownership check before awaited lifecycle preparation and removes the same check from the final creation callback, leaving no validation against the row actually committed.
Direct plugin write bypasses lifecycle fence: The public SDK upsert reaches the SQLite entry patcher, whose path does not enter lifecycle admission, so another plugin can replace the owner while preparation awaits.
Existing race invariant: Current tests already require a session mutation to recheck ownership after a direct replacement during lifecycle admission; the added title test covers only an owner mismatch present before preparation.
Findings 1 actionable finding [P1] Recheck plugin ownership in the final creation callback
Security Needs attention Ownership can change after early validation: A direct plugin SDK session write can replace pluginOwnerId between early validation and the final session creation callback, which then lacks an owner check.

How this fits together

Gateway session creation prepares titles and worktrees before writing the session record that plugins and the Control UI consume. The UI combines live Gateway events with restored history to display startup progress.

flowchart LR
  A[User starts session] --> B[Gateway session creation]
  B --> C[Title and worktree preparation]
  C --> D[Session record write]
  D --> E[Plugin session access]
  D --> F[Gateway events]
  F --> G[Control UI startup status]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied retry and UI evidence does not demonstrate rejection of a direct plugin SDK ownership replacement during the new awaited preparation window before final commit. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Recheck plugin ownership in the final creation callback (P1) - The early ownership check now runs before awaited title/worktree preparation, but the final createSessionEntryWithTranscript callback no longer rechecks it. A plugin can directly upsert the same session with a different owner during that await, allowing this request to commit prepared work against the replacement owner. Revalidate ownership inside the callback and cover the direct SDK-upsert race.
  • Resolve security concern: Ownership can change after early validation - A direct plugin SDK session write can replace pluginOwnerId between early validation and the final session creation callback, which then lacks an owner check.
  • Resolve merge risk (P1) - Merging permits a plugin whose ownership was valid before preparation to commit prepared work after another plugin has replaced that session's owner.
  • Complete next step (P2) - The final owner-boundary repair and deterministic concurrency regression are focused repair work.
  • Improve patch quality - Restore final ownership validation at the final session write.
  • Improve patch quality - Add final-effect proof that direct SDK owner replacement is rejected before session or worktree commit.

Findings

  • [P1] Recheck plugin ownership in the final creation callback — src/gateway/session-create-service.ts:909-917
  • [high] Ownership can change after early validation — src/gateway/session-create-service.ts:909
Agent review details

Security

Needs attention: The patch removes final plugin-ownership validation after an awaited operation.

PR surface

Source +158, Tests +467, Docs 0. Total +625 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 14 356 198 +158
Tests 11 717 250 +467
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 26 1074 449 +625

Review metrics

Metric Value Why it matters
Production vs test delta production +39, tests/support +586 The production change moves an ownership check across an awaited lifecycle boundary despite substantial focused test coverage.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server.sessions.create.projects.test-support.ts, serialized state: ui/src/pages/chat/tool-stream.ts, unknown-data-model-change: src/gateway/server.sessions.create.projects.test-support.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #133488
Summary: This PR is the candidate repair for the session retry and progress issue; the raw-prompt branch-name report is adjacent work.

Members:

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

Merge-risk options

Maintainer options:

  1. Restore the final ownership fence (recommended)
    Revalidate plugin ownership immediately before the final session write and add a concurrent SDK-upsert regression test.
  2. Pause the PR
    Do not merge while a plugin can replace ownership after early validation and before side effects commit.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Restore final plugin-ownership validation at the session creation commit boundary and add a barrier test using direct SDK session upsert during preparation.

Technical review

Best possible solution:

Restore ownership validation immediately inside the final session-creation callback and prove a direct SDK owner replacement is rejected before commit.

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

Yes, source reproducible: direct SDK upsert can replace ownership during the awaited preparation window, though this read-only review did not execute the race.

Is this the best way to solve the issue?

No: the early rejection avoids unnecessary work but must be paired with final ownership validation at the actual commit boundary.

Full review comments:

  • [P1] Recheck plugin ownership in the final creation callback — src/gateway/session-create-service.ts:909-917
    The early ownership check now runs before awaited title/worktree preparation, but the final createSessionEntryWithTranscript callback no longer rechecks it. A plugin can directly upsert the same session with a different owner during that await, allowing this request to commit prepared work against the replacement owner. Revalidate ownership inside the callback and cover the direct SDK-upsert race.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: The introduced race can let one plugin perform session work against another plugin's record.
  • merge-risk: 🚨 security-boundary: Final plugin-owner validation is removed after awaited preparation, permitting stale authority to reach commit.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied retry and UI evidence does not demonstrate rejection of a direct plugin SDK ownership replacement during the new awaited preparation window before final commit. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Ownership can change after early validation — src/gateway/session-create-service.ts:909
    A direct plugin SDK session write can replace pluginOwnerId between early validation and the final session creation callback, which then lacks an owner check.
    Confidence: 0.93

Acceptance criteria:

  • [P1] Run focused Gateway plugin-ownership and session-title tests in the repair lane.
  • [P1] Exercise the barrier scenario with direct SDK owner replacement during preparation and verify no stale-owner commit.
  • [P1] Re-run the existing Control UI delayed-history and pre-ACK startup tests.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-08-30T20:07:14.131Z sha 4874083 :: needs real behavior proof before merge. :: [P1] Recheck plugin ownership in the atomic creation callback

@steipete

Copy link
Copy Markdown
Contributor Author

The repair is ready for the final maintainer checkpoint at source head 4874083984aab3a04473d2dc40c452c7002b76b2.

The one-time rebase is patch-equivalent (git range-diff reports the same patch). All repaired production files still match the inspected build/browser proof; upstream-only changes are the Control UI docs and existing outbox test assertions. The following focused suites also passed on the rebased head:

node scripts/run-vitest.mjs src/gateway/dashboard-session-title.test.ts src/gateway/server.sessions.create.projects.test.ts src/gateway/server.sessions.create.titles.test.ts src/gateway/server-methods/session-discussion.test.ts
node scripts/run-vitest.mjs run --config test/vitest/vitest.ui.config.ts --configLoader runner ui/src/pages/chat/chat-send.test.ts ui/src/pages/chat/chat-gateway.test.ts ui/src/pages/chat/run-lifecycle.test.ts ui/src/pages/chat/chat-history.inflight.test.ts ui/src/pages/chat/chat-history.startup.test.ts ui/src/pages/chat/tool-stream.startup.node.test.ts ui/src/pages/chat/tool-stream.node.test.ts ui/src/pages/chat/tool-stream-fallback.node.test.ts

Results: 74 Gateway tests and 657 UI tests passed. The frozen candidate had already passed the ordinary complete changed-file checks, pnpm build, 55 additional focused siblings, 17 Chromium cases and three final browser replays, plus isolated Codex autoreview at its default P0 threshold. The attached recording uses a real built Gateway, normal UI and actual Git with a loopback mock model: one title request across setup failure/reload/retry, then one agent request and a persisted successful session. It does not claim authenticated external-provider execution.

Production LOC remains +237/-198 (net +39); tests/support +836/-250 (net +586, including fixture moves); docs +1/-1. No schema, config, protocol, version, dependency or baseline change. Related #131480 (raw-prompt branch fallback) remains outside this repair.

Exact-head CI run 33332334661 completed successfully on attempt 1, including openclaw/ci-gate. Native review artifacts validate at this head.

ClawSweeper follow-up is now documented in the PR body: its proposed competing-plugin race is excluded by the existing canonical-key lifecycle lock. A temporary boundary probe paused actual worktree preparation, concurrently issued a foreign-plugin create, then verified the allowed caller succeeded and the foreign caller was rejected without changing the saved owner/session/worktree. The probe passed; source bytes are unchanged. The requested duplicate callback check is therefore skipped with this evidence. The existing schema and storage format are unchanged.

@steipete
steipete merged commit af8dad8 into main Aug 30, 2026
330 checks passed
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 30, 2026
@steipete
steipete deleted the steipete/duplicate-session-naming-653be6 branch August 30, 2026 20:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Session startup retries repeat naming and progress can move backward

1 participant