Skip to content

Keep requests for a session that takes them with basecamp connect next - #1063

Open
robzolkos wants to merge 13 commits into
mainfrom
connect-session-queue
Open

robzolkos wants to merge 13 commits into
mainfrom
connect-session-queue

Conversation

@robzolkos

@robzolkos robzolkos commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 Drafted by Claude Code for review.

Why

A connector session sometimes never hears a request it should get
(card).
The basecamp-connect skill watches the connector's stdout with a Claude Code
Monitor armed persistent: true. Claude Code no longer has persistent, so
every watch now expires and has to be re-armed. A re-armed watch replays the
whole output file, and the session has to remember which requests it already
handled. The usual fix, a grep -v skip list, holds the newest request back
until the next one arrives, because the grep Claude Code's Bash runs is an
embedded ugrep whose -v waits for the following line. Today's skill sends
these sessions to --orchestrator instead.

This replaces #902, a skill-side watcher, with the connector keeping requests
until a session takes them.

What changes

Connector (opt-in). basecamp connect -P <p> --session-queue keeps each
trusted request in its ledger as session_pending, instead of printing its
request line. Stdout prints {"type":"queued","event_id":N,"recording_id":M}
in place of the request line; the intake and verdict lines continue as before.
Three commands read and close the queue over a socket in the profile's state
directory:

  • basecamp connect next [--wait] [--except <ids>] prints every eligible
    request line, byte for byte the line plain basecamp connect prints for the
    same record. --wait blocks until there is one. Reading writes nothing.
  • basecamp connect pending [<id>] shows what is waiting, and what is
    withheld and why.
  • basecamp connect ack <id> closes a request the session has taken on.

A request is handed over only while the running connector would still hand
it over:

  • no hold, and not tagged for review by one
  • served projects readable
  • served, inside --project, or a Ping the run hears
  • its own people still stand where they did when it was admitted: the
    performer, the requester and the author whose words were trusted. That
    covers whether each is the operator, allowlisted, an allowed agent or in
    the Ping, plus the trust mode, whether the project is served, and the one
    setting the trigger turns on. It's recorded with each verdict.

So someone removed from a Ping or the allowlist since is not answered. Adding
a colleague, changing an agent cap or serving another project holds nothing
back. A withheld request becomes eligible
again by itself when the condition clears, and stays until it is acked or
discarded (discard now accepts one).

Without the flag, nothing changes: the stdout bytes, status and the runner
are as before. The flag is refused with --shadow and with anything that
starts the runner.

Skill. basecamp-connect checks basecamp connect --help for
--session-queue.

With it, the session:

  • starts the connector with the flag
  • runs one background basecamp connect next --wait, whose exit wakes it
  • checks each request with pending <id> before acting on it
  • acks right after a worker launches, or after its own reply or refusal
  • after a compaction, or in a new session, settles anything unacked with
    pending
  • if the connector dies, runs doctor and starts it again once in the same
    mode
  • if a crashed session left its queue connector running, asks the person
    whether another session still works from it, and otherwise takes it over

A request waiting on the person, such as a repo choice, stays unacked.

Without the flag (an older CLI), the skill does exactly what it does today:
the Monitor flow where the Monitor takes persistent, otherwise
--orchestrator. Restarts keep the mode the session started in.

Hooks and the runner. The compaction notice names the waiter only when
this session's own connector started with the queue. Every other session gets
today's text, byte for byte. The orchestrator's mapping says the queue
commands are not its to run.

Compatibility

CLI Skill Result
older older unchanged
this older unchanged (the queue is off without the flag)
older this today's flow (Monitor, or --orchestrator)
this this the session queue
  • Other starts say what waits. A start without --session-queue never
    hands these requests over, so it logs how many wait for a session.
  • Migration 17. This is ledger migration 17. A basecamp older than this
    refuses a ledger this one has opened, as it refuses any newer schema.
    After upgrading, basecamp connect status asks for the connector to start
    once before it reads the ledger, as it does after every migration.
  • Exit codes. next and pending exit 0 when they answer, 1 on a usage
    error, 11 when no connector for the profile runs the queue, 12 when the
    connector stopped before answering, and 130/143 on a signal.

Known limits

  • A pre-existing gap stays. If the connector crashes while acknowledging
    a burst of requests, and restarts more than a minute after the request was
    made, that request is dropped. Every mode already has this gap, and the
    queue doesn't widen it.
  • No membership re-check. Removing a person from a Basecamp project while
    their request waits does not withhold it. Revoking them in connect.json
    does.
  • One acting session per profile. Delivery to the session is
    at-least-once. The skill settles a repeat against its workers or the reply
    thread, and asks the person when it can't tell.

Verification

  • bin/ci green.

  • Real binaries, against an isolated local bc3 (this branch and main side
    by side): 23 of 24 checks pass. The 24th is status on a ledger an older
    build wrote, which refuses until the connector starts once, as main does
    after every migration; it passes after that start. next --wait returned
    1.18 to 2.21 s after the mention was created (median 1.33 s, 10 of 10).

  • Live Claude Code sessions (2.1.332, interactive), running the skill
    against local bc3:

    Case Result
    Idle 75 min with the waiter armed, then /compact, then the connector killed 4 of 4 requests started a turn within 0.011 s of being queued; each was replied to once and acked
    Claude Code killed right after the waiter woke it, before any tool call 3 of 3 settled by a fresh session with pending: replied to once, acked
    This skill with main's CLI 3 of 3 took today's route; the queue was never used
    Main's skill with this CLI 3 of 3 behaved as main does; the compaction notice was main's, byte for byte

    Those runs found three gaps, now fixed in the skill: it asked before
    restarting a killed connector; it had no path for a connector a crashed
    session left running; and one session stopped its connector with a
    pattern match that also stopped other sessions' connectors. A second live
    run (on 99ccc7b) checked each fix, 2 of 2 each: a killed connector was
    restarted without asking, a crashed session's connector was taken over
    after one question with no second connector started, and a stop left a
    look-alike connector running. Since then, after review, a takeover stops
    the left-behind connector and starts the session's own, so the session
    can stop it later; that step was not run live.

  • --orchestrator, live against local bc3, this branch beside main:

    • Claude workers: 2 of 2 requests answered once on each build; the second request on the thread went to the same worker.
    • Codex worker: 1 of 1 answered once.
    • Connector killed after the handoff and restarted: the request was repeated and answered once, on both builds.
    • Output lines, runner state and ledger outcomes matched; the orchestrator never ran the queue commands.
  • Skill eval cases were added; their graders were checked against
    hand-written traces (8 of 8 correct pass, 54 of 54 wrong fail). The model
    run is this PR's Skill Evals job.

@robzolkos
robzolkos requested a review from a team as a code owner November 28, 2026 22:32
Copilot AI balanced review requested due to automatic review settings November 28, 2026 22:32
@github-actions github-actions Bot added commands CLI command implementations tests Tests (unit and e2e) skills Agent skills output Output formatting and presentation docs labels Nov 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues cause repeated loading of all queued request payloads, leave Monitor-free sessions without an authentication-recovery wake-up, and allow adopted connectors to remain running after intake is reported stopped.

3 open issues
What changed in this PR

Adds an opt-in, ledger-backed session queue so coding-agent sessions can retrieve connector requests when ready, rather than relying on continuous stdout monitoring.

Changes:

  • Adds --session-queue and the next, pending, and ack commands, with policy checks and durable request storage.
  • Updates the skill, compaction hook, status, console, and runner guidance while preserving older-CLI behavior.
  • Adds migration, command, compatibility, and skill-evaluation coverage.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
skills/​basecamp-connect/​SKILL.md Documents queue delivery, recovery, and legacy fallback.
skill-evals/​run Adds session-tool mocks and forbidden-sequence grading.
skill-evals/​README.md Documents the new evaluation features.
skill-evals/​cases/​basecamp-connect/​queue-reconciles-after-compaction.yml Covers pending-request reconciliation after compaction.
skill-evals/​cases/​basecamp-connect/​queue-launch-fails-no-ack.yml Checks failed launches remain unacknowledged.
skill-evals/​cases/​basecamp-connect/​queue-holds-repo-choice.yml Checks requests stay pending during repo selection.
skill-evals/​cases/​basecamp-connect/​queue-arms-waiter.yml Covers queue startup and background waiting.
skill-evals/​cases/​basecamp-connect/​queue-acks-after-dispatch.yml Checks acknowledgement follows worker dispatch.
skill-evals/​cases/​basecamp-connect/​old-cli-without-persistent-monitor.yml Covers the older-CLI orchestrator fallback.
skill-evals/​cases/​basecamp-connect/​old-cli-restarts-with-a-monitor.yml Checks restarts preserve legacy monitoring.
skill-evals/​cases/​basecamp-connect/​old-cli-persistent-monitor.yml Covers older-CLI persistent monitoring.
scripts/​check-eval-patterns.rb Recognizes the new evaluation keys and patterns.
internal/​output/​output_test.go Tests queue-specific exit codes.
internal/​output/​codes.go Defines queue unavailable and stopped exit codes.
internal/​connector/​skill_layout_test.go Checks per-request queue rules survive compaction.
internal/​connector/​session_queue.go Implements eligibility, reads, waiting, and socket service.
internal/​connector/​runner/​socket.go Shares socket setup and distinguishes connection failures.
internal/​connector/​runner/​runner.go Uses the shared socket listener.
internal/​connector/​runner/​runner_test.go Tests socket failure classification.
internal/​connector/​runner/​instructions.go Excludes session-queue operations from runner workflows.
internal/​connector/​runner/​instructions_test.go Tests runner guidance against the updated skill.
internal/​connector/​operator_invariants_test.go Preserves existing discard-error wording.
internal/​connector/​ndjson/​ndjson.go Shares line encoding across delivery modes.
internal/​connector/​ledger.go Adds the pending state and migration registration.
internal/​connector/​ledger_status.go Includes pending requests in status and diagnostics.
internal/​connector/​ledger_session.go Adds queue persistence, acknowledgements, and status reads.
internal/​connector/​ledger_migrations_test.go Tests migration from pre-queue ledgers.
internal/​connector/​ledger_events.go Extends records and transitions for queue storage.
internal/​connector/​ledger_decisions.go Allows discard and refuses redispatch of queued requests.
internal/​connector/​ledger_admission.go Persists admission policy fingerprints.
internal/​connector/​handoff.go Routes requests into the queue when enabled.
internal/​connector/​console/​view.go Displays queue health and waiting requests.
internal/​connector/​console/​snapshot.go Adds queue status to console snapshots.
internal/​connector/​console/​console_test.go Tests queue presentation.
internal/​connector/​admission/​verdict.go Attaches policy fingerprints to verdicts.
internal/​connector/​admission/​fingerprint.go Computes canonical, bucket-specific policy fingerprints.
internal/​connector/​admission/​fingerprint_test.go Tests fingerprint stability and policy-change sensitivity.
internal/​commands/​connect.go Registers and documents queue commands.
internal/​commands/​connect_session_queue.go Implements queue commands, signals, and status probes.
internal/​commands/​connect_session_queue_test.go Tests command output, compatibility, and socket errors.
internal/​commands/​connect_run.go Wires queue startup and rejects incompatible modes.
internal/​commands/​connect_operator.go Reports queue status and documents discard support.
internal/​commands/​connect_console.go Includes live queue probes in console snapshots.
internal/​commands/​agent_hook_rename.go Passes context into connector reload notices.
internal/​commands/​agent_hook_connector.go Selects queue-aware notices using session-task evidence.
internal/​commands/​agent_hook_connector_test.go Tests notice selection and legacy wording preservation.
e2e/​errors.bats Tests queue-command usage errors.
AGENTS.md Documents queue architecture and compatibility requirements.
.surface-skill-drift Registers hidden queue commands and flags for drift checks.

Review effort: Balanced

Comment thread internal/connector/ledger_session.go Resolved
Comment thread skills/basecamp-connect/SKILL.md Resolved
Comment thread skills/basecamp-connect/SKILL.md Resolved
Copilot AI balanced review requested due to automatic review settings November 28, 2026 23:01
@robzolkos

Copy link
Copy Markdown
Collaborator Author

🤖 Copilot's three threads on 99ccc7b:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A malformed or unreadable connect.json prevents queue commands from reaching the running connector, blocking pending from reporting projects_unreadable and next --wait from waiting for file repair.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Malformed connect.json prevents queue state reporting and waiting

internal/​commands/​connect_session_queue.go:218

If connect.json becomes malformed or unreadable while the queue connector is running, loadConnectProfile returns a usage error before the socket is contacted. Consequently, a fresh pending cannot report projects_unreadable, and a newly armed next --wait cannot remain waiting for the file to be repaired, even though the running queue implements both behaviors. Resolve the existing profile's state identity without requiring a usable policy file (as loadConnectProfileForReport does, with a known-state check), and let the running connector decide eligibility.

3 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 28, 2026 23:16
@robzolkos

Copy link
Copy Markdown
Collaborator Author

🤖 Copilot's review of 30afa1e found one previously missed issue, in its review body: a malformed connect.json stopped next, pending and ack before they reached the running connector. Fixed in 3e744e8. The commands now find the connector through the profile's state directory and report the file's error only when no connector answers. The new test TestTheSessionQueuesCommandsReachTheConnectorPastABrokenConnectJSON fails without the fix.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The durable ledger migration and crash/restart session recovery warrant human validation because the revised abandoned-connector shutdown/start takeover sequence has not been exercised live.

No open issues 🎉

Review effort: Balanced

The runner's socket is held to two rules: a directory only this user can
enter, and a socket file only this user can open. A second socket in the
connector's state directory should meet the same rules without copying
them, so runner.Listen and runner.Dial export what Runner.Run and Call
already did. Neither the runner's behavior nor Call's ErrNotRunning
changes.
Started with --session-queue, the connector keeps each trusted request in
its ledger as session_pending instead of printing its request line, and
stdout says only {"type":"queued","event_id":N,"recording_id":M}. A
session reads the requests when it is ready for them:

  basecamp connect next [--wait] [--except <ids>]   the request lines
  basecamp connect pending [<id>]                   what is withheld, and why
  basecamp connect ack <id>                         close one it took on

next prints, byte for byte, the line plain basecamp connect prints for the
same record, the acknowledgement boost included. Taking a line writes
nothing: a lost line is taken again, two readers get the same one, and the
ack is what closes it (discarded/handed_off, as a printed request is). A
kept request survives any number of restarts, and no plain or runner start
touches it.

next and pending go over a socket in the state directory, because only
the running connector can say what it would hand over now: nothing under
the hold, nothing a hold tagged for review, nothing while connect.json's
served projects cannot be read, nothing outside the served projects, the
run's --project or the Pings it hears, and nothing admitted under another
policy than the one it runs with. Every verdict now records
admission.Policy.Fingerprint of the policy it was made under, so someone
taken out of a Ping since is not answered. ack writes the ledger directly,
as discard does, which now also accepts a kept request.

The flag is per start, never kept, and refused with --shadow or with any
flag that starts the runner. next and pending exit 11 when no connector
runs the queue and 12 when it stopped before answering. Status and the
console show whether the queue is on, how many requests wait and are
withheld, and how old the oldest is.

This is ledger migration 17. A basecamp older than this refuses a ledger
this one has migrated, as it refuses any newer schema.
A request kept for a session was withheld as policy_changed whenever any
part of connect.json changed, so serving one more project, or editing
another project's Campfires, froze every request waiting. Its fingerprint
now covers the trust settings and the request's own project or Ping entry:
the rules its verdict turned on. Taking someone out of the Ping, off the
allowlist, or a Campfire out of the project's listening still withholds it.
… where the queue never ran

From the first code review of the session queue:

- status (styled and --json) says nothing of the queue for a profile
  whose connector does not run it and that has nothing kept: no
  session_queue object, no session_pending in the Queues line. Status's
  SessionQueue is now nil until a request is kept or a connector answers.
- status and the console ask the running connector for counts alone (a
  new "counts" call: pending, withheld, oldest kept) instead of every
  request line. A call that times out or fails other than by nobody
  listening is shown as unknown, never as off.
- runner.Dial says nobody listens only for a missing socket or one that
  refuses the call; any other failure is returned as it is, so next and
  pending exit 11 only when no connector runs. The runner's Call still
  reads every failure to connect as no runner.
- The connector's stop cuts short a request still being read, so a caller
  that sent half of one does not hold up the stop and the lock; a wait
  read whole is still told the connector stopped.
- next with an argument is the usage error (exit 1) its help promises.
- A policy whose served projects are unknown withholds every request, as
  a failed read of them does.
- The queue's read checks rows.Err before using the ids it read.
- The console's Working now says a queue connector keeps requests for
  basecamp connect next; connect's help says the queued line replaces the
  request line and that stdout's other lines continue.
- Tests: the request line pinned to the bytes origin/main writes, on
  stdout and from next; two waits blocked on an empty queue both given
  one request; process exit codes in the BATS suite.
A Claude Code session now starts the connector with --session-queue and
waits on a background `basecamp connect next --wait`, whose exit wakes it,
instead of a Monitor on stdout: Claude Code's monitors expire now, and a
re-armed one replays the file. Each request is checked with `pending
<id>` before it is acted on, acked right after its subagent starts (or
after the session's own refusal), and held in --except while the person
picks a repo. After a compaction, or in a new session, the session
settles what `pending` lists before it waits again.

The plugin can be newer than the CLI. When `basecamp connect --help`
doesn't list --session-queue, the skill keeps main's flow unchanged, in a
section of its own: the persistent Monitor, or --orchestrator without
one, and it tells the person once that an upgrade brings the queue.

- The compaction hook gives the queue's instructions only to a session
  whose transcript started a --session-queue connector that answers the
  queue's socket now (1s). Every other session, an older skill's
  included, gets main's notice byte for byte, which a test pins.
- The runner's mapping tells the orchestrator the waiter, pending, ack,
  --except and the compaction step are not its own: it never acks.
- The per-request steps still end inside the compaction cut (13,947 of
  14,000 characters): the terminal rule moved, unchanged, into Rules
  without exceptions, and the token-retry guidance into When the
  connector stops.
- Skill drift: next, pending, ack and their flags are baselined, hidden
  with the rest of connect.
- Six eval cases: arming the waiter, acking after dispatch, holding on a
  repo choice, settling after a compaction, and both older-CLI paths.
…om the connector's own start line

Settles the phase 2 review of the basecamp-connect skill's switch to the
session queue: each mode's per-request rules inside the compaction cut, ids
held until their ack lands, parked work rechecked on resume and after a
restart, the waiter armed only once the connector runs, only the current
waiter's exit acted on, reconcile evidence read where reply_to points,
discard named with its profile, and main's discard refusal restored.

The compaction hook now gives the queue text only when this session's own
background connector task logged connector: running with session_queue=true
and has not ended, never from a command line. The skill evals can see
background Bash, Monitor and Agent calls, and reject an order.
…and stop only your own

The live sessions asked before restarting a killed connector, had no path
when a crashed session's queue connector still held the profile, and one
stopped its connector with a pattern that also stopped other sessions'.
A session that took over a crashed session's connector could not stop it,
and the compaction notice did not know it ran the queue; it now stops that
connector and starts its own. With the queue, a token retry is waited out
with a one-shot background wait, not a monitor that may expire.
The queue's commands refused before calling the connector, so pending could
not say what the running connector withholds and a waiter could not wait
out the repair. They now reach it by the profile's state, and say the
file's error only when no connector answers.
A request kept for a session was withheld whenever anything in the trust
section or its project's entry changed, so adding a colleague to the
allowlist or changing an agent cap held back every request waiting. The
fingerprint now covers only the people the verdict rested on (performer,
requester, and the author whose words it trusted), whether each is the
operator, an allowlisted operator, an allowed agent or in the Ping, the
trust mode, whether the project is served, and the one setting the
trigger turns on. Those people are kept with the verdict, in the same
unreleased migration, so the queue checks the same people later.

A start without --session-queue now says how many requests wait for a
session, since no other start hands them over.
@robzolkos
robzolkos force-pushed the connect-session-queue branch from 3e744e8 to b24ea59 Compare December 1, 2026 13:01
Copilot AI balanced review requested due to automatic review settings December 1, 2026 13:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The queue-recovery rule can discard unfinished requests based on progress-only replies, and the hook rejects valid profile names, omitting pending-request reconciliation instructions after compaction.

2 open issues

Review effort: Balanced

Comment thread skills/basecamp-connect/SKILL.md Resolved
…read any profile setup accepts

A helper posts an interim reply on long work, so a reply from the agent
does not by itself mean a request was settled. After a compaction the
skill now acks only on the result or a refusal, and asks the person
otherwise. The compaction hook's start-line match now takes every profile
name setup accepts, including one starting with _ or -.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 13:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The revised takeover path sends SIGINT and starts a replacement before reconciliation but remains untested live, requiring human validation of shutdown ownership and pending-request recovery.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 50 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread skills/basecamp-connect/SKILL.md Resolved
Comment thread internal/commands/connect_console.go Resolved
Comment thread e2e/errors.bats Resolved
Comment thread internal/connector/ledger_session.go Resolved
Comment thread internal/commands/connect_operator.go Resolved
…ter evals

Retention now clears the people a verdict rested on, as it clears the
requester. Status and the start's warning share one queue-depth query,
and status cleans the probe error before printing it. The console asks
the queue for its counts with a short timeout, so a socket that holds
but never answers cannot stall each refresh.

The migration test now carries a record admitted before the upgrade and
hands it off after. The ack test decodes its JSON. The skill evals reject
a mixed --except list, a background setup, and a document listing without
--all; read the thread and boost lists rather than show; ask for the
reply's content; and the runner refuses a repeated session tool and no
longer fails every case on an empty reject_sequence.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 13:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approved

No active review issues are blocking the opt-in session queue change.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands CLI command implementations docs output Output formatting and presentation skills Agent skills tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants