Skip to content

Fix assistant job cancel flag compile failure#122

Open
adamcohenhillel wants to merge 2 commits into
mainfrom
codex/fix-agent-job-cancel-flag-key
Open

Fix assistant job cancel flag compile failure#122
adamcohenhillel wants to merge 2 commits into
mainfrom
codex/fix-agent-job-cancel-flag-key

Conversation

@adamcohenhillel

Copy link
Copy Markdown
Contributor

Summary

  • Fix the assistant background job cancel flag map to use Long keys matching AgentJobRecord.id.
  • Parse the public cancelJob(String) argument before looking up the running job flag.

This branch is based on PR #103 (28d1b48d) because the compile failure is introduced there; the final commit is the minimal fix (926f3768).

Evidence

Validation

  • ./scripts/check.sh
  • git diff --check

Notes

  • No device eval was run; this was a Java compile failure and the default assistant Java check now passes.

faiqq7 and others added 2 commits July 2, 2026 01:10
mAgentRunGeneration was a non-volatile int written on the UI thread
(runAgent, cancelAgentRun, live-voice starts) and read from the agent
background thread inside isCancelled(). Without synchronization the
agent thread has no visibility guarantee for writes from the UI
thread, so a cancellation could go unobserved. Converted to
AtomicInteger and updated every read/write site to use
incrementAndGet()/get().

OpenPhoneAgentJobScheduler.isCancelled() hardcoded false, so a
background agent_turn job could never be stopped once its thread
started. Added a per-job AtomicBoolean cancel flag (keyed by job id
in a ConcurrentHashMap) and a new cancelJob(String) entry point that
sets it; the flag is cleared in the job's finally block.

I also reviewed the pending-confirmation fields (mPendingActionId,
mPendingToolName, mPendingToolArguments, mPendingOneShotMessage)
called out in the issue. Every write site I found is either inside a
runOnUiThread block or a method only invoked from the UI thread, and
the one place a background Thread reads them (confirmPending) does so
via local finals captured before Thread.start(), which is safe under
Java's happens-before guarantee. I did not find an actual race on
these fields, so I left them unchanged rather than add synchronization
for a scenario I could not reproduce or confirm — flagging this in the
PR in case I've missed a call path.

Fixes #70
@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openphone-docs Ready Ready Preview, Comment Jul 4, 2026 4:07am

Request Review

@adamcohenhillel adamcohenhillel added the bug Something isn't working label Jul 4, 2026
@adamcohenhillel adamcohenhillel marked this pull request as ready for review July 11, 2026 20:06

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

Copy link
Copy Markdown

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: 926f37689b

ℹ️ 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 157 to +158
public boolean isCancelled() {
return false;
return cancelFlag.get() || Thread.currentThread().isInterrupted();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Wire background-job stops into the cancel flag

This cancellation check never becomes true from the actual background_job_stop tool: FrameworkToolExecutor.backgroundJobStop only updates AgentJobStore.stop(id) and schedules the next alarm, and a repo-wide search shows no caller for the new OpenPhoneAgentJobScheduler.cancelJob(...). When a built-in agent_turn job is already running, stopping it therefore leaves the model loop running until it finishes, after which store.markCompleted(...) can overwrite the stopped status; please signal this flag from the stop path and avoid completing canceled jobs as successful runs.

Useful? React with 👍 / 👎.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants