fix: restore goal accounting after thread resume (#24626)

## Why

Goal idle accounting is supposed to survive a thread resume. Previously,
the resume hook restored the active goal state inline from the extension
lifecycle contributor, which left the runtime handle without a reusable
restoration path and made the behavior hard to cover directly. When a
thread with an active goal was resumed, goal accounting could lose track
of the active idle goal instead of continuing to accrue elapsed time.

## What changed

- Moved thread-resume restoration into
`GoalRuntimeHandle::restore_after_resume()` so the runtime owns
rehydrating active goal accounting from persisted thread goal state.
- Kept disabled goal runtimes as a no-op and preserved the existing
warning path when persisted goal state cannot be loaded.
- Added a backend regression test that seeds an active goal, resumes the
thread, waits briefly, and verifies elapsed idle time is reflected on
the next external goal mutation.

## Testing

- Not run locally; this metadata update only rewrote the PR title/body.
This commit is contained in:
jif-oai authored and GitHub committed 2026-05-26 20:01:13 +02:00
1 parent 8a4a537e44
commit 823381e867
3 files changed
+88 -26

No files matched your search

+24
View File
@@ -192,6 +192,30 @@ impl GoalRuntimeHandle {
Ok(())
}
pub async fn restore_after_resume(&self) -> Result<(), String> {
if !self.is_enabled() {
return Ok(());
}
let goal = self
.inner
.state_dbs
.thread_goals()
.get_thread_goal(self.thread_id())
.await
.map_err(|err| err.to_string())?;
match goal {
Some(goal) if goal.status == codex_state::ThreadGoalStatus::Active => {
self.inner
.accounting_state
.mark_idle_goal_active(goal.goal_id);
self.inner.metrics.record_resumed();
}
Some(_) | None => self.inner.accounting_state.clear_active_goal(),
}
Ok(())
}
pub(crate) async fn inject_active_turn_steering(&self, item: ResponseInputItem) {
let Some(thread_manager) = self.inner.thread_manager.upgrade() else {
tracing::debug!("skipping goal steering because thread manager is unavailable");