Skip to content

improve: avoid reading sibling task history when starting a run - #156183

Merged
steipete merged 1 commit into
mainfrom
codex/team-r4-task-selection-20260923
Sep 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/team-r4-task-selection-20260923

Conversation

@steipete

@steipete steipete commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Starting a task unnecessarily reads and decodes retained tasks from other runs in the same child session.

User Impact

Task creation does less work as a conversation's task history grows. Task identity, reuse, ordering, lifecycle, and delivery behavior stay the same; no new configuration or migration is required.

Why This Change Was Made

Creation only reuses an exact run match, so its initial database selection no longer includes unrelated runs sharing the child session. The canonical publication readback retains its broader scope and concurrency/discovery guarantees. This follows the existing canonical-ID contract: creation and explicit identifier changes normalize run IDs, while Doctor and legacy imports repair historical identifiers before activation.

Evidence

The new database-boundary regression covers creation, exact-run reuse, and an absent run ID. On the pinned baseline each case decodes 32 unrelated retained details; the candidate passes all three with zero unrelated decodes while preserving the selected and historical records. The file took 1.493 seconds of reported test time, 30.41 seconds standalone wall with pnpm test src/tasks/task-registry-create.kernel.test.ts --maxWorkers=1. Hosted CI passed the same three cases in 32 ms of summed reported test time (12 / 10 / 10 ms), excluding shared setup, in the owning job.

A paired Linux x64 / Node 24.19.0 benchmark exercised the actual creation kernel and SQLite in an isolated Node worker. Each unprofiled ABBA cell performed 100 creations, with setup and warmup excluded:

Initial retained tasks Baseline median worker CPU Candidate median worker CPU Baseline / candidate wall
0 49.500 ms 26.407 ms 51.591 / 27.679 ms
1,000 1,017.907 ms 23.995 ms 1,027.499 / 22.467 ms

A separate counter run at 1,000 retained tasks observed 100,000 unrelated detail decodes (434,200,000 JSON bytes) before and zero after. Separate V8 allocation sampling, including collected objects, estimated 1,273,912,080 bytes before and 9,897,680 bytes after. Main-thread orchestration CPU was effectively unchanged (0.755 / 0.759 ms). These are initial-selection component measurements, excluding canonical publication/readback; they are not production-wide CPU savings.

Actual SQLite worker/Gateway dispatch integration exercised production write admission, creation receipts, publication, exact duplicate ordering, ACP backing reuse, and missing-origin second commits, with the agent provider mocked. It passed 50 of 51 local cases, including all 19 Gateway dispatch/terminal-lineage cases and all managed-link cases. The single existing retries a changed page without joining events accepted after its first read case timed out at its unchanged later-event barrier on a heavily loaded host; its fixtures use native creation and event/read paths rather than the changed worker selection. The original failure is retained; that same unchanged case passed on this exact head in hosted CI in 769 ms (owning job). An isolated Linux replay passed the original 29-test file group on the frozen baseline in 49.34 seconds. The candidate then passed all 116 creation, worker, Gateway, identifier, and Doctor sibling cases in 103.37 seconds. These passing replays do not establish a fixture fix. The remaining local task group did not start after that failure.

Full changed-file checks passed, including core/test typechecks, formatting, lint, dead-code scans, and repository guards. Independent managed P0–P2 review found no actionable findings. Exact-head CI passed on 6b5ea98cc97815b0c00ea7fc9897dd336e906f64.

The complete built-Gateway mock comparison used separate full baseline/candidate checkouts, Node 24.19.0, and four pinned CPUs. All eight ABBA cells verified six turns each (48 total), all 96 task-list probes succeeded, and every Gateway exited cleanly. Two-cell medians per variant were:

Initial retained tasks Gateway main CPU Gateway process CPU Load wall
0 2.104 → 2.739 s (+30.2%) 3.509 → 4.686 s (+33.5%) 8.102 → 8.747 s (+8.0%)
1000 2.697 → 2.791 s (+3.5%) 6.419 → 6.003 s (-6.5%) 9.012 → 8.971 s (-0.5%)

The empty-history control regressed, and neither cohort shows a main-thread CPU win. The 1,000-task cohort observed 6.5% lower process CPU with nearly unchanged wall time; this small comparison does not establish a uniform Gateway improvement or causal attribution of the differences. The 97.6% improvement applies only to the isolated initial-selection worker measurement above. Every macro cell had identical turn/probe counts and provider phase counts: six benchmark turns, six activity recaps, and one embedding request in the measured load.

The first two optional macro attempts ran zero measured turns: one seed helper omitted an environment-options argument; the next attempt was rejected by source verification because task-owned relocated build output remained in its checkout. The final proof used native dist/ layouts in isolated full checkouts. Original failures and all favorable/unfavorable results are retained.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 23, 2026 04:51
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 2:16 AM ET / 06:16 UTC (Revision 3).

ClawSweeper review

What this changes

Task creation stops loading unrelated runs from the same child session, with regression coverage for creation, reuse, and an absent run ID.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful, narrowly scoped optimization absent from current main. No actionable correctness or security findings remain; the supplied evidence supports reduced initial-selection work, without establishing a whole-Gateway performance improvement.

Priority: P2
Reviewed head: 6b5ea98cc97815b0c00ea7fc9897dd336e906f64

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, supported optimization with meaningful regression coverage and appropriately limited performance claims.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured Linux/Node benchmark exercises the actual creation kernel and SQLite worker and records eliminated unrelated decodes; built-Gateway runs supplement it with successful turns and task reads using a mocked provider. Whole-Gateway speedups remain unproven. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Linux/Node benchmark exercises the actual creation kernel and SQLite worker and records eliminated unrelated decodes; built-Gateway runs supplement it with successful turns and task reads using a mocked provider. Whole-Gateway speedups remain unproven. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The introduced patch removes child-session selection only from the creation kernel and adds three SQLite regression cases. The original blob was inspected. The verified test merge has the pinned base and head parents and preserves the same production change.
Selection and publication contracts: Reuse requires a matching run plus the existing runtime, owner, scope, child-session, flow, and ACP backing checks. The SQL reader trims requested identifiers, preserves ordering, and decodes selected rows. Publication in task-executor-create.async.ts retains childSessionKey in its broader readback scope; transaction admission and commit checks remain unchanged.
Existing identifier ownership: Creation and explicit identifier updates normalize run IDs; historical normalization belongs to Doctor and legacy imports. The merged #153509 explicitly establishes this contract and documents published-updater compatibility evidence. This PR changes neither persisted formats nor that upgrade contract.
Findings None None.
Security None None.

How this fits together

OpenClaw’s task registry records agent work in SQLite. Creation selects an existing matching run or creates a task, then a separate publication step refreshes the state used by the Gateway.

flowchart TD
  A[Task creation request] --> B[SQLite worker admission]
  B --> C[Select task ID and matching run]
  C --> D{Reusable task?}
  D -->|Yes| E[Reuse or update task]
  D -->|No| F[Create task]
  E --> G[Broader publication readback]
  F --> G
  G --> H[Gateway task state]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +86. Total +86 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 1 86 0 +86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 87 1 +86

Review metrics

Metric Value Why it matters
Initial-selection decoding 100,000 unrelated decodes before; 0 after The supplied 100-creation SQLite measurement demonstrates the targeted work reduction, excluding publication and overall Gateway costs.

Technical review

Best possible solution:

Keep creation selection bounded to eligible runs while preserving the existing canonical identifier, admission, and publication owners.

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

Yes, from source: current main selects and decodes sibling-session rows before rejecting unrelated run IDs; the supplied baseline measurements corroborate that path. This review did not execute target code.

Is this the best way to solve the issue?

Yes. Removing the redundant selector at the creation owner is a narrow solution that preserves reuse rules and broader publication discovery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e857fba397ba.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux/Node benchmark exercises the actual creation kernel and SQLite worker and records eliminated unrelated decodes; built-Gateway runs supplement it with successful turns and task reads using a mocked provider. Whole-Gateway speedups remain unproven. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured Linux/Node benchmark exercises the actual creation kernel and SQLite worker and records eliminated unrelated decodes; built-Gateway runs supplement it with successful turns and task reads using a mocked provider. Whole-Gateway speedups remain unproven. No stored-data contract changes.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded task-creation performance improvement for conversations with retained task history.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured Linux/Node benchmark exercises the actual creation kernel and SQLite worker and records eliminated unrelated decodes; built-Gateway runs supplement it with successful turns and task reads using a mocked provider. Whole-Gateway speedups remain unproven. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux/Node benchmark exercises the actual creation kernel and SQLite worker and records eliminated unrelated decodes; built-Gateway runs supplement it with successful turns and task reads using a mocked provider. Whole-Gateway speedups remain unproven. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The introduced patch removes child-session selection only from the creation kernel and adds three SQLite regression cases. The original blob was inspected. The verified test merge has the pinned base and head parents and preserves the same production change. (src/tasks/task-registry-create.kernel.ts:42, 6b5ea98cc978)
  • Selection and publication contracts: Reuse requires a matching run plus the existing runtime, owner, scope, child-session, flow, and ACP backing checks. The SQL reader trims requested identifiers, preserves ordering, and decodes selected rows. Publication in task-executor-create.async.ts retains childSessionKey in its broader readback scope; transaction admission and commit checks remain unchanged. (src/tasks/task-registry-create-rules.ts:28, 6b5ea98cc978)
  • Existing identifier ownership: Creation and explicit identifier updates normalize run IDs; historical normalization belongs to Doctor and legacy imports. The merged fix(tasks): keep identifier repair out of Gateway restore #153509 explicitly establishes this contract and documents published-updater compatibility evidence. This PR changes neither persisted formats nor that upgrade contract. (src/state/openclaw-state-db-task-identifiers.ts:14, fb46996e9639)
  • Still necessary on current main: Fetched main still passes childSessionKey into the initial creation snapshot. The latest supplied release predates this kernel path. No merged replacement for this optimization was established by the bounded related-work searches. (src/tasks/task-registry-create.kernel.ts:42, e857fba397ba)
  • Real SQLite performance evidence: The complete supplied PR body, captured under sourceRevision 507b57660269aec0100cd058ef9fee9446229efe25000856cecea6dc4e523fef, reports paired Linux/Node 24.19.0 executions of the actual creation kernel and SQLite worker. For 100 creations with 1,000 retained tasks, unrelated detail decodes fell from 100,000 to zero and median worker CPU from 1,017.907 ms to 23.995 ms. These measurements exclude publication readback. (src/tasks/task-registry-create.kernel.ts:43, 6b5ea98cc978)
  • Gateway proof and measurement limits: The captured body reports eight built-Gateway comparison cells with a mocked provider: 48 verified turns, 96 successful task-list probes, and clean exits. Empty-history process CPU increased 33.5%, while the 1,000-task cohort decreased 6.5%; neither showed a main-thread CPU win. The body explicitly limits causal and production-wide claims. It also retains the local test timeout and subsequent baseline/candidate replay results without claiming a fixture fix. (6b5ea98cc978)

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 (2 earlier review cycles)
  • reviewed 2026-09-23T04:59:25.902Z sha 6b5ea98 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-23T05:52:34.940Z sha 6b5ea98 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 Sep 23, 2026
@steipete
steipete enabled auto-merge (squash) September 23, 2026 06:25
@steipete
steipete merged commit 7dd0ce6 into main Sep 23, 2026
296 checks passed
@steipete
steipete deleted the codex/team-r4-task-selection-20260923 branch September 23, 2026 06:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

vincentkoc added a commit to ycmjbot-bot/openclaw that referenced this pull request Sep 23, 2026
* commit '3ab93b4ea59804b34d02a696382db16dc95189bb': (80 commits)
  fix(gateway): keep session refreshes moving during unrelated writes (openclaw#156286)
  chore(deps): update fs-safe to 0.18.2 (openclaw#156262)
  refactor(plugins): extract ClawHub plugin archives once (openclaw#156246)
  improve(llm-core): avoid unnecessary tool validation sets (openclaw#152066)
  fix(backup): verification accepts archives missing captured databases (openclaw#156211)
  fix: cancel Guest work when its original access is revoked (openclaw#156106)
  fix(test): classify drained legacy migration refusals
  fix(anthropic): finish Opus 5.5 defaults and thinking display (openclaw#156093)
  refactor(agents): share native harness tool execution (openclaw#154217)
  fix(ui): carry typed ownership through short-route resolution
  test(worktrees): accept additive gc result fields (openclaw#156127)
  test(tasks): close sqlite borrowers before registry reload (openclaw#156131)
  chore(autoreview): sync Astra high defaults (openclaw#156175)
  refactor(node-host): await prepared workspace storage (openclaw#149519)
  improve: speed up cold Node test planning (openclaw#156234)
  fix(doctor): avoid slow legacy ownership repair in source checkouts (openclaw#156238)
  improve: speed up native build artifact validation (openclaw#156219)
  fix(ui): preserve short-route resolution ownership
  fix(doctor): name retained session metadata conflicts (openclaw#156162)
  perf(tasks): bound creation selection to matching runs (openclaw#156183)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant