mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-25 05:07:05 +00:00
Cursor ACP sessions can fail mid-turn with a transient model error that the agent reports inline rather than as an RPC rejection. HAPI treated those turns as successful, so the session went quiet with no banner, no push, and no way to resume without retyping the prompt. This adds the full path: - detect: classify inline/stderr model errors from the Cursor ACP stream, requiring strong signatures before typing a failure as a model error - surface: persist `lastModelError` on session metadata; render a chat banner and a session-list indicator, with the prompt text kept out of list/SSE summaries so they never ship up to 32 KB of user prompt - notify: deliver a push for an unacknowledged error, watermarked on the hub copy so a restart does not re-page the same eventId - bridge & retry: offer a one-shot recovery prompt that replays the failed turn, bound to the originating eventId and gated so a real user turn always supersedes it. Auto-bridge is opt-in and defaults to OFF, persisted in hub settings and fanned out to live Cursor CLIs. Re-cut onto current upstream/main. The branch had accumulated 108 iterative hardening commits against a 289-commit-older base; replaying them individually would have re-resolved the same conflicts ~100 times. The pre-re-cut tip was 2c28a1365 if the granular history is ever needed. Absorbing upstream required adapting to three refactors that landed meanwhile: - `MessageQueue2` grew an `internal?: boolean` control-message flag upstream while this branch added richer `internal` provenance. Unified on a tagged `QueueItemInternal` union (`control` | `model-error-bridge`) so one field carries one concept. `hasPendingNonBridgeTurn()` now treats *any* internal item as non-user: otherwise a queued `/auto-review` control slash would have counted as a user turn and wrongly superseded a live bridge. - `AcpSdkBackend.prompt()` gained a `timing` callback upstream; merged it with this branch's `shouldSend` gate into a single options object. - The hub settings route moved to a unified `updateSettings` transaction. `autoBridgeTransientModelErrors` is applied outside that transaction because SyncEngine owns its CLI fan-out and rollback under its own lock. via [HAPI](https://hapi.run) Co-authored-by: HAPI <noreply@hapi.run>
This commit is contained in:
@@ -7,12 +7,14 @@ public enum PushType: String, Sendable {
|
||||
case ready
|
||||
case permissionRequest = "permission-request"
|
||||
case inputRequest = "input-request"
|
||||
case modelError = "model-error"
|
||||
}
|
||||
|
||||
/// `severity` — visual urgency accent (`hub/src/fcm/fcmService.ts`).
|
||||
public enum PushSeverity: String, Sendable {
|
||||
case info
|
||||
case warning
|
||||
case error
|
||||
}
|
||||
|
||||
/// Parsed `notifySummary` (JSON string, only on `ready`): the agent's
|
||||
@@ -69,6 +71,8 @@ public struct PushPayload: Equatable, Sendable {
|
||||
public var severity: PushSeverity?
|
||||
public var contractVersion: String?
|
||||
public var notifySummary: PushNotifySummary?
|
||||
/// Hub coalescing tag (`FcmSendPayload.tag`), when present.
|
||||
public var tag: String?
|
||||
|
||||
/// The contract version this client implements.
|
||||
public static let contractVersion = "1"
|
||||
@@ -90,7 +94,7 @@ public struct PushPayload: Equatable, Sendable {
|
||||
case .permissionRequest: return requestId != nil
|
||||
case .inputRequest: return false // Answer in the session, never via Allow/Deny or message Reply.
|
||||
case .ready: return true
|
||||
case nil: return false
|
||||
case .modelError, nil: return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +106,13 @@ public struct PushPayload: Equatable, Sendable {
|
||||
supportsActions ? rawType : nil
|
||||
}
|
||||
|
||||
/// Coalescing identity: prefer the hub-supplied `tag` (event-specific
|
||||
/// for `model-error`) before falling back to `type-<sessionId>`.
|
||||
public var notificationTag: String {
|
||||
if let tag, !tag.isPushBlank { return tag }
|
||||
return "\(rawType.isEmpty ? "unknown" : rawType)-\(sessionId)"
|
||||
}
|
||||
|
||||
/// Title to render; falls back to the session name, then a constant.
|
||||
public var displayTitle: String {
|
||||
if let title, !title.isPushBlank { return title }
|
||||
@@ -133,7 +144,8 @@ public struct PushPayload: Equatable, Sendable {
|
||||
requestId: String? = nil,
|
||||
severity: PushSeverity? = nil,
|
||||
contractVersion: String? = nil,
|
||||
notifySummary: PushNotifySummary? = nil
|
||||
notifySummary: PushNotifySummary? = nil,
|
||||
tag: String? = nil
|
||||
) {
|
||||
self.type = type
|
||||
self.rawType = rawType
|
||||
@@ -146,6 +158,7 @@ public struct PushPayload: Equatable, Sendable {
|
||||
self.severity = severity
|
||||
self.contractVersion = contractVersion
|
||||
self.notifySummary = notifySummary
|
||||
self.tag = tag
|
||||
}
|
||||
|
||||
// MARK: - Parsing
|
||||
@@ -169,7 +182,8 @@ public struct PushPayload: Equatable, Sendable {
|
||||
requestId: nonBlank(data["requestId"]),
|
||||
severity: data["severity"].flatMap(PushSeverity.init(rawValue:)),
|
||||
contractVersion: nonBlank(data["contractVersion"]),
|
||||
notifySummary: data["notifySummary"].flatMap(parseNotifySummary)
|
||||
notifySummary: data["notifySummary"].flatMap(parseNotifySummary),
|
||||
tag: nonBlank(data["tag"])
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user