Browser setup and isolation: stale pairing prompt, silent socket ids, shared profile
Part of #213.
This is follow-up D from section 8: browser-side setup and isolation, separate from the credential-rotation fix in the first PR and from the delivery/health/subscription follow-ups.
Summary
Three browser-surface failures make setup and repair harder than the visible status suggests. They can be fixed independently, and the first two are small:
- A stale CCCC pairing prompt blocks every retry. CCCC's own unsent pairing prompt is counted as an occupied composer, so a later pairing attempt fails with
pairing_composer_occupiedinstead of recognising and clearing its own abandoned draft. Reloading the page or deleting and recreating the Agent does not necessarily remove it. - A browser-session command can run without returning a result. The WebSocket accepts a command, executes it, and only replies when the request
idis a non-empty string. A numeric or structuredidproduces nocommand_result, so a successful command looks dropped. A reported remote-access path also saw no result for commands that should have carried a string id; that path still needs an end-to-end capture. - One browser process and profile serve every browser-delivered Agent of a provider. Pages are separate, but there is no automatic page-scoped recovery for a hung page; a closed page must be reopened, and a stuck page is reported to stall other Agents. The documented recovery contract needs a test that distinguishes page, profile and connector contention before profile-per-Agent isolation is promised.
Evidence labels used below:
- Source-confirmed at 66e26c85: checked against CCCC v0.4.54, commit
66e26c85ce0871ee5241e4ce01793f0b4a0f0f8c. - Reported: observed in an operator's setup/repair account; not independently reproduced in this draft.
- Proposed: a requested behaviour or test; not a claim that it exists today.
No new runtime reproduction or test execution is claimed here. The source references establish what the pinned code does, not which binary handled every historical request.
A. Stale CCCC pairing prompt is treated as a human draft
Reported. After an interrupted automatic pairing attempt, the ChatGPT new-chat composer kept CCCC's own unsent pairing prompt, including a spent wm_pair_ code. Every later pairing attempt for that Agent failed with pairing_composer_occupied; because the profile is shared, the same draft was reported to block new Agents on that provider profile as well. Reloading the page did not clear it; deleting and recreating the Agent did not clear it either. An operator eventually cleared it through browser automation.
Reproduction (reported):
- Start pairing an Agent on a new ChatGPT chat.
- Interrupt the attempt after CCCC has inserted its fixed pairing prompt but before the prompt is submitted and the receipt is verified. Closing the page, reloading it, or stopping the attempt are equivalent for this purpose.
- Retry pairing for the same Agent.
- Observe
pairing_composer_occupiedwhile the composer still contains CCCC's prompt.
Source-confirmed at 66e26c85:
crates/cccc-web/src/browser_surface/pairing.rs:33-36rejects pairing whenever the marked composer has any text. It does not ask whether that text is CCCC's own fixed prompt.crates/cccc-web/src/browser_surface/pairing.rs:55-58separately rejects any attachment. That check should remain.- The fixed prompt is built inline at
crates/cccc-web/src/routes/web_model_pairing.rs:156-158; the same text is not available to the browser-surface guard as a single shared constant. - The browser-session routes at
crates/cccc-web/src/routes/web_model_browser.rs:37-56expose open, close, reload, bind-current, delivery-preference, resume-delivery and the WebSocket. There is no scoped composer-clear action. - Health chooses
bind_chat/ "Choose a conversation" when the target is missing (crates/cccc-web/src/routes/web_model_browser.rs:596-597) without first checking that the composer holds unsent text. A stale CCCC prompt can therefore be reported as a missing conversation. - The pairing guard checks composer occupancy before readiness (
crates/cccc-web/src/browser_surface/pairing.rs:33-39), so a stale prompt can mask a sign-in or security-verification failure.
Smallest proposed change:
- Put the pairing prompt template in one shared function/constant used by both the route and the browser guard.
- In the pairing path, when the marked composer is occupied, compare the whole normalized draft with CCCC's fixed prompt containing exactly one
wm_pair_code. Clear only that exact draft, only from the composer the readiness pass marked, and read it back before continuing. Do not submit it. - Preserve a human draft, CCCC's prompt with appended text, and any attachment. Keep
pairing_composer_occupiedfor those cases. - Check sign-in/security-verification/not-ready states before reporting composer occupancy, so the caller gets the prerequisite reason rather than a misleading draft error.
- Health branch: when the composer has unsent text, recommend an explicit "clear or send the draft" action instead of "Choose a conversation". Section 8E should own the read-only projection; coordinate so there is one
clear_composerbranch. If 8E lands first, A reuses it and only the pairing response changes; otherwise A adds the minimal branch. - A general
clear_composeroperator action is a reasonable follow-up, but it needs its own guard: clear only CCCC-authored text unless an explicitforceis supplied, and never clear attachments implicitly. It is not required for the narrow pairing repair.
Acceptance tests:
- Exact CCCC stale prompt in the marked composer: pairing clears it, does not submit it, and proceeds.
- Human draft: unchanged; pairing still fails with
pairing_composer_occupied. - CCCC prompt plus appended human text: unchanged; still refused.
- Attachment present: still refused.
- Stale prompt plus sign-in or verification required: the response names the prerequisite, not
pairing_composer_occupied. - Health with an occupied composer reports an unsent-draft next action (reuse 8E's
clear_composerbranch if it has landed), not "Choose a conversation".
Size: S for the pairing-path clear and health reason. A guarded operator clear is S/M and can follow separately.
B. Browser-session command can execute with no command_result
Reported. From a remote operator connected through the authenticated browser-session WebSocket, frames streamed normally, but client commands (ping, key, click) produced no command_result. That held even for a healthy paired Agent. The commands may have executed; the caller could not tell.
Source-confirmed at 66e26c85:
- The WebSocket route is
crates/cccc-web/src/routes/web_model_browser.rs:55; it upgrades toserve_socketatcrates/cccc-web/src/routes/web_model_browser.rs:296-341. crates/cccc-web/src/browser_surface/interaction.rs:220reads the request id withand_then(Value::as_str). A numeric or structured id becomes"".crates/cccc-web/src/browser_surface/interaction.rs:229-244sendscommand_resultonly when that string id is non-empty. A successful command with a numeric id sends nothing; an error with a numeric id sends only a genericerror.- The command is executed before the reply decision (
crates/cccc-web/src/browser_surface/interaction.rs:221-227), so "no result" does not mean "not executed".
Reproduction:
- Connect to
/api/v1/web-model/browser-session/ws?group_id=…&actor_id=…with an authenticated browser-session client. - Send
{"t":"ping","id":7}(numeric), then a string-id command such as{"t":"ping","id":"probe-1"}. - Observe frames but no
command_resultfor the numeric id. The string id may work locally. - Repeat over the remote-access path. Capture whether the client frame is received, whether the command is held in
key_operation, and whether any result is sent. If string ids also fail there, that is a separate transport question, not evidence for the numeric-id cause.
Smallest proposed change:
- Parse
idas a JSON value rather than a string. - Reply with
command_resultfor every non-null id except an empty string, echoing the original id unchanged (including numeric and structured values). - Keep the existing no-result behaviour for missing, null and empty-string ids.
- Extract the reply construction into a small helper so it can be unit-tested without a live browser.
- Do not add a REST command fallback in the first fix. If the remote path still loses string-id replies after the id fix, a fallback is a separate API decision.
Acceptance tests:
- Numeric id
7: result hasid: 7and the correctok. - Structured id: echoed unchanged.
- String id: echoed unchanged on success and on error.
- Missing, null and empty-string id: no
command_result; existing generic error behaviour is unchanged. - Authenticated WebSocket end-to-end:
ping,keyandclickeach produce a result with the original id. - Remote-access end-to-end: the same commands produce results, or the capture identifies the transport boundary that drops them.
Size: S for the id/reply fix and unit tests. The remote end-to-end test may require existing browser-fixture infrastructure.
C. Shared browser/profile needs page-scoped recovery before profile sharding
Reported. With several browser-delivered Agents on one instance, one Agent's page stuck in a modal, verification interstitial or hung renderer stalled or failed delivery and pairing for the others until that page was cleared.
Source-confirmed at 66e26c85:
crates/cccc-web/src/routes/web_model_shared_browser.rs:42-49returns one profile path per provider.crates/cccc-web/src/routes/web_model_browser.rs:107-117opens every browser-delivered Agent with that same profile.crates/cccc-web/src/browser_surface.rs:353-375marks the Actor surface asshared_browser: true;crates/cccc-web/src/browser_surface.rs:585-619reuses one owner per profile and creates a new page in that owner for each Agent.crates/cccc-web/src/browser_surface/system_browser.rs:111passes the profile asuser_data_dir; the macOS path passes the same directory as--user-data-diratcrates/cccc-web/src/browser_surface/system_browser.rs:204.open_registeredreuses a surface only while its page target still exists; if the target is gone, it closes that key and creates a new page at the request URL (crates/cccc-web/src/browser_surface.rs:533-566). That is an explicit reopen, not automatic recovery of a hung page.- Shared surfaces disable the headless closed-page recovery:
crates/cccc-web/src/browser_surface.rs:683setsrecover_closed_pageonly for!shared_browser && Headless, whileensure_open_shared_actorusesshared_browser: trueandSystem(crates/cccc-web/src/browser_surface.rs:353-375). Theframerecovery branch atcrates/cccc-web/src/browser_surface/frame.rs:34-37is therefore not used for these Actor pages. - When a shared page is closed,
infocloses that Agent's surface (crates/cccc-web/src/browser_surface.rs:714-755); reopening creates a page in the same shared browser. There is no page-scoped recovery for a hung shared page. - The only recovery helper scans all pages and selects the first live one (
crates/cccc-web/src/browser_surface/page_recovery.rs:59-89); it is currently gated off for shared surfaces. If shared recovery is added, it must use the failed session's explicit target/URL, not this scan order. - The documented contract at
docs/guide/web-model-runtime.md:229says a browser crash "affects all shared windows and recovery uses their explicit bindings; it never adopts an unrelated tab." The explicit-reopen path uses the requested URL and does not scan other pages, but it does not recover a hung page, and the helper's scan order would be unsafe if reused. The same guide says all Agents share one profile and separate windows atdocs/guide/web-model-runtime.md:40, and that an unrelated composer draft is never overwritten atdocs/guide/web-model-runtime.md:168.
Reproduction (steps 1–3 reported; steps 4–5 proposed verification):
- Run two browser-delivered Agents, A and B, on one instance.
- Put A's page into a blocking state: a modal, a verification interstitial, or a hung renderer. A test hook is preferable to a manual provider challenge.
- Attempt delivery or pairing for B. Record whether B completes and whether A's health reports its own blocker.
- Close A's page while B's page is live, then inspect A's status and reopen A. Verify A gets its own page and never targets B's page.
- With A still hung, attempt a page-scoped close/reopen for A and record whether B is affected. This is the proposed recovery path; if A cannot be closed, the result should be a bounded error rather than a profile restart.
Smallest proposed change:
- Extend the existing explicit-reopen path into a page-scoped recovery for a hung shared page: identify only the failed Agent's target, try to close that page with a bounded timeout, recreate it at the saved conversation/start URL, and leave the other pages alone.
- If the target cannot be closed or recreated, return a bounded recovery error and leave the other Agents untouched. Do not fall back to scanning pages or restarting the shared profile.
- Add a test hook that blocks one page without blocking the browser process, and a two-Agent test that asserts A's blocker is reported on A while B still completes.
- Do not promise profile-per-Agent isolation in this fix. A separate profile/login per Agent is a larger product decision (L); page-scoped recovery and clear per-Agent health are the smaller first step. If the reported cross-Agent stall persists after recovery is scoped, the next step is a per-Agent or per-group profile option with an explicit separate-login cost.
Acceptance tests:
- Two Agents; block A; B's delivery and pairing complete; A's health reports A's own blocker.
- Close A's page while B is live; A reports its own closed surface; reopening A creates or uses A's own page and never targets B's page.
- A's recovery/clear action does not clear B's composer or navigate B's page.
- With two pages in one shared owner, a recovery implementation must match A's explicit target; a scan that could return B's page is rejected by the test.
- Browser-process crash recovery uses each Agent's explicit binding and never adopts an unrelated tab.
Size: M for page-scoped recovery and the two-Agent test. Profile-per-Agent sharding is L and is not proposed here.
Proposed order and size
| Part | Change | Size |
|---|---|---|
| A | Recognise and clear only CCCC's exact stale pairing prompt; correct the health reason; preserve human drafts/attachments | S |
| B | Echo command_result for non-null, non-empty JSON ids; unit and WebSocket tests |
S |
| C | Page-scoped recovery using the session's explicit target/URL; two-Agent isolation test | M |
| Later | Per-Agent/per-group browser profile and separate login | L, separate design |
A and B are independent and can land first. C should not be combined with profile sharding; scoping recovery is useful even if profile sharding is never adopted.
Serialization and prerequisites
Pairing is serialized per Agent (crates/cccc-web/src/routes/web_model_pairing.rs:109, using the control guard in crates/cccc-web/src/routes/web_model_delivery.rs:227), not per instance. The browser process/profile is shared, but each Agent has its own page. This draft does not propose an instance-wide pairing lock unless a two-Agent capture shows two pages contending for one composer, profile or connector resource. The test in C should establish whether the actual contention is the page, the profile, or the connector before adding a broader lock.
Sign-in and security verification already have distinct readiness fields (crates/cccc-web/src/browser_surface/prompt_submission.rs:729-751) and health actions (crates/cccc-web/src/routes/web_model_browser.rs:578-589). The gap is ordering and specificity: pairing checks composer occupancy first, and health can recommend "Choose a conversation" while the composer holds text. The proposed A change should surface the prerequisite instead of masking it. MFA is part of the provider's sign-in/verification flow; CCCC should report that the browser needs the operator, not attempt to automate it.
Out of scope
- Changing connector authentication, pairing authority, or which Agent owns a conversation.
- Automatic retry or replay of an ambiguous browser delivery; that is the separate #112 problem.
- A general "clear all drafts" operation. Only CCCC's exact fixed pairing prompt is safe to clear without explicit operator force.
- Per-Agent Chrome profiles, separate ChatGPT logins, or profile sharding as part of the first fix.
- Browser-process crash recovery beyond each Agent's explicit binding.
- Managed Remote Access authentication/transport changes; this change only makes command outcomes observable.
- The restored-target churn in #109. Current page-recovery code already treats a canceled page-URL read as a gone candidate (
crates/cccc-web/src/browser_surface/page_recovery.rs:22-56); this draft does not re-claim that failure. - Multi-Agent support itself (#115 / #106); the isolation problem only exists because multiple Agents are now supported.
Related upstream history
- #213 is the parent field report. This is its follow-up D.
- #112 (closed) covers an existing-chat prompt left staged but unsent after
submission_ambiguous, including later overwrite. It is adjacent delivery ambiguity, not a stale pairing prompt, a missing WebSocket result, or page recovery. This draft does not re-claim it. - #109 (open) covers browser-session open failing with repeated
oneshot canceledduring Chrome session restore. It is adjacent transient-target recovery; the current code already has canceled-target handling, so this draft does not re-claim it. - #115 (closed) requested multiple ChatGPT Web Model Agents per instance; #106 (closed PR) added multi-conversation/task handoff. This draft starts from that supported multi-Agent state and addresses isolation among the Agents.
- #175 (closed PR) routes real-Chrome browser fixtures to the nightly profile. Any new browser test should follow that test boundary rather than launch a real browser in normal PR CI.
- #80 (closed release PR) mentions Linux projected-browser isolation in its release notes; it is not a bug report for these paths.
A bounded search of open and closed upstream issues and pull requests found no direct duplicate for the three problems above. The closest hits are #213 itself (the parent), #112 and #109 (adjacent history), and #115/#106 (the multi-Agent feature).
Questions for maintainers
- For A, is a narrow pairing-path clear of CCCC's exact fixed prompt acceptable, or would you prefer an explicit operator
clear_composeraction as the only way to remove any draft? - For B, should the WebSocket protocol support numeric/structured ids, or should it require string ids and reject other shapes explicitly?
- For C, is page-scoped recovery using the session's explicit target the right first step before considering per-Agent profiles?
Parts A and the ID-handling portion of B shipped in 0.4.55. Pairing recognizes only CCCC's exact abandoned setup message, clears it without sending it, and preserves other drafts and attachments. Browser commands now echo non-null, non-empty JSON IDs unchanged in command_result, on success and failure. This includes numeric and structured IDs; missing, null and empty-string IDs retain notification behavior.
That does not establish that the reported remote-access case with string IDs is resolved. It also does not reproduce the shared-profile incident in C: our existing coverage exercises independent pages, closing/reopening one page and delayed navigation, rather than every verification interstitial or hung renderer. Before adding automatic page recovery or separate profiles, we need to distinguish A's blocking condition, whether B's own target remained reachable, and the precise operation/error on B. We will preserve drafts and uncertain-delivery evidence and will not adopt another actor's page or restart the shared profile as a generic repair. This issue still has those unresolved parts.