Skip to content

fix(bin): deliver Flowy results through a durable retrying outbox - #2882

Closed
cedmos wants to merge 9 commits into
kunchenguid:mainfrom
cedmos:fm/flowy-outbox-send-fix
Closed

cedmos wants to merge 9 commits into
kunchenguid:mainfrom
cedmos:fm/flowy-outbox-send-fix

Conversation

@cedmos

@cedmos cedmos commented Aug 23, 2026

Copy link
Copy Markdown

What Changed

  • bin/fm-completion-outbox.sh becomes a durable delivery path instead of a script that could not deliver at all. It resolves the endpoint from config/grok-flowy-webhook and the Bearer key from the Keychain, so a normal invocation needs no environment variable; the URL and the key are handed to curl -K - on stdin and the JSON payload goes through a umask 077 mode-600 file, so neither the endpoint nor the key ever appears in ps output.
  • Delivery is now record-first. One immutable record per task is written before any network call, carrying the result and its artifact path. A record retires, and its per-task receipt under state/flowy-outbox/delivered/ is written, only on HTTP 2xx; every other outcome leaves the record pending for a later pass, so a receipt cannot exist without a successful send. Records carry a monotonic ordinal so that same-second results still order correctly, and the aggregate state/flowy-last.md stays a display snapshot that never gains delivery authority and keeps its pending: line truthful.
  • bin/fm-watch.sh drains all pending records on every pass under a single wall-clock ceiling, and records terminal results on the signal path without opening a socket. Because the wake only becomes visible when the watcher process exits, the post-record drain is detached into its own process group with a bounded deadline and a TERM-then-KILL backstop, so delivery never delays the wake. The group signal verifies the child's pgid before signalling, matching the existing guard elsewhere in the file.
  • tests/fm-flowy-completion.test.sh covers the contract through the executable interface with a stubbed endpoint and no real webhook: a failed POST retried to success across watcher generations, two concurrent terminal results that do not overwrite each other, delivery state surviving a restart, the receipt-only-after-2xx rule, snapshot ordering, and that the key never reaches the process table.
  • docs/configuration.md gains the operator-facing setup and the FM_FLOWY_* bounds; docs/scripts.md gains the toolbelt row.

Risk Assessment

⚠️ Medium: The change is well covered and the delivery invariants are enforced at the code path rather than only documented, but it adds a detached child process and a process-group signal on the watcher's exit path, which is the highest-consequence area touched. The bounded deadline, pgid verification, and dead-owner lock takeover are the mitigations, and timing out retires nothing.

Testing

The validation pipeline's review, test, document, and lint steps all completed on this branch. The focused suite covers the delivery contract end to end against a stubbed endpoint, and each new case was demonstrated to be a genuine regression test by reverting the specific logic it guards. The three adjacent watcher suites that exercise the cleanup and poll paths were re-run because fm-watch.sh changed. ShellCheck is clean at the pinned version. The workflow linter reports its binary missing inside the pipeline's own shell; with the pinned actionlint 1.7.12 on PATH it validates all three workflow files and exits 0, and no workflow file is in scope for this branch.

No screenshot artifact applies: this change has no rendered UI surface. No real webhook was sent from the test suite, and no secret appears in the diff or in any committed file.

cedmos added 9 commits August 22, 2026 22:35
Completion delivery could not deliver at all, and the one place it wrote to
disk claimed a delivery that never happened.

fm-completion-outbox.sh required an FLOWY_WEBHOOK_URL environment variable and
never read config/grok-flowy-webhook, so an ordinary invocation aborted before
any send. When it did send, it POSTed text/plain with no Authorization header
rather than the JSON plus Keychain Bearer key the endpoint accepts. It wrote
state/flowy-last.md before the POST and regardless of its outcome, so disk
recorded a delivery that had not occurred, --dry-run overwrote that same
receipt, and the receipt omitted the required pending: line. A failed POST was
only logged: fm-watch.sh invoked the outbox on a changed status signal and then
advanced its seen marker, leaving nothing for a later pass to retry.

Delivery is now a two-stage durable outbox. A terminal result becomes an
immutable record under state/flowy-outbox/pending/<task>.<digest> before any
network call, keyed so a second distinct result for one task cannot overwrite
the first and an identical result is never resent. The drain reads the endpoint
from the URL file and the Keychain, POSTs JSON with a Bearer header, and retires
a record only on HTTP 2xx, writing its per-record receipt at that point. A
non-2xx, a transport failure, a missing URL file, or an unavailable key leaves
the record pending. state/flowy-last.md becomes an aggregate display snapshot
written only after a delivery, carrying its pending: line, and --dry-run now
writes nothing at all.

fm-watch.sh drains the outbox on every pass, so a result that failed to send
under an earlier watcher generation or before a restart is retried until it
lands; the signal path only records, which is a local write that cannot fail on
the network.

The endpoint is stubbed on PATH throughout the tests, so no test reaches a
network and no real URL or key appears in any fixture.
@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown

Confidence Score: 2/5

This PR should not merge until cleartext authenticated delivery is rejected and the synchronous drain respects short polling intervals; the Flowy-specific command-layer coupling should also be reconsidered.

The new path can expose its reusable Bearer credential over configured HTTP and can block signal scanning longer than the configured fractional polling cadence, while its fixed Flowy integration conflicts with the repository’s vendor-orthogonality requirement.

Files Needing Attention: bin/fm-completion-outbox.sh, bin/fm-watch.sh, docs/configuration.md

Security Review

The webhook URL validation permits cleartext HTTP, allowing the Keychain-derived Bearer credential and task result payload to cross the network without transport encryption.

Reviews (1): Last reviewed commit: "no-mistakes(lint): fix(test): use explic..." | Re-trigger Greptile

}
url=$(tr -d '\r\n' < "$WEBHOOK_FILE")
case "$url" in
https://*|http://*) printf '%s' "$url" ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 security Cleartext webhook exposes credentials

If config/grok-flowy-webhook specifies an http:// endpoint, this branch accepts it and sends the Keychain-derived Bearer credential and task result without transport encryption, exposing both to network observers or active intermediaries.

How this was verified: The accepted URL flows to the same curl request that carries the Authorization: Bearer header.

Suggested change
https://*|http://*) printf '%s' "$url" ;;
https://*) printf '%s' "$url" ;;

Comment thread bin/fm-watch.sh
Comment on lines +958 to +965
# POLL's whole-second part; any sub-second poll lands on the same one-second
# floor that POLL=1 already gets.
whole=${POLL%%.*}
case "$whole" in ''|*[!0-9]*) whole=0 ;; esac
bound=$((whole * 2 / 3))
fi
case "$bound" in ''|*[!0-9]*) bound=1 ;; esac
[ "$bound" -ge 1 ] || bound=1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Drain exceeds short poll cadence

When FM_POLL is 1 or a documented fractional value such as 0.2, the one-second floor makes the synchronous drain equal to or longer than the polling interval. Because that drain runs before signal scanning, a slow endpoint delays terminal-result detection beyond the configured cadence.

Comment thread bin/fm-watch.sh
Comment on lines +1091 to +1093
if [ -x "$FLOWY_COMPLETION_OUTBOX" ]; then
flowy_run_bounded_drain "$(flowy_drain_bound)" \
|| triage_log "Flowy completion outbox has undelivered results"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Watcher hardcodes vendor integration

The shared watcher now directly invokes a Flowy-specific outbox whose endpoint, credential identity, and state conventions are fixed in the command layer. This conflicts with the repository’s vendor-orthogonality requirement and makes another captain-facing intake require changes to shared watcher mechanics instead of substituting a generic delivery adapter.

Context Used: If there is a VISION.md file at the root of the re... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@cedmos

cedmos commented Aug 28, 2026

Copy link
Copy Markdown
Author

Closing this one: it wires a captain-local integration (Flowy/Workflowy intake with a private webhook endpoint and Keychain credential) into the shared watcher, which - as the review correctly flagged - conflicts with the repo's vendor-orthogonality. If a durable completion delivery is wanted upstream, it should come back as a generic outbox adapter with a pluggable endpoint, without Flowy-specific conventions in the command layer. Thanks for the review findings.

@cedmos cedmos closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant