Skip to content

refactor(sessions): follow the chat by key for stored delivery references - #200099

Merged
obviyus merged 4 commits into
mainfrom
obviyus/identity-follow-chat
Nov 16, 2026
Merged

obviyus merged 4 commits into
mainfrom
obviyus/identity-follow-chat

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A message edit, rewind or /new mints a new lifecycle revision. References that were stored before the change still compared that revision, so the result was dropped:

  • A background exec that exits after a rewind or edit is withheld. The chat gets the note "Background command result withheld … reset, rewound or moved".
  • A background result (cron or subagent) commit fails with session rebound.
  • An automatic goal continuation stops after an edit.
  • Deep-research jobs disappear from the chat after an edit ("not found in this conversation generation").
  • A queued outbound send and a memory audience lease are revoked after an edit.

Only the session key stays the same across edit, switch, reset and compaction.

Fix

  • Stored references match the chat by key alone (matchesSessionGeneration). Live transcript writers keep their exact transcript pin. A scheduled cron occurrence keeps its exact lifecycle (exactLifecycle).
  • Queued outbound sends follow the key across a reset.
  • A session event follows the key to the chat's current transcript before reply admission, so a compaction successor still gets the wake.
  • Deleted: followSessionEventTargetForHost, the exec withhold note, and the expectedLifecycleRevision thread through background results, cron conversation results, confirmed visible messages and outbound transcript pins.
  • Goal continuation matches by key and goal. Deep-research job views drop the revision compare; the job store stays per transcript.
  • New CI ratchet check:session-identity-ratchet: production src counts of expectedSessionId, expectedLifecycleRevision and .lifecycleRevision must not grow.

Not changed here:

  • Reactions still read by transcript id. Message ids are 8 hex characters and unique only within one transcript, so a key-wide read is not safe yet.
  • GitHub publication keeps its incarnation pin. Its transition worker stores the revision in publication rows, so following the key needs a stored-row change.
  • Subagent requester ids and process ownership belong to a separate change.

Production code: +48 / −208.

User impact

  • Results that finish after an edit, rewind or /new arrive in the chat as it is now.
  • A deleted chat still drops the result. Delete already stops the key's processes, subagents and queued inputs, so a recreated key gets nothing.
  • An archived chat gets no wake (same as before).

Proof

Source-tier scratch Gateway (ocx src), base = merge base, scripted model with a real background exec (exit after 60–75 s):

Journey Base Head
Rewind while exec runs withheld (note in chat) wake delivered
Edit (rewind + new message) while exec runs withheld wake delivered
Queued input across a rewind during an active turn input runs input runs
Archive while exec runs no wake no wake
Delete, then recreate the key no wake, process stopped no wake, process stopped
Compaction successor (new transcript id) wake delivered wake delivered

Focused tests: lease, session events, exec notify, goal continuation, deep research, background results, cron delivery, outbound transcript. pnpm tsgo:core and pnpm check:test-types pass.

@clawsweeper

clawsweeper Bot commented Nov 16, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling extensions: deep-research size: M labels Nov 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR makes retained delivery references follow a conversation key across edits and resets while preserving explicit live-writer fences.

Example: A background command finishes after agent:main:dashboard:reset-waiter receives a new lifecycle revision.

  • Before: The completion is withheld and the chat receives a withholding note.
  • After: The completion wakes the current conversation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful direction, but incomplete research ownership, confirmed consumer-test failures, and uninspectable runtime claims prevent a merge-ready assessment.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Delayed results and automatic continuations can disappear when users edit, rewind, or reset a chat.
Reason: The maintainer-authored direction addresses observable lost work, although research jobs remain partitioned by transcript ID.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this PR open: following the chat by key addresses a concrete delivery problem, but the research cutover is incomplete and affected consumer tests still enforce the previous behavior.

Priority: P2
Reviewed head: 802f71230fd6bcac449660ce0a723918eb221af7

Before merge

  • Complete or defer the research storage cutover (P2) - For agent:main:research, start a job under transcript-a and then edit the chat onto transcript-b. listResearchJobs and readResearchJob call ResearchState.open before this predicate, and job-state.ts:89 still hashes sessionId into the persisted namespace. The new context therefore reads a different store: listing stays empty and reading the old job still fails. The view incarnation also still hashes sessionId. Changing the post-lookup predicate leaves the stated root cause intact; complete storage selection with existing-data compatibility, or defer these research hunks and their behavior claim.
  • Migrate consumer tests with the changed lifecycle contract (P2) - Ordinary leases now accept a replaced lifecycle, but their consumers still assert the previous rejection and withholding behavior. Exact-head CI confirms failures in session-delivery-generation.incarnation.test.ts:36, session-delivery-generation.native.test.ts:97, session-event-handoff.test.ts, cron delivery/completion suites, and bash-tools.exec-background-followup.test.ts:697. Research tests also retain the removed error expectation. Update these existing suites together: ordinary retained references should follow the key, while deliberate exactTranscript/exactLifecycle fences must retain their negative controls. Leaving the contradictory tests makes this cutover fail CI and omits the required regression coverage for the new contract.

Findings

  • [P2] Complete or defer the research storage cutover — extensions/deep-research/src/view-state.ts:10-12
  • [P2] Migrate consumer tests with the changed lifecycle contract — src/config/sessions/session-delivery-generation-memory.ts:30-32

Tests

  • Missing end-to-end proof: Attach redacted Gateway terminal output or logs showing exec completion after rewind and compaction, plus research list/read after transcript rotation; the submitted table provides no inspectable run evidence or base-red/head-green regression output.
Agent review details

How this fits together

Background producers retain conversation references; session admission resolves the current transcript, checks authority, and delivers events or commits visible results.

flowchart LR
  A[Background producers] --> B[Stored conversation key]
  B --> C[Session admission]
  C --> D[Current authority]
  D --> E[Current transcript]
  E --> F[Chat result]
Loading

Technical review

Best possible solution:

Keep key-following delivery in the existing session owner, migrate its consumer tests, and defer research changes until its transcript-keyed storage can follow the same contract safely.

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

Current-main lifecycle comparisons and the exec withholding path establish the reported failure from source; no target code was executed during this review.

Is this the best way to solve the issue?

Using the existing session owner to resolve retained references by key is appropriate, but changing research predicates cannot repair a lookup that already selected the wrong persisted namespace.

Full review comments:

  • [P2] Complete or defer the research storage cutover — extensions/deep-research/src/view-state.ts:10-12
    For agent:main:research, start a job under transcript-a and then edit the chat onto transcript-b. listResearchJobs and readResearchJob call ResearchState.open before this predicate, and job-state.ts:89 still hashes sessionId into the persisted namespace. The new context therefore reads a different store: listing stays empty and reading the old job still fails. The view incarnation also still hashes sessionId. Changing the post-lookup predicate leaves the stated root cause intact; complete storage selection with existing-data compatibility, or defer these research hunks and their behavior claim.
    Confidence: 0.99
  • [P2] Migrate consumer tests with the changed lifecycle contract — src/config/sessions/session-delivery-generation-memory.ts:30-32
    Ordinary leases now accept a replaced lifecycle, but their consumers still assert the previous rejection and withholding behavior. Exact-head CI confirms failures in session-delivery-generation.incarnation.test.ts:36, session-delivery-generation.native.test.ts:97, session-event-handoff.test.ts, cron delivery/completion suites, and bash-tools.exec-background-followup.test.ts:697. Research tests also retain the removed error expectation. Update these existing suites together: ordinary retained references should follow the key, while deliberate exactTranscript/exactLifecycle fences must retain their negative controls. Leaving the contradictory tests makes this cutover fail CI and omits the required regression coverage for the new contract.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/config/sessions/session-delivery-generation.incarnation.test.ts src/config/sessions/session-delivery-generation.native.test.ts src/auto-reply/reply/session-event-handoff.test.ts
  • pnpm test src/agents/bash-tools.exec-background-followup.test.ts src/auto-reply/reply/goal-continuation.test.ts
  • pnpm test src/cron/isolated-agent/current-session-completion.test.ts src/cron/isolated-agent/destination-completion.test.ts src/cron/isolated-agent/delivery-dispatch.structured.test.ts
  • pnpm test extensions/deep-research/src/jobs.test.ts src/sessions/background-session-result.test.ts src/infra/outbound/deliver-confirmed-visible.test.ts
  • pnpm tsgo:core

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 3bbf675 adds src/config/sessions/session-delivery-generation-memory.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3bbf67501123; files: src/config/sessions/session-delivery-generation-memory.ts)

PR surface

Source -164, Tests -8, Config +1, Other +89. Total -82 across 30 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 21 50 214 -164
Tests 6 13 21 -8
Docs 0 0 0 0
Config 1 1 0 +1
Generated 0 0 0 0
Other 2 89 0 +89
Total 30 153 235 -82

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This addresses lost delayed results and interrupted continuation after conversation edits, with a limited session-lifecycle scope.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 16, 2026, 8:00 AM ET / 13:00 UTC.

obviyus and others added 4 commits November 16, 2026 20:36
…nces

Stored and retained references (exec wakes, session events, memory audience,
queued outbound sends, background results, goal continuation, deep-research
job views) now match the chat by its session key. An edit, rewind or reset no
longer withholds a result; a deleted chat still refuses it. Live-writer fences
keep their exact transcript pin, and a scheduled occurrence keeps its exact
lifecycle.

Deletes the reset withhold path and its transcript note, and adds a CI
ratchet so production pins on session id and lifecycle revision cannot grow.

