Skip to content

fix(core): preserve pending human waits during idle cleanup - #50499

Open
jamie-dit wants to merge 1 commit into
anomalyco:devfrom
jamie-dit:preserve-human-waits
Open

jamie-dit wants to merge 1 commit into
anomalyco:devfrom
jamie-dit:preserve-human-waits

Conversation

@jamie-dit

Copy link
Copy Markdown

Issue for this PR

Closes #48999

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The location inactivity sweep interrupts sessions after an hour without durable activity. Waiting for a question or permission answer produces no durable activity, so an unanswered request can be cancelled while the user is away.

Before interrupting owners, check the cached location for pending forms or permissions. If either exists, renew its deadline and leave the original request alive. Protect the whole location so another session waiting for that answer is not interrupted either.

Explicit Stop still works. Locations without pending requests still expire, including stalled executions. An unanswered request retains the location's services in memory. This does not add restart persistence or synchronise new request creation with the eviction check.

Related: anomalyco/opencode#46509: fix(core): preserve approvals across location cleanup. This patch targets the current v2 sweep, which interrupts executions before invalidating the location.

How did you verify your code works?

The new wait tests fail without the fix. With it, a question survives 12 simulated hours and accepts its original answer. Tests also cover permission waits, explicit Stop, shared locations, one to three stalled executions, and work admitted during cleanup.

The permission test uses a minimal permission-service fixture; the form and execution services are real. The existing permission suite also passes.

From packages/core:

bun run test test/location-activity.test.ts test/location-layer.test.ts test/permission.test.ts test/form.test.ts

146 passed, 2 skipped. Package typecheck, repository-wide bun run check (35 tasks), and formatting checks passed.

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
Contributor

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.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

(The only result is the current PR #50499 itself, plus PR #46509 which is already referenced in the description as related prior work, not a duplicate.)

@jamie-dit

Copy link
Copy Markdown
Author

Fixes #48999. The Closes line doesn't register because this PR targets v2, not the default branch, which is why needs:issue was added. Could a maintainer clear the label?

@thiago-carneiro

Copy link
Copy Markdown

This is the right policy shape for #51343's problem 1 (renew while a human wait is pending, explicit Stop still interrupts) — thanks for including the tests.

One heads-up, no action needed: I'm planning to propose a config surface on top of this shape — per-tool wait timeouts, where 0 means never expires — as a follow-up issue, so the renewal policy stays yours and the customization is a layer above it. Happy to help with rebase/testing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interrupted - causing my long important prompt to vanish.

2 participants