# ask-gpt bounded prompt submission

audience: AI coding agents first.

Status: DONE
Priority: FIRE
Task IDs: #1
Source request: Owner reports `ask-gpt` became unreliable after latest upgrade: calls often hang silently, agents assume progress, no prompt reaches ChatGPT, and owner discovers hours later that no work started. Investigate root cause; restore reliable prompt submission; NEVER permit silent indefinite waiting.

## Outcome

Installed `/home/user/.local/bin/ask-gpt` either proves prompt submission and reports visible progress, or exits nonzero with an actionable error within a bounded time. Callers can never mistake an unsent prompt for active work.

## Acceptance criteria

- Reproduce or capture the no-prompt silent wait at the smallest request boundary.
- Identify evidenced root cause before implementation.
- Add deterministic regression covering the failed boundary.
- Emit immediate, truthful lifecycle status before and after prompt submission.
- Bound every pre-submission wait; timeout MUST exit nonzero and identify the failed stage.
- Preserve valid long-running response generation after confirmed submission.
- Keep account isolation, browser authentication, seat concurrency, attachment staging, and resume behavior intact.
- Install candidate before landing; invoke real installed entrypoint and prove prompt reaches ChatGPT.
- Run focused tests and full gptbridge suite cleanly.
- Commit, land, deploy, reinstall, and repeat installed proof from landed source.

## Preserved WIP/ref/path

- Worktree: `/home/user/Projects/overdeck/.worktrees/fix-ask-gpt-hangs`.
- Branch: `wt/fix-ask-gpt-hangs` from `origin/main` at `8d7542a91`.
- Installed entrypoint: `/home/user/.local/bin/ask-gpt` → deploy clone.
- Existing active ask-gpt attachment and X-display plans remain independent; do not overwrite their WIP.

## Constraints

- Follow systematic debugging: evidence first; no speculative timeout patch.
- Never hide browser/daemon failures behind retries.
- Timeout starts at one monotonic pre-submission deadline shared across seat wait, dispatch lock/pacing, and prompt acceptance. NEVER reset budget at a boundary.
- Dispatch lock acquisition MUST use bounded nonblocking retries; NEVER block indefinitely in `flock`.
- Every successful acceptance path MUST emit `submitted` exactly once before streaming.
- Status MUST distinguish queued, browser startup, prompt submission, submitted, response streaming, and failed.
- No broad process kills, registry bootstrap, credential mutation, or account reassignment.
- Touch only the evidenced gptbridge seam and its tests.

```text
DO NOT: print nothing while waiting; retry forever; call browser startup "progress"; return success before submission.
TARGET: visible stage → bounded submission acknowledgement → response stream, or explicit nonzero failure.
```

## Execution steps

1. Inspect recent gptbridge changes and trace CLI → trusted launcher → daemon → browser prompt submission.
2. Capture installed logs/process state during one bounded reproduction; locate last completed boundary.
3. Compare broken path with deterministic working tests and previous implementation.
4. State and minimally test one root-cause hypothesis.
5. Add failing regression at exact seam.
6. Implement smallest root-cause repair plus truthful stage visibility and bounded pre-submission failure.
7. Run focused tests; install candidate atomically; prove real installed prompt submission.
8. Run full gptbridge verification; resolve every signal.
9. Commit, land through project path, deploy, reinstall, and repeat installed proof.

## Current receipt

Candidate installed and live-proven before landing. Root cause: browser-seat acquisition and dispatch pacing/locking could wait indefinitely before prompt submission; ordinary agent calls hid stage progress. Old daemon evidence: active 1, queued 38, median turn 6,125.4 seconds. Repair uses one monotonic 120-second pre-submission deadline across seat acquisition, nonblocking dispatch lock, dispatch pacing, and acceptance; emits queued/submitting/submitted truthfully; cleans queue state; validates timeout. Independent review findings resolved. Affected deterministic suite: 49 passed. Committed `60752170a`; landed/deployed main `71632cc78`. Canonical deployed daemon reports exact version `71632cc7817a6118613c3f4f8b94657f9dfad0c4`. Clean post-restart installed proof exit 0 returned exactly `ASK_GPT_LANDED_OK`, conversation `6a7c6a21-8d20-83ec-a573-f298fdf8e8f6`, canonical log present. Final health: ready, queue 0, active 0, median 22.0 seconds. Earlier occupied-seat probe correctly failed nonzero at deadline rather than hanging; subsequent clean proof showed occupancy came from a competing active caller, not phantom cleanup. Deployment emitted pre-existing shim-drift hazards in unrelated worktrees; no overlap with this fix. Unrelated K3s package-signature findings untouched.

## Next executable action

None. Runtime installed, landed, deployed, restarted, and owner-visible proof complete.
