Skip to content

fix(task): propagate resume and history storage failures - #307

Merged
agenteinstinct1-max merged 2 commits into
dev-vibecodedfrom
instinct/task-storage-failures
Oct 13, 2026
Merged

agenteinstinct1-max merged 2 commits into
dev-vibecodedfrom
instinct/task-storage-failures

Conversation

@agenteinstinct1-max

@agenteinstinct1-max agenteinstinct1-max commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #284 and #285.

Type of change

  • Bug fix

What does this PR do?

Closes #284 and #285.

Only typed NotFound recovers a missing resumed task. Storage defects propagate instead of creating a replacement child. History recovery failure also propagates; when execution and recovery both fail, preserve both causes. Listener unsubscribe remains in its finalizer.

Worker implementation independently checked on Bun 1.3.14: five new native storage-failure regressions pass, 35 assertions. The worker's broader task suite had one existing background-completion timeout; that claim is not a substitute for current CI. Full typecheck is not claimed locally.

BackgroundJob's displayed error may show only the first of combined causes. The actual cause is preserved here; no claim that presentation is fixed. Full current merge-tree CI and Kilo or Arena review are required before integration.

How did you verify your code works?

Independent native focused regressions passed: 5 tests, 35 assertions. Actual current remote merge-commit Linux and Windows test jobs and all 17 typecheck tasks passed. Pinned Effect storage-failure probe also verifies compound causes.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@agenteinstinct1-max
agenteinstinct1-max force-pushed the instinct/task-storage-failures branch 2 times, most recently from 585d32c to 1192f48 Compare October 13, 2026 20:05
// it is combined explicitly. Neither failure is recoverable here.
Effect.catchCause((cause) =>
Effect.logError("Child write evidence history unavailable", { sessionID: nextSession.id, cause }),
Effect.failCause(Exit.isFailure(exit) ? Cause.combine(exit.cause, cause) : cause),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Cause.combine duplicates main cause in finalizer

Effect.onExit finalizers in Effect v4 automatically combine their failure cause with the main effect's cause when the main effect also failed. Explicitly calling Cause.combine(exit.cause, cause) here causes the main cause to appear twice in the final combined cause (once from the main effect, once from the finalizer's explicit combine, and the runtime combines them again).

The fix is to simply fail with the recovery cause and let the runtime combine automatically:

Suggested change
Effect.failCause(Exit.isFailure(exit) ? Cause.combine(exit.cause, cause) : cause),
Effect.failCause(cause),

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

const history = yield* sessions.messages({ sessionID: nextSession.id })
yield* projectWrites(history.flatMap((message) => message.parts))
}).pipe(
// Effect v4 finalizer failures replace the original cause unless

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Comment is misleading about explicit combine being needed

The comment states "Effect v4 finalizer failures replace the original cause unless it is combined explicitly." This is incorrect — Effect v4 automatically combines finalizer failures with the original cause. The explicit Cause.combine at line 608 is what causes the duplication.

Consider updating the comment to reflect actual behavior:

Suggested change
// Effect v4 finalizer failures replace the original cause unless
// Effect v4 automatically combines finalizer failures with the original cause.
// Fail with the recovery cause only; the runtime will combine if the main effect failed.

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

? yield* sessions.get(SessionID.make(params.task_id)).pipe(Effect.catchCause(() => Effect.succeed(undefined)))
? yield* sessions
.get(SessionID.make(params.task_id))
.pipe(Effect.catchIf(NotFoundError.isInstance, () => Effect.succeed(undefined)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Add comment explaining catchIf vs catchCause behavior

The change from catchCause to catchIf(NotFoundError.isInstance) intentionally narrows error handling: only typed NotFoundError failures are caught; defects (Die), interrupts, and other failure types propagate. This is correct per the PR intent, but a brief comment would clarify why catchIf is used and that defects/interrupts are not swallowed.

Suggested change
.pipe(Effect.catchIf(NotFoundError.isInstance, () => Effect.succeed(undefined)))
.pipe(Effect.catchIf(NotFoundError.isInstance, () => Effect.succeed(undefined)))

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge (pending green run of tool.task - storage failures on [email protected])

Scope. Review base 62045858… is absent locally, so reviewed via the full PR diff. The only diff material added after the last review commit is a single type annotation at task.test.ts:2218 (input: SessionPrompt.PromptInput — valid export, prompt.ts:1913). No issues in the incremental change.

Re-evaluation of the 3 prior findings (same changed lines)

  • task.ts:258 — SUGGESTION (catchIf vs catchCause). Correct. catchIf(NotFoundError.isInstance, …) narrows recovery to typed NotFoundError so storage Effect.die defects/interrupts propagate, satisfying the PR intent and the resume {storage,not-found-defect} tests (0 children/metadata/prompt writes, child unchanged). No action.
  • task.ts:605 — SUGGESTION (comment "misleading"). Invalidated: the comment accurately states Effect v4 finalizer semantics (see 608), so it is correct, not misleading.
  • task.ts:608 — CRITICAL (Cause.combine duplicates main cause). Could not reproduce in this environment: [email protected] is not installed (packages/opencode/node_modules empty), so onExit semantics can't be read and the bundled 15-assertion storage-failure test can't be executed. The dispositive version-specific probe (issue comment 6155083708, citing the pinned [email protected]) shows onExit's finalizer runs via flatMap(finalizer, _ => originalExit), so a failing finalizer replaces the main cause rather than auto-combining — making the explicit Cause.combine(exit.cause, cause) required to preserve both causes ("when execution and recovery both fail, preserve both causes"). The PR's deliberate combine and the test asserting the cause contains taskError/historyError/Exit.Failure exactly once corroborate this. If the original premise (Effect v4 always auto-combines onExit finalizers) were confirmed against this exact pin, the finding would resurface — but current evidence invalidates it.

No new inline comments posted.

Files Reviewed (2 files)
  • packages/opencode/src/tool/task.ts - re-evaluated (no action)
  • packages/opencode/test/tool/task.test.ts - re-evaluated (no action)
Previous Review Summaries (2 snapshots, latest commit 6204585)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 6204585)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/opencode/src/tool/task.ts
  • packages/opencode/test/tool/task.test.ts

Previous review (commit 1192f48)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 2
Issue Details (click to expand)

CRITICAL

File Line Issue
packages/opencode/src/tool/task.ts 608 Cause.combine duplicates main cause in finalizer

SUGGESTION

File Line Issue
packages/opencode/src/tool/task.ts 605 Comment is misleading about explicit combine being needed
packages/opencode/src/tool/task.ts 258 Add comment explaining catchIf vs catchCause behavior
Files Reviewed (2 files)
  • packages/opencode/src/tool/task.ts - 3 issues
  • packages/opencode/test/tool/task.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by free · Input: 164.1K · Output: 25.5K · Cached: 354.6K

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator Author

Independent adjudication of the reported Cause.combine critical finding: it does not reproduce with this repository's pinned Effect 4.0.0-beta.83.

onExitPrimitive runs the finalizer through flatMap(finalizer, _ => originalExit). A failing finalizer replaces the original cause in this version; it does not combine it automatically.

A native fault probe on this checkout gives:

  • Without explicit combine: only the recovery error remains.
  • With Cause.combine(originalCause, recoveryCause): exactly the main error and recovery error, once each.

The two actual task history-recovery fault regressions also pass independently (15 assertions), including exact cause length 2 and listener unsubscribe. Removing the explicit combine would lose the original execution defect. No source change was made for this finding. Fresh current merge-tree CI and review remain required after integration advances.

@agenteinstinct1-max
agenteinstinct1-max force-pushed the instinct/task-storage-failures branch from 1192f48 to 6204585 Compare October 13, 2026 20:59
@agenteinstinct1-max
agenteinstinct1-max force-pushed the instinct/task-storage-failures branch from 6204585 to 4c07771 Compare October 13, 2026 21:29
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot closed this Oct 13, 2026
@agenteinstinct1-max
agenteinstinct1-max merged commit 2220edf into dev-vibecoded Oct 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant