Skip to content

feat(COD-302): integrate runner and approval workflow - #7

Merged
Midhat-kazmi merged 2 commits into
mainfrom
feat/COD-302-runner-integration
Nov 14, 2026
Merged

Midhat-kazmi merged 2 commits into
mainfrom
feat/COD-302-runner-integration

Conversation

@Midhat-kazmi

Copy link
Copy Markdown
Collaborator

Summary

Integrates the runner with the daemon for COD-302.

Changes

  • Added runner event handling and SQLite event persistence.
  • Added preflight checks and start options.
  • Implemented the task.finished → approval.requested workflow.
  • Added approval state transitions and command receipt handling.
  • Updated daemon dependencies.

Testing

  • TypeScript compilation passed.
  • Fake-runner end-to-end workflow passed.
  • Approval command successfully transitioned the session to approved.

@imtahirabatool imtahirabatool left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice work. The event saving with its own seq, the command receipts, the provider_status preflight and approve/reject through canTransition are all in the right shape. A few things before this can merge:

Blocking

  1. @codehands/runner path only works on your machine. daemon/package.json has file:../codehands-agent/runner, which resolves to codehands-backend/codehands-agent/runner. That folder isn't in the repo, so npm install fails for anyone else. The same goes for the ../../codehands-contracts/src/... imports. Let's agree on one layout (sibling folders: file:../../codehands-agent/runner) and put it in the README. Also, the runner's main is dist/index.js, so it needs a build (its prepare runs tsc on install).
  2. The real runner never runs. runner is always createFakeRunner(...). Without CODEHANDS_FAKE_RUNNER=1, tasks are claimed and stay queued forever, and every command is refused with "Real runner is not connected yet". The PR title says it integrates the runner. Either wire createRunner() (or createEngine()) for real mode, or retitle it as the fake-mode step and fail the session in real mode instead of leaving it queued.
  3. agent: "codehands" (the engine) is rejected. isSupportedAgent and start-options.ts only allow codex and claude-code. Contracts v0.2.0 has AgentKind = "claude-code" | "codex" | "codehands", and Milestone 1 runs through the engine (createEngine from @codehands/runner). Please allow codehands. Preflight for it is the same as claude-code.
  4. The DB file and env var were renamed. state.db became codehands.db, and CODEHANDS_DB became CODEHANDS_DB_PATH. The migration header, the README and the apps all use ~/.codehands/state.db, so after this change the daemon and the app read different databases. Please revert, or rename it everywhere in the same PR.
  5. Merge conflicts with main. watcher.ts changed on main in PR #8/#9, so this needs a rebase.

Should fix

  1. Restart doesn't clean up the runner. recoverSessions() marks running sessions as failed in SQLite, but the runner still has its own session file and worktree for them. Call runner.recover() once at startup (it's on the type createRunner() returns). Later, for crash resume (Milestone 1), this becomes engine.recover(), and its resumable sessions get resumed instead of failed. I'll send the exact code.
  2. A stream that ends with no result leaves the session running forever. After the for await in consumeRunnerEvents, if the session is still running (no approval.requested, task.failed or task.stopped arrived), move it to failed with a reason like "runner ended without a result".
  3. Missing budgetUsd. buildStartOptions doesn't pass it, and that's what caps Claude Code's spend. Please pass it from the task (or a default like 0.5). Passing models (the per-step map) too would let the engine use the task's models.
  4. The approve commit message is always "Approved by user". The runner uses this as the commit message on the branch. Use the task prompt (or a title) instead.
  5. Preflight blocks the loop, and may be wrong on Windows. spawnSync with shell: false can't find claude.cmd/codex.cmd when they're npm shims, so they'd show as not_installed. It also blocks the 500 ms loop for up to 10 s for every task. Please check claude auth status actually exists in the installed version, and think about caching the result for a minute.

Tidy-ups

  1. daemon/src/fake-runner.ts isn't used (the watcher uses the runner package's createFakeRunner). It also skips approval.requested, and its resume restarts seq at 1. Please delete it.
  2. The provider_status upsert appears 4 times (preflight.ts, provider-events.ts and twice in watcher.ts). Keep one function and use it everywhere. saveProviderStatus and saveProviderEvent aren't called anywhere.
  3. saveRunnerEvent, buildStartOptions and the preflight helpers open a new DB connection on every call (one per event). Pass the watcher's db in instead.
  4. There are no automated tests. A couple of watcher tests with the fake runner would help a lot: claim → running → awaiting_approval → approve, and stop/resume. Use a temp DB via the env var.

Happy to pair on 2, 3 and 6 since they touch the runner/engine. 🙌

@Midhat-kazmi
Midhat-kazmi merged commit a24d10a into main Nov 14, 2026
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.

2 participants