Repository navigation
fix(chat): Close privacy, recovery, and delivery gaps in the message pipeline - #728
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Revamp chat specs to close gaps found in a full review of the message receive/process pipeline: - Conversation visibility comes from source signals (channel_type, is_private), never id prefixes; persisted destination visibility is the authority for transcript tools, dashboards, and telemetry, and unconfirmed visibility fails closed to private. - Task execution gains normative poison-work retry bounds, heartbeat quarantine of unreadable conversation records, fenced record writes, and retryable ingress failure semantics. - Resumability requires parked (awaiting_resume) messages to reach the model, recovery of lease-expired running sessions, fenced session-log appends, best-effort host-only activity events, and forbids terminal completion before destination acceptance. - Slack delivery defines one shared author gate across all entry paths including edited-message mentions, fail-fast bot identity, and richer-payload dedupe for app_mention/message twins. - Slack outbound expands retry classes to connection failures and 5xx and requires destination-installation token resolution. - Turn handling bans raw error text in user-visible failures and fails bot-authored passive traffic closed to silence. Co-Authored-By: Claude Fable 5 <[email protected]>
Close ingress and outbound holes found in the chat architecture review: - Edited-message mentions now pass the same author gate as fresh messages. The message_changed path previously hardcoded author flags, letting Slack Connect external users and bot-authored edits start agent turns that fresh messages from the same authors could not. - Bot identity resolution fails retryably instead of caching a failed auth.test for the process lifetime, which silently disabled self-message filtering (reply loops) and mention detection. - Transient routing failures before durable mailbox append return 503 so Slack redelivers, instead of acking and dropping the message. - Outbound retries now cover connection-phase failures and Slack 5xx with clamped Retry-After; timed-out posts are never retried to avoid duplicate messages, and the web-api client's internal unbounded retry policy is disabled. - Outbound writes resolve the destination workspace's installation token from ambient context, hard-failing for team-scoped calls instead of silently posting with the env token. Co-Authored-By: Claude Fable 5 <[email protected]>
Conversation visibility was inferred from Slack channel-id prefixes (C = public), but modern Slack private channels also receive C-prefixed ids, so private-channel content leaked through cross-conversation thread reads, dashboard transcripts, and unredacted gen_ai telemetry. Capture visibility from the Events API channel_type signal at the runtime boundary, persist it on junior_destinations with a confirmation timestamp (expand-only migration), and fail closed everywhere on the read side: - resolveConversationPrivacy never classifies public from an id; prefixes only narrow toward private. - Cross-conversation Slack thread reads require persisted confirmed-public visibility in the same workspace. - Dashboard reporting redacts unconfirmed and legacy rows. - Sentry gen_ai capture derives privacy from the signal-seeded ambient context. Legacy prefix-classified rows read as private until a live event signal re-confirms them; private-to-public conversion converges on the next message. Co-Authored-By: Claude Fable 5 <[email protected]>
Implement the poison-work and recovery contracts from the updated task-execution spec: - Pending inbound messages carry a durable attempt count, incremented only when a failed run made no durable progress. Messages exceeding the limit are consumed with a terminal failure record instead of requeuing forever; a deterministic pre-input-commit failure previously reposted a failure reply every queue cycle indefinitely. - Failed runs record recovery state, send one nudge, and acknowledge the delivery instead of both nudging and NACKing, which scheduled two future deliveries per failure. - Queue deliveries for unparsable conversation records are acknowledged as rejected, and heartbeat removes such records from the active index instead of letting them permanently occupy the bounded oldest-first scan and starve recovery for every other conversation. - Duplicate app_mention/message twin events upgrade a still-pending payload when the duplicate carries file attachments the stored event lacks. - Conversation record writes revalidate the mutation lock via extendLock immediately before writing, so a stalled mutator fails loudly instead of clobbering a newer record. Co-Authored-By: Claude Fable 5 <[email protected]>
Implement the updated resumability and turn-handling contracts for the runtime layer: - Messages arriving while a conversation awaits continuation are durably appended to the session log before the mailbox record is consumed, so the resumed run answers them. Previously they were consumed without ever becoming model-visible: a correction sent during a parked run was silently dropped and the original instruction completed unchanged. - A follow-up during an auth pause supersedes the pause and runs as a fresh turn instead of waiting on authorization that may never come; the auth link stays reusable and late callbacks become stale no-ops. - Hard worker death no longer strands a running session: recovery re-parks lease-expired running records at their last durable safe boundary and continues them, or terminally fails with the standard visible fallback when no continuable boundary survives. - Raw exception text is never delivered as reply text; only genuine model-authored partial output survives to the user, and the sanitized fallback with its event id owns failure copy. - Host-only activity appends are best-effort: a reporting-write failure no longer kills the in-flight model turn as a fake provider error. - Non-final poison attempts stay silent instead of posting a failure reply per retry, and lost-input-commit replays no longer duplicate the user prompt in Pi history. Co-Authored-By: Claude Fable 5 <[email protected]>
Generation completing is not delivery. The final assistant reply was committed to the durable session log and the record marked completed before any Slack post, so a failed post poisoned later turns' history with an answer the user never saw, a crash between generation and post lost the reply with no redelivery, and a post-delivery persistence blip posted a contradictory failure reply after the correct answer. - Final assistant messages and the completed record commit now happen only after the destination accepts the reply; an undelivered reply structurally never exists in durable history. - Crash between generation and post is recovered by the stranded running-session path: regenerate from the last durable boundary, post once, then commit. - Reply-executor gains the finalReplyDelivered guard slack-resume already had: post-acceptance persistence failures are retried, logged, and never mark a delivered turn failed. - Dispatch runner persists its delivered marker with retries and marks the dispatch terminal after acceptance, so redelivery suppresses re-posts instead of regenerating. - The resumability spec now records that delivered semantics ride the acceptance-gated completed transition rather than a session-log event no consumer needs. Co-Authored-By: Claude Fable 5 <[email protected]>
The continue handler threw 'Stored Slack requester is required for resume' when a session record lacked a stored requester, NACKing the queue delivery and permanently blocking affected conversations from completing. Resolve the resume requester without ever throwing from beforeStart: a matching stored requester is used as before; a missing one is recovered from the durable conversation work record when its team and user match the resume actor (never fabricated otherwise); and when no matching identity exists the session is terminally failed with the standard visible fallback so the conversation unblocks and the user is not left in silence. Fixes GH-727 Co-Authored-By: Claude Fable 5 <[email protected]>
Apply the accepted findings from the adversarial review pass over the architecture-fix branch: - Parked-conversation input appends now run under the same thread resume lock the resume path holds, closing a lost-update race with a concurrently resumed slice; a busy lock leaves the mailbox message pending instead of consuming it. Dedupe is per message (keyed by inbound timestamp and text) so partial-overlap redeliveries cannot duplicate a user prompt in durable history. - The redundant-ack delete is best-effort so its failure can no longer skip the delivered-marker commit and re-trigger regeneration of an already-delivered reply. - Completed-record persistence no longer fabricates slice 1 when no running record exists; the local runner passes its single slice explicitly. - Narrow over-claiming spec text: session-log fencing describes the implemented call-site serialization, erasure is marked deferred, and verification items point at their real test layers. - Cleanups: inline the one-hop final-attempt wrapper, share one persist-retry helper, derive redacted-label sets from their source, capture the swallowed session-log append via logException, tighten the visibility-confirmation row type, correct the stale C-prefix comment, and add missing JSDoc on token precedence, retry classification, and poison gates. - Test repairs: non-vacuous dashboard-reporting assertion, dashboard redacted-label coverage, and channel_type pass-through on edited message ingress so visibility can confirm from edit-only traffic. Co-Authored-By: Claude Fable 5 <[email protected]>
Keep Slack mailbox messages pending when a live resume owns the input path, without consuming delivery retry attempts. Bind idle continuation recovery to the destination Slack installation token. Add a policy for balancing correctness fixes against simplicity and maintainability, and align the focused tests with that policy. Co-Authored-By: GPT-5 Codex <[email protected]>
5291719 to
4fbe1d0
Compare
|
had codex run through and clean up some stuff, gonna land and try to pull out the analysis of fable tomorrow |
dcramer
left a comment
There was a problem hiding this comment.
theres enough half way through that we need to make serious changes and not land as-is
| return owner ? `${owner} · ${id}` : id; | ||
| } | ||
|
|
||
| const REDACTED_CHANNEL_LABELS = new Set([ |
There was a problem hiding this comment.
this as a label for when its redacted makes sense, but not for parsing if its redacted
| * private channels also use `C`-prefixed ids — so prefixes may only narrow | ||
| * toward private and unsigned `C` sources fail closed to private. | ||
| */ | ||
| function slackSourceType( |
There was a problem hiding this comment.
this really should be within the slack provider boundary
| * Persist the post-delivery dispatch state with a short retry so a transient | ||
| * state write does not drop the delivered marker that suppresses re-posts. | ||
| */ | ||
| async function persistRuntimePatchWithRetry( |
There was a problem hiding this comment.
seems like the classic "add a useless wrapper function"
| reply.sandboxDependencyProfileHash ?? sandboxDependencyProfileHash, | ||
| }); | ||
| } catch (persistError) { | ||
| logException( |
There was a problem hiding this comment.
we need a better pattern for logs - more domain context so we dont have to bind every arg everywhere, or just ignoring the args and maybe capturing activeSpanId? its just too much boilerplate everywhere
| * including legacy prefix-derived values — are unconfirmed and must read | ||
| * as private. Appended last to match the expand-only migration order. | ||
| */ | ||
| visibilityConfirmedAt: timestamptz("visibility_confirmed_at"), |
There was a problem hiding this comment.
i dont like this - seems like a bad fix when we can either 1) data migration or 2) fix this without a schema change. transcripts TTL at the end of the day, and visibility is deterministic
| * confirmed value, id prefixes may narrow toward private (`D`/`G`) but a `C` | ||
| * prefix stays `unknown` because modern private channels also use it. | ||
| */ | ||
| function slackDestinationVisibility( |
There was a problem hiding this comment.
this is slack specific and has no place in our core schema/storage layer...
| } | ||
|
|
||
| /** Project joined destination columns into source-confirmed visibility. */ | ||
| function confirmedVisibilityFromRow( |
There was a problem hiding this comment.
this whole thing is a bad design - the 'visibility confirmed' concept
Default historical Slack destination visibility to private and remove the visibility confirmation schema column. Keep Slack channel-type interpretation in Slack runtime code, require plugin callers to pass normalized source visibility, and expose dashboard redaction as structured report data instead of parsing labels. Co-Authored-By: GPT-5 Codex <[email protected]>
Replace the queued conversation worker handoff with an attempt object that owns ack, drain, and final-attempt state. This keeps Slack failure suppression based on whether the attempted input was accepted instead of exposing retry-policy mechanics through the Slack runtime. Rename the mailbox failure path around attempts and dead-lettering, and update the focused Slack and worker tests for final-attempt fallback behavior. Co-Authored-By: GPT-5 Codex <[email protected]>
Update the requester profile assertion for private-default conversation visibility. Unlabeled Slack conversations without source-confirmed public visibility now aggregate under the private conversation bucket instead of the public channel fallback. Co-Authored-By: GPT-5 Codex <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5c3321f. Configure here.
Give D-channel memory storage fixtures the required private Slack source type. This keeps the passive-extraction privacy test aligned with the normalized plugin API source schema. Co-Authored-By: GPT-5 Codex <[email protected]>
Document that provider SDKs, payloads, formatting rules, and transport details stay inside provider-owned modules. Add a dependency-cruiser rule that blocks direct Slack SDK imports outside Slack-owned chat modules. Co-Authored-By: GPT-5 Codex <[email protected]>
Complete API dispatch session records after Slack accepts a failed-turn fallback, since destination delivery is the durable completion boundary. Require Slack final reply plans to contain visible delivery before marking a turn delivered, while preserving side-effect-only completion for successful Slack tool actions. Co-Authored-By: GPT-5 Codex <[email protected]>

Junior's message receive→process→deliver pipeline went through a full architecture review; this branch tightens the specs where they were wrong or silent, then implements the fixes against them. The specs commit is the contract diff — reading it first makes the code review mostly a conformance check.
What changes in behavior:
C-prefixed ids, so prefix inference classified them public — exposing private transcripts through cross-conversation thread reads, dashboard transcripts, and unredactedgen_aitelemetry. Visibility now comes from the Events APIchannel_typesignal, is persisted onjunior_destinationswith a confirmation timestamp (expand-only migration0002), and every read surface fails closed to private.message_changedpath hardcoded author flags. Bot identity resolution also fails retryably now instead of caching a failedauth.testfor the process lifetime, which silently disabled self-reply-loop protection and mention detection.awaiting_resume) are appended to the session log under the resume lock instead of being consumed invisibly; hard worker death mid-run resumes from the last durable boundary or fails visibly; ingress failures before durable mailbox append return 503 so Slack redelivers.completedonly after Slack accepts the reply, so a failed post cannot poison later turns' history with an answer the user never saw, and post-acceptance persistence blips cannot post a contradictory failure reply after the correct one. Continuations that lack a stored requester now recover identity from the durable conversation record or terminally fail with a visible fallback instead of NACK-looping the continue queue.Retry-After(timed-out posts are never retried, avoiding duplicates), and writes resolve the destination workspace's installation token rather than a process-global env token.Rollout notes:
junior upgradeapplies migration0002(nullablevisibility_confirmed_atonjunior_destinations). The runtime degrades gracefully if code runs before the migration: metadata writes log and skip, turns are unaffected.Review order:
specs/first, then ingress + privacy (chat/ingress/,conversation-privacy.ts,conversations/sql/), thenchat/task-execution/, then runtime (respond.ts,runtime/reply-executor.ts,runtime/agent-continue-runner.ts), thenslack/client.ts/slack/outbound.ts.Accepted windows (documented in the specs): a crash in the instant between Slack acceptance and the completed-record commit can still double-post via stranded recovery — irreducible without an outbox, which the spec deliberately avoids; multi-workspace continuation delivery fails closed pending installation-token plumbing through resume paths.
Fixes GH-727
🤖 Generated with Claude Code