Skip to content

refactor(auto-reply): simplify runtime bookkeeping - #173452

Merged
steipete merged 2 commits into
mainfrom
deslop/z03-1-runtime-bookkeeping-20261015
Oct 15, 2026
Merged

steipete merged 2 commits into
mainfrom
deslop/z03-1-runtime-bookkeeping-20261015

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Reply admission had accumulated a second ownership system around the actual session, database and delivery owners: transitive rotation histories, per-database barrier source maps, physical-file capture handoffs, and an in-memory generation-fenced compatibility proxy. These mechanisms mainly reconstructed transient interleavings; they were not the owners of security policy or durable writes.

Changes

Use an ordered walk over captured predecessor operations plus the authoritative session row for compaction continuation, including consecutive observed compactions. Keep ordinary settlement promises, but remove the lineage snapshots, source merging and alias-source updates around them. Let the existing session facts owner select the event destination rather than maintaining an additional physical-source capture protocol. Use one backing session-entry store instead of generation/timestamp arbitration and a Proxy. Combine aggregate source cancellation with AbortSignal.any rather than transferring controller/listener ownership at adoption.

Keep current tool/send policy at security effects, physical database admission, durable input and output, FIFO, ordinary shutdown settlement and the standalone session-memory backend unchanged. The finalization watchdog stays: human report #106112 documents repeated Slack production wedges. Human-backed stale drain recovery (#130810) and durable ingress dedupe recovery (#139341) also stay.

Production delta against base 164e243: 109 added, 732 deleted, 623 net lines removed. Test/support reductions are separate and remove only pins for the retired interleavings; normal compaction, wrong-store rejection, policy downgrade, cancellation, durable alias settlement and restart tests remain.

Best-effort tradeoffs accepted

Evidence

  • Initial published cut passed core typecheck, scoped lint, formatting, diff whitespace, runtime import cycles (0), madge cycles (0), and isolated review through P2. The final five-file CI repair separately passed fresh isolated P2 review (scoped-clean), targeted core typecheck, supported source-backed scoped lint, and formatting/whitespace.
  • Executed lint-suppression guard: baseline failure for the unchanged src/infra/sqlite-worker-store.test-support.ts|typescript/unbound-method|1 entry introduced by fix: preserve session caches when database workers exit #173239. Both that file and the expected allowlist are unchanged from the base; no suppression or allowlist entry was added here.
  • Executed changed-file checks: conflict markers, line-cap growth, max-lines suppressions and assertion safety passed. The environment-name budget fails at 452 against 453; the exact baseline-index owner replay reproduces it. This diff changes no environment variable name. No full changed-check success is claimed.
  • The first test command stopped at that tooling guard before reaching auto-reply. Its separate earlier 16-file replay had passing session-event permission/background-completion cases but was superseded by the repair. The final frozen seven-file replay passed all seven Gateway compaction-handoff cases, including consecutive observed compactions. After hosted CI passed, the optional remaining local infra stage was stopped and its task-owned children joined; it reported no assertions and is not claimed passing. No load-only delay is classified as a product failure.

Exact-head hosted CI run 38806369139 is GREEN for repaired head 310724c, including openclaw/ci-gate. No inherited-red exception is used. Local load-only delays are not product failures. No timeouts, retries, skips, suppressions, schemas, dependencies, config keys or public protocol shapes were added or weakened.

First-head CI attribution

Run 38801516200 on 7a56590 completed with six failing test jobs. checks-node-changed-compact-small-7 exposed storeless successor selection; checks-node-changed-compact-large-20 exposed the observed consecutive-compaction chain. Both are repaired in production, with their tests unchanged. small-20, large-4, small-22, and large-12 exposed the retired store-rebind observation, cross-operation callback lineage, reader-error rewrapping and held recovery-claim observation pins described above; only those pins were retired or updated, preserving refusal/no-write, physical authority and settlement coverage. openclaw/ci-gate reported these failures; none is classified inherited. The separate PR-context failure required authored section headings, now corrected. No CI job was rerun.

@clawsweeper