Co-authored-by: obviyus <[email protected]>
@obviyus
obviyus force-pushed the obviyus/identity-follow-chat branch from d495229 to e0e51b2 Compare November 16, 2026 15:10
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: the failing jobs on e0e51b2 fail on current main (59d9759) with the same tests, run locally from source at that main commit:

  • checks-node-changed-compact-small-22: src/agents/embedded-agent-runner/run.prepared-harness-source-delivery.integration.test.ts (7 failed on main).
  • checks-node-changed-extensions-bundle-11: extensions/codex/src/app-server/run-attempt.context-engine.test.ts > "persists the admitted user prompt before an async item buffered during turn startup" (fails on main).
  • checks-node-changed-extensions-bundle-20-1: extensions/browser/src/cli/browser-cli-shared.test.ts > "preserves failure and interruption output policy (json=true)" (fails on main and on this branch's merge base).

This PR does not touch these files or their owners. Exact-head local ClawSweeper review is clean, and the source-tier Gateway E2E (rewind, edit, queued input, archive, delete, compaction successor) is in the PR body.

@obviyus
obviyus merged commit edbc5bc into main Nov 16, 2026
230 of 235 checks passed
@obviyus
obviyus deleted the obviyus/identity-follow-chat branch November 16, 2026 15:43
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in edbc5bc. Bug: an edit, rewind or reset withheld background exec wakes, background results, queued sends and goal continuations, because stored references compared the lifecycle revision. Fix: stored references follow the chat by key; live writers and scheduled occurrences keep their exact pins. Proof: source-tier Gateway, base withholds and head delivers on rewind and edit; delete still drops and stops the work; a compaction successor still delivers.

vincentkoc added a commit that referenced this pull request Nov 16, 2026
…tgres-compaction-watched-prompt-20261116

* commit '9e810f7101557b006d5ff223d955f14dc43329f0': (23 commits)
  chore(ui): refresh control ui locales (#200164)
  fix(update): stop reporting unset git config keys as failing checks (#200153)
  test: consolidate redundant coverage (198793, part 2) (#198936)
  revert: skills-used full-transcript scan on every chat history page (#200159)
  refactor(sessions): follow the chat by key for stored delivery references (#200099)
  fix(update): bridge 2026.11.5-beta.4 updaters (#200152)
  fix(gateway): avoid filesystem stalls during catalog refresh (#200136)
  fix(ci): match update refusal probe to selected candidate (#200043)
  fix(agents): keep read-only steering carriers when publishing suppressed user envelopes (#200156)
  test: consolidate suites while retaining recovery owners (#198933)
  test: consolidate redundant coverage (198789, part 2) (#198932)
  refactor(cli): consolidate camera command tests (#200144)
  fix(cli): avoid initializing provider runtime during cleanup (#200139)
  fix(ui): show mobile destinations without the drawer exit delay (#198879)
  chore(ui): refresh control ui locales (#200146)
  fix(knowledge): keep historical claims distinct and reject changed retries (#200140)
  fix(ui): align dropdown arrows on mobile New Session
  improve(sessions): archive inactive transcripts by default (#199899)
  refactor(agents): own background commands and yield waits by the chat (#200097)
  fix(models): guessed non-chat models leave the default picker instead of being refused (#200102)
  ...
jalehman added a commit that referenced this pull request Nov 16, 2026
#200099 made deep-research job views and their view token follow the
transcript (session id) instead of the lifecycle revision, so an edit
or rewind keeps the conversation's research visible. The Gateway
routing test still expected a lifecycle-only change to retire those
jobs. Assert retention there instead, and move the retired-job denial
checks onto the reset that changes the session id.
jalehman added a commit that referenced this pull request Nov 16, 2026
…#200245)

#200099 made deep-research job views and their view token follow the
transcript (session id) instead of the lifecycle revision, so an edit
or rewind keeps the conversation's research visible. The Gateway
routing test still expected a lifecycle-only change to retire those
jobs. Assert retention there instead, and move the retired-job denial
checks onto the reset that changes the session id.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…nces (openclaw#200099)

## Problem

A message edit, rewind or `/new` mints a new lifecycle revision. References that were stored before the change still compared that revision, so the result was dropped:

- A background exec that exits after a rewind or edit is withheld. The chat gets the note "Background command result withheld … reset, rewound or moved".
- A background result (cron or subagent) commit fails with `session rebound`.
- An automatic goal continuation stops after an edit.
- Deep-research jobs disappear from the chat after an edit ("not found in this conversation generation").
- A queued outbound send and a memory audience lease are revoked after an edit.

Only the session key stays the same across edit, switch, reset and compaction.

## Fix

- Stored references match the chat by key alone (`matchesSessionGeneration`). Live transcript writers keep their exact transcript pin. A scheduled cron occurrence keeps its exact lifecycle (`exactLifecycle`).
- Queued outbound sends follow the key across a reset.
- A session event follows the key to the chat's current transcript before reply admission, so a compaction successor still gets the wake.
- Deleted: `followSessionEventTargetForHost`, the exec withhold note, and the `expectedLifecycleRevision` thread through background results, cron conversation results, confirmed visible messages and outbound transcript pins.
- Goal continuation matches by key and goal. Deep-research job views drop the revision compare; the job store stays per transcript.
- New CI ratchet `check:session-identity-ratchet`: production `src` counts of `expectedSessionId`, `expectedLifecycleRevision` and `.lifecycleRevision` must not grow.

Not changed here:
- Reactions still read by transcript id. Message ids are 8 hex characters and unique only within one transcript, so a key-wide read is not safe yet.
- GitHub publication keeps its incarnation pin. Its transition worker stores the revision in publication rows, so following the key needs a stored-row change.
- Subagent requester ids and process ownership belong to a separate change.

Production code: +48 / −208.

## User impact

- Results that finish after an edit, rewind or `/new` arrive in the chat as it is now.
- A deleted chat still drops the result. Delete already stops the key's processes, subagents and queued inputs, so a recreated key gets nothing.
- An archived chat gets no wake (same as before).

## Proof

Source-tier scratch Gateway (`ocx src`), base = merge base, scripted model with a real background `exec` (exit after 60–75 s):

| Journey | Base | Head |
|---|---|---|
| Rewind while exec runs | withheld (note in chat) | wake delivered |
| Edit (rewind + new message) while exec runs | withheld | wake delivered |
| Queued input across a rewind during an active turn | input runs | input runs |
| Archive while exec runs | no wake | no wake |
| Delete, then recreate the key | no wake, process stopped | no wake, process stopped |
| Compaction successor (new transcript id) | wake delivered | wake delivered |

Focused tests: lease, session events, exec notify, goal continuation, deep research, background results, cron delivery, outbound transcript. `pnpm tsgo:core` and `pnpm check:test-types` pass.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…openclaw#200245)

openclaw#200099 made deep-research job views and their view token follow the
transcript (session id) instead of the lifecycle revision, so an edit
or rewind keeps the conversation's research visible. The Gateway
routing test still expected a lifecycle-only change to retire those
jobs. Assert retention there instead, and move the retired-job denial
checks onto the reset that changes the session id.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 20, 2026
…tent lane

assertion-safety at 6e1a925 reported "subagent-registry-shutdown-
notices.ts: 1 > 0". The cause was the cast that typed a parsed backup row.
The undo now builds that row from its validated fields, so there is no
assertion.

test-lines at 6e1a925: net +113645 against a 400 allowance plus a
113043 credit, 202 over. The base e7de8c3 nets +113070, so this lane
grew test lines by 575. The new continuation-shutdown-intent.txt record
breaks that down per item: +271 for the item 1-3 restart custody pins
(the custody suite +7, plus the shared registry world +264, which holds
the helpers moved out of the suite) and +304 for item 4 (shutdown-
notices +228, the continuations CLI +76).

session-identity lists the same 31 files at e7de8c3 and here,
entry for entry. That is upstream's openclaw#200099 residual, unchanged by this
lane.

Refs openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…aw#194724)

* fix(goals): continue local Codex goals without operator roles

* docs: remove local goal continuation note

* test(goals): cover local continuations without operator authority

Prove local Codex continuation eligibility at enqueue and admission while retaining worker and required-placement denials.

Co-authored-by: VACInc <[email protected]>

* test(goals): remove unnecessary line allocation

Co-authored-by: VACInc <[email protected]>

---------

Co-authored-by: VACInc <[email protected]>

(cherry picked from commit ec41ea8)

Release adaptation: Require operator authority only for remote worker goals; keep local placement and existing admitted source checks. Existing baseline contains collected-child companion 3e78932. Later session-key and filesystem changes not prerequisites. Personally inspected sibling codex-rs/app-server/src/request_processors/thread_goal_processor.rs:149-251: local active goal runtime effects reuse materialized thread and GoalService.

Follow-up dispositions: edbc5bc refactor(sessions): follow the chat by key for stored delivery references (openclaw#200099); 2c4413a fix: reduce Gateway stalls under filesystem pressure (openclaw#197510); 3e78932 fix: Goals stall after collected child work

Validation: Baseline focused run timed out45 in compiled subprocess preparation before assertions; not red proof. Scoped diff/check and admission/placement guards inspected; full fixed regression queued for final focused group.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 28f718e2f9854c83fb6bed1fdcb9ae73b69286c0)
(cherry picked from commit cf62b191e81adf86f72ac06a096f6adb18a7d0d8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: deep-research gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: L 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