Skip to content

fix(tasks): clone only the requested task page - #114277

Merged
vincentkoc merged 6 commits into
openclaw:mainfrom
LZY3538:codex/fix-105425-task-list-page-cloning
Jul 28, 2026
Merged

vincentkoc merged 6 commits into
openclaw:mainfrom
LZY3538:codex/fix-105425-task-list-page-cloning

Conversation

@LZY3538

@LZY3538 LZY3538 commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #105425

What Problem This Solves

Fixes an issue where tasks.list deep-cloned every retained task record before filtering and pagination, causing memory allocation and garbage-collection work to grow with the full task history.

Why This Change Was Made

Filtering and activity ordering now happen inside the task registry through declarative status/agent/session query fields. No caller callback receives authoritative mutable records, and only the bounded requested page is defensively cloned before leaving the registry boundary. Cursor ordering and response summaries remain unchanged.

User Impact

Listing a small page of tasks no longer deep-clones discarded history records, reducing memory and GC overhead for large task archives.

Evidence

  • AI-assisted change; manually reviewed across the Gateway handler, registry owner boundary, cursor semantics, task summary mapping, SQLite storage, and existing registry callers.
  • The prior P2 finding is resolved: listTaskRecordPage no longer accepts matches or compare callbacks. Filtering, legacy agent fallback, session ownership matching, and activity ordering are registry-owned; callers receive only cloned page records.
  • The branch was rebased onto current origin/main 5b58d8540d.
  • The focused handler regression proves a two-record page makes exactly two registry-boundary structuredClone calls.
  • node scripts/run-vitest.mjs src/gateway/server-methods/tasks.test.ts — 12/12 passed.
  • node scripts/run-vitest.mjs src/tasks/task-registry.test.ts — 119/119 passed.
  • Targeted oxlint and git diff --check passed on exact head 879e1ff10a.
  • A previous unrelated CI shard failure was src/node-host/config.test.ts failing chmod with ENOENT on a temporary SQLite journal; the touched task files were not in that failure, while 296 files / 3,630 tests in the shard passed. Fresh exact-head checks are allowed to rerun.

Real behavior proof

Behavior or issue addressed:

A real Gateway tasks.list WebSocket request for 25 records must have clone work bounded by the requested page, not by the retained SQLite history size, after the registry owner-boundary correction.

Real environment tested:

Windows x64, Node 24.18.0, exact rebased head 879e1ff10a. Two isolated production Gateway runs used real loopback WebSockets, protocol v4 operator connection, and the shared openclaw.sqlite task store. Channels/providers were disabled because they are outside this RPC.

Exact steps or command run after this patch:

node --import tsx .proof-task-gateway-ws.ts 2500
node --import tsx .proof-task-gateway-ws.ts 5000

Each runner seeded SQLite before Gateway startup, opened ws://127.0.0.1:<port>, completed the real connect handshake, invoked tasks.list with limit: 25, counted all process-wide structuredClone calls during that RPC, and closed the Gateway cleanly.

Evidence after fix:

history=2500  rpcOk=true  returned=25  nextCursor=25  totalRpcCloneCalls=75  elapsed=17.86ms
history=5000  rpcOk=true  returned=25  nextCursor=25  totalRpcCloneCalls=75  elapsed=17.07ms

The full Gateway count includes the 25 registry clones plus bounded protocol/event snapshot copies; it remained exactly 75 when retained history doubled. The focused handler regression separately proves the registry owner itself clones exactly the returned page.

Observed result after fix:

Both real Gateway requests returned the same 25-record page and cursor, and total clone count stayed constant as SQLite history doubled from 2,500 to 5,000 records. Filtering and sorting never exposed retained task objects outside the registry.

What was not tested:

This proof used Windows and histories up to 5,000 records. Cross-platform SQLite behavior and larger archives were not benchmarked; ordering/filter/cursor semantics remain covered by the 131 focused tests.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Jul 27, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 8:08 AM ET / 12:08 UTC.

ClawSweeper review

What this changes

The PR makes Gateway tasks.list obtain an already-filtered, ordered, paginated task page from the task registry, so only returned records are defensively cloned.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for maintainer review. The patch has a sound registry-ownership shape and includes credible real Gateway proof, but GitHub currently reports the branch as dirty against main; resolve the merge conflict and revalidate the exact merged result before landing.

Priority: P2
Reviewed head: 879e1ff10a89636a0a517c36fd2154b6b972f174

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused design, tests, and real Gateway proof are strong; merge readiness is held only by the dirty current-base integration state.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body gives after-fix real Gateway WebSocket evidence from two SQLite-backed histories and shows the same returned page/cursor with constant clone work as history doubled.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body gives after-fix real Gateway WebSocket evidence from two SQLite-backed histories and shows the same returned page/cursor with constant clone work as history doubled.
Evidence reviewed 5 items Registry-owned query boundary: The PR removes Gateway-local session and agent matching plus activity ordering, and introduces a registry-owned listTaskRecordPage query with declarative status, agent, session, offset, and limit inputs. This keeps authoritative retained records inside the task registry until the selected page is cloned.
Gateway integration: The handler switches from listTaskRecordsUnsorted to listTaskRecordPage, preserving response mapping while obtaining only a bounded page from the registry.
Focused regression coverage: The PR adds a handler test that creates six records, requests a two-record page, and asserts exactly two structuredClone calls at the registry boundary.
Findings None None.
Security None None.

How this fits together

Gateway clients call tasks.list to retrieve task summaries and a pagination cursor. The task registry owns retained task records; it filters and orders them, then returns a cloned page for Gateway to serialize safely.

flowchart LR
  A[Gateway client request] --> B[Gateway task-list handler]
  B --> C[Task registry page query]
  C --> D[Ownership filters and activity order]
  D --> E[Clone requested task page]
  E --> F[Summaries and next cursor]
  F --> G[Gateway response]
Loading

Before merge

  • Resolve merge risk (P1) - GitHub reports a dirty merge state against current main; the final three-way result could require resolving overlapping task-list behavior, so the provided branch proof is not yet proof of the merge result.
  • Complete next step (P2) - A maintainer or contributor must resolve the current merge conflict and validate the resulting three-way merge; no discrete source-level defect is identified for an automated repair lane.
Agent review details

Security

None.

PR surface

Source +21, Tests +25. Total +46 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 81 60 +21
Tests 1 25 0 +25
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 106 60 +46

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Rebase or resolve the branch onto current main, preserve the registry-owned filtering/order/page boundary, then rerun the focused task-registry and Gateway handler coverage on the resulting head.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Rebase or resolve the branch onto current main, preserve the registry-owned filtering/order/page boundary, then rerun the focused task-registry and Gateway handler coverage on the resulting head.

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

Yes, source-reproducible: the changed path is a Gateway tasks.list request with a small limit against a larger task history, and the PR supplies real Gateway WebSocket output showing bounded clone work. I could not independently execute the path because the read-only command sandbox failed before commands started.

Is this the best way to solve the issue?

Yes, conditionally: a registry-owned declarative page query is the narrowest maintainable fix because it prevents Gateway callers from receiving retained mutable records merely to filter and sort them. The branch still needs conflict resolution and fresh proof on the actual merged head.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a targeted task-list performance and allocation fix with limited blast radius, while the observable request behavior remains intended to stay unchanged.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 PR body gives after-fix real Gateway WebSocket evidence from two SQLite-backed histories and shows the same returned page/cursor with constant clone work as history doubled.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body gives after-fix real Gateway WebSocket evidence from two SQLite-backed histories and shows the same returned page/cursor with constant clone work as history doubled.

Evidence

What I checked:

  • Registry-owned query boundary: The PR removes Gateway-local session and agent matching plus activity ordering, and introduces a registry-owned listTaskRecordPage query with declarative status, agent, session, offset, and limit inputs. This keeps authoritative retained records inside the task registry until the selected page is cloned. (src/tasks/task-registry-query.ts:39, 879e1ff10a89)
  • Gateway integration: The handler switches from listTaskRecordsUnsorted to listTaskRecordPage, preserving response mapping while obtaining only a bounded page from the registry. (src/gateway/server-methods/tasks.ts:14, 879e1ff10a89)
  • Focused regression coverage: The PR adds a handler test that creates six records, requests a two-record page, and asserts exactly two structuredClone calls at the registry boundary. (src/gateway/server-methods/tasks.test.ts:255, 879e1ff10a89)
  • Real behavior proof: The PR body reports two real Windows loopback Gateway WebSocket runs at histories of 2,500 and 5,000 records. Both returned 25 records with the same cursor and 75 total process-wide clone calls, supporting bounded work as retained history doubles. (879e1ff10a89)
  • Fresh merge state: The supplied live PR metadata reports mergeable: false and mergeableState: dirty against main. The current branch must be rebased or conflict-resolved and the resolved merge result rechecked before merging. (f67bdbbfe0b8)

Likely related people:

  • LZY3538: Authored all three commits on this focused task-registry and Gateway change; no local feature-history command could run because the read-only command sandbox failed before process start. (role: current implementation contributor; confidence: low; commits: 76b2176e68d7, 2b2c0d4636f3, 879e1ff10a89; files: src/tasks/task-registry-query.ts, src/gateway/server-methods/tasks.ts, src/gateway/server-methods/tasks.test.ts)

Rank-up moves

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

  • Resolve or rebase the branch onto current main and rerun the focused task-list tests on the resolved head.
  • Confirm the fresh three-way result preserves status, agent, session, ordering, and cursor semantics.

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 (6 earlier review cycles)
  • reviewed 2026-07-27T04:00:55.908Z sha dcbb6d96225cd7456fc90a0ab4ebe6ceb5d14f38 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-27T06:39:39.478Z sha dcbb6d96225cd7456fc90a0ab4ebe6ceb5d14f38 :: needs changes before merge. :: [P2] Keep retained registry records inside the registry boundary
  • reviewed 2026-07-27T06:59:03.605Z sha 2b2c0d4 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-27T07:07:06.385Z sha 2b2c0d4 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-27T07:24:23.461Z sha 879e1ff :: needs maintainer review before merge. :: none
  • reviewed 2026-07-27T07:30:24.707Z sha 879e1ff :: needs maintainer review before merge. :: none

@LZY3538

LZY3538 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 27, 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 repository_dispatch).
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Jul 27, 2026
@LZY3538
LZY3538 force-pushed the codex/fix-105425-task-list-page-cloning branch from dcbb6d9 to 2b2c0d4 Compare July 27, 2026 06:53
@LZY3538

LZY3538 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 27, 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 repository_dispatch).
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 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 27, 2026
@LZY3538

LZY3538 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper review — exact head 879e1ff removes the stale public taskUpdatedAt export reported by the dependency/dead-code CI shard. Focused tasks tests remain 12/12 and task-registry tests 119/119; targeted oxlint and git diff --check pass. The PR body now points to the exact head.

@clawsweeper

clawsweeper Bot commented Jul 27, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc vincentkoc self-assigned this Jul 28, 2026
* origin/main: (199 commits)
  refactor(workboard): tidy Control UI card execution helpers (openclaw#115195)
  perf(agents): amortize history-limit eviction with hysteresis (openclaw#115273) (openclaw#115281)
  fix: schema-version refusal blames a downgrade that never happened and cannot identify the stale install (openclaw#115232)
  fix: restore Fish completion after global CLI options (openclaw#115222)
  refactor(agents): collapse the client-tool catalog branch (openclaw#115212)
  fix(macos): signed rebuild no longer stalls on app shutdown (openclaw#103957)
  fix(agents): prevent repeated Code Mode output across waits (openclaw#115213)
  refactor(ui): split Profile (identity) from Usage (statistics) (openclaw#115245)
  fix(channels): report a channel that cannot receive as unhealthy instead of connected (openclaw#115229)
  fix(cli): reject malformed infer model refs (openclaw#115225)
  feat(ui): finish the Lobsterdex at 42 with wild variants, squish fix, and blink variance (openclaw#115264)
  test(migrations): avoid mtime precision in checkpoint fixture (openclaw#115269)
  test(signal): verify archive limits without malformed tar (openclaw#115270)
  refactor(sessions): isolate legacy transcript fixtures (openclaw#115231)
  fix(discord): clear pending launch watchdog (openclaw#115100)
  fix(agents): stop quadratic subagent prompt rendering (openclaw#115263)
  fix(memory-core): recover dreaming cron reconciliation (openclaw#115174)
  fix(qa-lab): filter incompatible channel scenarios (openclaw#115087)
  fix(android): respect locale in compact labels
  test(i18n): prove iOS discovery catalog ownership
  ...
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer verification on 8a14ff62ed9f07a5b7bad49bbcd7bf8ff65af9a4:

  • resolved the current-main integration while preserving registry-owned filtering, activity ordering, stable task-id tie-breaking, cursor semantics, and page-only defensive cloning
  • Gateway task handler: 14/14 passed
  • task registry: 119/119 passed
  • scoped changed checks passed formatting, guards, core production/test typechecks, lint, boundaries, and import-cycle checks
  • full build passed, including 146 public plugin SDK subpaths and Control UI performance gates
  • fresh autoreview is clean (0.93)

Remote proof: https://github.com/openclaw/openclaw/actions/runs/30379013930

@vincentkoc
vincentkoc merged commit 57f8240 into openclaw:main Jul 28, 2026
121 of 123 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 28, 2026
…224005-host

* origin/main: (72 commits)
  fix: macOS-only Parallels smoke harness regression (#75293)
  fix(ios): use configured speech language for system voice (#113372)
  refactor: centralize isolated agent test ownership (#115340)
  test(ui): stabilize browser route readiness (#115320)
  fix(cron): clear automation after failed scheduler shutdown (#115316)
  fix: keep isolated gateway workspaces and skills inside state dir (#114487)
  docs: document local TTS on macOS, Linux, and Windows (#110230)
  fix(tasks): clone only the requested task page (#114277)
  fix(agents): prevent Code Mode resume loss and unbounded preparation (#115314)
  fix(process): preserve the first process cancellation reason (#115317)
  fix(nostr): report unavailable ingress when queue open fails (#115313)
  fix: prevent Slack and Feishu ingress startup leaks (#115295)
  fix(slack): avoid unsafe emphasis boundaries (#111575)
  fix: prevent changed checks from expanding into full lint (#115322)
  fix(codex): stabilize prompts and expose real cache regressions (#115238)
  refactor(ui): derive page route specs from the route table (#115214)
  fix(compaction): plan cut points in trigger units (#111886) (#115309)
  fix: prevent cron and gateway stress-run timeouts (#115241)
  fix(ci): validate frozen Matrix QA targets (#115298)
  test(macos): block real process fallthrough (#113337)
  ...

# Conflicts:
#	CHANGELOG.md
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
* fix(tasks): clone only paginated task records

* fix(tasks): keep page queries registry-owned

* fix(tasks): keep update timestamp helper private

---------

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
…afea23-host

* origin/main: (72 commits)
  fix: macOS-only Parallels smoke harness regression (openclaw#75293)
  fix(ios): use configured speech language for system voice (openclaw#113372)
  refactor: centralize isolated agent test ownership (openclaw#115340)
  test(ui): stabilize browser route readiness (openclaw#115320)
  fix(cron): clear automation after failed scheduler shutdown (openclaw#115316)
  fix: keep isolated gateway workspaces and skills inside state dir (openclaw#114487)
  docs: document local TTS on macOS, Linux, and Windows (openclaw#110230)
  fix(tasks): clone only the requested task page (openclaw#114277)
  fix(agents): prevent Code Mode resume loss and unbounded preparation (openclaw#115314)
  fix(process): preserve the first process cancellation reason (openclaw#115317)
  fix(nostr): report unavailable ingress when queue open fails (openclaw#115313)
  fix: prevent Slack and Feishu ingress startup leaks (openclaw#115295)
  fix(slack): avoid unsafe emphasis boundaries (openclaw#111575)
  fix: prevent changed checks from expanding into full lint (openclaw#115322)
  fix(codex): stabilize prompts and expose real cache regressions (openclaw#115238)
  refactor(ui): derive page route specs from the route table (openclaw#115214)
  fix(compaction): plan cut points in trigger units (openclaw#111886) (openclaw#115309)
  fix: prevent cron and gateway stress-run timeouts (openclaw#115241)
  fix(ci): validate frozen Matrix QA targets (openclaw#115298)
  test(macos): block real process fallthrough (openclaw#113337)
  ...

# Conflicts:
#	CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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: M 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.

[Bug] Unbounded task history cloning in listTaskRecordsUnsorted

2 participants