clawsweeper Bot commented Oct 15, 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 October 15, 2026 20:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T21:04:00.256931Z 310724c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a56590b03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 225 to 227
void registeredBarrier.settled.then(() =>
flushReplyOperationAfterClear(operation, registeredBarrier.source.sessionId),
flushReplyOperationAfterClear(operation, registeredBarrier.operation.sessionId),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the successor session in after-clear callbacks

When a same-store successor starts from the predecessor session and rotates it during compaction while the predecessor's delivery barrier is pending, this flushes the predecessor's stale ID because registeredBarrier.operation remains the original operation. scheduleFollowupDrainAfterReplyOperationClear then cannot retarget queued runs to the successor session, so follow-ups can continue against obsolete conversation context; the unchanged cases in reply-run-registry.test.ts lines 408-430 explicitly expect rotated-session for same-store and storeless successors and will fail with this implementation. Preserve the authoritative same-lineage successor session rather than the original operation snapshot.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR simplifies reply admission, session-entry bookkeeping, background-event targeting, and aggregate cancellation.

Example: An older source in a collected message batch is cancelled after adoption.

  • Before: Only the latest source retains client-cancellation ownership after adoption.
  • After: Any retained source signal can cancel the whole batch, an explicitly accepted tradeoff.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The maintenance direction is worthwhile, but confirmed session regressions and absent final-effect authority evidence prevent a passing review.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
Reason: The maintainer-authored direction removes substantial duplicate bookkeeping, and its explicitly accepted edge cases require no additional product approval.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep this maintainer-authored PR open: the simplification has an approved direction, but two session-admission regressions need repair.

Priority: P2
Reviewed head: 7a56590b035d76b95fc1a28514a408fe471aec12

Before merge

  • Add real behavior proof - Authority-chain proof required: exercise captured background events through the changed target and handoff owners, showing authorized execution/delivery succeeds and producer revocation or session replacement prevents provider, tool, and transport I/O after queued or awaited work resumes. The complete current body and discussion provide test claims, while the inspected images show historical refresh errors. Provide redacted logs or terminal output without keys, IPs, phone numbers, or private endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Preserve the successor session in delayed clear callbacks (P1) - When a same-store successor starts from first-session and compacts to rotated-session while the predecessor's delivery barrier remains pending, registeredBarrier.operation still refers to the predecessor. This callback therefore receives first-session. scheduleFollowupDrainAfterReplyOperationClear sees no changed admission ID and cannot retarget queued work to the compacted session. Preserve the same-store successor's authoritative session without adopting unrelated-store replacements. The unchanged registry cases at lines 408–430 fail for both same-store and storeless successors in exact-head CI, confirming the existing review comment.
  • Preserve admission for unpinned storeless turns (P2) - Calls without storePath or expectedSessionId may supply their own provisional session ID while waiting for the active operation. The new unconditional membership test treats that provisional ID as a pinned identity and rejects it once the active operation finishes; the earlier initialization check can instead leave that provisional ID unchanged when completion occurs during foreground maintenance. Existing exact-head CI demonstrates both outcomes: queued-session is rejected in the waiting-follow-up case, and new-session survives instead of post-compact-session in the active-compaction case. Apply lineage refusal to an actual expected-session binding and preserve the unpinned handoff behavior.
  • Resolve security review attention item - Live effect assertions remain connected, but the changed retained-event authority boundary needs final-effect verification.
  • Resolve merge risk - Retained background-event authority now spans physical-source recapture and config-store remapping; verify that this cannot carry a captured permission ceiling into an unauthorized replacement session.

Findings

  • [P1] Preserve the successor session in delayed clear callbacks — src/auto-reply/reply/reply-run-registry.operation.ts:225-227
  • [P2] Preserve admission for unpinned storeless turns — src/auto-reply/reply/reply-turn-admission.ts:688-692

Tests

  • Missing end-to-end proof: Supply allowed and revoked/replaced-session background-event execution and delivery traces through the changed owners; the inspected historical screenshots and CI tests do not establish that final-effect contract.
Agent review details

How this fits together

The auto-reply runtime admits foreground and queued turns, binds them to session and database owners, and coordinates execution, cancellation, and delivery settlement.

flowchart TD
  A[Incoming messages and background events] --> B[Reply admission]
  B --> C[Session and database owners]
  C --> D[Reply operation registry]
  D --> E[Agent execution]
  E --> F[Delivery and settlement]
  F --> G[Follow-up queue]
Loading

Technical review

Best possible solution:

Keep the simpler owners while preserving successor-session callbacks, unpinned storeless admission, and final-effect authority enforcement.

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

The introduced source paths and exact-head hosted CI establish both listed regressions; this read-only review ran no target code.

Is this the best way to solve the issue?

The ownership simplification follows repository direction and records its tradeoffs, but ordinary session handoff behavior must survive the removal of secondary tracking.

Full review comments:

  • [P1] Preserve the successor session in delayed clear callbacks — src/auto-reply/reply/reply-run-registry.operation.ts:225-227
    When a same-store successor starts from first-session and compacts to rotated-session while the predecessor's delivery barrier remains pending, registeredBarrier.operation still refers to the predecessor. This callback therefore receives first-session. scheduleFollowupDrainAfterReplyOperationClear sees no changed admission ID and cannot retarget queued work to the compacted session. Preserve the same-store successor's authoritative session without adopting unrelated-store replacements. The unchanged registry cases at lines 408–430 fail for both same-store and storeless successors in exact-head CI, confirming the existing review comment.
    Confidence: 0.99
  • [P2] Preserve admission for unpinned storeless turns — src/auto-reply/reply/reply-turn-admission.ts:688-692
    Calls without storePath or expectedSessionId may supply their own provisional session ID while waiting for the active operation. The new unconditional membership test treats that provisional ID as a pinned identity and rejects it once the active operation finishes; the earlier initialization check can instead leave that provisional ID unchanged when completion occurs during foreground maintenance. Existing exact-head CI demonstrates both outcomes: queued-session is rejected in the waiting-follow-up case, and new-session survives instead of post-compact-session in the active-compaction case. Apply lineage refusal to an actual expected-session binding and preserve the unpinned handoff behavior.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Verify retained event authority (recommended)
    Exercise the changed event owner through execution and delivery, showing allowed work succeeds and revoked or replaced-session work is rejected before provider, tool, or transport I/O.
  2. Defer the event-authority simplification
    Retain the existing event-target fences and review that portion separately with focused final-effect evidence.

Provenance checked

  • Compaction continuation and barrier lineage changes intended behavior with a stated reason (a5f1d09: Preserve current session facts when compaction completes during admission, with database-scoped lineage and rekey isolation; the current body deliberately accepts less reconstruction of unobserved interleavings.)
  • Session-entry generation arbitration changes intended behavior with a stated reason (408abcd: Consolidate generation-fenced follow-up ownership into the canonical session handle; the current body deliberately replaces generation and timestamp arbitration with one backing store.)
  • Background event target custody changes intended behavior with a stated reason (753a7a5: Carry original session, route, permission ceiling, and cancellation through ordinary execution; the current body explicitly delegates source selection to canonical facts preparation while retaining effect checks.)
  • Placement sampling during recovery admission changes intended behavior with a stated reason (c447f98: Allow same-destination claim settlement after Stop while rejecting destination changes; the current body explicitly selects one preparatory sample and leaves actual execution claims authoritative.)
  • Aggregate cancellation handoff changes intended behavior with a stated reason (1b8d837: Preserve queued prompt cancellation and lifecycle ownership; the current body explicitly accepts cancellation of the adopted batch by any retained source signal.)

Testing

Proof path: in-process harness.

Security

Needs attention: Live effect assertions remain connected, but the changed retained-event authority boundary needs final-effect verification.

Evidence

What I checked:

  • Introduced patch and accepted direction: The pinned introduction diff matches the reviewed head. The maintainer-authored body explicitly accepts reduced interleaving reconstruction, placement sampling, physical-source recapture, and broader aggregate cancellation. (7a56590b035d)
  • Successor session regression confirmed: Delayed clear callbacks now read the predecessor operation's session ID. The unchanged same-store and storeless successor cases expect rotated-session; exact-head CI reports both failing at reply-run-registry.test.ts:430. This independently confirms the existing Codex review comment at refactor(auto-reply): simplify runtime bookkeeping #173452 (comment). (src/auto-reply/reply/reply-run-registry.operation.ts:226, 7a56590b035d)
  • Unpinned storeless admission regression: The new ownership-membership check also runs without expectedSessionId. Exact-head CI reports an already-waiting follow-up rejected with a session-change error and a visible turn retaining new-session instead of post-compact-session. (src/auto-reply/reply/reply-turn-admission.ts:688, 7a56590b035d)
  • Authority remains checked at execution and delivery: Background events pass assertEffectCurrent into execution admission and outbound delivery. It checks producer ownership, retained session facts, permission narrowing, and config publication; routeReply forwards the assertion to the final adapter handoff. Capture-time physical-source and lifecycle fences are nevertheless removed. (src/auto-reply/reply/session-event-handoff.ts:233, 7a56590b035d)
  • Prepared media inspected: Both downloaded screenshots show historical conversation-refresh errors, including the improved Refresh action; neither shows this head executing background events or rejecting revoked authority before effects. (7a56590b035d)
  • Placement provenance: fix: keep follow-up replies from failing during local turn settlement #172458 establishes the Stop/follow-up settlement contract and separates preparatory placement selection from execution-claim authority; the current body explicitly explains its narrower sampling choice. (src/auto-reply/reply/restart-recovery-placement.ts:5, c447f98e554a)

Likely related people:

  • Peter Steinberger: Raw commit 753a7a5 adds src/auto-reply/reply/session-event-target.ts:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 753a7a57be10; files: src/auto-reply/reply/session-event-target.ts)
  • Shakker: Raw commit c447f98 adds src/auto-reply/reply/restart-recovery-placement.ts:6 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c447f98e554a; files: src/auto-reply/reply/restart-recovery-placement.ts)

PR surface

Source -635, Tests -437. Total -1072 across 18 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 11 97 732 -635
Tests 7 52 489 -437
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 149 1221 -1072

Review metrics

Metric Value Why it matters
Production versus test changes Production +97/-732; tests and support +52/-489 The reduction removes secondary bookkeeping owners; the two identified session regressions still need repair.

Labels

Label changes:

  • add P2: This is useful maintenance with concrete introduced session regressions, rather than an established urgent production incident.
  • add merge-risk: 🚨 session-state: Delayed follow-up callbacks can retain an obsolete session ID, and unpinned storeless admission can reject or misbind waiting turns.
  • add merge-risk: 🚨 security-boundary: Removing event-target authority fences requires final-effect evidence that retained work cannot execute or deliver after its producer or destination authority is revoked.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: This is useful maintenance with concrete introduced session regressions, rather than an established urgent production incident.
  • merge-risk: 🚨 session-state: Delayed follow-up callbacks can retain an obsolete session ID, and unpinned storeless admission can reject or misbind waiting turns.
  • merge-risk: 🚨 security-boundary: Removing event-target authority fences requires final-effect evidence that retained work cannot execute or deliver after its producer or destination authority is revoked.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 October 15, 2026, 4:48 PM ET / 20:48 UTC.

@steipete
steipete merged commit a578746 into main Oct 15, 2026
141 checks passed
@steipete
steipete deleted the deslop/z03-1-runtime-bookkeeping-20261015 branch October 15, 2026 23:16
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor Author

Verified the follow-up on main: bd18e16 restores the post-admission client-cancellation handoff while keeping original operator grant revocation independent. The complete src/auto-reply/reply/queue.authority.test.ts passes 15/15 on 44e80ff314a2 with pnpm test src/auto-reply/reply/queue.authority.test.ts --maxWorkers=1 (79.56 seconds wall time).

The failure was premature client cancellation, not revived operator authority. I stood down the overlapping fixture repair after confirming the landed owner fix. The expectation updates carried by #166464 and #157806 should preserve the restored main contract when rebased: an older client cancellation stays ineffective after admission, while original grant revocation still cancels the turn and blocks effects.

RomneyDa added a commit to wangmiao0668000666/openclaw that referenced this pull request Oct 16, 2026
…estructure

Merge main into the PR branch. openclaw#173452 moved the stale-config check from
admission to assertEffectCurrent, which still rejects a deferred event at
execution start, so the event is still dropped on main. Port the
re-admission onto the new boundary, give each re-admission its own
MessageSid so retained inbound dedupe of the adopted attempt does not drop
it, and replace the old mocked-adoption cases with a real queue/dispatcher
regression (session-event-config-readmission.test.ts).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
* refactor(auto-reply): simplify runtime bookkeeping

* fix(auto-reply): preserve captured compaction continuation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. 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.

1 participant